forked from Code52/carnac
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathPreferencesViewModel.cs
More file actions
178 lines (145 loc) · 6.54 KB
/
PreferencesViewModel.cs
File metadata and controls
178 lines (145 loc) · 6.54 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Windows.Input;
using System.Windows.Media;
using Carnac.Logic;
using Carnac.Logic.Enums;
using Carnac.Logic.Models;
using Carnac.Logic.Native;
using SettingsProviderNet;
namespace Carnac.UI
{
public class PreferencesViewModel : NotifyPropertyChanged
{
readonly ISettingsProvider settingsProvider;
public PreferencesViewModel(ISettingsProvider settingsProvider, IScreenManager screenManager)
{
this.settingsProvider = settingsProvider;
Screens = new ObservableCollection<DetailedScreen>(screenManager.GetScreens());
Settings = settingsProvider.GetSettings<PopupSettings>();
PlaceScreen();
AvailableColors = new ObservableCollection<AvailableColor>();
var properties = typeof(Colors).GetProperties(BindingFlags.Static | BindingFlags.Public);
foreach (var prop in properties)
{
var name = prop.Name;
var value = (Color)prop.GetValue(null, null);
var availableColor = new AvailableColor(name, value);
if (Settings.FontColor == name)
FontColor = availableColor;
if (Settings.ItemBackgroundColor == name)
ItemBackgroundColor = availableColor;
AvailableColors.Add(availableColor);
}
SaveCommand = new DelegateCommand(SaveSettings);
ResetToDefaultsCommand = new DelegateCommand(() => settingsProvider.ResetToDefaults<PopupSettings>());
VisitCommand = new DelegateCommand(Visit);
}
public ICommand VisitCommand { get; private set; }
public ICommand ResetToDefaultsCommand { get; private set; }
public ICommand SaveCommand { get; private set; }
public ObservableCollection<AvailableColor> AvailableColors { get; private set; }
public ObservableCollection<DetailedScreen> Screens { get; set; }
public DetailedScreen SelectedScreen { get; set; }
public PopupSettings Settings { get; set; }
public string Version
{
get { return Assembly.GetExecutingAssembly().GetName().Version.ToString(); }
}
readonly List<string> authors = new List<string>
{
"Brendan Forster",
"Alex Friedman",
"Jon Galloway",
"Jake Ginnivan",
"Paul Jenkins",
"Dmitry Pursanov",
"Chris Sainty",
"Andrew Tobin",
"Henrik Andersson"
};
readonly List<string> components = new List<string>
{
"MahApps.Metro",
"Fody",
"NSubstitute",
"Reactive Extensions",
"Squirrel.Windows"
};
public string Authors
{
get { return string.Join(", ", authors); }
}
public string Components
{
get { return string.Join(", ", components); }
}
public AvailableColor FontColor { get; set; }
public AvailableColor ItemBackgroundColor { get; set; }
void Visit()
{
try
{
Process.Start("http://code52.org/carnac/");
}
catch
{
//I forget what exceptions can be raised if the browser is crashed?
}
}
void SaveSettings()
{
if (Screens.Count < 1)
return;
if (SelectedScreen == null)
SelectedScreen = Screens.First();
Settings.Screen = SelectedScreen.Index;
if (SelectedScreen.NotificationPlacementTopLeft)
Settings.Placement = NotificationPlacement.TopLeft;
else if (SelectedScreen.NotificationPlacementBottomLeft)
Settings.Placement = NotificationPlacement.BottomLeft;
else if (SelectedScreen.NotificationPlacementTopRight)
Settings.Placement = NotificationPlacement.TopRight;
else if (SelectedScreen.NotificationPlacementBottomRight)
Settings.Placement = NotificationPlacement.BottomRight;
else
Settings.Placement = NotificationPlacement.BottomLeft;
PlaceScreen();
Settings.SettingsConfigured = true;
Settings.FontColor = FontColor.Name;
Settings.ItemBackgroundColor = ItemBackgroundColor.Name;
settingsProvider.SaveSettings(Settings);
}
void PlaceScreen()
{
if (Screens == null)
return;
SelectedScreen = Screens.FirstOrDefault(s => s.Index == Settings.Screen);
if (SelectedScreen == null)
return;
switch (Settings.Placement)
{
case NotificationPlacement.TopLeft:
SelectedScreen.NotificationPlacementTopLeft = true;
break;
case NotificationPlacement.BottomLeft:
SelectedScreen.NotificationPlacementBottomLeft = true;
break;
case NotificationPlacement.TopRight:
SelectedScreen.NotificationPlacementTopRight = true;
break;
case NotificationPlacement.BottomRight:
SelectedScreen.NotificationPlacementBottomRight = true;
break;
default:
SelectedScreen.NotificationPlacementBottomLeft = true;
break;
}
Settings.Left = SelectedScreen.Left;
Settings.Top = SelectedScreen.Top;
}
}
}