1
1
using Flow . Launcher . Core . Resource ;
2
2
using Flow . Launcher . Infrastructure . UserSettings ;
3
3
using System ;
4
+ using System . Linq ;
4
5
using System . Windows ;
5
6
using System . Windows . Input ;
6
7
@@ -12,7 +13,7 @@ public partial class CustomShortcutSetting : Window
12
13
private bool update = false ;
13
14
public string Key { get ; set ; }
14
15
public string Value { get ; set ; }
15
- public CustomShortcutModel ShortCut => ( Key , Value ) ;
16
+ public CustomShortcutModel ShortCut ;
16
17
17
18
public CustomShortcutSetting ( Settings settings )
18
19
{
@@ -24,6 +25,7 @@ public CustomShortcutSetting(CustomShortcutModel shortcut, Settings settings)
24
25
{
25
26
Key = shortcut . Key ;
26
27
Value = shortcut . Value ;
28
+ ShortCut = shortcut ;
27
29
_settings = settings ;
28
30
update = true ;
29
31
InitializeComponent ( ) ;
@@ -37,17 +39,32 @@ private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
37
39
38
40
private void BtnAdd_OnClick ( object sender , RoutedEventArgs e )
39
41
{
42
+ bool modified = false ;
40
43
if ( String . IsNullOrEmpty ( Key ) || String . IsNullOrEmpty ( Value ) )
41
44
{
42
45
MessageBox . Show ( InternationalizationManager . Instance . GetTranslation ( "emptyShortcut" ) ) ;
43
46
return ;
44
47
}
45
- if ( ! update && ( _settings . CustomShortcuts . Contains ( new CustomShortcutModel ( Key , Value ) ) || _settings . BuiltinShortcuts . Contains ( new BuiltinShortcutModel ( Key , Value , null ) ) ) )
48
+ if ( ! update )
46
49
{
47
- MessageBox . Show ( InternationalizationManager . Instance . GetTranslation ( "dulplicateShortcut" ) ) ;
48
- return ;
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 ;
49
66
}
50
- DialogResult = true ;
67
+ DialogResult = modified ;
51
68
Close ( ) ;
52
69
}
53
70
0 commit comments