Skip to content

Commit

Permalink
Merge pull request #87 from Diaskhan/dev/Enter_and_BackSpace_in_Filep…
Browse files Browse the repository at this point in the history
…anel

fix Enter and Backspace  Bahiouvr
  • Loading branch information
anovik authored Sep 13, 2024
2 parents f4ad480 + e01ad10 commit 3c636fe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/SmartCommander/ViewModels/FilesPaneViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,14 @@ public FilesPaneViewModel(MainWindowViewModel mainVM)
EditCommand = ReactiveCommand.Create(Edit);
ZipCommand = ReactiveCommand.Create(Zip);
UnzipCommand = ReactiveCommand.Create(Unzip);
FilesPaneEnterCommand = ReactiveCommand.Create(() => ProcessCurrentItem());
FilesPaneBackspaceCommand = ReactiveCommand.Create(() => ProcessCurrentItem(true));
ShowViewerDialog = new Interaction<ViewerViewModel, ViewerViewModel?>();
_mainVM = mainVM;
}

public ReactiveCommand<Unit, Unit>? EnterCommand { get; }
public ReactiveCommand<Unit, Unit>? FilesPaneEnterCommand { get; }
public ReactiveCommand<Unit, Unit>? FilesPaneBackspaceCommand { get; }
public ReactiveCommand<Unit, Unit>? ViewCommand { get; }
public ReactiveCommand<Unit, Unit>? EditCommand { get; }
public ReactiveCommand<Unit, Unit>? ZipCommand { get; }
Expand Down Expand Up @@ -377,12 +380,20 @@ public void CreateNewFolder(string name)
Directory.CreateDirectory(newFolder);
}

private void ProcessCurrentItem()
private void ProcessCurrentItem(bool goToParent = false)
{
if (CurrentItem == null)
{
return;
}

if (goToParent)
{
CurrentDirectory = Directory.GetParent(CurrentDirectory) != null ? Directory.GetParent(CurrentDirectory)!.FullName :
CurrentDirectory;
return;
}

if (CurrentItem.IsFolder)
{
if (CurrentItem.FullName == "..")
Expand Down
4 changes: 4 additions & 0 deletions src/SmartCommander/Views/FilesPane.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
<Setter Property="IsVisible" Value="False" />
</Style>
</DataGrid.Styles>
<DataGrid.KeyBindings>
<KeyBinding Gesture="Enter" Command="{Binding FilesPaneEnterCommand}" />
<KeyBinding Gesture="Back" Command="{Binding FilesPaneBackspaceCommand}"/>
</DataGrid.KeyBindings>
<DataGrid.ContextFlyout>
<MenuFlyout>
<MenuItem Header="{x:Static assets:Resources.View}" Command="{Binding ViewCommand}"></MenuItem>
Expand Down

0 comments on commit 3c636fe

Please sign in to comment.