aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs
blob: b1ba03109707be7634e8a68c6c0d00b9974ffaff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using MaterialDesignThemes.Wpf;
using Tango.MachineStudio.Common.Notifications;
using Tango.MachineStudio.UI.Windows;
using System.Windows.Media;
using Tango.Core;
using System.Collections.ObjectModel;

namespace Tango.MachineStudio.UI.Notifications
{
    public class DefaultNotificationProvider : ExtendedObject, INotificationProvider
    {
        public ObservableCollection<TaskItem> TaskItems { get; private set; }

        public bool HasTaskItems
        {
            get { return TaskItems.Count > 0; }
        }

        private TaskItem _currentTaskItem;

        public TaskItem CurrentTaskItem
        {
            get { return _currentTaskItem; }
            set { _currentTaskItem = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(HasTaskItems)); }
        }

        public DefaultNotificationProvider()
        {
            TaskItems = new ObservableCollection<TaskItem>();
        }

        public bool ShowModalWindow<T>(PackIconKind icon, string title, object context) where T : FrameworkElement
        {
            return ShowModalWindow(icon, title, Activator.CreateInstance<T>(), context);
        }

        public bool? ShowModalWindow(Window window)
        {
            window.Owner = Application.Current.MainWindow;
            MainWindow.Instance.shadowGrid.Visibility = Visibility.Visible;
            bool result = window.ShowDialog().Value;
            MainWindow.Instance.shadowGrid.Visibility = Visibility.Hidden;
            return result;
        }

        public bool ShowModalWindow(PackIconKind icon, string title, FrameworkElement content, object context)
        {
            DialogWindow dialog = new DialogWindow(content);
            dialog.DataContext = context;
            dialog.InnerTitle = title;
            dialog.Owner = Application.Current.MainWindow;
            MainWindow.Instance.shadowGrid.Visibility = Visibility.Visible;
            bool result = dialog.ShowDialog().Value;
            MainWindow.Instance.shadowGrid.Visibility = Visibility.Hidden;
            return result;
        }

        public bool? ShowDialog(PackIconKind icon, Brush iconColor, string message, bool hasCancel)
        {
            MainWindow.Instance.shadowGrid.Visibility = Visibility.Visible;

            var result = new MessageBoxWindow()
            {
                Owner = Application.Current.MainWindow,
                Message = message,
                IconKind = icon,
                IconColor = iconColor,
                HasCancel = hasCancel

            }.ShowDialog();

            MainWindow.Instance.shadowGrid.Visibility = Visibility.Hidden;
            return result;
        }

        public void ShowError(string message)
        {
            ShowDialog(PackIconKind.Exclamation, Brushes.Red, message, false);
        }

        public void ShowInfo(string message)
        {
            ShowDialog(PackIconKind.Information, Brushes.Black, message, false);
        }

        public bool ShowQuestion(string message)
        {
            return ShowDialog(PackIconKind.CommentQuestionOutline, Brushes.Black, message, true).Value;
        }

        public void ShowWarnning(string message)
        {
            ShowDialog(PackIconKind.Exclamation, Brushes.DarkOrange, message, false);
        }

        public void PushTaskItem(TaskItem taskItem)
        {
            TaskItems.Add(taskItem);
            CurrentTaskItem = taskItem;
        }

        public TaskItem PushTaskItem(string message)
        {
            TaskItem item = new TaskItem(this);
            item.Message = message;
            PushTaskItem(item);
            return item;
        }

        public void PopTaskItem(TaskItem taskItem)
        {
            TaskItems.Remove(taskItem);

            if (TaskItems.Count > 0)
            {
                CurrentTaskItem = TaskItems.Last();
            }

            RaisePropertyChanged(nameof(HasTaskItems));
        }
    }
}