Skip to content

Commit c977757

Browse files
committed
code_review: commit 9f155d7 from heartacker:heartacker/issue1595
- Combine `EnableReflog`, `EnableFirstParentInHistories`, `SimplifyByDecoration` attribute into one `HistoryShowFlags` - Re-design toolbar buttons in `HISTORY` page switcher because there're too many buttons. Signed-off-by: leo <longshuang@msn.cn>
1 parent 9f155d7 commit c977757

File tree

9 files changed

+87
-103
lines changed

9 files changed

+87
-103
lines changed

src/Models/HistoryShowFlags.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
3+
namespace SourceGit.Models
4+
{
5+
[Flags]
6+
public enum HistoryShowFlags
7+
{
8+
None = 0,
9+
Reflog = 1 << 0,
10+
FirstParentOnly = 1 << 1,
11+
SimplifyByDecoration = 1 << 2,
12+
}
13+
}

src/Models/RepositorySettings.cs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,11 @@ public string DefaultRemote
1414
set;
1515
} = string.Empty;
1616

17-
public bool SimplifyByDecoration
17+
public HistoryShowFlags HistoryShowFlags
1818
{
1919
get;
2020
set;
21-
} = false;
22-
23-
public bool EnableReflog
24-
{
25-
get;
26-
set;
27-
} = false;
28-
29-
public bool EnableFirstParentInHistories
30-
{
31-
get;
32-
set;
33-
} = false;
21+
} = HistoryShowFlags.None;
3422

3523
public bool EnableTopoOrderInHistories
3624
{

src/Resources/Icons.axaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
<StreamGeometry x:Key="Icons.File.Remove">M896 320c0-19-6-32-19-45l-192-192c-13-13-26-19-45-19H192c-38 0-64 26-64 64v768c0 38 26 64 64 64h640c38 0 64-26 64-64V320zm-256 384H384c-19 0-32-13-32-32s13-32 32-32h256c19 0 32 13 32 32s-13 32-32 32zm166-384H640V128l192 192h-26z</StreamGeometry>
5151
<StreamGeometry x:Key="Icons.Filter">M599 425 599 657 425 832 425 425 192 192 832 192Z</StreamGeometry>
5252
<StreamGeometry x:Key="Icons.Fingerprint">M505 74c-145 3-239 68-239 68-12 8-15 25-7 37 9 13 25 15 38 6 0 0 184-136 448 2 12 7 29 3 36-10 8-13 3-29-12-37-71-38-139-56-199-63-23-3-44-3-65-3m17 111c-254-3-376 201-376 201-8 12-5 29 7 37 12 8 29 4 39-10 0 0 103-178 329-175 226 3 325 173 325 173 8 12 24 17 37 9 14-8 17-24 9-37 0 0-117-195-370-199m-31 106c-72 5-140 31-192 74C197 449 132 603 204 811c5 14 20 21 34 17 14-5 21-20 16-34-66-191-7-316 79-388 84-69 233-85 343-17 54 34 96 93 118 151 22 58 20 114 3 141-18 28-54 38-86 30-32-8-58-31-59-80-1-73-58-118-118-125-57-7-123 24-140 92-32 125 49 302 238 361 14 4 29-3 34-17 4-14-3-29-18-34-163-51-225-206-202-297 10-41 46-55 84-52 37 4 69 26 69 73 2 70 48 117 100 131 52 13 112-3 144-52 33-50 28-120 3-188-26-68-73-136-140-178a356 356 0 00-213-52m15 104v0c-76 3-152 42-195 125-56 106-31 215 7 293 38 79 90 131 90 131 10 11 27 11 38 0s11-26 0-38c0 0-46-47-79-116s-54-157-8-244c48-90 133-111 208-90 76 22 140 88 138 186-2 15 9 28 24 29 15 1 27-10 29-27 3-122-79-210-176-239a246 246 0 00-75-9m9 213c-15 0-26 13-26 27 0 0 1 63 36 124 36 61 112 119 244 107 15-1 26-13 25-28-1-15-14-26-30-25-116 11-165-33-193-81-28-47-29-98-29-98a27 27 0 00-27-27z</StreamGeometry>
53-
<StreamGeometry x:Key="Icons.FirstParentFilter">m211 611a142 142 0 00-90-4v-190a142 142 0 0090-4v198zm0 262v150h-90v-146a142 142 0 0090-4zm0-723a142 142 0 00-90-4v-146h90zm-51 246a115 115 0 11115-115 115 115 0 01-115 115zm0 461a115 115 0 11115-115 115 115 0 01-115 115zm256-691h563v90h-563zm0 461h563v90h-563zm0-282h422v90h-422zm0 474h422v90h-422z</StreamGeometry>
5453
<StreamGeometry x:Key="Icons.Folder">M853 267H514c-4 0-6-2-9-4l-38-66c-13-21-38-36-64-36H171c-41 0-75 34-75 75v555c0 41 34 75 75 75h683c41 0 75-34 75-75V341c0-41-34-75-75-75zm-683-43h233c4 0 6 2 9 4l38 66c13 21 38 36 64 36H853c6 0 11 4 11 11v75h-704V235c0-6 4-11 11-11zm683 576H171c-6 0-11-4-11-11V480h704V789c0 6-4 11-11 11z</StreamGeometry>
5554
<StreamGeometry x:Key="Icons.Folder.Add">M1088 227H609L453 78a11 11 0 00-7-3H107a43 43 0 00-43 43v789a43 43 0 0043 43h981a43 43 0 0043-43V270a43 43 0 00-43-43zM757 599c0 5-5 9-10 9h-113v113c0 5-4 9-9 9h-56c-5 0-9-4-9-9V608h-113c-5 0-10-4-10-9V543c0-5 5-9 10-9h113V420c0-5 4-9 9-9h56c5 0 9 4 9 9V533h113c5 0 10 4 10 9v56z</StreamGeometry>
5655
<StreamGeometry x:Key="Icons.Folder.Open">M922 450c-6-9-15-13-26-13h-11V341c0-41-34-75-75-75H514c-4 0-6-2-9-4l-38-66c-13-21-38-36-64-36H171c-41 0-75 34-75 75v597c0 6 2 13 6 19 6 9 15 13 26 13h640c13 0 26-9 30-21l128-363c4-11 2-21-4-30zM171 224h233c4 0 6 2 9 4l38 66c13 21 38 36 64 36H811c6 0 11 4 11 11v96H256c-13 0-26 9-30 21l-66 186V235c0-6 4-11 11-11zm574 576H173l105-299h572l-105 299z</StreamGeometry>
@@ -102,7 +101,6 @@
102101
<StreamGeometry x:Key="Icons.Push">M592 768h-160c-27 0-48-21-48-48V384h-175c-36 0-53-43-28-68L485 11c15-15 40-15 55 0l304 304c25 25 7 68-28 68H640v336c0 27-21 48-48 48zm432-16v224c0 27-21 48-48 48H48c-27 0-48-21-48-48V752c0-27 21-48 48-48h272v16c0 62 50 112 112 112h160c62 0 112-50 112-112v-16h272c27 0 48 21 48 48zm-248 176c0-22-18-40-40-40s-40 18-40 40s18 40 40 40s40-18 40-40zm128 0c0-22-18-40-40-40s-40 18-40 40s18 40 40 40s40-18 40-40z</StreamGeometry>
103102
<StreamGeometry x:Key="Icons.Quit">M563 555c0 28-23 51-51 51-28 0-51-23-51-51L461 113c0-28 23-51 51-51s51 23 51 51L563 555 563 555zM85 535c0-153 81-287 201-362 24-15 55-8 70 16C371 214 363 245 340 260 248 318 187 419 187 535c0 180 146 325 325 325 180-0 325-146 325-325 0-119-64-223-160-280-24-14-32-46-18-70 14-24 46-32 70-18 125 74 210 211 210 367 0 236-191 427-427 427C276 963 85 772 85 535</StreamGeometry>
104103
<StreamGeometry x:Key="Icons.Rebase">M277 85a149 149 0 00-43 292v230a32 32 0 0064 0V555h267A160 160 0 00725 395v-12a149 149 0 10-64-5v17a96 96 0 01-96 96H299V383A149 149 0 00277 85zM228 720a32 32 0 00-37-52 150 150 0 00-53 68 32 32 0 1060 23 85 85 0 0130-39zm136-52a32 32 0 00-37 52 86 86 0 0130 39 32 32 0 1060-23 149 149 0 00-53-68zM204 833a32 32 0 10-55 32 149 149 0 0063 58 32 32 0 0028-57 85 85 0 01-36-33zm202 32a32 32 0 00-55-32 85 85 0 01-36 33 32 32 0 0028 57 149 149 0 0063-58z</StreamGeometry>
105-
<StreamGeometry x:Key="Icons.Reference">M467 556c0-0 0-1 0-1C467 555 467 556 467 556zM467 556c0-0 0-0 0-0C467 556 467 556 467 556zM467 556c-0 0-0 0-0 0C467 557 467 557 467 556zM468 549C468 532 468 541 468 549L468 549zM468 549c0 1-0 1-0 2C468 551 468 550 468 549zM468 552c-0 1-0 2-0 3C467 554 468 553 468 552zM736 549C736 532 736 541 736 549L736 549zM289 378l0 179 89 0c-1 80-89 89-89 89l45 45c0 0 129-15 134-134L467 378 289 378zM959 244l0 536c0 99-80 179-179 179L244 959c-99 0-179-80-179-179L65 244c0-99 80-179 179-179l536 0C879 65 959 145 959 244zM869 289c0-74-60-134-134-134L289 155c-74 0-134 60-134 134l0 447c0 74 60 134 134 134l447 0c74 0 134-60 134-134L869 289zM557 557l89 0c-1 80-89 89-89 89l45 45c0 0 129-15 134-134L735 378 557 378 557 557z</StreamGeometry>
106104
<StreamGeometry x:Key="Icons.Relation">m224 154a166 166 0 00-166 166v192a166 166 0 00166 166h64v-76h-64a90 90 0 01-90-90v-192a90 90 0 0190-90h320a90 90 0 0190 90v192a90 90 0 01-90 90h-128v77h128a166 166 0 00166-167v-192a166 166 0 00-166-166h-320zm166 390a90 90 0 0190-90h128v-76h-128a166 166 0 00-166 166v192a166 166 0 00166 166h320a166 166 0 00166-166v-192a166 166 0 00-166-166h-64v77h64a90 90 0 0190 90v192a90 90 0 01-90 90h-320a90 90 0 01-90-90v-192z</StreamGeometry>
107105
<StreamGeometry x:Key="Icons.Remote">M512 128M706 302a289 289 0 00-173 44 27 27 0 1029 46 234 234 0 01125-36c23 0 45 3 66 9 93 28 161 114 161 215C914 704 813 805 687 805H337C211 805 110 704 110 580c0-96 61-178 147-210C282 263 379 183 495 183a245 245 0 01210 119z</StreamGeometry>
108106
<StreamGeometry x:Key="Icons.Remote.Add">M364 512h67v108h108v67h-108v108h-67v-108h-108v-67h108v-108zm298-64A107 107 0 01768 555C768 614 720 660 660 660h-108v-54h-108v-108h-94v108h-94c4-21 22-47 44-51l-1-12a75 75 0 0171-75a128 128 0 01239-7a106 106 0 0153-14z</StreamGeometry>

src/Resources/Locales/en_US.axaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,9 +668,10 @@
668668
<x:String x:Key="Text.Repository.Search.ByPath" xml:space="preserve">Path</x:String>
669669
<x:String x:Key="Text.Repository.Search.BySHA" xml:space="preserve">SHA</x:String>
670670
<x:String x:Key="Text.Repository.Search.InCurrentBranch" xml:space="preserve">Current Branch</x:String>
671-
<x:String x:Key="Text.Repository.ShowFirstParentOnly" xml:space="preserve">Show first-parent only</x:String>
671+
<x:String x:Key="Text.Repository.ShowDecoratedCommitsOnly" xml:space="preserve">Decorated commits only</x:String>
672+
<x:String x:Key="Text.Repository.ShowFirstParentOnly" xml:space="preserve">First-parent only</x:String>
673+
<x:String x:Key="Text.Repository.ShowFlags" xml:space="preserve">SHOW FLAGS</x:String>
672674
<x:String x:Key="Text.Repository.ShowLostCommits" xml:space="preserve">Show lost commits</x:String>
673-
<x:String x:Key="Text.Repository.SimplifyByDecoration" xml:space="preserve">Show Decorate Commits Only</x:String>
674675
<x:String x:Key="Text.Repository.ShowSubmodulesAsTree" xml:space="preserve">Show Submodules as Tree</x:String>
675676
<x:String x:Key="Text.Repository.ShowTagsAsTree" xml:space="preserve">Show Tags as Tree</x:String>
676677
<x:String x:Key="Text.Repository.Skip" xml:space="preserve">SKIP</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,9 @@
672672
<x:String x:Key="Text.Repository.Search.ByPath" xml:space="preserve">路径</x:String>
673673
<x:String x:Key="Text.Repository.Search.BySHA" xml:space="preserve">提交指纹</x:String>
674674
<x:String x:Key="Text.Repository.Search.InCurrentBranch" xml:space="preserve">仅在当前分支中查找</x:String>
675+
<x:String x:Key="Text.Repository.ShowDecoratedCommitsOnly" xml:space="preserve">仅显示分支、标签所引用的提交</x:String>
675676
<x:String x:Key="Text.Repository.ShowFirstParentOnly" xml:space="preserve">仅显示合并提交中的第一个提交</x:String>
677+
<x:String x:Key="Text.Repository.ShowFlags" xml:space="preserve">显示内容</x:String>
676678
<x:String x:Key="Text.Repository.ShowLostCommits" xml:space="preserve">显示丢失引用的提交</x:String>
677679
<x:String x:Key="Text.Repository.ShowSubmodulesAsTree" xml:space="preserve">以树型结构展示</x:String>
678680
<x:String x:Key="Text.Repository.ShowTagsAsTree" xml:space="preserve">以树型结构展示</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,9 @@
672672
<x:String x:Key="Text.Repository.Search.ByPath" xml:space="preserve">路徑</x:String>
673673
<x:String x:Key="Text.Repository.Search.BySHA" xml:space="preserve">提交編號</x:String>
674674
<x:String x:Key="Text.Repository.Search.InCurrentBranch" xml:space="preserve">僅搜尋目前分支</x:String>
675+
<x:String x:Key="Text.Repository.ShowDecoratedCommitsOnly" xml:space="preserve">只顯示分支和標籤引用的提交</x:String>
675676
<x:String x:Key="Text.Repository.ShowFirstParentOnly" xml:space="preserve">只顯示合併提交的第一父提交</x:String>
677+
<x:String x:Key="Text.Repository.ShowFlags" xml:space="preserve">顯示內容</x:String>
676678
<x:String x:Key="Text.Repository.ShowLostCommits" xml:space="preserve">顯示遺失參照的提交</x:String>
677679
<x:String x:Key="Text.Repository.ShowSubmodulesAsTree" xml:space="preserve">以樹型結構展示</x:String>
678680
<x:String x:Key="Text.Repository.ShowTagsAsTree" xml:space="preserve">以樹型結構展示</x:String>

src/ViewModels/Repository.cs

Lines changed: 61 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -91,43 +91,14 @@ public object SelectedView
9191
set => SetProperty(ref _selectedView, value);
9292
}
9393

94-
public bool SimplifyByDecoration
94+
public Models.HistoryShowFlags HistoryShowFlags
9595
{
96-
get => _settings.SimplifyByDecoration;
96+
get => _settings.HistoryShowFlags;
9797
set
9898
{
99-
if (value != _settings.SimplifyByDecoration)
99+
if (value != _settings.HistoryShowFlags)
100100
{
101-
_settings.SimplifyByDecoration = value;
102-
OnPropertyChanged();
103-
Task.Run(RefreshCommits);
104-
}
105-
}
106-
}
107-
108-
public bool EnableReflog
109-
{
110-
get => _settings.EnableReflog;
111-
set
112-
{
113-
if (value != _settings.EnableReflog)
114-
{
115-
_settings.EnableReflog = value;
116-
OnPropertyChanged();
117-
Task.Run(RefreshCommits);
118-
}
119-
}
120-
}
121-
122-
public bool EnableFirstParentInHistories
123-
{
124-
get => _settings.EnableFirstParentInHistories;
125-
set
126-
{
127-
if (value != _settings.EnableFirstParentInHistories)
128-
{
129-
_settings.EnableFirstParentInHistories = value;
130-
OnPropertyChanged();
101+
_settings.HistoryShowFlags = value;
131102
Task.Run(RefreshCommits);
132103
}
133104
}
@@ -1281,12 +1252,13 @@ public void RefreshCommits()
12811252
else
12821253
builder.Append("--date-order ");
12831254

1284-
if (_settings.EnableReflog)
1255+
if (_settings.HistoryShowFlags.HasFlag(Models.HistoryShowFlags.Reflog))
12851256
builder.Append("--reflog ");
1286-
if (_settings.EnableFirstParentInHistories)
1257+
1258+
if (_settings.HistoryShowFlags.HasFlag(Models.HistoryShowFlags.FirstParentOnly))
12871259
builder.Append("--first-parent ");
1288-
// only show commits with decorators
1289-
if (_settings.SimplifyByDecoration)
1260+
1261+
if (_settings.HistoryShowFlags.HasFlag(Models.HistoryShowFlags.SimplifyByDecoration))
12901262
builder.Append("--simplify-by-decoration ");
12911263

12921264
var filters = _settings.BuildHistoriesFilter();
@@ -1296,7 +1268,7 @@ public void RefreshCommits()
12961268
builder.Append(filters);
12971269

12981270
var commits = new Commands.QueryCommits(_fullpath, builder.ToString()).GetResultAsync().Result;
1299-
var graph = Models.CommitGraph.Parse(commits, _settings.EnableFirstParentInHistories);
1271+
var graph = Models.CommitGraph.Parse(commits, _settings.HistoryShowFlags.HasFlag(Models.HistoryShowFlags.FirstParentOnly));
13001272

13011273
Dispatcher.UIThread.Invoke(() =>
13021274
{
@@ -1822,7 +1794,7 @@ public ContextMenu CreateContextMenuForCustomAction()
18221794
return menu;
18231795
}
18241796

1825-
public ContextMenu CreateContextMenuForHistoriesPage()
1797+
public ContextMenu CreateContextMenuForHistoryAdvancedOption()
18261798
{
18271799
var layout = new MenuItem();
18281800
layout.Header = App.Text("Repository.HistoriesLayout");
@@ -1849,6 +1821,43 @@ public ContextMenu CreateContextMenuForHistoriesPage()
18491821
ev.Handled = true;
18501822
};
18511823

1824+
var showFlags = new MenuItem();
1825+
showFlags.Header = App.Text("Repository.ShowFlags");
1826+
showFlags.IsEnabled = false;
1827+
1828+
var reflog = new MenuItem();
1829+
reflog.Header = App.Text("Repository.ShowLostCommits");
1830+
reflog.Tag = "--reflog";
1831+
if (_settings.HistoryShowFlags.HasFlag(Models.HistoryShowFlags.Reflog))
1832+
reflog.Icon = App.CreateMenuIcon("Icons.Check");
1833+
reflog.Click += (_, e) =>
1834+
{
1835+
ToggleHistoryShowFlag(Models.HistoryShowFlags.Reflog);
1836+
e.Handled = true;
1837+
};
1838+
1839+
var firstParentOnly = new MenuItem();
1840+
firstParentOnly.Header = App.Text("Repository.ShowFirstParentOnly");
1841+
firstParentOnly.Tag = "--first-parent";
1842+
if (_settings.HistoryShowFlags.HasFlag(Models.HistoryShowFlags.FirstParentOnly))
1843+
firstParentOnly.Icon = App.CreateMenuIcon("Icons.Check");
1844+
firstParentOnly.Click += (_, e) =>
1845+
{
1846+
ToggleHistoryShowFlag(Models.HistoryShowFlags.FirstParentOnly);
1847+
e.Handled = true;
1848+
};
1849+
1850+
var simplifyByDecoration = new MenuItem();
1851+
simplifyByDecoration.Header = App.Text("Repository.ShowDecoratedCommitsOnly");
1852+
simplifyByDecoration.Tag = "--simplify-by-decoration";
1853+
if (_settings.HistoryShowFlags.HasFlag(Models.HistoryShowFlags.SimplifyByDecoration))
1854+
simplifyByDecoration.Icon = App.CreateMenuIcon("Icons.Check");
1855+
simplifyByDecoration.Click += (_, e) =>
1856+
{
1857+
ToggleHistoryShowFlag(Models.HistoryShowFlags.SimplifyByDecoration);
1858+
e.Handled = true;
1859+
};
1860+
18521861
var order = new MenuItem();
18531862
order.Header = App.Text("Repository.HistoriesOrder");
18541863
order.IsEnabled = false;
@@ -1890,6 +1899,11 @@ public ContextMenu CreateContextMenuForHistoriesPage()
18901899
menu.Items.Add(horizontal);
18911900
menu.Items.Add(vertical);
18921901
menu.Items.Add(new MenuItem() { Header = "-" });
1902+
menu.Items.Add(showFlags);
1903+
menu.Items.Add(reflog);
1904+
menu.Items.Add(firstParentOnly);
1905+
menu.Items.Add(simplifyByDecoration);
1906+
menu.Items.Add(new MenuItem() { Header = "-" });
18931907
menu.Items.Add(order);
18941908
menu.Items.Add(dateOrder);
18951909
menu.Items.Add(topoOrder);
@@ -3091,6 +3105,14 @@ private void CalcMatchedFilesForSearching()
30913105
MatchedFilesForSearching = matched;
30923106
}
30933107

3108+
private void ToggleHistoryShowFlag(Models.HistoryShowFlags flag)
3109+
{
3110+
if (_settings.HistoryShowFlags.HasFlag(flag))
3111+
HistoryShowFlags -= flag;
3112+
else
3113+
HistoryShowFlags |= flag;
3114+
}
3115+
30943116
private async void AutoFetchImpl(object sender)
30953117
{
30963118
try

0 commit comments

Comments
 (0)