Skip to content

Commit 70caa00

Browse files
committed
feature: add an option to set the default active tab in commit details panel (#1784)
NOTE: This option only affects the tab that is activated when the commit details panel is first displayed after the repository is opened. After that, the repository will retain the last activated tab instead of resetting to the default. Signed-off-by: leo <[email protected]>
1 parent d5f1890 commit 70caa00

File tree

12 files changed

+55
-32
lines changed

12 files changed

+55
-32
lines changed

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@
567567
<x:String x:Key="Text.Preferences.General.MaxHistoryCommits" xml:space="preserve">History Commits</x:String>
568568
<x:String x:Key="Text.Preferences.General.ShowAuthorTime" xml:space="preserve">Show author time instead of commit time in graph</x:String>
569569
<x:String x:Key="Text.Preferences.General.ShowChangesPageByDefault" xml:space="preserve">Show `LOCAL CHANGES` page by default</x:String>
570+
<x:String x:Key="Text.Preferences.General.ShowChangesTabInCommitDetailByDefault" xml:space="preserve">Show `CHANGES` tab in commit detail by default</x:String>
570571
<x:String x:Key="Text.Preferences.General.ShowChildren" xml:space="preserve">Show children in the commit details</x:String>
571572
<x:String x:Key="Text.Preferences.General.ShowTagsInGraph" xml:space="preserve">Show tags in commit graph</x:String>
572573
<x:String x:Key="Text.Preferences.General.SubjectGuideLength" xml:space="preserve">Subject Guide Length</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@
571571
<x:String x:Key="Text.Preferences.General.MaxHistoryCommits" xml:space="preserve">最大历史提交数</x:String>
572572
<x:String x:Key="Text.Preferences.General.ShowAuthorTime" xml:space="preserve">在提交路线图中显示修改时间而非提交时间</x:String>
573573
<x:String x:Key="Text.Preferences.General.ShowChangesPageByDefault" xml:space="preserve">默认显示【本地更改】页</x:String>
574+
<x:String x:Key="Text.Preferences.General.ShowChangesTabInCommitDetailByDefault" xml:space="preserve">在提交详情页默认打开【变更对比】标签页</x:String>
574575
<x:String x:Key="Text.Preferences.General.ShowChildren" xml:space="preserve">在提交详情页中显示子提交列表</x:String>
575576
<x:String x:Key="Text.Preferences.General.ShowTagsInGraph" xml:space="preserve">在提交路线图中显示标签</x:String>
576577
<x:String x:Key="Text.Preferences.General.SubjectGuideLength" xml:space="preserve">SUBJECT字数检测</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@
571571
<x:String x:Key="Text.Preferences.General.MaxHistoryCommits" xml:space="preserve">最大歷史提交數</x:String>
572572
<x:String x:Key="Text.Preferences.General.ShowAuthorTime" xml:space="preserve">在提交路線圖中顯示修改時間而非提交時間</x:String>
573573
<x:String x:Key="Text.Preferences.General.ShowChangesPageByDefault" xml:space="preserve">預設顯示「本機變更」頁面</x:String>
574+
<x:String x:Key="Text.Preferences.General.ShowChangesTabInCommitDetailByDefault" xml:space="preserve">在提交詳細資訊頁面預設顯示【變更對比】</x:String>
574575
<x:String x:Key="Text.Preferences.General.ShowChildren" xml:space="preserve">在提交詳細資訊中顯示後續提交</x:String>
575576
<x:String x:Key="Text.Preferences.General.ShowTagsInGraph" xml:space="preserve">在路線圖中顯示標籤</x:String>
576577
<x:String x:Key="Text.Preferences.General.SubjectGuideLength" xml:space="preserve">提交標題字數偵測</x:String>

src/ViewModels/CommitDetail.cs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,34 @@
1010

1111
namespace SourceGit.ViewModels
1212
{
13+
public class CommitDetailSharedData
14+
{
15+
public int ActiveTabIndex
16+
{
17+
get;
18+
set;
19+
}
20+
21+
public CommitDetailSharedData()
22+
{
23+
ActiveTabIndex = Preferences.Instance.ShowChangesInCommitDetailByDefault ? 1 : 0;
24+
}
25+
}
26+
1327
public partial class CommitDetail : ObservableObject, IDisposable
1428
{
1529
public Repository Repository
1630
{
1731
get => _repo;
1832
}
1933

20-
public int ActivePageIndex
34+
public int ActiveTabIndex
2135
{
22-
get => _rememberActivePageIndex ? _repo.CommitDetailActivePageIndex : _activePageIndex;
36+
get => _sharedData.ActiveTabIndex;
2337
set
2438
{
25-
if (_rememberActivePageIndex)
26-
_repo.CommitDetailActivePageIndex = value;
27-
else
28-
_activePageIndex = value;
29-
30-
OnPropertyChanged();
39+
if (value != _sharedData.ActiveTabIndex)
40+
_sharedData.ActiveTabIndex = value;
3141
}
3242
}
3343

@@ -142,10 +152,10 @@ public bool CanOpenRevisionFileWithDefaultEditor
142152
private set => SetProperty(ref _canOpenRevisionFileWithDefaultEditor, value);
143153
}
144154

145-
public CommitDetail(Repository repo, bool rememberActivePageIndex)
155+
public CommitDetail(Repository repo, CommitDetailSharedData sharedData)
146156
{
147157
_repo = repo;
148-
_rememberActivePageIndex = rememberActivePageIndex;
158+
_sharedData = sharedData ?? new CommitDetailSharedData();
149159
WebLinks = Models.CommitLink.Get(repo.Remotes);
150160
}
151161

@@ -569,8 +579,7 @@ private async Task SetViewingCommitAsync(Models.Object file)
569579
private static partial Regex REG_SHA_FORMAT();
570580

571581
private Repository _repo = null;
572-
private bool _rememberActivePageIndex = true;
573-
private int _activePageIndex = 0;
582+
private CommitDetailSharedData _sharedData = null;
574583
private Models.Commit _commit = null;
575584
private Models.CommitFullMessage _fullMessage = null;
576585
private Models.CommitSignInfo _signInfo = null;

src/ViewModels/DirHistories.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public DirHistories(Repository repo, string dir, string revision = null)
4848
Title = dir;
4949

5050
_repo = repo;
51-
_detail = new CommitDetail(repo, false);
51+
_detail = new CommitDetail(repo, null);
5252
_detail.SearchChangeFilter = dir;
5353

5454
Task.Run(async () =>

src/ViewModels/Histories.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public GridLength BottomArea
8989
public Histories(Repository repo)
9090
{
9191
_repo = repo;
92+
_commitDetailSharedData = new CommitDetailSharedData();
9293
}
9394

9495
public void Dispose()
@@ -173,7 +174,7 @@ public void Select(IList commits)
173174
}
174175
else
175176
{
176-
var commitDetail = new CommitDetail(_repo, true);
177+
var commitDetail = new CommitDetail(_repo, _commitDetailSharedData);
177178
commitDetail.Commit = commit;
178179
DetailContext = commitDetail;
179180
}
@@ -392,14 +393,15 @@ private void NavigateTo(Models.Commit commit)
392393
}
393394
else
394395
{
395-
var commitDetail = new CommitDetail(_repo, true);
396+
var commitDetail = new CommitDetail(_repo, _commitDetailSharedData);
396397
commitDetail.Commit = commit;
397398
DetailContext = commitDetail;
398399
}
399400
}
400401
}
401402

402403
private Repository _repo = null;
404+
private CommitDetailSharedData _commitDetailSharedData = null;
403405
private bool _isLoading = true;
404406
private List<Models.Commit> _commits = new List<Models.Commit>();
405407
private Models.CommitGraph _graph = null;

src/ViewModels/InteractiveRebase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public object Detail
122122
public InteractiveRebase(Repository repo, Models.Commit on, InteractiveRebasePrefill prefill = null)
123123
{
124124
_repo = repo;
125-
_commitDetail = new CommitDetail(repo, false);
125+
_commitDetail = new CommitDetail(repo, null);
126126
Current = repo.CurrentBranch;
127127
On = on;
128128
IsLoading = true;

src/ViewModels/Preferences.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ public bool ShowLocalChangesByDefault
125125
set;
126126
} = false;
127127

128+
public bool ShowChangesInCommitDetailByDefault
129+
{
130+
get;
131+
set;
132+
} = false;
133+
128134
public int MaxHistoryCommits
129135
{
130136
get => _maxHistoryCommits;

src/ViewModels/Repository.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -472,12 +472,6 @@ public bool IsAutoFetching
472472
private set => SetProperty(ref _isAutoFetching, value);
473473
}
474474

475-
public int CommitDetailActivePageIndex
476-
{
477-
get;
478-
set;
479-
} = 0;
480-
481475
public AvaloniaList<Models.IssueTracker> IssueTrackers
482476
{
483477
get;

src/Views/CommitDetail.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
1010
x:Class="SourceGit.Views.CommitDetail"
1111
x:DataType="vm:CommitDetail">
12-
<TabControl SelectedIndex="{Binding ActivePageIndex, Mode=TwoWay}" Padding="4">
12+
<TabControl SelectedIndex="{Binding ActiveTabIndex, Mode=TwoWay}" Padding="4">
1313
<!-- Information Page -->
1414
<TabItem>
1515
<TabItem.Header>

0 commit comments

Comments
 (0)