1
1
using Flow . Launcher . Core . Resource ;
2
- using Flow . Launcher . Infrastructure . UserSettings ;
2
+ using Flow . Launcher . ViewModel ;
3
3
using System ;
4
- using System . Linq ;
5
4
using System . Windows ;
6
5
using System . Windows . Input ;
7
6
8
7
namespace Flow . Launcher
9
8
{
10
9
public partial class CustomShortcutSetting : Window
11
10
{
12
- private Settings _settings ;
13
- private bool update = false ;
11
+ private SettingWindowViewModel viewModel ;
14
12
public string Key { get ; set ; }
15
13
public string Value { get ; set ; }
16
- public CustomShortcutModel ShortCut ;
14
+ private string originalKey { get ; init ; } = null ;
15
+ private string originalValue { get ; init ; } = null ;
16
+ bool update = false ;
17
17
18
- public CustomShortcutSetting ( Settings settings )
18
+ public CustomShortcutSetting ( SettingWindowViewModel vm )
19
19
{
20
- _settings = settings ;
20
+ viewModel = vm ;
21
21
InitializeComponent ( ) ;
22
22
}
23
23
24
- public CustomShortcutSetting ( CustomShortcutModel shortcut , Settings settings )
24
+ public CustomShortcutSetting ( string key , string value , SettingWindowViewModel vm )
25
25
{
26
- Key = shortcut . Key ;
27
- Value = shortcut . Value ;
28
- ShortCut = shortcut ;
29
- _settings = settings ;
26
+ viewModel = vm ;
27
+ Key = key ;
28
+ Value = value ;
29
+ originalKey = key ;
30
+ originalValue = value ;
30
31
update = true ;
31
32
InitializeComponent ( ) ;
32
33
}
@@ -39,32 +40,19 @@ private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
39
40
40
41
private void BtnAdd_OnClick ( object sender , RoutedEventArgs e )
41
42
{
42
- bool modified = false ;
43
43
if ( String . IsNullOrEmpty ( Key ) || String . IsNullOrEmpty ( Value ) )
44
44
{
45
45
MessageBox . Show ( InternationalizationManager . Instance . GetTranslation ( "emptyShortcut" ) ) ;
46
46
return ;
47
47
}
48
- if ( ! update )
48
+ // Check if key is modified or adding a new one
49
+ if ( ( ( update && originalKey != Key ) || ! update )
50
+ && viewModel . ShortcutExists ( Key ) )
49
51
{
50
- ShortCut = new CustomShortcutModel ( Key , Value ) ;
51
- if ( _settings . CustomShortcuts . Any ( x => x . Key == Key ) || _settings . BuiltinShortcuts . Any ( x => x . Key == Key ) )
52
- {
53
- MessageBox . Show ( InternationalizationManager . Instance . GetTranslation ( "duplicateShortcut" ) ) ;
54
- return ;
55
- }
56
- modified = true ;
57
- }
58
- else
59
- {
60
- if ( ShortCut . Key != Key && _settings . CustomShortcuts . Any ( x => x . Key == Key ) || _settings . BuiltinShortcuts . Any ( x => x . Key == Key ) )
61
- {
62
- MessageBox . Show ( InternationalizationManager . Instance . GetTranslation ( "duplicateShortcut" ) ) ;
63
- return ;
64
- }
65
- modified = ShortCut . Key != Key || ShortCut . Value != Value ;
52
+ MessageBox . Show ( InternationalizationManager . Instance . GetTranslation ( "duplicateShortcut" ) ) ;
53
+ return ;
66
54
}
67
- DialogResult = modified ;
55
+ DialogResult = ! update || originalKey != Key || originalValue != Value ;
68
56
Close ( ) ;
69
57
}
70
58
0 commit comments