4
4
using System . Threading . Tasks ;
5
5
using System . Windows ;
6
6
using System . Windows . Input ;
7
+ using CommunityToolkit . Mvvm . DependencyInjection ;
7
8
using Flow . Launcher . Core . Resource ;
8
9
using Flow . Launcher . Helper ;
9
10
using Flow . Launcher . Infrastructure . Hotkey ;
11
+ using Flow . Launcher . Infrastructure . UserSettings ;
10
12
11
13
namespace Flow . Launcher
12
14
{
13
15
public partial class HotkeyControl
14
16
{
15
- public IHotkeySettings HotkeySettings {
16
- get { return ( IHotkeySettings ) GetValue ( HotkeySettingsProperty ) ; }
17
- set { SetValue ( HotkeySettingsProperty , value ) ; }
18
- }
19
-
20
- public static readonly DependencyProperty HotkeySettingsProperty = DependencyProperty . Register (
21
- nameof ( HotkeySettings ) ,
22
- typeof ( IHotkeySettings ) ,
23
- typeof ( HotkeyControl ) ,
24
- new PropertyMetadata ( )
25
- ) ;
26
17
public string WindowTitle {
27
18
get { return ( string ) GetValue ( WindowTitleProperty ) ; }
28
19
set { SetValue ( WindowTitleProperty , value ) ; }
@@ -71,8 +62,7 @@ private static void OnHotkeyChanged(DependencyObject d, DependencyPropertyChange
71
62
return ;
72
63
}
73
64
74
- hotkeyControl . SetKeysToDisplay ( new HotkeyModel ( hotkeyControl . Hotkey ) ) ;
75
- hotkeyControl . CurrentHotkey = new HotkeyModel ( hotkeyControl . Hotkey ) ;
65
+ hotkeyControl . RefreshHotkeyInterface ( hotkeyControl . Hotkey ) ;
76
66
}
77
67
78
68
@@ -90,25 +80,132 @@ public ICommand? ChangeHotkey
90
80
}
91
81
92
82
93
- public static readonly DependencyProperty HotkeyProperty = DependencyProperty . Register (
94
- nameof ( Hotkey ) ,
95
- typeof ( string ) ,
83
+ public static readonly DependencyProperty TypeProperty = DependencyProperty . Register (
84
+ nameof ( Type ) ,
85
+ typeof ( HotkeyType ) ,
96
86
typeof ( HotkeyControl ) ,
97
- new FrameworkPropertyMetadata ( "" , FrameworkPropertyMetadataOptions . BindsTwoWayByDefault , OnHotkeyChanged )
87
+ new FrameworkPropertyMetadata ( HotkeyType . Hotkey , FrameworkPropertyMetadataOptions . BindsTwoWayByDefault , OnHotkeyChanged )
98
88
) ;
99
89
90
+ public HotkeyType Type
91
+ {
92
+ get { return ( HotkeyType ) GetValue ( TypeProperty ) ; }
93
+ set { SetValue ( TypeProperty , value ) ; }
94
+ }
95
+
96
+ public enum HotkeyType
97
+ {
98
+ Hotkey ,
99
+ PreviewHotkey ,
100
+ OpenContextMenuHotkey ,
101
+ SettingWindowHotkey ,
102
+ CycleHistoryUpHotkey ,
103
+ CycleHistoryDownHotkey ,
104
+ SelectPrevPageHotkey ,
105
+ SelectNextPageHotkey ,
106
+ AutoCompleteHotkey ,
107
+ AutoCompleteHotkey2 ,
108
+ SelectPrevItemHotkey ,
109
+ SelectPrevItemHotkey2 ,
110
+ SelectNextItemHotkey ,
111
+ SelectNextItemHotkey2
112
+ }
113
+
114
+ // We can initialize settings in static field because it has been constructed in App constuctor
115
+ // and it will not construct settings instances twice
116
+ private static readonly Settings _settings = Ioc . Default . GetRequiredService < Settings > ( ) ;
117
+
100
118
public string Hotkey
101
119
{
102
- get { return ( string ) GetValue ( HotkeyProperty ) ; }
103
- set { SetValue ( HotkeyProperty , value ) ; }
120
+ get
121
+ {
122
+ return Type switch
123
+ {
124
+ HotkeyType . Hotkey => _settings . Hotkey ,
125
+ HotkeyType . PreviewHotkey => _settings . PreviewHotkey ,
126
+ HotkeyType . OpenContextMenuHotkey => _settings . OpenContextMenuHotkey ,
127
+ HotkeyType . SettingWindowHotkey => _settings . SettingWindowHotkey ,
128
+ HotkeyType . CycleHistoryUpHotkey => _settings . CycleHistoryUpHotkey ,
129
+ HotkeyType . CycleHistoryDownHotkey => _settings . CycleHistoryDownHotkey ,
130
+ HotkeyType . SelectPrevPageHotkey => _settings . SelectPrevPageHotkey ,
131
+ HotkeyType . SelectNextPageHotkey => _settings . SelectNextPageHotkey ,
132
+ HotkeyType . AutoCompleteHotkey => _settings . AutoCompleteHotkey ,
133
+ HotkeyType . AutoCompleteHotkey2 => _settings . AutoCompleteHotkey2 ,
134
+ HotkeyType . SelectPrevItemHotkey => _settings . SelectPrevItemHotkey ,
135
+ HotkeyType . SelectPrevItemHotkey2 => _settings . SelectPrevItemHotkey2 ,
136
+ HotkeyType . SelectNextItemHotkey => _settings . SelectNextItemHotkey ,
137
+ HotkeyType . SelectNextItemHotkey2 => _settings . SelectNextItemHotkey2 ,
138
+ _ => string . Empty
139
+ } ;
140
+ }
141
+ set
142
+ {
143
+ switch ( Type )
144
+ {
145
+ case HotkeyType . Hotkey :
146
+ _settings . Hotkey = value ;
147
+ break ;
148
+ case HotkeyType . PreviewHotkey :
149
+ _settings . PreviewHotkey = value ;
150
+ break ;
151
+ case HotkeyType . OpenContextMenuHotkey :
152
+ _settings . OpenContextMenuHotkey = value ;
153
+ break ;
154
+ case HotkeyType . SettingWindowHotkey :
155
+ _settings . SettingWindowHotkey = value ;
156
+ break ;
157
+ case HotkeyType . CycleHistoryUpHotkey :
158
+ _settings . CycleHistoryUpHotkey = value ;
159
+ break ;
160
+ case HotkeyType . CycleHistoryDownHotkey :
161
+ _settings . CycleHistoryDownHotkey = value ;
162
+ break ;
163
+ case HotkeyType . SelectPrevPageHotkey :
164
+ _settings . SelectPrevPageHotkey = value ;
165
+ break ;
166
+ case HotkeyType . SelectNextPageHotkey :
167
+ _settings . SelectNextPageHotkey = value ;
168
+ break ;
169
+ case HotkeyType . AutoCompleteHotkey :
170
+ _settings . AutoCompleteHotkey = value ;
171
+ break ;
172
+ case HotkeyType . AutoCompleteHotkey2 :
173
+ _settings . AutoCompleteHotkey2 = value ;
174
+ break ;
175
+ case HotkeyType . SelectPrevItemHotkey :
176
+ _settings . SelectPrevItemHotkey = value ;
177
+ break ;
178
+ case HotkeyType . SelectNextItemHotkey :
179
+ _settings . SelectNextItemHotkey = value ;
180
+ break ;
181
+ case HotkeyType . SelectPrevItemHotkey2 :
182
+ _settings . SelectPrevItemHotkey2 = value ;
183
+ break ;
184
+ case HotkeyType . SelectNextItemHotkey2 :
185
+ _settings . SelectNextItemHotkey2 = value ;
186
+ break ;
187
+ default :
188
+ return ;
189
+ }
190
+
191
+ // After setting the hotkey, we need to refresh the interface
192
+ RefreshHotkeyInterface ( Hotkey ) ;
193
+ }
104
194
}
105
195
106
196
public HotkeyControl ( )
107
197
{
108
198
InitializeComponent ( ) ;
109
199
110
200
HotkeyList . ItemsSource = KeysToDisplay ;
111
- SetKeysToDisplay ( CurrentHotkey ) ;
201
+
202
+ RefreshHotkeyInterface ( Hotkey ) ;
203
+ }
204
+
205
+ private void RefreshHotkeyInterface ( string hotkey )
206
+ {
207
+ SetKeysToDisplay ( new HotkeyModel ( Hotkey ) ) ;
208
+ CurrentHotkey = new HotkeyModel ( Hotkey ) ;
112
209
}
113
210
114
211
private static bool CheckHotkeyAvailability ( HotkeyModel hotkey , bool validateKeyGesture ) =>
@@ -133,7 +230,7 @@ private async Task OpenHotkeyDialog()
133
230
HotKeyMapper . RemoveHotkey ( Hotkey ) ;
134
231
}
135
232
136
- var dialog = new HotkeyControlDialog ( Hotkey , DefaultHotkey , HotkeySettings , WindowTitle ) ;
233
+ var dialog = new HotkeyControlDialog ( Hotkey , DefaultHotkey , WindowTitle ) ;
137
234
await dialog . ShowAsync ( ) ;
138
235
switch ( dialog . ResultType )
139
236
{
0 commit comments