From 9d13b17aafc84d62e47f16fdbfc30ba00b1f3710 Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 29 May 2024 20:48:51 +0800 Subject: [PATCH] feature: double-click on single-selecte change tree or file tree will expand/collapse folder node --- src/Models/TreeDataGridSelectionModel.cs | 13 +++++++++---- src/SourceGit.csproj | 2 +- src/ViewModels/CommitDetail.cs | 14 +++++++++++--- src/Views/CommitChanges.axaml | 9 ++++++++- src/Views/CommitChanges.axaml.cs | 16 ++++++++++++++-- src/Views/RevisionCompare.axaml | 9 ++++++++- src/Views/RevisionCompare.axaml.cs | 13 +++++++++++++ src/Views/RevisionFiles.axaml | 6 ++++++ 8 files changed, 70 insertions(+), 12 deletions(-) diff --git a/src/Models/TreeDataGridSelectionModel.cs b/src/Models/TreeDataGridSelectionModel.cs index 071d3414..efdda2a4 100644 --- a/src/Models/TreeDataGridSelectionModel.cs +++ b/src/Models/TreeDataGridSelectionModel.cs @@ -171,22 +171,27 @@ namespace SourceGit.Models if (!IsSelected(modelIndex)) { PointerSelect(sender, row, e); + _pressedPoint = s_InvalidPoint; } else { var point = e.GetCurrentPoint(sender); if (point.Properties.IsRightButtonPressed) + { + _pressedPoint = s_InvalidPoint; return; + } if (e.KeyModifiers == KeyModifiers.Control) { Deselect(modelIndex); } - else if (e.ClickCount == 2) + else if (e.ClickCount % 2 == 0) { _rowDoubleTapped?.Invoke(this, e); + e.Handled = true; } - else + else if (sender.RowSelection.Count > 1) { using (BatchUpdate()) { @@ -194,9 +199,9 @@ namespace SourceGit.Models Select(modelIndex); } } + + _pressedPoint = s_InvalidPoint; } - - _pressedPoint = s_InvalidPoint; } else { diff --git a/src/SourceGit.csproj b/src/SourceGit.csproj index a3d38391..2830712a 100644 --- a/src/SourceGit.csproj +++ b/src/SourceGit.csproj @@ -1,6 +1,6 @@  - WinExe + Exe net8.0 true App.manifest diff --git a/src/ViewModels/CommitDetail.cs b/src/ViewModels/CommitDetail.cs index 9fd320fd..b4a1fadf 100644 --- a/src/ViewModels/CommitDetail.cs +++ b/src/ViewModels/CommitDetail.cs @@ -511,14 +511,22 @@ namespace SourceGit.ViewModels } }; - source.Selection = new Models.TreeDataGridSelectionModel(source, x => x.Children); - source.RowSelection.SingleSelect = true; - source.RowSelection.SelectionChanged += (s, _) => + var selection = new Models.TreeDataGridSelectionModel(source, x => x.Children); + selection.SingleSelect = true; + selection.RowDoubleTapped += (s, e) => + { + var model = s as Models.TreeDataGridSelectionModel; + var node = model.SelectedItem; + if (node != null && node.IsFolder) + node.IsExpanded = !node.IsExpanded; + }; + selection.SelectionChanged += (s, _) => { if (s is Models.TreeDataGridSelectionModel selection) RefreshViewRevisionFile(selection.SelectedItem?.Backend as Models.Object); }; + source.Selection = selection; RevisionFiles = source; } diff --git a/src/Views/CommitChanges.axaml b/src/Views/CommitChanges.axaml index eccd0952..78c6bdb8 100644 --- a/src/Views/CommitChanges.axaml +++ b/src/Views/CommitChanges.axaml @@ -50,7 +50,14 @@ ViewMode="{Binding Source={x:Static vm:Preference.Instance}, Path=CommitChangeViewMode}" Changes="{Binding VisibleChanges}" SelectedChanges="{Binding SelectedChanges, Mode=TwoWay}" - ContextRequested="OnChangeContextRequested"/> + ContextRequested="OnChangeContextRequested" + ChangeDoubleTapped="OnChangeDoubleTapped"> + + + + diff --git a/src/Views/CommitChanges.axaml.cs b/src/Views/CommitChanges.axaml.cs index d9ac6c2e..f1d7633f 100644 --- a/src/Views/CommitChanges.axaml.cs +++ b/src/Views/CommitChanges.axaml.cs @@ -1,5 +1,5 @@ -using Avalonia; using Avalonia.Controls; +using Avalonia.Interactivity; namespace SourceGit.Views { @@ -19,7 +19,19 @@ namespace SourceGit.Views { var menu = vm.CreateChangeContextMenu(selected[0]); (sender as Control)?.OpenContextMenu(menu); - } + } + } + + e.Handled = true; + } + + private void OnChangeDoubleTapped(object sender, RoutedEventArgs e) + { + if (sender is ChangeCollectionView view) + { + var selected = view.tree?.RowSelection?.SelectedItem as ViewModels.FileTreeNode; + if (selected != null && selected.IsFolder) + selected.IsExpanded = !selected.IsExpanded; } e.Handled = true; diff --git a/src/Views/RevisionCompare.axaml b/src/Views/RevisionCompare.axaml index 9411c174..5e7d2ee1 100644 --- a/src/Views/RevisionCompare.axaml +++ b/src/Views/RevisionCompare.axaml @@ -105,7 +105,14 @@ ViewMode="{Binding Source={x:Static vm:Preference.Instance}, Path=CommitChangeViewMode}" Changes="{Binding VisibleChanges}" SelectedChanges="{Binding SelectedChanges, Mode=TwoWay}" - ContextRequested="OnChangeContextRequested"/> + ContextRequested="OnChangeContextRequested" + ChangeDoubleTapped="OnChangeDoubleTapped"> + + + + diff --git a/src/Views/RevisionCompare.axaml.cs b/src/Views/RevisionCompare.axaml.cs index e3ecb2b7..a7066639 100644 --- a/src/Views/RevisionCompare.axaml.cs +++ b/src/Views/RevisionCompare.axaml.cs @@ -1,5 +1,6 @@ using Avalonia.Controls; using Avalonia.Input; +using Avalonia.Interactivity; namespace SourceGit.Views { @@ -21,6 +22,18 @@ namespace SourceGit.Views e.Handled = true; } + private void OnChangeDoubleTapped(object sender, RoutedEventArgs e) + { + if (sender is ChangeCollectionView view) + { + var selected = view.tree?.RowSelection?.SelectedItem as ViewModels.FileTreeNode; + if (selected != null && selected.IsFolder) + selected.IsExpanded = !selected.IsExpanded; + } + + e.Handled = true; + } + private void OnPressedSHA(object sender, PointerPressedEventArgs e) { if (DataContext is ViewModels.RevisionCompare vm && sender is TextBlock block) diff --git a/src/Views/RevisionFiles.axaml b/src/Views/RevisionFiles.axaml index c46632f6..ea98bef2 100644 --- a/src/Views/RevisionFiles.axaml +++ b/src/Views/RevisionFiles.axaml @@ -56,6 +56,12 @@ + + + +