12
12
using Rubberduck . Resources ;
13
13
using Rubberduck . Resources . Settings ;
14
14
using Rubberduck . Parsing . Common ;
15
+ using System . Collections . Specialized ;
16
+ using Rubberduck . UI . WPF ;
15
17
16
18
namespace Rubberduck . UI . Settings
17
19
{
@@ -79,19 +81,32 @@ public DisplayLanguageSetting SelectedLanguage
79
81
}
80
82
}
81
83
82
- private ObservableCollection < HotkeySetting > _hotkeys ;
83
- public ObservableCollection < HotkeySetting > Hotkeys
84
+ private ObservableViewModelCollection < HotkeySettingViewModel > _hotkeys ;
85
+ public ObservableViewModelCollection < HotkeySettingViewModel > Hotkeys
84
86
{
85
87
get => _hotkeys ;
86
88
set
87
89
{
88
90
if ( _hotkeys != value )
89
91
{
92
+ if ( _hotkeys != null )
93
+ {
94
+ _hotkeys . ElementPropertyChanged -= InvalidateShouldDisplayWarning ;
95
+ }
96
+ if ( value != null )
97
+ {
98
+ value . ElementPropertyChanged += InvalidateShouldDisplayWarning ;
99
+ }
90
100
_hotkeys = value ;
91
101
OnPropertyChanged ( ) ;
102
+ OnPropertyChanged ( nameof ( ShouldDisplayHotkeyModificationLabel ) ) ;
92
103
}
93
104
}
94
105
}
106
+ private void InvalidateShouldDisplayWarning ( object sender , ElementPropertyChangedEventArgs < HotkeySettingViewModel > e )
107
+ {
108
+ OnPropertyChanged ( nameof ( ShouldDisplayHotkeyModificationLabel ) ) ;
109
+ }
95
110
96
111
public bool ShouldDisplayHotkeyModificationLabel
97
112
{
@@ -259,7 +274,7 @@ private void ShowLogFolder()
259
274
public void UpdateConfig ( Configuration config )
260
275
{
261
276
config . UserSettings . GeneralSettings = GetCurrentGeneralSettings ( ) ;
262
- config . UserSettings . HotkeySettings . Settings = Hotkeys . ToArray ( ) ;
277
+ config . UserSettings . HotkeySettings . Settings = Hotkeys . Select ( vm => vm . Unwrap ( ) ) . ToArray ( ) ;
263
278
}
264
279
265
280
public void SetToDefaults ( Configuration config )
@@ -290,13 +305,13 @@ protected override void TransferSettingsToView(Rubberduck.Settings.GeneralSettin
290
305
TransferSettingsToView ( toLoad , null ) ;
291
306
}
292
307
293
- private void TransferSettingsToView ( IGeneralSettings general , IHotkeySettings hottkey )
308
+ private void TransferSettingsToView ( IGeneralSettings general , IHotkeySettings hotkey )
294
309
{
295
310
SelectedLanguage = Languages . FirstOrDefault ( culture => culture . Code == general . Language . Code ) ;
296
311
297
- Hotkeys = hottkey == null
298
- ? new ObservableCollection < HotkeySetting > ( )
299
- : new ObservableCollection < HotkeySetting > ( hottkey . Settings ) ;
312
+ Hotkeys = hotkey == null
313
+ ? new ObservableViewModelCollection < HotkeySettingViewModel > ( )
314
+ : new ObservableViewModelCollection < HotkeySettingViewModel > ( hotkey . Settings . Select ( data => new HotkeySettingViewModel ( data ) ) ) ;
300
315
ShowSplashAtStartup = general . CanShowSplash ;
301
316
CheckVersionAtStartup = general . CanCheckVersion ;
302
317
CompileBeforeParse = general . CompileBeforeParse ;
@@ -352,8 +367,60 @@ protected override void ExportSettings(Rubberduck.Settings.GeneralSettings setti
352
367
dialog . ShowDialog ( ) ;
353
368
if ( string . IsNullOrEmpty ( dialog . FileName ) ) return ;
354
369
Service . Save ( settings , dialog . FileName ) ;
355
- _hotkeyService . Save ( new HotkeySettings { Settings = Hotkeys . ToArray ( ) } , dialog . FileName ) ;
370
+ _hotkeyService . Save ( new HotkeySettings { Settings = Hotkeys . Select ( vm => vm . Unwrap ( ) ) . ToArray ( ) } , dialog . FileName ) ;
356
371
}
357
372
}
358
373
}
374
+
375
+ public class HotkeySettingViewModel : ViewModelBase
376
+ {
377
+ private readonly HotkeySetting wrapped ;
378
+
379
+ public HotkeySettingViewModel ( HotkeySetting wrapped )
380
+ {
381
+ this . wrapped = wrapped ;
382
+ }
383
+
384
+ public HotkeySetting Unwrap ( ) { return wrapped ; }
385
+
386
+ public string Key1
387
+ {
388
+ get { return wrapped . Key1 ; }
389
+ set { wrapped . Key1 = value ; OnPropertyChanged ( ) ; }
390
+ }
391
+
392
+ public bool IsEnabled
393
+ {
394
+ get { return wrapped . IsEnabled ; }
395
+ set { wrapped . IsEnabled = value ; OnPropertyChanged ( ) ; }
396
+ }
397
+
398
+ public bool HasShiftModifier
399
+ {
400
+ get { return wrapped . HasShiftModifier ; }
401
+ set { wrapped . HasShiftModifier = value ; OnPropertyChanged ( ) ; OnPropertyChanged ( nameof ( IsValid ) ) ; }
402
+ }
403
+
404
+ public bool HasAltModifier
405
+ {
406
+ get { return wrapped . HasAltModifier ; }
407
+ set { wrapped . HasAltModifier = value ; OnPropertyChanged ( ) ; OnPropertyChanged ( nameof ( IsValid ) ) ; }
408
+ }
409
+
410
+ public bool HasCtrlModifier
411
+ {
412
+ get { return wrapped . HasCtrlModifier ; }
413
+ set { wrapped . HasCtrlModifier = value ; OnPropertyChanged ( ) ; OnPropertyChanged ( nameof ( IsValid ) ) ; }
414
+ }
415
+
416
+ public string CommandTypeName
417
+ {
418
+ get { return wrapped . CommandTypeName ; }
419
+ set { wrapped . CommandTypeName = value ; OnPropertyChanged ( ) ; }
420
+ }
421
+
422
+ public bool IsValid { get { return wrapped . IsValid ; } }
423
+ // FIXME If this is the only use, the property should be inlined to here
424
+ public string Prompt { get { return wrapped . Prompt ; } }
425
+ }
359
426
}
0 commit comments