mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-20 11:44: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,61 +32,63 @@
|
|||
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate DataType="vm:BranchTreeNode">
|
||||
<Grid Height="24"
|
||||
Margin="{Binding Depth, Converter={x:Static c:IntConverters.ToTreeMargin}}"
|
||||
ColumnDefinitions="16,*"
|
||||
ToolTip.Tip="{Binding Tooltip}">
|
||||
<Border Background="Transparent" PointerPressed="OnNodePointerPressed">
|
||||
<Grid Height="24"
|
||||
Margin="{Binding Depth, Converter={x:Static c:IntConverters.ToTreeMargin}}"
|
||||
ColumnDefinitions="16,*"
|
||||
ToolTip.Tip="{Binding Tooltip}">
|
||||
|
||||
<!-- Tree Expander -->
|
||||
<v:BranchTreeNodeToggleButton Grid.Column="0"
|
||||
Classes="tree_expander"
|
||||
Focusable="False"
|
||||
HorizontalAlignment="Center"
|
||||
IsChecked="{Binding IsExpanded, Mode=OneWay}"
|
||||
IsVisible="{Binding !IsBranch}"/>
|
||||
<!-- Tree Expander -->
|
||||
<v:BranchTreeNodeToggleButton Grid.Column="0"
|
||||
Classes="tree_expander"
|
||||
Focusable="False"
|
||||
HorizontalAlignment="Center"
|
||||
IsChecked="{Binding IsExpanded, Mode=OneWay}"
|
||||
IsVisible="{Binding !IsBranch}"/>
|
||||
|
||||
<!-- Content Area (allows double-click) -->
|
||||
<Grid Grid.Column="1"
|
||||
Background="Transparent"
|
||||
ColumnDefinitions="18,*,Auto,Auto"
|
||||
DoubleTapped="OnDoubleTappedBranchNode">
|
||||
<!-- Content Area (allows double-click) -->
|
||||
<Grid Grid.Column="1"
|
||||
Background="Transparent"
|
||||
ColumnDefinitions="18,*,Auto,Auto"
|
||||
DoubleTapped="OnDoubleTappedBranchNode">
|
||||
|
||||
<!-- Icon -->
|
||||
<v:BranchTreeNodeIcon Grid.Column="0"
|
||||
Node="{Binding}"
|
||||
IsExpanded="{Binding IsExpanded}"/>
|
||||
<!-- Icon -->
|
||||
<v:BranchTreeNodeIcon Grid.Column="0"
|
||||
Node="{Binding}"
|
||||
IsExpanded="{Binding IsExpanded}"/>
|
||||
|
||||
<!-- Name -->
|
||||
<TextBlock Grid.Column="1"
|
||||
Classes="primary"
|
||||
Text="{Binding Name}"
|
||||
FontWeight="{Binding IsCurrent, Converter={x:Static c:BoolConverters.IsBoldToFontWeight}}"
|
||||
TextTrimming="CharacterEllipsis"/>
|
||||
<!-- Name -->
|
||||
<TextBlock Grid.Column="1"
|
||||
Classes="primary"
|
||||
Text="{Binding Name}"
|
||||
FontWeight="{Binding IsCurrent, Converter={x:Static c:BoolConverters.IsBoldToFontWeight}}"
|
||||
TextTrimming="CharacterEllipsis"/>
|
||||
|
||||
<!-- Upstream invalid tip -->
|
||||
<Border Grid.Column="2"
|
||||
Width="12" Height="12"
|
||||
Margin="8,0"
|
||||
Background="Transparent"
|
||||
ToolTip.Tip="{DynamicResource Text.BranchUpstreamInvalid}"
|
||||
IsVisible="{Binding ShowUpstreamGoneTip}">
|
||||
<Path Data="{StaticResource Icons.Error}" Fill="DarkOrange"/>
|
||||
</Border>
|
||||
<!-- Upstream invalid tip -->
|
||||
<Border Grid.Column="2"
|
||||
Width="12" Height="12"
|
||||
Margin="8,0"
|
||||
Background="Transparent"
|
||||
ToolTip.Tip="{DynamicResource Text.BranchUpstreamInvalid}"
|
||||
IsVisible="{Binding ShowUpstreamGoneTip}">
|
||||
<Path Data="{StaticResource Icons.Error}" Fill="DarkOrange"/>
|
||||
</Border>
|
||||
|
||||
<!-- Tracking status -->
|
||||
<v:BranchTreeNodeTrackStatusPresenter Grid.Column="2"
|
||||
VerticalAlignment="Center"
|
||||
FontFamily="{DynamicResource Fonts.Monospace}"
|
||||
FontSize="10"
|
||||
Foreground="{DynamicResource Brush.BadgeFG}"
|
||||
Background="{DynamicResource Brush.Badge}"/>
|
||||
<!-- Tracking status -->
|
||||
<v:BranchTreeNodeTrackStatusPresenter Grid.Column="2"
|
||||
VerticalAlignment="Center"
|
||||
FontFamily="{DynamicResource Fonts.Monospace}"
|
||||
FontSize="10"
|
||||
Foreground="{DynamicResource Brush.BadgeFG}"
|
||||
Background="{DynamicResource Brush.Badge}"/>
|
||||
|
||||
<!-- Filter Mode Switcher -->
|
||||
<v:FilterModeSwitchButton Grid.Column="3"
|
||||
Margin="0,0,12,0"
|
||||
Mode="{Binding FilterMode}"/>
|
||||
<!-- Filter Mode Switcher -->
|
||||
<v:FilterModeSwitchButton Grid.Column="3"
|
||||
Margin="0,0,12,0"
|
||||
Mode="{Binding FilterMode}"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</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)
|
||||
{
|
||||
if (_disableSelectionChangingEvent)
|
||||
|
@ -343,9 +368,6 @@ namespace SourceGit.Views
|
|||
if (selected == null || selected.Count == 0)
|
||||
return;
|
||||
|
||||
if (selected.Count == 1 && selected[0] is ViewModels.BranchTreeNode { Backend: Models.Branch branch })
|
||||
repo.NavigateToCommit(branch.Head);
|
||||
|
||||
var prev = null as ViewModels.BranchTreeNode;
|
||||
foreach (var row in Rows)
|
||||
{
|
||||
|
|
|
@ -26,36 +26,36 @@
|
|||
SelectionChanged="OnRowSelectionChanged">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate DataType="vm:TagTreeNode">
|
||||
<Grid ColumnDefinitions="16,Auto,*,Auto"
|
||||
Margin="{Binding Depth, Converter={x:Static c:IntConverters.ToTreeMargin}}"
|
||||
Background="Transparent"
|
||||
ContextRequested="OnRowContextRequested"
|
||||
DoubleTapped="OnDoubleTappedNode"
|
||||
ToolTip.Tip="{Binding ToolTip}">
|
||||
<v:TagTreeNodeToggleButton Grid.Column="0"
|
||||
Classes="tree_expander"
|
||||
Focusable="False"
|
||||
HorizontalAlignment="Center"
|
||||
IsChecked="{Binding IsExpanded, Mode=OneWay}"
|
||||
IsVisible="{Binding IsFolder}"/>
|
||||
<Border Height="24" Background="Transparent" PointerPressed="OnRowPointerPressed" DoubleTapped="OnDoubleTappedNode" ContextRequested="OnRowContextRequested">
|
||||
<Grid ColumnDefinitions="16,Auto,*,Auto"
|
||||
Margin="{Binding Depth, Converter={x:Static c:IntConverters.ToTreeMargin}}"
|
||||
VerticalAlignment="Center"
|
||||
ToolTip.Tip="{Binding ToolTip}">
|
||||
<v:TagTreeNodeToggleButton Grid.Column="0"
|
||||
Classes="tree_expander"
|
||||
Focusable="False"
|
||||
HorizontalAlignment="Center"
|
||||
IsChecked="{Binding IsExpanded, Mode=OneWay}"
|
||||
IsVisible="{Binding IsFolder}"/>
|
||||
|
||||
<v:TagTreeNodeIcon Grid.Column="1"
|
||||
Node="{Binding .}"
|
||||
IsExpanded="{Binding IsExpanded, Mode=OneWay}"/>
|
||||
<v:TagTreeNodeIcon Grid.Column="1"
|
||||
Node="{Binding .}"
|
||||
IsExpanded="{Binding IsExpanded, Mode=OneWay}"/>
|
||||
|
||||
<TextBlock Grid.Column="2"
|
||||
Classes="primary"
|
||||
Text="{Binding FullPath, Converter={x:Static c:PathConverters.PureFileName}}"
|
||||
Margin="8,0,0,0"/>
|
||||
<TextBlock Grid.Column="2"
|
||||
Classes="primary"
|
||||
Text="{Binding FullPath, Converter={x:Static c:PathConverters.PureFileName}}"
|
||||
Margin="8,0,0,0"/>
|
||||
|
||||
<ContentControl Grid.Column="3" Content="{Binding Tag}">
|
||||
<ContentControl.DataTemplates>
|
||||
<DataTemplate DataType="m:Tag">
|
||||
<v:FilterModeSwitchButton Margin="0,0,12,0" Mode="{Binding FilterMode}"/>
|
||||
</DataTemplate>
|
||||
</ContentControl.DataTemplates>
|
||||
</ContentControl>
|
||||
</Grid>
|
||||
<ContentControl Grid.Column="3" Content="{Binding Tag}">
|
||||
<ContentControl.DataTemplates>
|
||||
<DataTemplate DataType="m:Tag">
|
||||
<v:FilterModeSwitchButton Margin="0,0,12,0" Mode="{Binding FilterMode}"/>
|
||||
</DataTemplate>
|
||||
</ContentControl.DataTemplates>
|
||||
</ContentControl>
|
||||
</Grid>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
|
@ -69,23 +69,22 @@
|
|||
SelectionChanged="OnRowSelectionChanged">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate DataType="m:Tag">
|
||||
<Grid ColumnDefinitions="Auto,*,Auto"
|
||||
Background="Transparent"
|
||||
ContextRequested="OnRowContextRequested"
|
||||
ToolTip.Tip="{Binding Message}">
|
||||
<Path Grid.Column="0"
|
||||
Margin="8,0,0,0"
|
||||
Width="12" Height="12"
|
||||
Data="{StaticResource Icons.Tag}"/>
|
||||
<Border Height="24" Background="Transparent" PointerPressed="OnRowPointerPressed" ContextRequested="OnRowContextRequested">
|
||||
<Grid ColumnDefinitions="Auto,*,Auto" VerticalAlignment="Center" ToolTip.Tip="{Binding Message}">
|
||||
<Path Grid.Column="0"
|
||||
Margin="8,0,0,0"
|
||||
Width="12" Height="12"
|
||||
Data="{StaticResource Icons.Tag}"/>
|
||||
|
||||
<TextBlock Grid.Column="1"
|
||||
Classes="primary"
|
||||
Text="{Binding Name}"
|
||||
Margin="8,0,0,0"
|
||||
TextTrimming="CharacterEllipsis"/>
|
||||
<TextBlock Grid.Column="1"
|
||||
Classes="primary"
|
||||
Text="{Binding Name}"
|
||||
Margin="8,0,0,0"
|
||||
TextTrimming="CharacterEllipsis"/>
|
||||
|
||||
<v:FilterModeSwitchButton Grid.Column="2" Margin="0,0,12,0" Mode="{Binding FilterMode}"/>
|
||||
</Grid>
|
||||
<v:FilterModeSwitchButton Grid.Column="2" Margin="0,0,12,0" Mode="{Binding FilterMode}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
|
|
|
@ -199,15 +199,27 @@ namespace SourceGit.Views
|
|||
|
||||
private void OnDoubleTappedNode(object sender, TappedEventArgs e)
|
||||
{
|
||||
if (sender is Grid { DataContext: ViewModels.TagTreeNode node })
|
||||
{
|
||||
if (node.IsFolder)
|
||||
ToggleNodeIsExpanded(node);
|
||||
}
|
||||
if (sender is Control { DataContext: ViewModels.TagTreeNode { IsFolder: true } node })
|
||||
ToggleNodeIsExpanded(node);
|
||||
|
||||
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)
|
||||
{
|
||||
var control = sender as Control;
|
||||
|
@ -240,11 +252,8 @@ namespace SourceGit.Views
|
|||
else if (selected is Models.Tag tag)
|
||||
selectedTag = tag;
|
||||
|
||||
if (selectedTag != null && DataContext is ViewModels.Repository repo)
|
||||
{
|
||||
if (selectedTag != null)
|
||||
RaiseEvent(new RoutedEventArgs(SelectionChangedEvent));
|
||||
repo.NavigateToCommit(selectedTag.SHA);
|
||||
}
|
||||
}
|
||||
|
||||
private void MakeTreeRows(List<ViewModels.TagTreeNode> rows, List<ViewModels.TagTreeNode> nodes)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue