mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-20 19:55:00 +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>
|
<ListBox.ItemTemplate>
|
||||||
<DataTemplate DataType="vm:BranchTreeNode">
|
<DataTemplate DataType="vm:BranchTreeNode">
|
||||||
<Grid Height="24"
|
<Border Background="Transparent" PointerPressed="OnNodePointerPressed">
|
||||||
Margin="{Binding Depth, Converter={x:Static c:IntConverters.ToTreeMargin}}"
|
<Grid Height="24"
|
||||||
ColumnDefinitions="16,*"
|
Margin="{Binding Depth, Converter={x:Static c:IntConverters.ToTreeMargin}}"
|
||||||
ToolTip.Tip="{Binding Tooltip}">
|
ColumnDefinitions="16,*"
|
||||||
|
ToolTip.Tip="{Binding Tooltip}">
|
||||||
|
|
||||||
<!-- Tree Expander -->
|
<!-- Tree Expander -->
|
||||||
<v:BranchTreeNodeToggleButton Grid.Column="0"
|
<v:BranchTreeNodeToggleButton Grid.Column="0"
|
||||||
Classes="tree_expander"
|
Classes="tree_expander"
|
||||||
Focusable="False"
|
Focusable="False"
|
||||||
HorizontalAlignment="Center"
|
HorizontalAlignment="Center"
|
||||||
IsChecked="{Binding IsExpanded, Mode=OneWay}"
|
IsChecked="{Binding IsExpanded, Mode=OneWay}"
|
||||||
IsVisible="{Binding !IsBranch}"/>
|
IsVisible="{Binding !IsBranch}"/>
|
||||||
|
|
||||||
<!-- Content Area (allows double-click) -->
|
<!-- Content Area (allows double-click) -->
|
||||||
<Grid Grid.Column="1"
|
<Grid Grid.Column="1"
|
||||||
Background="Transparent"
|
Background="Transparent"
|
||||||
ColumnDefinitions="18,*,Auto,Auto"
|
ColumnDefinitions="18,*,Auto,Auto"
|
||||||
DoubleTapped="OnDoubleTappedBranchNode">
|
DoubleTapped="OnDoubleTappedBranchNode">
|
||||||
|
|
||||||
<!-- Icon -->
|
<!-- Icon -->
|
||||||
<v:BranchTreeNodeIcon Grid.Column="0"
|
<v:BranchTreeNodeIcon Grid.Column="0"
|
||||||
Node="{Binding}"
|
Node="{Binding}"
|
||||||
IsExpanded="{Binding IsExpanded}"/>
|
IsExpanded="{Binding IsExpanded}"/>
|
||||||
|
|
||||||
<!-- Name -->
|
<!-- Name -->
|
||||||
<TextBlock Grid.Column="1"
|
<TextBlock Grid.Column="1"
|
||||||
Classes="primary"
|
Classes="primary"
|
||||||
Text="{Binding Name}"
|
Text="{Binding Name}"
|
||||||
FontWeight="{Binding IsCurrent, Converter={x:Static c:BoolConverters.IsBoldToFontWeight}}"
|
FontWeight="{Binding IsCurrent, Converter={x:Static c:BoolConverters.IsBoldToFontWeight}}"
|
||||||
TextTrimming="CharacterEllipsis"/>
|
TextTrimming="CharacterEllipsis"/>
|
||||||
|
|
||||||
<!-- Upstream invalid tip -->
|
<!-- Upstream invalid tip -->
|
||||||
<Border Grid.Column="2"
|
<Border Grid.Column="2"
|
||||||
Width="12" Height="12"
|
Width="12" Height="12"
|
||||||
Margin="8,0"
|
Margin="8,0"
|
||||||
Background="Transparent"
|
Background="Transparent"
|
||||||
ToolTip.Tip="{DynamicResource Text.BranchUpstreamInvalid}"
|
ToolTip.Tip="{DynamicResource Text.BranchUpstreamInvalid}"
|
||||||
IsVisible="{Binding ShowUpstreamGoneTip}">
|
IsVisible="{Binding ShowUpstreamGoneTip}">
|
||||||
<Path Data="{StaticResource Icons.Error}" Fill="DarkOrange"/>
|
<Path Data="{StaticResource Icons.Error}" Fill="DarkOrange"/>
|
||||||
</Border>
|
</Border>
|
||||||
|
|
||||||
<!-- Tracking status -->
|
<!-- Tracking status -->
|
||||||
<v:BranchTreeNodeTrackStatusPresenter Grid.Column="2"
|
<v:BranchTreeNodeTrackStatusPresenter Grid.Column="2"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
FontFamily="{DynamicResource Fonts.Monospace}"
|
FontFamily="{DynamicResource Fonts.Monospace}"
|
||||||
FontSize="10"
|
FontSize="10"
|
||||||
Foreground="{DynamicResource Brush.BadgeFG}"
|
Foreground="{DynamicResource Brush.BadgeFG}"
|
||||||
Background="{DynamicResource Brush.Badge}"/>
|
Background="{DynamicResource Brush.Badge}"/>
|
||||||
|
|
||||||
<!-- Filter Mode Switcher -->
|
<!-- Filter Mode Switcher -->
|
||||||
<v:FilterModeSwitchButton Grid.Column="3"
|
<v:FilterModeSwitchButton Grid.Column="3"
|
||||||
Margin="0,0,12,0"
|
Margin="0,0,12,0"
|
||||||
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,36 +26,36 @@
|
||||||
SelectionChanged="OnRowSelectionChanged">
|
SelectionChanged="OnRowSelectionChanged">
|
||||||
<ListBox.ItemTemplate>
|
<ListBox.ItemTemplate>
|
||||||
<DataTemplate DataType="vm:TagTreeNode">
|
<DataTemplate DataType="vm:TagTreeNode">
|
||||||
<Grid ColumnDefinitions="16,Auto,*,Auto"
|
<Border Height="24" Background="Transparent" PointerPressed="OnRowPointerPressed" DoubleTapped="OnDoubleTappedNode" ContextRequested="OnRowContextRequested">
|
||||||
Margin="{Binding Depth, Converter={x:Static c:IntConverters.ToTreeMargin}}"
|
<Grid ColumnDefinitions="16,Auto,*,Auto"
|
||||||
Background="Transparent"
|
Margin="{Binding Depth, Converter={x:Static c:IntConverters.ToTreeMargin}}"
|
||||||
ContextRequested="OnRowContextRequested"
|
VerticalAlignment="Center"
|
||||||
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"
|
Focusable="False"
|
||||||
Focusable="False"
|
HorizontalAlignment="Center"
|
||||||
HorizontalAlignment="Center"
|
IsChecked="{Binding IsExpanded, Mode=OneWay}"
|
||||||
IsChecked="{Binding IsExpanded, Mode=OneWay}"
|
IsVisible="{Binding IsFolder}"/>
|
||||||
IsVisible="{Binding IsFolder}"/>
|
|
||||||
|
|
||||||
<v:TagTreeNodeIcon Grid.Column="1"
|
<v:TagTreeNodeIcon Grid.Column="1"
|
||||||
Node="{Binding .}"
|
Node="{Binding .}"
|
||||||
IsExpanded="{Binding IsExpanded, Mode=OneWay}"/>
|
IsExpanded="{Binding IsExpanded, Mode=OneWay}"/>
|
||||||
|
|
||||||
<TextBlock Grid.Column="2"
|
<TextBlock Grid.Column="2"
|
||||||
Classes="primary"
|
Classes="primary"
|
||||||
Text="{Binding FullPath, Converter={x:Static c:PathConverters.PureFileName}}"
|
Text="{Binding FullPath, Converter={x:Static c:PathConverters.PureFileName}}"
|
||||||
Margin="8,0,0,0"/>
|
Margin="8,0,0,0"/>
|
||||||
|
|
||||||
<ContentControl Grid.Column="3" Content="{Binding Tag}">
|
<ContentControl Grid.Column="3" Content="{Binding Tag}">
|
||||||
<ContentControl.DataTemplates>
|
<ContentControl.DataTemplates>
|
||||||
<DataTemplate DataType="m:Tag">
|
<DataTemplate DataType="m:Tag">
|
||||||
<v:FilterModeSwitchButton Margin="0,0,12,0" Mode="{Binding FilterMode}"/>
|
<v:FilterModeSwitchButton Margin="0,0,12,0" Mode="{Binding FilterMode}"/>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ContentControl.DataTemplates>
|
</ContentControl.DataTemplates>
|
||||||
</ContentControl>
|
</ContentControl>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
</Border>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ListBox.ItemTemplate>
|
</ListBox.ItemTemplate>
|
||||||
</ListBox>
|
</ListBox>
|
||||||
|
@ -69,23 +69,22 @@
|
||||||
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"
|
<Path Grid.Column="0"
|
||||||
ToolTip.Tip="{Binding Message}">
|
Margin="8,0,0,0"
|
||||||
<Path Grid.Column="0"
|
Width="12" Height="12"
|
||||||
Margin="8,0,0,0"
|
Data="{StaticResource Icons.Tag}"/>
|
||||||
Width="12" Height="12"
|
|
||||||
Data="{StaticResource Icons.Tag}"/>
|
|
||||||
|
|
||||||
<TextBlock Grid.Column="1"
|
<TextBlock Grid.Column="1"
|
||||||
Classes="primary"
|
Classes="primary"
|
||||||
Text="{Binding Name}"
|
Text="{Binding Name}"
|
||||||
Margin="8,0,0,0"
|
Margin="8,0,0,0"
|
||||||
TextTrimming="CharacterEllipsis"/>
|
TextTrimming="CharacterEllipsis"/>
|
||||||
|
|
||||||
<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 })
|
||||||
{
|
ToggleNodeIsExpanded(node);
|
||||||
if (node.IsFolder)
|
|
||||||
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