-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppState.cs
138 lines (112 loc) · 3.45 KB
/
AppState.cs
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
129
130
131
132
133
134
135
136
137
138
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
namespace Elite_Dangerous_Addon_Launcher_V2
{
public class AppState : INotifyPropertyChanged
{
#region Private Fields
private static AppState _instance;
// Modify CloseAllAppsOnExit property to implement INotifyPropertyChanged
private bool _closeAllAppsOnExit;
private Profile _currentProfile;
private ObservableCollection<Profile> _profiles;
private MyApp _selectedApp;
#endregion Private Fields
#region Private Constructors
public IEnumerable<Profile> OtherProfiles
{
get
{
if (Profiles == null || CurrentProfile == null)
{
return Enumerable.Empty<Profile>();
}
return Profiles.Except(new[] { CurrentProfile });
}
}
private AppState()
{
Apps = new ObservableCollection<MyApp>();
Profiles = new ObservableCollection<Profile>();
CloseAllAppsOnExit = false;
}
#endregion Private Constructors
#region Public Events
public event PropertyChangedEventHandler PropertyChanged;
#endregion Public Events
#region Public Properties
public static AppState Instance
{
get
{
if (_instance == null)
{
_instance = new AppState();
}
return _instance;
}
}
public ObservableCollection<MyApp> Apps { get; set; }
public bool CloseAllAppsOnExit
{
get { return _closeAllAppsOnExit; }
set
{
if (_closeAllAppsOnExit != value)
{
_closeAllAppsOnExit = value;
OnPropertyChanged();
}
}
}
public MyApp CurrentApp { get; set; }
public Profile CurrentProfile
{
get { return _currentProfile; }
set
{
if (_currentProfile != value)
{
_currentProfile = value;
OnPropertyChanged();
// Notify that OtherProfiles may have changed when CurrentProfile changes
OnPropertyChanged(nameof(OtherProfiles));
}
}
}
public ObservableCollection<Profile> Profiles
{
get { return _profiles; }
set
{
if (_profiles != value)
{
_profiles = value;
OnPropertyChanged();
}
}
}
public MyApp SelectedApp
{
get { return _selectedApp; }
set
{
if (_selectedApp != value)
{
_selectedApp = value;
OnPropertyChanged();
}
}
}
#endregion Public Properties
#region Protected Methods
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion Protected Methods
}
}