Skip to content

Commit 4aea07a

Browse files
authored
Added a shortcut to open folders in Terminal (#8268)
1 parent 1d565e0 commit 4aea07a

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

src/Files/Views/ColumnShellPage.xaml.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
using Windows.UI.Xaml.Media;
3434
using Windows.UI.Xaml.Media.Animation;
3535
using Windows.UI.Xaml.Navigation;
36-
36+
using Files.Interacts;
3737
using SortDirection = Files.Enums.SortDirection;
3838

3939
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
@@ -190,6 +190,32 @@ public ColumnShellPage()
190190
SystemNavigationManager.GetForCurrentView().BackRequested += ColumnShellPage_BackRequested;
191191

192192
App.DrivesManager.PropertyChanged += DrivesManager_PropertyChanged;
193+
194+
PreviewKeyDown += ColumnShellPage_PreviewKeyDown;
195+
}
196+
197+
private async void ColumnShellPage_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
198+
{
199+
var ctrlPressed = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);
200+
var tabInstance = CurrentPageType == typeof(DetailsLayoutBrowser) || CurrentPageType == typeof(GridViewBrowser);
201+
202+
if (tabInstance && e.Key == (VirtualKey)192 && ctrlPressed) // VirtualKey for ` (accent key)
203+
{
204+
string path;
205+
// Check if there is a folder selected, if not use the current directory.
206+
if (SlimContentPage?.SelectedItem is not null &&
207+
SlimContentPage?.SelectedItem.PrimaryItemAttribute == StorageItemTypes.Folder)
208+
{
209+
path = SlimContentPage.SelectedItem.ItemPath;
210+
}
211+
else
212+
{
213+
path = FilesystemViewModel.WorkingDirectory;
214+
}
215+
216+
await NavigationHelpers.OpenDirectoryInTerminal(path);
217+
e.Handled = true;
218+
}
193219
}
194220

195221
private async void ColumnShellPage_ToolbarPathItemLoaded(object sender, ToolbarPathItemLoadedEventArgs e)
@@ -848,6 +874,7 @@ private void SelectSidebarItemFromPath(Type incomingSourcePageType = null)
848874

849875
public void Dispose()
850876
{
877+
PreviewKeyDown -= ColumnShellPage_PreviewKeyDown;
851878
Window.Current.CoreWindow.PointerPressed -= CoreWindow_PointerPressed;
852879
SystemNavigationManager.GetForCurrentView().BackRequested -= ColumnShellPage_BackRequested;
853880
App.DrivesManager.PropertyChanged -= DrivesManager_PropertyChanged;

src/Files/Views/ModernShellPage.xaml.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,32 @@ public ModernShellPage()
185185
SystemNavigationManager.GetForCurrentView().BackRequested += ModernShellPage_BackRequested;
186186

187187
App.DrivesManager.PropertyChanged += DrivesManager_PropertyChanged;
188+
189+
PreviewKeyDown += ModernShellPage_PreviewKeyDown;
190+
}
191+
192+
private async void ModernShellPage_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
193+
{
194+
var ctrlPressed = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);
195+
var tabInstance = CurrentPageType == typeof(DetailsLayoutBrowser) || CurrentPageType == typeof(GridViewBrowser);
196+
197+
if (tabInstance && e.Key == (VirtualKey)192 && ctrlPressed) // VirtualKey for ` (accent key)
198+
{
199+
string path;
200+
// Check if there is a folder selected, if not use the current directory.
201+
if (SlimContentPage?.SelectedItem is not null &&
202+
SlimContentPage?.SelectedItem.PrimaryItemAttribute == StorageItemTypes.Folder)
203+
{
204+
path = SlimContentPage.SelectedItem.ItemPath;
205+
}
206+
else
207+
{
208+
path = FilesystemViewModel.WorkingDirectory;
209+
}
210+
211+
await NavigationHelpers.OpenDirectoryInTerminal(path);
212+
e.Handled = true;
213+
}
188214
}
189215

190216
private void InitToolbarCommands()
@@ -957,6 +983,7 @@ private void SelectSidebarItemFromPath(Type incomingSourcePageType = null)
957983

958984
public void Dispose()
959985
{
986+
PreviewKeyDown -= ModernShellPage_PreviewKeyDown;
960987
Window.Current.CoreWindow.PointerPressed -= CoreWindow_PointerPressed;
961988
SystemNavigationManager.GetForCurrentView().BackRequested -= ModernShellPage_BackRequested;
962989
App.DrivesManager.PropertyChanged -= DrivesManager_PropertyChanged;

0 commit comments

Comments
 (0)