2828using Windows . UI . Xaml . Media . Imaging ;
2929using Windows . Management . Deployment ;
3030using Windows . Storage . Streams ;
31+ using Windows . System ;
32+ using Microsoft . UI . Xaml . Controls ;
3133
3234namespace Files
3335{
@@ -65,6 +67,7 @@ public static ProHome OccupiedInstance
6567 public static ObservableCollection < SidebarItem > sideBarItems = new ObservableCollection < SidebarItem > ( ) ;
6668 public static ObservableCollection < WSLDistroItem > linuxDistroItems = new ObservableCollection < WSLDistroItem > ( ) ;
6769 public static FormFactorMode FormFactor { get ; set ; } = FormFactorMode . Regular ;
70+ ApplicationDataContainer localSettings ;
6871
6972 public App ( )
7073 {
@@ -79,12 +82,142 @@ public App()
7982 Clipboard . ContentChanged += Clipboard_ContentChanged ;
8083 Clipboard_ContentChanged ( null , null ) ;
8184 AppCenter . Start ( "682666d1-51d3-4e4a-93d0-d028d43baaa0" , typeof ( Analytics ) , typeof ( Crashes ) ) ;
85+ localSettings = ApplicationData . Current . LocalSettings ;
8286 SetPropertiesFromLocalSettings ( ) ;
8387 PopulatePinnedSidebarItems ( ) ;
8488 DetectWSLDistros ( ) ;
8589 QuickLookIntegration ( ) ;
8690 }
8791
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+
88221 private async void DetectWSLDistros ( )
89222 {
90223 try
@@ -136,14 +269,12 @@ private async void DetectWSLDistros()
136269
137270 private async void QuickLookIntegration ( )
138271 {
139- ApplicationData . Current . LocalSettings . Values [ "Arguments" ] = "CheckQuickLookAvailability" ;
272+ localSettings . Values [ "Arguments" ] = "CheckQuickLookAvailability" ;
140273 await FullTrustProcessLauncher . LaunchFullTrustProcessForCurrentAppAsync ( ) ;
141274 }
142275
143276 private void SetPropertiesFromLocalSettings ( )
144277 {
145- ApplicationDataContainer localSettings = ApplicationData . Current . LocalSettings ;
146-
147278 if ( localSettings . Values [ "theme" ] == null )
148279 {
149280 localSettings . Values [ "theme" ] = "Default" ;
@@ -180,10 +311,10 @@ private void SetPropertiesFromLocalSettings()
180311 }
181312
182313 this . RequestedTheme = SettingsPages . Personalization . TV . ThemeValue ;
183- DetectCustomLocations ( localSettings ) ;
314+ DetectCustomLocations ( ) ;
184315 }
185316
186- private async void DetectCustomLocations ( ApplicationDataContainer localSettings )
317+ private async void DetectCustomLocations ( )
187318 {
188319 // Detect custom locations set from Windows
189320 localSettings . Values [ "Arguments" ] = "DetectUserPaths" ;
@@ -660,7 +791,37 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
660791 watcher . Start ( ) ;
661792 // Ensure the current window is active
662793 Window . Current . Activate ( ) ;
794+ Window . Current . CoreWindow . KeyDown += CoreWindow_KeyDown ;
795+ Window . Current . CoreWindow . Dispatcher . AcceleratorKeyActivated += Dispatcher_AcceleratorKeyActivated ;
796+
797+ }
798+ }
663799
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+ }
664825 }
665826 }
666827
@@ -695,6 +856,8 @@ protected override void OnActivated(IActivatedEventArgs args)
695856 watcher . EnumerationCompleted += Watcher_EnumerationCompleted ;
696857 watcher . Start ( ) ;
697858 Window . Current . Activate ( ) ;
859+ Window . Current . CoreWindow . KeyDown += CoreWindow_KeyDown ;
860+ Window . Current . CoreWindow . Dispatcher . AcceleratorKeyActivated += Dispatcher_AcceleratorKeyActivated ;
698861 return ;
699862 }
700863
0 commit comments