28
28
using Windows . UI . Xaml . Media . Imaging ;
29
29
using Windows . Management . Deployment ;
30
30
using Windows . Storage . Streams ;
31
+ using Windows . System ;
32
+ using Microsoft . UI . Xaml . Controls ;
31
33
32
34
namespace Files
33
35
{
@@ -65,6 +67,7 @@ public static ProHome OccupiedInstance
65
67
public static ObservableCollection < SidebarItem > sideBarItems = new ObservableCollection < SidebarItem > ( ) ;
66
68
public static ObservableCollection < WSLDistroItem > linuxDistroItems = new ObservableCollection < WSLDistroItem > ( ) ;
67
69
public static FormFactorMode FormFactor { get ; set ; } = FormFactorMode . Regular ;
70
+ ApplicationDataContainer localSettings ;
68
71
69
72
public App ( )
70
73
{
@@ -79,12 +82,142 @@ public App()
79
82
Clipboard . ContentChanged += Clipboard_ContentChanged ;
80
83
Clipboard_ContentChanged ( null , null ) ;
81
84
AppCenter . Start ( "682666d1-51d3-4e4a-93d0-d028d43baaa0" , typeof ( Analytics ) , typeof ( Crashes ) ) ;
85
+ localSettings = ApplicationData . Current . LocalSettings ;
82
86
SetPropertiesFromLocalSettings ( ) ;
83
87
PopulatePinnedSidebarItems ( ) ;
84
88
DetectWSLDistros ( ) ;
85
89
QuickLookIntegration ( ) ;
86
90
}
87
91
92
+ public void CloseOpenPopups ( )
93
+ {
94
+ var popups = VisualTreeHelper . GetOpenPopups ( Window . Current ) ;
95
+ foreach ( var popup in popups )
96
+ {
97
+ if ( popup . Child is ContentDialog )
98
+ {
99
+ ( popup . Child as ContentDialog ) . Hide ( ) ;
100
+ }
101
+ }
102
+ }
103
+
104
+ public Popup GetOpenPopupByDialog ( ContentDialog dialog )
105
+ {
106
+ var popups = VisualTreeHelper . GetOpenPopups ( Window . Current ) ;
107
+ foreach ( var popup in popups )
108
+ {
109
+ if ( popup . Child is ContentDialog )
110
+ {
111
+ if ( ( popup . Child as ContentDialog ) == dialog )
112
+ {
113
+ return popup ;
114
+ }
115
+ }
116
+ }
117
+ return null ;
118
+ }
119
+
120
+ private async void CoreWindow_KeyDown ( CoreWindow sender , KeyEventArgs args )
121
+ {
122
+ var ctrl = Window . Current . CoreWindow . GetKeyState ( VirtualKey . Control ) ;
123
+ var shift = Window . Current . CoreWindow . GetKeyState ( VirtualKey . Shift ) ;
124
+ var alt = Window . Current . CoreWindow . GetKeyState ( VirtualKey . Menu ) ;
125
+ if ( App . OccupiedInstance != null )
126
+ {
127
+ if ( ctrl . HasFlag ( CoreVirtualKeyStates . Down ) )
128
+ {
129
+ if ( shift . HasFlag ( CoreVirtualKeyStates . Down ) )
130
+ {
131
+ if ( ( App . OccupiedInstance . ItemDisplayFrame . Content as BaseLayout ) != null )
132
+ {
133
+ switch ( args . VirtualKey )
134
+ {
135
+ case VirtualKey . N :
136
+ Window . Current . CoreWindow . KeyDown -= CoreWindow_KeyDown ;
137
+ await App . addItemDialog . ShowAsync ( ) ;
138
+ Window . Current . CoreWindow . KeyDown += CoreWindow_KeyDown ;
139
+ break ;
140
+ }
141
+ }
142
+ }
143
+ else
144
+ {
145
+ if ( ( App . OccupiedInstance . ItemDisplayFrame . Content as BaseLayout ) != null )
146
+ {
147
+ switch ( args . VirtualKey )
148
+ {
149
+ case VirtualKey . C :
150
+ App . OccupiedInstance . instanceInteraction . CopyItem_ClickAsync ( null , null ) ;
151
+ break ;
152
+ case VirtualKey . X :
153
+ App . OccupiedInstance . instanceInteraction . CutItem_Click ( null , null ) ;
154
+ break ;
155
+ case VirtualKey . V :
156
+ App . OccupiedInstance . instanceInteraction . PasteItem_ClickAsync ( null , null ) ;
157
+ break ;
158
+ case VirtualKey . A :
159
+ App . OccupiedInstance . instanceInteraction . SelectAllItems ( ) ;
160
+ break ;
161
+ }
162
+ }
163
+
164
+ switch ( args . VirtualKey )
165
+ {
166
+ case VirtualKey . N :
167
+ var filesUWPUri = new Uri ( "files-uwp:" ) ;
168
+ await Launcher . LaunchUriAsync ( filesUWPUri ) ;
169
+ break ;
170
+ case VirtualKey . W :
171
+ if ( ( ( Window . Current . Content as Frame ) . Content as InstanceTabsView ) . TabStrip . TabItems . Count == 1 )
172
+ {
173
+ Application . Current . Exit ( ) ;
174
+ }
175
+ else if ( ( ( Window . Current . Content as Frame ) . Content as InstanceTabsView ) . TabStrip . TabItems . Count > 1 )
176
+ {
177
+ ( ( Window . Current . Content as Frame ) . Content as InstanceTabsView ) . TabStrip . TabItems . RemoveAt ( ( ( Window . Current . Content as Frame ) . Content as InstanceTabsView ) . TabStrip . SelectedIndex ) ;
178
+ }
179
+ break ;
180
+ }
181
+ }
182
+ }
183
+ else if ( ctrl . HasFlag ( CoreVirtualKeyStates . None ) && alt . HasFlag ( CoreVirtualKeyStates . None ) )
184
+ {
185
+ if ( ( App . OccupiedInstance . ItemDisplayFrame . Content as BaseLayout ) != null )
186
+ {
187
+ switch ( args . VirtualKey )
188
+ {
189
+ case VirtualKey . Delete :
190
+ App . OccupiedInstance . instanceInteraction . DeleteItem_Click ( null , null ) ;
191
+ break ;
192
+ case VirtualKey . Enter :
193
+ if ( ( App . OccupiedInstance . ItemDisplayFrame . Content as BaseLayout ) . IsQuickLookEnabled )
194
+ {
195
+ App . OccupiedInstance . instanceInteraction . ToggleQuickLook ( ) ;
196
+ }
197
+ else
198
+ {
199
+ App . OccupiedInstance . instanceInteraction . List_ItemClick ( null , null ) ;
200
+ }
201
+ break ;
202
+ }
203
+
204
+ if ( App . OccupiedInstance . ItemDisplayFrame . SourcePageType == typeof ( PhotoAlbum ) )
205
+ {
206
+ switch ( args . VirtualKey )
207
+ {
208
+ case VirtualKey . F2 :
209
+ if ( ( App . OccupiedInstance . ItemDisplayFrame . Content as BaseLayout ) . SelectedItems . Count > 0 )
210
+ {
211
+ App . OccupiedInstance . instanceInteraction . RenameItem_Click ( null , null ) ;
212
+ }
213
+ break ;
214
+ }
215
+ }
216
+ }
217
+ }
218
+ }
219
+ }
220
+
88
221
private async void DetectWSLDistros ( )
89
222
{
90
223
try
@@ -136,14 +269,12 @@ private async void DetectWSLDistros()
136
269
137
270
private async void QuickLookIntegration ( )
138
271
{
139
- ApplicationData . Current . LocalSettings . Values [ "Arguments" ] = "CheckQuickLookAvailability" ;
272
+ localSettings . Values [ "Arguments" ] = "CheckQuickLookAvailability" ;
140
273
await FullTrustProcessLauncher . LaunchFullTrustProcessForCurrentAppAsync ( ) ;
141
274
}
142
275
143
276
private void SetPropertiesFromLocalSettings ( )
144
277
{
145
- ApplicationDataContainer localSettings = ApplicationData . Current . LocalSettings ;
146
-
147
278
if ( localSettings . Values [ "theme" ] == null )
148
279
{
149
280
localSettings . Values [ "theme" ] = "Default" ;
@@ -180,10 +311,10 @@ private void SetPropertiesFromLocalSettings()
180
311
}
181
312
182
313
this . RequestedTheme = SettingsPages . Personalization . TV . ThemeValue ;
183
- DetectCustomLocations ( localSettings ) ;
314
+ DetectCustomLocations ( ) ;
184
315
}
185
316
186
- private async void DetectCustomLocations ( ApplicationDataContainer localSettings )
317
+ private async void DetectCustomLocations ( )
187
318
{
188
319
// Detect custom locations set from Windows
189
320
localSettings . Values [ "Arguments" ] = "DetectUserPaths" ;
@@ -660,7 +791,37 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
660
791
watcher . Start ( ) ;
661
792
// Ensure the current window is active
662
793
Window . Current . Activate ( ) ;
794
+ Window . Current . CoreWindow . KeyDown += CoreWindow_KeyDown ;
795
+ Window . Current . CoreWindow . Dispatcher . AcceleratorKeyActivated += Dispatcher_AcceleratorKeyActivated ;
796
+
797
+ }
798
+ }
663
799
800
+ private void Dispatcher_AcceleratorKeyActivated ( CoreDispatcher sender , AcceleratorKeyEventArgs args )
801
+ {
802
+ if ( args . KeyStatus . IsMenuKeyDown )
803
+ {
804
+ switch ( args . VirtualKey )
805
+ {
806
+ case VirtualKey . Left :
807
+ NavigationActions . Back_Click ( null , null ) ;
808
+ break ;
809
+ case VirtualKey . Right :
810
+ NavigationActions . Forward_Click ( null , null ) ;
811
+ break ;
812
+ case VirtualKey . F :
813
+ App . OccupiedInstance . RibbonArea . RibbonTabView . SelectedIndex = 0 ;
814
+ break ;
815
+ case VirtualKey . H :
816
+ App . OccupiedInstance . RibbonArea . RibbonTabView . SelectedIndex = 1 ;
817
+ break ;
818
+ case VirtualKey . S :
819
+ App . OccupiedInstance . RibbonArea . RibbonTabView . SelectedIndex = 2 ;
820
+ break ;
821
+ case VirtualKey . V :
822
+ App . OccupiedInstance . RibbonArea . RibbonTabView . SelectedIndex = 3 ;
823
+ break ;
824
+ }
664
825
}
665
826
}
666
827
@@ -695,6 +856,8 @@ protected override void OnActivated(IActivatedEventArgs args)
695
856
watcher . EnumerationCompleted += Watcher_EnumerationCompleted ;
696
857
watcher . Start ( ) ;
697
858
Window . Current . Activate ( ) ;
859
+ Window . Current . CoreWindow . KeyDown += CoreWindow_KeyDown ;
860
+ Window . Current . CoreWindow . Dispatcher . AcceleratorKeyActivated += Dispatcher_AcceleratorKeyActivated ;
698
861
return ;
699
862
}
700
863
0 commit comments