feature: double-click on single-selecte change tree or file tree will expand/collapse folder node

This commit is contained in:
leo 2024-05-29 20:48:51 +08:00
parent cce4e5348c
commit 9d13b17aaf
8 changed files with 70 additions and 12 deletions

View file

@ -171,22 +171,27 @@ namespace SourceGit.Models
if (!IsSelected(modelIndex)) if (!IsSelected(modelIndex))
{ {
PointerSelect(sender, row, e); PointerSelect(sender, row, e);
_pressedPoint = s_InvalidPoint;
} }
else else
{ {
var point = e.GetCurrentPoint(sender); var point = e.GetCurrentPoint(sender);
if (point.Properties.IsRightButtonPressed) if (point.Properties.IsRightButtonPressed)
{
_pressedPoint = s_InvalidPoint;
return; return;
}
if (e.KeyModifiers == KeyModifiers.Control) if (e.KeyModifiers == KeyModifiers.Control)
{ {
Deselect(modelIndex); Deselect(modelIndex);
} }
else if (e.ClickCount == 2) else if (e.ClickCount % 2 == 0)
{ {
_rowDoubleTapped?.Invoke(this, e); _rowDoubleTapped?.Invoke(this, e);
e.Handled = true;
} }
else else if (sender.RowSelection.Count > 1)
{ {
using (BatchUpdate()) using (BatchUpdate())
{ {
@ -194,10 +199,10 @@ namespace SourceGit.Models
Select(modelIndex); Select(modelIndex);
} }
} }
}
_pressedPoint = s_InvalidPoint; _pressedPoint = s_InvalidPoint;
} }
}
else else
{ {
if (!sender.TryGetRow(e.Source as Control, out var test)) if (!sender.TryGetRow(e.Source as Control, out var test))

View file

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>WinExe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport> <BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>App.manifest</ApplicationManifest> <ApplicationManifest>App.manifest</ApplicationManifest>

View file

@ -511,14 +511,22 @@ namespace SourceGit.ViewModels
} }
}; };
source.Selection = new Models.TreeDataGridSelectionModel<FileTreeNode>(source, x => x.Children); var selection = new Models.TreeDataGridSelectionModel<FileTreeNode>(source, x => x.Children);
source.RowSelection.SingleSelect = true; selection.SingleSelect = true;
source.RowSelection.SelectionChanged += (s, _) => selection.RowDoubleTapped += (s, e) =>
{
var model = s as Models.TreeDataGridSelectionModel<FileTreeNode>;
var node = model.SelectedItem;
if (node != null && node.IsFolder)
node.IsExpanded = !node.IsExpanded;
};
selection.SelectionChanged += (s, _) =>
{ {
if (s is Models.TreeDataGridSelectionModel<FileTreeNode> selection) if (s is Models.TreeDataGridSelectionModel<FileTreeNode> selection)
RefreshViewRevisionFile(selection.SelectedItem?.Backend as Models.Object); RefreshViewRevisionFile(selection.SelectedItem?.Backend as Models.Object);
}; };
source.Selection = selection;
RevisionFiles = source; RevisionFiles = source;
} }

View file

@ -50,7 +50,14 @@
ViewMode="{Binding Source={x:Static vm:Preference.Instance}, Path=CommitChangeViewMode}" ViewMode="{Binding Source={x:Static vm:Preference.Instance}, Path=CommitChangeViewMode}"
Changes="{Binding VisibleChanges}" Changes="{Binding VisibleChanges}"
SelectedChanges="{Binding SelectedChanges, Mode=TwoWay}" SelectedChanges="{Binding SelectedChanges, Mode=TwoWay}"
ContextRequested="OnChangeContextRequested"/> ContextRequested="OnChangeContextRequested"
ChangeDoubleTapped="OnChangeDoubleTapped">
<v:ChangeCollectionView.Styles>
<Style Selector="TreeDataGridExpanderCell" x:DataType="vm:FileTreeNode">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
</Style>
</v:ChangeCollectionView.Styles>
</v:ChangeCollectionView>
</Border> </Border>
</Grid> </Grid>

View file

@ -1,5 +1,5 @@
using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Interactivity;
namespace SourceGit.Views namespace SourceGit.Views
{ {
@ -24,5 +24,17 @@ namespace SourceGit.Views
e.Handled = true; 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;
}
} }
} }

View file

@ -105,7 +105,14 @@
ViewMode="{Binding Source={x:Static vm:Preference.Instance}, Path=CommitChangeViewMode}" ViewMode="{Binding Source={x:Static vm:Preference.Instance}, Path=CommitChangeViewMode}"
Changes="{Binding VisibleChanges}" Changes="{Binding VisibleChanges}"
SelectedChanges="{Binding SelectedChanges, Mode=TwoWay}" SelectedChanges="{Binding SelectedChanges, Mode=TwoWay}"
ContextRequested="OnChangeContextRequested"/> ContextRequested="OnChangeContextRequested"
ChangeDoubleTapped="OnChangeDoubleTapped">
<v:ChangeCollectionView.Styles>
<Style Selector="TreeDataGridExpanderCell" x:DataType="vm:FileTreeNode">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
</Style>
</v:ChangeCollectionView.Styles>
</v:ChangeCollectionView>
</Border> </Border>
</Grid> </Grid>

View file

@ -1,5 +1,6 @@
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Interactivity;
namespace SourceGit.Views namespace SourceGit.Views
{ {
@ -21,6 +22,18 @@ namespace SourceGit.Views
e.Handled = true; 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) private void OnPressedSHA(object sender, PointerPressedEventArgs e)
{ {
if (DataContext is ViewModels.RevisionCompare vm && sender is TextBlock block) if (DataContext is ViewModels.RevisionCompare vm && sender is TextBlock block)

View file

@ -56,6 +56,12 @@
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</TreeDataGrid.Resources> </TreeDataGrid.Resources>
<TreeDataGrid.Styles>
<Style Selector="TreeDataGridExpanderCell" x:DataType="vm:FileTreeNode">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
</Style>
</TreeDataGrid.Styles>
</TreeDataGrid> </TreeDataGrid>
</Border> </Border>
</Grid> </Grid>