aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/FSE/Modules/Tango.FSE.Diagnostics/ViewModels/DiagnosticsTabViewVM.cs
blob: 78e829d27e33acf07496f031a25597aa0393e064 (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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Tango.Core.Commands;
using Tango.Core.DI;
using Tango.FSE.Common;
using Tango.FSE.Common.Authentication;
using Tango.FSE.Common.Diagnostics;
using Tango.FSE.Diagnostics.Project;
using Tango.PMR.Diagnostics;
using Tango.Settings;

namespace Tango.FSE.Diagnostics.ViewModels
{
    public class DiagnosticsTabViewVM : FSEViewModelWithModuleSettings<DiagnosticsSettings>
    {
        private DiagnosticsProjectTab _tab;
        public DiagnosticsProjectTab Tab
        {
            get { return _tab; }
            set { _tab = value; RaisePropertyChangedAuto(); OnTabChanged(); }
        }

        private bool _isSelected;
        public bool IsSelected
        {
            get { return _isSelected; }
            set { _isSelected = value; RaisePropertyChangedAuto(); OnIsSelectedChanged(); }
        }

        private bool _isVisible;
        public new bool IsVisible
        {
            get { return _isVisible; }
            set { _isVisible = value; RaisePropertyChangedAuto(); OnIsSelectedChanged(); }
        }

        private DiagnosticsWidget _selectedWidget;
        public DiagnosticsWidget SelectedWidget
        {
            get { return _selectedWidget; }
            set { _selectedWidget = value; RaisePropertyChangedAuto(); }
        }

        private bool _isWidgetSettingsOpened;
        public bool IsWidgetSettingsOpened
        {
            get { return _isWidgetSettingsOpened; }
            set { _isWidgetSettingsOpened = value; RaisePropertyChangedAuto(); }
        }

        private bool _editMode;
        public bool EditMode
        {
            get { return _editMode; }
            set { _editMode = value; RaisePropertyChangedAuto(); Tab.Widgets.ToList().ForEach(x => x.EditMode = value); }
        }

        private bool _showGridLines;
        public bool ShowGridLines
        {
            get { return _showGridLines; }
            set { _showGridLines = value; RaisePropertyChangedAuto(); }
        }

        public RelayCommand<DiagnosticsWidget> OpenWidgetSettingsCommand { get; set; }

        public RelayCommand CloseWidgetSettingsCommand { get; set; }

        public DiagnosticsTabViewVM()
        {
            OpenWidgetSettingsCommand = new RelayCommand<DiagnosticsWidget>(OpenWidgetSettings);
            CloseWidgetSettingsCommand = new RelayCommand(() => { IsWidgetSettingsOpened = false; SelectedWidget = null; });
        }

        private void OpenWidgetSettings(DiagnosticsWidget widget)
        {
            IsWidgetSettingsOpened = true;
        }

        private void OnIsSelectedChanged()
        {
            Tab.Widgets.ToList().ForEach(x => x.IsVisible = IsSelected && IsVisible);
        }

        public void PopulateDiagnosticsData(DiagnosticsPackage package)
        {
            foreach (var widget in Tab.Widgets.ToList())
            {
                widget.OnDiagnosticsData(package);
            }
        }

        private void OnTabChanged()
        {
            if (Tab != null)
            {
                Tab.Widgets.CollectionChanged += Widgets_CollectionChanged;
            }
        }

        private void Widgets_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            Tab.Widgets.ToList().ForEach(x => x.EditMode = EditMode);
        }
    }
}