Skip to content

Commit ba6fc2c

Browse files
committed
ux: when the repository only has one remote, hide the remote name in compact decorator
Signed-off-by: leo <longshuang@msn.cn>
1 parent e3c9384 commit ba6fc2c

6 files changed

Lines changed: 67 additions & 14 deletions

File tree

src/ViewModels/Histories.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,14 @@ public Models.Bisect Bisect
129129

130130
public Models.Branch CurrentBranch
131131
{
132-
get => _repo.CurrentBranch;
132+
get => _currentBranch;
133+
set => SetProperty(ref _currentBranch, value);
134+
}
135+
136+
public bool HasSingleRemote
137+
{
138+
get => _hasSingleRemote;
139+
set => SetProperty(ref _hasSingleRemote, value);
133140
}
134141

135142
public AvaloniaList<Models.IssueTracker> IssueTrackers
@@ -195,11 +202,6 @@ public Histories(Repository repo)
195202
_commitDetailSharedData = new CommitDetailSharedData();
196203
}
197204

198-
public void NotifyCurrentBranchChanged()
199-
{
200-
OnPropertyChanged(nameof(CurrentBranch));
201-
}
202-
203205
public Models.BisectState UpdateBisectInfo()
204206
{
205207
var test = Path.Combine(_repo.GitDir, "BISECT_START");
@@ -526,6 +528,8 @@ private void GenerateGraph(List<Models.Commit> commits)
526528
}
527529

528530
private Repository _repo = null;
531+
private Models.Branch _currentBranch = null;
532+
private bool _hasSingleRemote = false;
529533
private CommitDetailSharedData _commitDetailSharedData = null;
530534
private bool _isLoading = true;
531535
private List<Models.Commit> _commits = [];

src/ViewModels/Repository.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,14 @@ public string Filter
158158
public List<Models.Remote> Remotes
159159
{
160160
get => _remotes;
161-
private set => SetProperty(ref _remotes, value);
161+
private set
162+
{
163+
if (SetProperty(ref _remotes, value))
164+
{
165+
if (_histories != null)
166+
_histories.HasSingleRemote = value != null && value.Count == 1;
167+
}
168+
}
162169
}
163170

164171
public List<Models.Branch> Branches
@@ -175,7 +182,9 @@ private set
175182
var oldHead = _currentBranch?.Head;
176183
if (SetProperty(ref _currentBranch, value))
177184
{
178-
_histories?.NotifyCurrentBranchChanged();
185+
if (_histories != null)
186+
_histories.CurrentBranch = value;
187+
179188
if (value != null && !value.Head.Equals(oldHead, StringComparison.Ordinal) && _workingCopy is { UseAmend: true })
180189
_workingCopy.UseAmend = false;
181190
}

src/Views/CommitRefsPresenter.cs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ public bool UseCompactBranchNames
121121
set => SetValue(UseCompactBranchNamesProperty, value);
122122
}
123123

124+
public static readonly StyledProperty<bool> HasSingleRemoteProperty =
125+
AvaloniaProperty.Register<CommitRefsPresenter, bool>(nameof(HasSingleRemote));
126+
127+
public bool HasSingleRemote
128+
{
129+
get => GetValue(HasSingleRemoteProperty);
130+
set => SetValue(HasSingleRemoteProperty, value);
131+
}
132+
124133
public static readonly StyledProperty<bool> UseGraphColorProperty =
125134
AvaloniaProperty.Register<CommitRefsPresenter, bool>(nameof(UseGraphColor));
126135

@@ -173,6 +182,7 @@ public override void Render(DrawingContext context)
173182
var x = 1.5;
174183
var y = 0.5;
175184
var remoteIcon = CommitRefsIconCache.Instance.GetIcon(Models.DecoratorType.RemoteBranchHead);
185+
var hasSingleRemote = HasSingleRemote;
176186

177187
context.FillRectangle(Brushes.Transparent, Bounds);
178188

@@ -212,13 +222,23 @@ public override void Render(DrawingContext context)
212222
if (item.Remotes.Count > 0)
213223
{
214224
var rx = x + 20 + item.Label.WidthIncludingTrailingWhitespace + 4;
215-
foreach (var remote in item.Remotes)
225+
226+
if (hasSingleRemote)
216227
{
217228
context.DrawLine(new Pen(item.Brush), new Point(rx, y), new Point(rx, y + 16));
218229
using (context.PushTransform(Matrix.CreateTranslation(rx + 4, y + 4)))
219230
context.DrawGeometry(fg, null, remoteIcon);
220-
context.DrawText(remote, new Point(rx + 16, y + 8.0 - remote.Height * 0.5));
221-
rx += remote.WidthIncludingTrailingWhitespace + 22;
231+
}
232+
else
233+
{
234+
foreach (var remote in item.Remotes)
235+
{
236+
context.DrawLine(new Pen(item.Brush), new Point(rx, y), new Point(rx, y + 16));
237+
using (context.PushTransform(Matrix.CreateTranslation(rx + 4, y + 4)))
238+
context.DrawGeometry(fg, null, remoteIcon);
239+
context.DrawText(remote, new Point(rx + 16, y + 8.0 - remote.Height * 0.5));
240+
rx += remote.WidthIncludingTrailingWhitespace + 22;
241+
}
222242
}
223243
}
224244

@@ -268,6 +288,7 @@ protected override Size MeasureOverride(Size availableSize)
268288
}
269289

270290
var useCompactBranchNames = UseCompactBranchNames;
291+
var hasSingleRemote = HasSingleRemote;
271292
var typeface = new Typeface(FontFamily);
272293
var typefaceHead = new Typeface(FontFamily, FontStyle.Normal, FontWeight.Bold);
273294
var typefaceRemote = new Typeface(FontFamily, FontStyle.Italic, FontWeight.Bold);
@@ -345,7 +366,12 @@ protected override Size MeasureOverride(Size availableSize)
345366
fg);
346367

347368
item.Remotes.Add(remote);
348-
item.Width += remote.WidthIncludingTrailingWhitespace + 22;
369+
370+
if (hasSingleRemote)
371+
item.Width += 18;
372+
else
373+
item.Width += remote.WidthIncludingTrailingWhitespace + 22;
374+
349375
skippedIdx.Add(j);
350376
}
351377
}

src/Views/Histories.axaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@
127127
FontSize="12"
128128
VerticalAlignment="Center"
129129
UseGraphColor="{Binding IsHighlightedInGraph, Mode=OneWay}"
130-
UseCompactBranchNames="{Binding Source={x:Static vm:Preferences.Instance}, Path=UseCompactBranchNamesInGraph}"/>
130+
UseCompactBranchNames="{Binding Source={x:Static vm:Preferences.Instance}, Path=UseCompactBranchNamesInGraph}"
131+
HasSingleRemote="{Binding $parent[v:Histories].HasSingleRemote}"/>
131132

132133
<v:CommitSubjectPresenter Grid.Column="3"
133134
Height="26"

src/Views/Histories.axaml.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,18 @@ public Models.Bisect Bisect
321321
set => SetAndRaise(BisectProperty, ref _bisect, value);
322322
}
323323

324+
public static readonly DirectProperty<Histories, bool> HasSingleRemoteProperty =
325+
AvaloniaProperty.RegisterDirect<Histories, bool>(
326+
nameof(HasSingleRemote),
327+
static o => o.HasSingleRemote,
328+
static (o, v) => o.HasSingleRemote = v);
329+
330+
public bool HasSingleRemote
331+
{
332+
get => _hasSingleRemote;
333+
set => SetAndRaise(HasSingleRemoteProperty, ref _hasSingleRemote, value);
334+
}
335+
324336
public static readonly DirectProperty<Histories, AvaloniaList<Models.IssueTracker>> IssueTrackersProperty =
325337
AvaloniaProperty.RegisterDirect<Histories, AvaloniaList<Models.IssueTracker>>(
326338
nameof(IssueTrackers),
@@ -1734,9 +1746,9 @@ private async Task InteractiveRebaseWithPrefillActionAsync(ViewModels.Repository
17341746
await this.ShowDialogAsync(new ViewModels.InteractiveRebase(repo, on, prefill));
17351747
}
17361748

1737-
17381749
private Models.Branch _currentBranch = null;
17391750
private Models.Bisect _bisect = null;
1751+
private bool _hasSingleRemote = false;
17401752
private AvaloniaList<Models.IssueTracker> _issueTrackers = null;
17411753
private bool _isScrollToTopVisible = false;
17421754
private bool _isDetailsPanelExpanded = true;

src/Views/Repository.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,7 @@
10131013
<v:Histories DataContext="{Binding Histories, Mode=OneWay}"
10141014
CurrentBranch="{Binding CurrentBranch, Mode=OneWay}"
10151015
Bisect="{Binding Bisect, Mode=OneWay}"
1016+
HasSingleRemote="{Binding HasSingleRemote, Mode=OneWay}"
10161017
IssueTrackers="{Binding IssueTrackers, Mode=OneWay}">
10171018
<v:Histories.IsDetailsPanelExpanded>
10181019
<MultiBinding Converter="{x:Static BoolConverters.Or}">

0 commit comments

Comments
 (0)