Skip to content

Support Delete key everywhere #1412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/ViewModels/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,18 @@ public void CheckoutBranch(Models.Branch branch)
}
}

public void DeleteBranch(Models.Branch branch)
{
if (CanCreatePopup())
ShowPopup(new DeleteBranch(this, branch));
}

public void DeleteRemote(Models.Remote remote)
{
if (CanCreatePopup())
ShowPopup(new DeleteRemote(this, remote));
}

public void DeleteMultipleBranches(List<Models.Branch> branches, bool isLocal)
{
if (CanCreatePopup())
Expand All @@ -1382,6 +1394,12 @@ public void CreateNewTag()
ShowPopup(new CreateTag(this, _currentBranch));
}

public void DeleteTag(Models.Tag tag)
{
if (CanCreatePopup())
ShowPopup(new DeleteTag(this, tag));
}

public void AddRemote()
{
if (CanCreatePopup())
Expand Down
6 changes: 6 additions & 0 deletions src/ViewModels/StashesPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,12 @@ private void RefreshVisible()
}
}

public void Drop(Models.Stash stash)
{
if (_repo.CanCreatePopup())
_repo.ShowPopup(new DropStash(_repo, stash));
}

private Repository _repo = null;
private List<Models.Stash> _stashes = [];
private List<Models.Stash> _visibleStashes = [];
Expand Down
1 change: 1 addition & 0 deletions src/Views/BranchTree.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
ItemsSource="{Binding #ThisControl.Rows}"
SelectionMode="Multiple"
SelectionChanged="OnNodesSelectionChanged"
KeyDown="OnListKeyDown"
ContextRequested="OnTreeContextRequested">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
Expand Down
38 changes: 38 additions & 0 deletions src/Views/BranchTree.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,44 @@ private void OnTreeContextRequested(object _1, ContextRequestedEventArgs _2)
}
}

private void OnListKeyDown(object _, KeyEventArgs e)
{
if (e.Key is not (Key.Delete or Key.Back))
return;

var repo = DataContext as ViewModels.Repository;
if (repo?.Settings == null)
return;

var selected = BranchesPresenter.SelectedItems;
if (selected == null || selected.Count == 0)
return;

if (selected is [ViewModels.BranchTreeNode { Backend: Models.Remote remote }])
{
repo.DeleteRemote(remote);
e.Handled = true;
return;
}

var branches = new List<Models.Branch>();
foreach (var item in selected)
{
if (item is ViewModels.BranchTreeNode node)
CollectBranchesInNode(branches, node);
}

if (branches.Find(x => x.IsCurrent) != null)
return;

if (branches.Count == 1)
repo.DeleteBranch(branches[0]);
else
repo.DeleteMultipleBranches(branches, branches[0].IsLocal);

e.Handled = true;
}

private void OnDoubleTappedBranchNode(object sender, TappedEventArgs _)
{
if (sender is Grid { DataContext: ViewModels.BranchTreeNode node })
Expand Down
1 change: 1 addition & 0 deletions src/Views/StashesPage.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
ItemsSource="{Binding VisibleStashes}"
SelectedItem="{Binding SelectedStash, Mode=TwoWay}"
SelectionMode="Single"
KeyDown="OnStashKeyDown"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Auto">
<ListBox.Styles>
Expand Down
16 changes: 16 additions & 0 deletions src/Views/StashesPage.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Avalonia.Controls;
using Avalonia.Input;

namespace SourceGit.Views
{
Expand Down Expand Up @@ -33,6 +34,21 @@ private void OnStashContextRequested(object sender, ContextRequestedEventArgs e)
e.Handled = true;
}

private void OnStashKeyDown(object sender, KeyEventArgs e)
{
if (e.Key is not (Key.Delete or Key.Back))
return;

if (DataContext is not ViewModels.StashesPage vm)
return;

if (sender is not ListBox { SelectedValue: Models.Stash stash })
return;

vm.Drop(stash);
e.Handled = true;
}

private void OnChangeContextRequested(object sender, ContextRequestedEventArgs e)
{
if (DataContext is ViewModels.StashesPage vm && sender is Grid grid)
Expand Down
2 changes: 2 additions & 0 deletions src/Views/TagsView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<ListBox Classes="repo_left_content_list"
ItemsSource="{Binding Rows}"
SelectionMode="Single"
KeyDown="OnKeyDown"
SelectionChanged="OnSelectionChanged">

<ListBox.DataTemplates>
Expand Down Expand Up @@ -88,6 +89,7 @@
Margin="8,0,0,0"
ItemsSource="{Binding Tags}"
SelectionMode="Single"
KeyDown="OnKeyDown"
SelectionChanged="OnSelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate DataType="m:Tag">
Expand Down
12 changes: 12 additions & 0 deletions src/Views/TagsView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,18 @@ private void OnSelectionChanged(object sender, SelectionChangedEventArgs _)
if (selectedTag != null)
RaiseEvent(new RoutedEventArgs(SelectionChangedEvent));
}

private void OnKeyDown(object sender, KeyEventArgs e)
{
if (sender is not ListBox { SelectedValue: Models.Tag tag })
return;

if (DataContext is not ViewModels.Repository repo)
return;

repo.DeleteTag(tag);
e.Handled = true;
}
}
}

1 change: 1 addition & 0 deletions src/Views/ViewLogs.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
ItemsSource="{Binding Logs}"
SelectedItem="{Binding SelectedLog, Mode=TwoWay}"
SelectionMode="Single"
KeyDown="OnLogKeyDown"
Grid.IsSharedSizeScope="True"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Auto">
Expand Down
13 changes: 13 additions & 0 deletions src/Views/ViewLogs.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Avalonia.Controls;
using Avalonia.Input;

namespace SourceGit.Views
{
Expand Down Expand Up @@ -39,5 +40,17 @@ private void OnLogContextRequested(object sender, ContextRequestedEventArgs e)

e.Handled = true;
}

private void OnLogKeyDown(object _, KeyEventArgs e)
{
if (e.Key is not (Key.Delete or Key.Back))
return;

if (DataContext is not ViewModels.ViewLogs vm)
return;

vm.Logs.Remove(vm.SelectedLog);
e.Handled = true;
}
}
}
26 changes: 17 additions & 9 deletions src/Views/Welcome.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,28 @@ private void SetupTreeNodeDragAndDrop(object sender, RoutedEventArgs _)

private void OnTreeViewKeyDown(object _, KeyEventArgs e)
{
if (TreeContainer.SelectedItem is ViewModels.RepositoryNode node && e.Key == Key.Enter)
if (TreeContainer.SelectedItem is ViewModels.RepositoryNode node)
{
if (node.IsRepository)
if (e.Key == Key.Enter)
{
var parent = this.FindAncestorOfType<Launcher>();
if (parent is { DataContext: ViewModels.Launcher launcher })
launcher.OpenRepositoryInTab(node, null);
if (node.IsRepository)
{
var parent = this.FindAncestorOfType<Launcher>();
if (parent is { DataContext: ViewModels.Launcher launcher })
launcher.OpenRepositoryInTab(node, null);
}
else
{
ViewModels.Welcome.Instance.ToggleNodeIsExpanded(node);
}

e.Handled = true;
}
else
else if (e.Key is Key.Delete or Key.Back)
{
ViewModels.Welcome.Instance.ToggleNodeIsExpanded(node);
node.Delete();
e.Handled = true;
}

e.Handled = true;
}
}

Expand Down
Loading