mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 04:04:59 +00:00
refactor: use PointerPressed
event instead of ListBox.SelectionChanged
event to navigate to commit (#1230)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
345ad06aba
commit
7890f7abbf
4 changed files with 133 additions and 101 deletions
|
@ -32,6 +32,7 @@
|
||||||
|
|
||||||
<ListBox.ItemTemplate>
|
<ListBox.ItemTemplate>
|
||||||
<DataTemplate DataType="vm:BranchTreeNode">
|
<DataTemplate DataType="vm:BranchTreeNode">
|
||||||
|
<Border Background="Transparent" PointerPressed="OnNodePointerPressed">
|
||||||
<Grid Height="24"
|
<Grid Height="24"
|
||||||
Margin="{Binding Depth, Converter={x:Static c:IntConverters.ToTreeMargin}}"
|
Margin="{Binding Depth, Converter={x:Static c:IntConverters.ToTreeMargin}}"
|
||||||
ColumnDefinitions="16,*"
|
ColumnDefinitions="16,*"
|
||||||
|
@ -87,6 +88,7 @@
|
||||||
Mode="{Binding FilterMode}"/>
|
Mode="{Binding FilterMode}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
</Border>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ListBox.ItemTemplate>
|
</ListBox.ItemTemplate>
|
||||||
</ListBox>
|
</ListBox>
|
||||||
|
|
|
@ -318,6 +318,31 @@ namespace SourceGit.Views
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnNodePointerPressed(object sender, PointerPressedEventArgs e)
|
||||||
|
{
|
||||||
|
var p = e.GetCurrentPoint(this);
|
||||||
|
if (!p.Properties.IsLeftButtonPressed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (DataContext is not ViewModels.Repository repo)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (sender is not Border { DataContext: ViewModels.BranchTreeNode node })
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (node.Backend is not Models.Branch branch)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (BranchesPresenter.SelectedItems is { Count: > 0 })
|
||||||
|
{
|
||||||
|
var ctrl = OperatingSystem.IsMacOS() ? KeyModifiers.Meta : KeyModifiers.Control;
|
||||||
|
if (e.KeyModifiers.HasFlag(ctrl) || e.KeyModifiers.HasFlag(KeyModifiers.Shift))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
repo.NavigateToCommit(branch.Head);
|
||||||
|
}
|
||||||
|
|
||||||
private void OnNodesSelectionChanged(object _, SelectionChangedEventArgs e)
|
private void OnNodesSelectionChanged(object _, SelectionChangedEventArgs e)
|
||||||
{
|
{
|
||||||
if (_disableSelectionChangingEvent)
|
if (_disableSelectionChangingEvent)
|
||||||
|
@ -343,9 +368,6 @@ namespace SourceGit.Views
|
||||||
if (selected == null || selected.Count == 0)
|
if (selected == null || selected.Count == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (selected.Count == 1 && selected[0] is ViewModels.BranchTreeNode { Backend: Models.Branch branch })
|
|
||||||
repo.NavigateToCommit(branch.Head);
|
|
||||||
|
|
||||||
var prev = null as ViewModels.BranchTreeNode;
|
var prev = null as ViewModels.BranchTreeNode;
|
||||||
foreach (var row in Rows)
|
foreach (var row in Rows)
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,11 +26,10 @@
|
||||||
SelectionChanged="OnRowSelectionChanged">
|
SelectionChanged="OnRowSelectionChanged">
|
||||||
<ListBox.ItemTemplate>
|
<ListBox.ItemTemplate>
|
||||||
<DataTemplate DataType="vm:TagTreeNode">
|
<DataTemplate DataType="vm:TagTreeNode">
|
||||||
|
<Border Height="24" Background="Transparent" PointerPressed="OnRowPointerPressed" DoubleTapped="OnDoubleTappedNode" ContextRequested="OnRowContextRequested">
|
||||||
<Grid ColumnDefinitions="16,Auto,*,Auto"
|
<Grid ColumnDefinitions="16,Auto,*,Auto"
|
||||||
Margin="{Binding Depth, Converter={x:Static c:IntConverters.ToTreeMargin}}"
|
Margin="{Binding Depth, Converter={x:Static c:IntConverters.ToTreeMargin}}"
|
||||||
Background="Transparent"
|
VerticalAlignment="Center"
|
||||||
ContextRequested="OnRowContextRequested"
|
|
||||||
DoubleTapped="OnDoubleTappedNode"
|
|
||||||
ToolTip.Tip="{Binding ToolTip}">
|
ToolTip.Tip="{Binding ToolTip}">
|
||||||
<v:TagTreeNodeToggleButton Grid.Column="0"
|
<v:TagTreeNodeToggleButton Grid.Column="0"
|
||||||
Classes="tree_expander"
|
Classes="tree_expander"
|
||||||
|
@ -56,6 +55,7 @@
|
||||||
</ContentControl.DataTemplates>
|
</ContentControl.DataTemplates>
|
||||||
</ContentControl>
|
</ContentControl>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
</Border>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ListBox.ItemTemplate>
|
</ListBox.ItemTemplate>
|
||||||
</ListBox>
|
</ListBox>
|
||||||
|
@ -69,10 +69,8 @@
|
||||||
SelectionChanged="OnRowSelectionChanged">
|
SelectionChanged="OnRowSelectionChanged">
|
||||||
<ListBox.ItemTemplate>
|
<ListBox.ItemTemplate>
|
||||||
<DataTemplate DataType="m:Tag">
|
<DataTemplate DataType="m:Tag">
|
||||||
<Grid ColumnDefinitions="Auto,*,Auto"
|
<Border Height="24" Background="Transparent" PointerPressed="OnRowPointerPressed" ContextRequested="OnRowContextRequested">
|
||||||
Background="Transparent"
|
<Grid ColumnDefinitions="Auto,*,Auto" VerticalAlignment="Center" ToolTip.Tip="{Binding Message}">
|
||||||
ContextRequested="OnRowContextRequested"
|
|
||||||
ToolTip.Tip="{Binding Message}">
|
|
||||||
<Path Grid.Column="0"
|
<Path Grid.Column="0"
|
||||||
Margin="8,0,0,0"
|
Margin="8,0,0,0"
|
||||||
Width="12" Height="12"
|
Width="12" Height="12"
|
||||||
|
@ -86,6 +84,7 @@
|
||||||
|
|
||||||
<v:FilterModeSwitchButton Grid.Column="2" Margin="0,0,12,0" Mode="{Binding FilterMode}"/>
|
<v:FilterModeSwitchButton Grid.Column="2" Margin="0,0,12,0" Mode="{Binding FilterMode}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
</Border>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ListBox.ItemTemplate>
|
</ListBox.ItemTemplate>
|
||||||
</ListBox>
|
</ListBox>
|
||||||
|
|
|
@ -199,15 +199,27 @@ namespace SourceGit.Views
|
||||||
|
|
||||||
private void OnDoubleTappedNode(object sender, TappedEventArgs e)
|
private void OnDoubleTappedNode(object sender, TappedEventArgs e)
|
||||||
{
|
{
|
||||||
if (sender is Grid { DataContext: ViewModels.TagTreeNode node })
|
if (sender is Control { DataContext: ViewModels.TagTreeNode { IsFolder: true } node })
|
||||||
{
|
|
||||||
if (node.IsFolder)
|
|
||||||
ToggleNodeIsExpanded(node);
|
ToggleNodeIsExpanded(node);
|
||||||
}
|
|
||||||
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnRowPointerPressed(object sender, PointerPressedEventArgs e)
|
||||||
|
{
|
||||||
|
var p = e.GetCurrentPoint(this);
|
||||||
|
if (!p.Properties.IsLeftButtonPressed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (DataContext is not ViewModels.Repository repo)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (sender is Control { DataContext: Models.Tag tag })
|
||||||
|
repo.NavigateToCommit(tag.SHA);
|
||||||
|
else if (sender is Control { DataContext: ViewModels.TagTreeNode { Tag: { } nodeTag } })
|
||||||
|
repo.NavigateToCommit(nodeTag.SHA);
|
||||||
|
}
|
||||||
|
|
||||||
private void OnRowContextRequested(object sender, ContextRequestedEventArgs e)
|
private void OnRowContextRequested(object sender, ContextRequestedEventArgs e)
|
||||||
{
|
{
|
||||||
var control = sender as Control;
|
var control = sender as Control;
|
||||||
|
@ -240,11 +252,8 @@ namespace SourceGit.Views
|
||||||
else if (selected is Models.Tag tag)
|
else if (selected is Models.Tag tag)
|
||||||
selectedTag = tag;
|
selectedTag = tag;
|
||||||
|
|
||||||
if (selectedTag != null && DataContext is ViewModels.Repository repo)
|
if (selectedTag != null)
|
||||||
{
|
|
||||||
RaiseEvent(new RoutedEventArgs(SelectionChangedEvent));
|
RaiseEvent(new RoutedEventArgs(SelectionChangedEvent));
|
||||||
repo.NavigateToCommit(selectedTag.SHA);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MakeTreeRows(List<ViewModels.TagTreeNode> rows, List<ViewModels.TagTreeNode> nodes)
|
private void MakeTreeRows(List<ViewModels.TagTreeNode> rows, List<ViewModels.TagTreeNode> nodes)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue