-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Expand file tree
/
Copy pathGrabAndMoveViewModel.cs
More file actions
208 lines (175 loc) · 6.79 KB
/
Copy pathGrabAndMoveViewModel.cs
File metadata and controls
208 lines (175 loc) · 6.79 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Text.Json;
using global::PowerToys.GPOWrapper;
using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
using Microsoft.PowerToys.Settings.UI.SerializationContext;
namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
public partial class GrabAndMoveViewModel : PageViewModelBase
{
protected override string ModuleName => GrabAndMoveSettings.ModuleName;
private GeneralSettings GeneralSettingsConfig { get; set; }
private Func<string, int> SendConfigMSG { get; }
private GpoRuleConfigured _enabledGpoRuleConfiguration;
private bool _enabledStateIsGPOConfigured;
private bool _isEnabled;
private GrabAndMoveSettings _moduleSettings;
public GrabAndMoveSettings ModuleSettings => _moduleSettings;
public GrabAndMoveViewModel(ISettingsRepository<GeneralSettings> settingsRepository, GrabAndMoveSettings moduleSettings, Func<string, int> ipcMSGCallBackFunc)
{
ArgumentNullException.ThrowIfNull(settingsRepository);
GeneralSettingsConfig = settingsRepository.SettingsConfig;
_moduleSettings = moduleSettings ?? new GrabAndMoveSettings();
InitializeEnabledValue();
SendConfigMSG = ipcMSGCallBackFunc ?? (_ => 0);
}
private void InitializeEnabledValue()
{
_enabledGpoRuleConfiguration = GPOWrapper.GetConfiguredGrabAndMoveEnabledValue();
if (_enabledGpoRuleConfiguration == GpoRuleConfigured.Disabled || _enabledGpoRuleConfiguration == GpoRuleConfigured.Enabled)
{
_enabledStateIsGPOConfigured = true;
_isEnabled = _enabledGpoRuleConfiguration == GpoRuleConfigured.Enabled;
}
else
{
_isEnabled = GeneralSettingsConfig.Enabled.GrabAndMove;
}
}
public bool IsEnabled
{
get => _isEnabled;
set
{
if (_enabledStateIsGPOConfigured)
{
return;
}
if (value != _isEnabled)
{
_isEnabled = value;
GeneralSettingsConfig.Enabled.GrabAndMove = value;
OutGoingGeneralSettings snd = new OutGoingGeneralSettings(GeneralSettingsConfig);
SendConfigMSG(snd.ToString());
OnPropertyChanged(nameof(IsEnabled));
}
}
}
public bool IsEnabledGpoConfigured
{
get => _enabledStateIsGPOConfigured;
}
// 0 = Alt, 1 = Win
public int ModifierKey
{
get => _moduleSettings.Properties.ModifierKey.Value;
set
{
if (_moduleSettings.Properties.ModifierKey.Value != value)
{
_moduleSettings.Properties.ModifierKey.Value = value;
NotifyModuleSettingsChanged();
OnPropertyChanged(nameof(ModifierKey));
OnPropertyChanged(nameof(IsAltModifier));
}
}
}
public bool IsAltModifier => ModifierKey == 0;
public bool ShouldAbsorbAlt
{
get => _moduleSettings.Properties.ShouldAbsorbAlt.Value;
set
{
if (_moduleSettings.Properties.ShouldAbsorbAlt.Value != value)
{
_moduleSettings.Properties.ShouldAbsorbAlt.Value = value;
NotifyModuleSettingsChanged();
OnPropertyChanged(nameof(ShouldAbsorbAlt));
}
}
}
public bool ShowGeometry
{
get => _moduleSettings.Properties.ShowGeometry.Value;
set
{
if (_moduleSettings.Properties.ShowGeometry.Value != value)
{
_moduleSettings.Properties.ShowGeometry.Value = value;
NotifyModuleSettingsChanged();
OnPropertyChanged(nameof(ShowGeometry));
}
}
}
public bool UseAltResize
{
get => _moduleSettings.Properties.UseAltResize.Value;
set
{
if (_moduleSettings.Properties.UseAltResize.Value != value)
{
_moduleSettings.Properties.UseAltResize.Value = value;
NotifyModuleSettingsChanged();
OnPropertyChanged(nameof(UseAltResize));
}
}
}
public bool UseMiddleClickMaximize
{
get => _moduleSettings.Properties.UseMiddleClickMaximize.Value;
set
{
if (_moduleSettings.Properties.UseMiddleClickMaximize.Value != value)
{
_moduleSettings.Properties.UseMiddleClickMaximize.Value = value;
NotifyModuleSettingsChanged();
OnPropertyChanged(nameof(UseMiddleClickMaximize));
}
}
}
public bool DoNotActivateOnGameMode
{
get => _moduleSettings.Properties.DoNotActivateOnGameMode.Value;
set
{
if (_moduleSettings.Properties.DoNotActivateOnGameMode.Value != value)
{
_moduleSettings.Properties.DoNotActivateOnGameMode.Value = value;
NotifyModuleSettingsChanged();
OnPropertyChanged(nameof(DoNotActivateOnGameMode));
}
}
}
public string ExcludedApps
{
get => _moduleSettings.Properties.ExcludedApps.Value;
set
{
if (_moduleSettings.Properties.ExcludedApps.Value != value)
{
_moduleSettings.Properties.ExcludedApps.Value = value;
NotifyModuleSettingsChanged();
OnPropertyChanged(nameof(ExcludedApps));
}
}
}
private void NotifyModuleSettingsChanged()
{
SndGrabAndMoveSettings outSettings = new(_moduleSettings);
SndModuleSettings<SndGrabAndMoveSettings> outIpcMessage = new(outSettings);
SendConfigMSG(outIpcMessage.ToJsonString());
}
public void RefreshEnabledState()
{
InitializeEnabledValue();
OnPropertyChanged(nameof(IsEnabled));
}
}
}