Skip to content

Commit bf8e392

Browse files
committed
feature: supports to hide AUTHOR and SHA columns in HISTORY (#2097)
Signed-off-by: leo <longshuang@msn.cn>
1 parent 6c2a89b commit bf8e392

File tree

10 files changed

+107
-23
lines changed

10 files changed

+107
-23
lines changed

src/Models/RepositoryUIStates.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,25 @@ public HistoryShowFlags HistoryShowFlags
1515
set;
1616
} = HistoryShowFlags.None;
1717

18-
public bool EnableTopoOrderInHistories
18+
public bool IsAuthorColumnVisibleInHistory
19+
{
20+
get;
21+
set;
22+
} = true;
23+
24+
public bool IsSHAColumnVisibleInHistory
25+
{
26+
get;
27+
set;
28+
} = true;
29+
30+
public bool EnableTopoOrderInHistory
1931
{
2032
get;
2133
set;
2234
} = false;
2335

24-
public bool OnlyHighlightCurrentBranchInHistories
36+
public bool OnlyHighlightCurrentBranchInHistory
2537
{
2638
get;
2739
set;
@@ -386,7 +398,7 @@ public string BuildHistoryParams()
386398

387399
var builder = new StringBuilder();
388400

389-
if (EnableTopoOrderInHistories)
401+
if (EnableTopoOrderInHistory)
390402
builder.Append("--topo-order ");
391403
else
392404
builder.Append("--date-order ");

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@
474474
<x:String x:Key="Text.Histories.Header.SHA" xml:space="preserve">SHA</x:String>
475475
<x:String x:Key="Text.Histories.Header.Time" xml:space="preserve">COMMIT TIME</x:String>
476476
<x:String x:Key="Text.Histories.Selected" xml:space="preserve">SELECTED {0} COMMITS</x:String>
477+
<x:String x:Key="Text.Histories.ShowColumns" xml:space="preserve">SHOW COLUMNS</x:String>
477478
<x:String x:Key="Text.Histories.Tips" xml:space="preserve">Hold 'Ctrl' or 'Shift' to select multiple commits.</x:String>
478479
<x:String x:Key="Text.Histories.Tips.MacOS" xml:space="preserve">Hold ⌘ or ⇧ to select multiple commits.</x:String>
479480
<x:String x:Key="Text.Histories.Tips.Prefix" xml:space="preserve">TIPS:</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@
478478
<x:String x:Key="Text.Histories.Header.SHA" xml:space="preserve">提交指纹</x:String>
479479
<x:String x:Key="Text.Histories.Header.Time" xml:space="preserve">提交时间</x:String>
480480
<x:String x:Key="Text.Histories.Selected" xml:space="preserve">已选中 {0} 项提交</x:String>
481+
<x:String x:Key="Text.Histories.ShowColumns" xml:space="preserve">显示列</x:String>
481482
<x:String x:Key="Text.Histories.Tips" xml:space="preserve">可以按住 Ctrl 或 Shift 键选择多个提交</x:String>
482483
<x:String x:Key="Text.Histories.Tips.MacOS" xml:space="preserve">可以按住 ⌘ 或 ⇧ 键选择多个提交</x:String>
483484
<x:String x:Key="Text.Histories.Tips.Prefix" xml:space="preserve">小提示:</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@
478478
<x:String x:Key="Text.Histories.Header.SHA" xml:space="preserve">提交編號</x:String>
479479
<x:String x:Key="Text.Histories.Header.Time" xml:space="preserve">提交時間</x:String>
480480
<x:String x:Key="Text.Histories.Selected" xml:space="preserve">已選取 {0} 項提交</x:String>
481+
<x:String x:Key="Text.Histories.ShowColumns" xml:space="preserve">顯示欄位</x:String>
481482
<x:String x:Key="Text.Histories.Tips" xml:space="preserve">可以按住 Ctrl 或 Shift 鍵選擇多個提交</x:String>
482483
<x:String x:Key="Text.Histories.Tips.MacOS" xml:space="preserve">可以按住 ⌘ 或 ⇧ 鍵選擇多個提交</x:String>
483484
<x:String x:Key="Text.Histories.Tips.Prefix" xml:space="preserve">小提示:</x:String>

src/ViewModels/Histories.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,32 @@ public bool IsLoading
1818
set => SetProperty(ref _isLoading, value);
1919
}
2020

21+
public bool IsAuthorColumnVisible
22+
{
23+
get => _repo.UIStates.IsAuthorColumnVisibleInHistory;
24+
set
25+
{
26+
if (_repo.UIStates.IsAuthorColumnVisibleInHistory != value)
27+
{
28+
_repo.UIStates.IsAuthorColumnVisibleInHistory = value;
29+
OnPropertyChanged();
30+
}
31+
}
32+
}
33+
34+
public bool IsSHAColumnVisible
35+
{
36+
get => _repo.UIStates.IsSHAColumnVisibleInHistory;
37+
set
38+
{
39+
if (_repo.UIStates.IsSHAColumnVisibleInHistory != value)
40+
{
41+
_repo.UIStates.IsSHAColumnVisibleInHistory = value;
42+
OnPropertyChanged();
43+
}
44+
}
45+
}
46+
2147
public List<Models.Commit> Commits
2248
{
2349
get => _commits;

src/ViewModels/Repository.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ public object SelectedView
7979
set => SetProperty(ref _selectedView, value);
8080
}
8181

82-
public bool EnableTopoOrderInHistories
82+
public bool EnableTopoOrderInHistory
8383
{
84-
get => _uiStates.EnableTopoOrderInHistories;
84+
get => _uiStates.EnableTopoOrderInHistory;
8585
set
8686
{
87-
if (value != _uiStates.EnableTopoOrderInHistories)
87+
if (value != _uiStates.EnableTopoOrderInHistory)
8888
{
89-
_uiStates.EnableTopoOrderInHistories = value;
89+
_uiStates.EnableTopoOrderInHistory = value;
9090
RefreshCommits();
9191
}
9292
}
@@ -105,14 +105,14 @@ private set
105105
}
106106
}
107107

108-
public bool OnlyHighlightCurrentBranchInHistories
108+
public bool OnlyHighlightCurrentBranchInHistory
109109
{
110-
get => _uiStates.OnlyHighlightCurrentBranchInHistories;
110+
get => _uiStates.OnlyHighlightCurrentBranchInHistory;
111111
set
112112
{
113-
if (value != _uiStates.OnlyHighlightCurrentBranchInHistories)
113+
if (value != _uiStates.OnlyHighlightCurrentBranchInHistory)
114114
{
115-
_uiStates.OnlyHighlightCurrentBranchInHistories = value;
115+
_uiStates.OnlyHighlightCurrentBranchInHistory = value;
116116
OnPropertyChanged();
117117
}
118118
}

src/Views/Histories.axaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165
</DataGridTemplateColumn.CellTemplate>
166166
</DataGridTemplateColumn>
167167

168-
<DataGridTemplateColumn MinWidth="80" CanUserResize="True" IsReadOnly="True">
168+
<DataGridTemplateColumn MinWidth="80" CanUserResize="True" IsReadOnly="True" IsVisible="{Binding IsAuthorColumnVisible, Mode=OneWay}">
169169
<DataGridTemplateColumn.Width>
170170
<Binding Source="{x:Static vm:Preferences.Instance}"
171171
Path="Layout.AuthorColumnWidth"
@@ -198,7 +198,7 @@
198198
</DataGridTemplateColumn.CellTemplate>
199199
</DataGridTemplateColumn>
200200

201-
<DataGridTemplateColumn MinWidth="100" CanUserResize="False" IsReadOnly="True">
201+
<DataGridTemplateColumn MinWidth="100" CanUserResize="False" IsReadOnly="True" IsVisible="{Binding IsSHAColumnVisible, Mode=OneWay}">
202202
<DataGridTemplateColumn.Header>
203203
<TextBlock Classes="table_header" Text="{DynamicResource Text.Histories.Header.SHA}" HorizontalAlignment="Center"/>
204204
</DataGridTemplateColumn.Header>

src/Views/Histories.axaml.cs

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,16 @@ private void OnCommitListSelectionChanged(object _, SelectionChangedEventArgs e)
216216

217217
private void OnCommitListContextRequested(object sender, ContextRequestedEventArgs e)
218218
{
219-
if (sender is DataGrid { SelectedItems: { } selected } dataGrid &&
220-
e.Source is Control { DataContext: Models.Commit })
219+
if (e.Source is Control { DataContext: Models.Commit })
221220
{
222221
var repoView = this.FindAncestorOfType<Repository>();
223222
if (repoView is not { DataContext: ViewModels.Repository repo })
224223
return;
225224

225+
var selected = CommitListContainer.SelectedItems;
226+
if (selected is not { Count: > 0 })
227+
return;
228+
226229
var commits = new List<Models.Commit>();
227230
for (var i = selected.Count - 1; i >= 0; i--)
228231
{
@@ -233,14 +236,54 @@ private void OnCommitListContextRequested(object sender, ContextRequestedEventAr
233236
if (selected.Count > 1)
234237
{
235238
var menu = CreateContextMenuForMultipleCommits(repo, commits);
236-
menu.Open(dataGrid);
239+
menu.Open(CommitListContainer);
237240
}
238241
else if (selected.Count == 1)
239242
{
240243
var menu = CreateContextMenuForSingleCommit(repo, commits[0]);
241-
menu.Open(dataGrid);
244+
menu.Open(CommitListContainer);
242245
}
243246
}
247+
else if (e.Source is Control elem)
248+
{
249+
var headersPresenter = CommitListContainer.FindDescendantOfType<DataGridColumnHeadersPresenter>();
250+
if (!headersPresenter.IsVisualAncestorOf(elem))
251+
return;
252+
253+
if (DataContext is not ViewModels.Histories vm)
254+
return;
255+
256+
var columnsHeader = new MenuItem();
257+
columnsHeader.Header = App.Text("Histories.ShowColumns");
258+
columnsHeader.IsEnabled = false;
259+
260+
var authorColumn = new MenuItem();
261+
authorColumn.Header = App.Text("Histories.Header.Author");
262+
if (vm.IsAuthorColumnVisible)
263+
authorColumn.Icon = App.CreateMenuIcon("Icons.Check");
264+
authorColumn.Click += (_, ev) =>
265+
{
266+
vm.IsAuthorColumnVisible = !vm.IsAuthorColumnVisible;
267+
ev.Handled = true;
268+
};
269+
270+
var shaColumn = new MenuItem();
271+
shaColumn.Header = App.Text("Histories.Header.SHA");
272+
if (vm.IsSHAColumnVisible)
273+
shaColumn.Icon = App.CreateMenuIcon("Icons.Check");
274+
shaColumn.Click += (_, ev) =>
275+
{
276+
vm.IsSHAColumnVisible = !vm.IsSHAColumnVisible;
277+
ev.Handled = true;
278+
};
279+
280+
var menu = new ContextMenu();
281+
menu.Items.Add(columnsHeader);
282+
menu.Items.Add(new MenuItem() { Header = "-" });
283+
menu.Items.Add(authorColumn);
284+
menu.Items.Add(shaColumn);
285+
menu.Open(CommitListContainer);
286+
}
244287

245288
e.Handled = true;
246289
}

src/Views/Repository.axaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
Classes="line_path"
106106
Width="26" Height="26"
107107
Background="Transparent"
108-
IsChecked="{Binding OnlyHighlightCurrentBranchInHistories, Mode=TwoWay}"
108+
IsChecked="{Binding OnlyHighlightCurrentBranchInHistory, Mode=TwoWay}"
109109
ToolTip.Tip="{DynamicResource Text.Repository.OnlyHighlightCurrentBranchInGraph}">
110110
<Path Width="12" Height="12" Data="{StaticResource Icons.LightOn}"/>
111111
</ToggleButton>
@@ -851,7 +851,7 @@
851851
<v:Histories CurrentBranch="{Binding $parent[v:Repository].((vm:Repository)DataContext).CurrentBranch}"
852852
Bisect="{Binding Bisect}"
853853
IssueTrackers="{Binding $parent[v:Repository].((vm:Repository)DataContext).IssueTrackers}"
854-
OnlyHighlightCurrentBranch="{Binding $parent[v:Repository].((vm:Repository)DataContext).OnlyHighlightCurrentBranchInHistories}"
854+
OnlyHighlightCurrentBranch="{Binding $parent[v:Repository].((vm:Repository)DataContext).OnlyHighlightCurrentBranchInHistory}"
855855
NavigationId="{Binding NavigationId}"/>
856856
</DataTemplate>
857857

src/Views/Repository.axaml.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,22 +407,22 @@ private void OnOpenAdvancedHistoriesOption(object sender, RoutedEventArgs e)
407407
var dateOrder = new MenuItem();
408408
dateOrder.Header = App.Text("Repository.HistoriesOrder.ByDate");
409409
dateOrder.Tag = "--date-order";
410-
if (!repo.EnableTopoOrderInHistories)
410+
if (!repo.EnableTopoOrderInHistory)
411411
dateOrder.Icon = App.CreateMenuIcon("Icons.Check");
412412
dateOrder.Click += (_, ev) =>
413413
{
414-
repo.EnableTopoOrderInHistories = false;
414+
repo.EnableTopoOrderInHistory = false;
415415
ev.Handled = true;
416416
};
417417

418418
var topoOrder = new MenuItem();
419419
topoOrder.Header = App.Text("Repository.HistoriesOrder.Topo");
420420
topoOrder.Tag = "--topo-order";
421-
if (repo.EnableTopoOrderInHistories)
421+
if (repo.EnableTopoOrderInHistory)
422422
topoOrder.Icon = App.CreateMenuIcon("Icons.Check");
423423
topoOrder.Click += (_, ev) =>
424424
{
425-
repo.EnableTopoOrderInHistories = true;
425+
repo.EnableTopoOrderInHistory = true;
426426
ev.Handled = true;
427427
};
428428

0 commit comments

Comments
 (0)