mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-16 16:05:00 +00:00
feature: support delete key everywhere (#1412)
This commit is contained in:
parent
5494093261
commit
196b454ae8
11 changed files with 127 additions and 11 deletions
|
@ -1359,6 +1359,18 @@ namespace SourceGit.ViewModels
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
public void DeleteMultipleBranches(List<Models.Branch> branches, bool isLocal)
|
||||||
{
|
{
|
||||||
if (CanCreatePopup())
|
if (CanCreatePopup())
|
||||||
|
@ -1383,6 +1395,12 @@ namespace SourceGit.ViewModels
|
||||||
ShowPopup(new CreateTag(this, _currentBranch));
|
ShowPopup(new CreateTag(this, _currentBranch));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void DeleteTag(Models.Tag tag)
|
||||||
|
{
|
||||||
|
if (CanCreatePopup())
|
||||||
|
ShowPopup(new DeleteTag(this, tag));
|
||||||
|
}
|
||||||
|
|
||||||
public void AddRemote()
|
public void AddRemote()
|
||||||
{
|
{
|
||||||
if (CanCreatePopup())
|
if (CanCreatePopup())
|
||||||
|
|
|
@ -314,6 +314,12 @@ namespace SourceGit.ViewModels
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Drop(Models.Stash stash)
|
||||||
|
{
|
||||||
|
if (_repo.CanCreatePopup())
|
||||||
|
_repo.ShowPopup(new DropStash(_repo, stash));
|
||||||
|
}
|
||||||
|
|
||||||
private Repository _repo = null;
|
private Repository _repo = null;
|
||||||
private List<Models.Stash> _stashes = [];
|
private List<Models.Stash> _stashes = [];
|
||||||
private List<Models.Stash> _visibleStashes = [];
|
private List<Models.Stash> _visibleStashes = [];
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
ItemsSource="{Binding #ThisControl.Rows}"
|
ItemsSource="{Binding #ThisControl.Rows}"
|
||||||
SelectionMode="Multiple"
|
SelectionMode="Multiple"
|
||||||
SelectionChanged="OnNodesSelectionChanged"
|
SelectionChanged="OnNodesSelectionChanged"
|
||||||
|
KeyDown="OnListKeyDown"
|
||||||
ContextRequested="OnTreeContextRequested">
|
ContextRequested="OnTreeContextRequested">
|
||||||
<ListBox.ItemsPanel>
|
<ListBox.ItemsPanel>
|
||||||
<ItemsPanelTemplate>
|
<ItemsPanelTemplate>
|
||||||
|
|
|
@ -450,6 +450,44 @@ namespace SourceGit.Views
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 _)
|
private void OnDoubleTappedBranchNode(object sender, TappedEventArgs _)
|
||||||
{
|
{
|
||||||
if (sender is Grid { DataContext: ViewModels.BranchTreeNode node })
|
if (sender is Grid { DataContext: ViewModels.BranchTreeNode node })
|
||||||
|
|
|
@ -65,6 +65,7 @@
|
||||||
ItemsSource="{Binding VisibleStashes}"
|
ItemsSource="{Binding VisibleStashes}"
|
||||||
SelectedItem="{Binding SelectedStash, Mode=TwoWay}"
|
SelectedItem="{Binding SelectedStash, Mode=TwoWay}"
|
||||||
SelectionMode="Single"
|
SelectionMode="Single"
|
||||||
|
KeyDown="OnStashKeyDown"
|
||||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||||
ScrollViewer.VerticalScrollBarVisibility="Auto">
|
ScrollViewer.VerticalScrollBarVisibility="Auto">
|
||||||
<ListBox.Styles>
|
<ListBox.Styles>
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Input;
|
||||||
|
|
||||||
namespace SourceGit.Views
|
namespace SourceGit.Views
|
||||||
{
|
{
|
||||||
|
@ -33,6 +34,21 @@ namespace SourceGit.Views
|
||||||
e.Handled = true;
|
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)
|
private void OnChangeContextRequested(object sender, ContextRequestedEventArgs e)
|
||||||
{
|
{
|
||||||
if (DataContext is ViewModels.StashesPage vm && sender is Grid grid)
|
if (DataContext is ViewModels.StashesPage vm && sender is Grid grid)
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
<ListBox Classes="repo_left_content_list"
|
<ListBox Classes="repo_left_content_list"
|
||||||
ItemsSource="{Binding Rows}"
|
ItemsSource="{Binding Rows}"
|
||||||
SelectionMode="Single"
|
SelectionMode="Single"
|
||||||
|
KeyDown="OnKeyDown"
|
||||||
SelectionChanged="OnSelectionChanged">
|
SelectionChanged="OnSelectionChanged">
|
||||||
|
|
||||||
<ListBox.DataTemplates>
|
<ListBox.DataTemplates>
|
||||||
|
@ -88,6 +89,7 @@
|
||||||
Margin="8,0,0,0"
|
Margin="8,0,0,0"
|
||||||
ItemsSource="{Binding Tags}"
|
ItemsSource="{Binding Tags}"
|
||||||
SelectionMode="Single"
|
SelectionMode="Single"
|
||||||
|
KeyDown="OnKeyDown"
|
||||||
SelectionChanged="OnSelectionChanged">
|
SelectionChanged="OnSelectionChanged">
|
||||||
<ListBox.ItemTemplate>
|
<ListBox.ItemTemplate>
|
||||||
<DataTemplate DataType="m:Tag">
|
<DataTemplate DataType="m:Tag">
|
||||||
|
|
|
@ -214,6 +214,18 @@ namespace SourceGit.Views
|
||||||
if (selectedTag != null)
|
if (selectedTag != null)
|
||||||
RaiseEvent(new RoutedEventArgs(SelectionChangedEvent));
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,7 @@
|
||||||
ItemsSource="{Binding Logs}"
|
ItemsSource="{Binding Logs}"
|
||||||
SelectedItem="{Binding SelectedLog, Mode=TwoWay}"
|
SelectedItem="{Binding SelectedLog, Mode=TwoWay}"
|
||||||
SelectionMode="Single"
|
SelectionMode="Single"
|
||||||
|
KeyDown="OnLogKeyDown"
|
||||||
Grid.IsSharedSizeScope="True"
|
Grid.IsSharedSizeScope="True"
|
||||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
|
||||||
ScrollViewer.VerticalScrollBarVisibility="Auto">
|
ScrollViewer.VerticalScrollBarVisibility="Auto">
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Input;
|
||||||
|
|
||||||
namespace SourceGit.Views
|
namespace SourceGit.Views
|
||||||
{
|
{
|
||||||
|
@ -39,5 +40,17 @@ namespace SourceGit.Views
|
||||||
|
|
||||||
e.Handled = true;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,20 +94,28 @@ namespace SourceGit.Views
|
||||||
|
|
||||||
private void OnTreeViewKeyDown(object _, KeyEventArgs e)
|
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 (node.IsRepository)
|
||||||
if (parent is { DataContext: ViewModels.Launcher launcher })
|
{
|
||||||
launcher.OpenRepositoryInTab(node, null);
|
var parent = this.FindAncestorOfType<Launcher>();
|
||||||
}
|
if (parent is { DataContext: ViewModels.Launcher launcher })
|
||||||
else
|
launcher.OpenRepositoryInTab(node, null);
|
||||||
{
|
}
|
||||||
ViewModels.Welcome.Instance.ToggleNodeIsExpanded(node);
|
else
|
||||||
}
|
{
|
||||||
|
ViewModels.Welcome.Instance.ToggleNodeIsExpanded(node);
|
||||||
|
}
|
||||||
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
|
}
|
||||||
|
else if (e.Key is Key.Delete or Key.Back)
|
||||||
|
{
|
||||||
|
node.Delete();
|
||||||
|
e.Handled = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue