mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -08:00
revert: remove issue link support in commit list
* improve render performance * the links in commit list are very easy to click by mistake
This commit is contained in:
parent
d601ca6b23
commit
a145d6e4c3
3 changed files with 4 additions and 168 deletions
|
@ -1,7 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Avalonia.Collections;
|
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Platform.Storage;
|
using Avalonia.Platform.Storage;
|
||||||
using Avalonia.VisualTree;
|
using Avalonia.VisualTree;
|
||||||
|
@ -55,11 +54,6 @@ namespace SourceGit.ViewModels
|
||||||
set => SetProperty(ref _detailContext, value);
|
set => SetProperty(ref _detailContext, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AvaloniaList<Models.IssueTrackerRule> IssueTrackerRules
|
|
||||||
{
|
|
||||||
get => _repo.Settings.IssueTrackerRules;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Histories(Repository repo)
|
public Histories(Repository repo)
|
||||||
{
|
{
|
||||||
_repo = repo;
|
_repo = repo;
|
||||||
|
|
|
@ -77,11 +77,10 @@
|
||||||
FontSize="10"
|
FontSize="10"
|
||||||
VerticalAlignment="Center"/>
|
VerticalAlignment="Center"/>
|
||||||
|
|
||||||
<v:CommitSubjectPresenter Classes="primary"
|
<TextBlock Classes="primary"
|
||||||
Subject="{Binding Subject}"
|
Text="{Binding Subject}"
|
||||||
IssueTrackerRules="{Binding $parent[v:Histories].IssueTrackerRules}"
|
Opacity="{Binding Opacity}"
|
||||||
Opacity="{Binding Opacity}"
|
FontWeight="{Binding FontWeight}"/>
|
||||||
FontWeight="{Binding FontWeight}"/>
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Border>
|
</Border>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|
|
@ -1,17 +1,13 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Collections;
|
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Controls.Documents;
|
|
||||||
using Avalonia.Controls.Primitives;
|
using Avalonia.Controls.Primitives;
|
||||||
using Avalonia.Input;
|
using Avalonia.Input;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
using Avalonia.Media;
|
using Avalonia.Media;
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
using Avalonia.Utilities;
|
|
||||||
using Avalonia.VisualTree;
|
using Avalonia.VisualTree;
|
||||||
|
|
||||||
namespace SourceGit.Views
|
namespace SourceGit.Views
|
||||||
|
@ -157,149 +153,6 @@ namespace SourceGit.Views
|
||||||
private Status _status = Status.Normal;
|
private Status _status = Status.Normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CommitSubjectPresenter : TextBlock
|
|
||||||
{
|
|
||||||
public static readonly StyledProperty<string> SubjectProperty =
|
|
||||||
AvaloniaProperty.Register<CommitSubjectPresenter, string>(nameof(Subject));
|
|
||||||
|
|
||||||
public string Subject
|
|
||||||
{
|
|
||||||
get => GetValue(SubjectProperty);
|
|
||||||
set => SetValue(SubjectProperty, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static readonly StyledProperty<AvaloniaList<Models.IssueTrackerRule>> IssueTrackerRulesProperty =
|
|
||||||
AvaloniaProperty.Register<CommitSubjectPresenter, AvaloniaList<Models.IssueTrackerRule>>(nameof(IssueTrackerRules));
|
|
||||||
|
|
||||||
public AvaloniaList<Models.IssueTrackerRule> IssueTrackerRules
|
|
||||||
{
|
|
||||||
get => GetValue(IssueTrackerRulesProperty);
|
|
||||||
set => SetValue(IssueTrackerRulesProperty, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override Type StyleKeyOverride => typeof(TextBlock);
|
|
||||||
|
|
||||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
|
||||||
{
|
|
||||||
base.OnPropertyChanged(change);
|
|
||||||
|
|
||||||
if (change.Property == SubjectProperty || change.Property == IssueTrackerRulesProperty)
|
|
||||||
{
|
|
||||||
Inlines.Clear();
|
|
||||||
_matches = null;
|
|
||||||
ClearHoveredIssueLink();
|
|
||||||
|
|
||||||
var subject = Subject;
|
|
||||||
if (string.IsNullOrEmpty(subject))
|
|
||||||
return;
|
|
||||||
|
|
||||||
var rules = IssueTrackerRules;
|
|
||||||
if (rules == null || rules.Count == 0)
|
|
||||||
{
|
|
||||||
Inlines.Add(new Run(subject));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var matches = new List<Models.IssueTrackerMatch>();
|
|
||||||
foreach (var rule in rules)
|
|
||||||
rule.Matches(matches, subject);
|
|
||||||
|
|
||||||
if (matches.Count == 0)
|
|
||||||
{
|
|
||||||
Inlines.Add(new Run(subject));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
matches.Sort((l, r) => l.Start - r.Start);
|
|
||||||
_matches = matches;
|
|
||||||
|
|
||||||
int pos = 0;
|
|
||||||
foreach (var match in matches)
|
|
||||||
{
|
|
||||||
if (match.Start > pos)
|
|
||||||
Inlines.Add(new Run(subject.Substring(pos, match.Start - pos)));
|
|
||||||
|
|
||||||
match.Link = new Run(subject.Substring(match.Start, match.Length));
|
|
||||||
match.Link.Classes.Add("issue_link");
|
|
||||||
Inlines.Add(match.Link);
|
|
||||||
|
|
||||||
pos = match.Start + match.Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pos < subject.Length)
|
|
||||||
Inlines.Add(new Run(subject.Substring(pos)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnPointerMoved(PointerEventArgs e)
|
|
||||||
{
|
|
||||||
base.OnPointerMoved(e);
|
|
||||||
|
|
||||||
if (_matches != null)
|
|
||||||
{
|
|
||||||
var padding = Padding;
|
|
||||||
var point = e.GetPosition(this) - new Point(padding.Left, padding.Top);
|
|
||||||
point = new Point(
|
|
||||||
MathUtilities.Clamp(point.X, 0, Math.Max(TextLayout.WidthIncludingTrailingWhitespace, 0)),
|
|
||||||
MathUtilities.Clamp(point.Y, 0, Math.Max(TextLayout.Height, 0)));
|
|
||||||
|
|
||||||
var textPosition = TextLayout.HitTestPoint(point).TextPosition;
|
|
||||||
foreach (var match in _matches)
|
|
||||||
{
|
|
||||||
if (!match.Intersect(textPosition, 1))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (match == _lastHover)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_lastHover = match;
|
|
||||||
_lastHover.Link.Classes.Add("issue_link_hovered");
|
|
||||||
|
|
||||||
SetCurrentValue(CursorProperty, Cursor.Parse("Hand"));
|
|
||||||
ToolTip.SetTip(this, match.URL);
|
|
||||||
ToolTip.SetIsOpen(this, true);
|
|
||||||
e.Handled = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ClearHoveredIssueLink();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnPointerPressed(PointerPressedEventArgs e)
|
|
||||||
{
|
|
||||||
if (_lastHover != null)
|
|
||||||
{
|
|
||||||
Native.OS.OpenBrowser(_lastHover.URL);
|
|
||||||
ClearHoveredIssueLink();
|
|
||||||
e.Handled = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
base.OnPointerPressed(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnPointerExited(PointerEventArgs e)
|
|
||||||
{
|
|
||||||
base.OnPointerExited(e);
|
|
||||||
ClearHoveredIssueLink();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ClearHoveredIssueLink()
|
|
||||||
{
|
|
||||||
if (_lastHover != null)
|
|
||||||
{
|
|
||||||
ToolTip.SetTip(this, null);
|
|
||||||
SetCurrentValue(CursorProperty, Cursor.Parse("Arrow"));
|
|
||||||
_lastHover.Link.Classes.Remove("issue_link_hovered");
|
|
||||||
_lastHover = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Models.IssueTrackerMatch> _matches = null;
|
|
||||||
private Models.IssueTrackerMatch _lastHover = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class CommitTimeTextBlock : TextBlock
|
public class CommitTimeTextBlock : TextBlock
|
||||||
{
|
{
|
||||||
public static readonly StyledProperty<bool> ShowAsDateTimeProperty =
|
public static readonly StyledProperty<bool> ShowAsDateTimeProperty =
|
||||||
|
@ -607,16 +460,6 @@ namespace SourceGit.Views
|
||||||
set => SetValue(NavigationIdProperty, value);
|
set => SetValue(NavigationIdProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AvaloniaList<Models.IssueTrackerRule> IssueTrackerRules
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (DataContext is ViewModels.Histories histories)
|
|
||||||
return histories.IssueTrackerRules;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static Histories()
|
static Histories()
|
||||||
{
|
{
|
||||||
NavigationIdProperty.Changed.AddClassHandler<Histories>((h, _) =>
|
NavigationIdProperty.Changed.AddClassHandler<Histories>((h, _) =>
|
||||||
|
|
Loading…
Reference in a new issue