mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-22 02:45:00 +00:00
code_review: PR #1416
- Split `DoubleTapped` into two methods: `CheckoutBranchByDecorator` and `CheckoutBranchByCommit` - Move `DoubleTappedEvent` from whole ListBox to the row tapped actually - Do nothing if the decorator double-clicked is HEAD - Code-style Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
88fd8f32f1
commit
af2b644792
6 changed files with 101 additions and 92 deletions
|
@ -17,6 +17,7 @@ namespace SourceGit.Views
|
|||
public IBrush Brush { get; set; } = null;
|
||||
public bool IsHead { get; set; } = false;
|
||||
public double Width { get; set; } = 0.0;
|
||||
public Models.Decorator Decorator { get; set; } = null;
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<FontFamily> FontFamilyProperty =
|
||||
|
@ -93,6 +94,19 @@ namespace SourceGit.Views
|
|||
ShowTagsProperty);
|
||||
}
|
||||
|
||||
public Models.Decorator DecoratorAt(Point point)
|
||||
{
|
||||
var x = 0.0;
|
||||
foreach (var item in _items)
|
||||
{
|
||||
x += item.Width;
|
||||
if (point.X < x)
|
||||
return item.Decorator;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void Render(DrawingContext context)
|
||||
{
|
||||
if (_items.Count == 0)
|
||||
|
@ -156,22 +170,6 @@ namespace SourceGit.Views
|
|||
InvalidateMeasure();
|
||||
}
|
||||
|
||||
public Models.Decorator DecoratorAt(Point point)
|
||||
{
|
||||
if (DataContext is not Models.Commit commit)
|
||||
return null;
|
||||
|
||||
var x = 0.0;
|
||||
for (var i = 0; i < _items.Count; i++)
|
||||
{
|
||||
x += _items[i].Width + 4;
|
||||
if (point.X < x)
|
||||
return commit.Decorators[i];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override Size MeasureOverride(Size availableSize)
|
||||
{
|
||||
_items.Clear();
|
||||
|
@ -214,7 +212,8 @@ namespace SourceGit.Views
|
|||
{
|
||||
Label = label,
|
||||
Brush = normalBG,
|
||||
IsHead = isHead
|
||||
IsHead = isHead,
|
||||
Decorator = decorator,
|
||||
};
|
||||
|
||||
StreamGeometry geo;
|
||||
|
|
|
@ -70,7 +70,6 @@
|
|||
LayoutUpdated="OnCommitListLayoutUpdated"
|
||||
SelectionChanged="OnCommitListSelectionChanged"
|
||||
ContextRequested="OnCommitListContextRequested"
|
||||
DoubleTapped="OnCommitListDoubleTapped"
|
||||
KeyDown="OnCommitListKeyDown">
|
||||
<ListBox.Styles>
|
||||
<Style Selector="ListBoxItem">
|
||||
|
@ -117,7 +116,7 @@
|
|||
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate DataType="m:Commit">
|
||||
<Grid Height="26">
|
||||
<Grid Height="26" Background="Transparent" DoubleTapped="OnCommitListItemDoubleTapped">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition SharedSizeGroup="AuthorName" Width="Auto"/>
|
||||
|
|
|
@ -169,22 +169,6 @@ namespace SourceGit.Views
|
|||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void OnCommitListDoubleTapped(object sender, TappedEventArgs e)
|
||||
{
|
||||
if (DataContext is ViewModels.Histories histories && sender is ListBox { SelectedItems.Count: 1 })
|
||||
{
|
||||
Models.Decorator decorator = null;
|
||||
if (e.Source is CommitRefsPresenter crp)
|
||||
decorator = crp.DecoratorAt(e.GetPosition(crp));
|
||||
|
||||
var source = e.Source as Control;
|
||||
var item = source.FindAncestorOfType<ListBoxItem>();
|
||||
if (item is { DataContext: Models.Commit commit })
|
||||
histories.DoubleTapped(commit, decorator);
|
||||
}
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void OnCommitListKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (!e.KeyModifiers.HasFlag(OperatingSystem.IsMacOS() ? KeyModifiers.Meta : KeyModifiers.Control))
|
||||
|
@ -228,6 +212,25 @@ namespace SourceGit.Views
|
|||
}
|
||||
}
|
||||
|
||||
private void OnCommitListItemDoubleTapped(object sender, TappedEventArgs e)
|
||||
{
|
||||
e.Handled = true;
|
||||
|
||||
if (DataContext is ViewModels.Histories histories &&
|
||||
CommitListContainer.SelectedItems is { Count: 1 } &&
|
||||
sender is Grid { DataContext: Models.Commit commit })
|
||||
{
|
||||
if (e.Source is CommitRefsPresenter crp)
|
||||
{
|
||||
var decorator = crp.DecoratorAt(e.GetPosition(crp));
|
||||
if (histories.CheckoutBranchByDecorator(decorator))
|
||||
return;
|
||||
}
|
||||
|
||||
histories.CheckoutBranchByCommit(commit);
|
||||
}
|
||||
}
|
||||
|
||||
private double _lastScrollY = 0;
|
||||
private double _lastAuthorNameColumnWidth = 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue