Skip to content

Commit 26fef12

Browse files
committed
feature: add Focus on Current Branch mode (#2836)
- When this is toggled, all history filters will be cleared. And only commits belongs to the current branch will be listed in `Dashboard` page. - Manually add a branch/tag history filter will disable this feature automatically Signed-off-by: leo <longshuang@msn.cn>
1 parent 8591664 commit 26fef12

6 files changed

Lines changed: 83 additions & 10 deletions

File tree

‎src/Models/RepositoryUIStates.cs‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,12 @@ public string LastCommitMessage
225225
set;
226226
} = string.Empty;
227227

228+
public bool FocusOnCurrentBranch
229+
{
230+
get;
231+
set;
232+
} = false;
233+
228234
public AvaloniaList<HistoryFilter> HistoryFilters
229235
{
230236
get;
@@ -429,13 +435,20 @@ public string BuildHistoryParams(string gitDir)
429435
if (HistoryShowFlags.HasFlag(HistoryShowFlags.SimplifyByDecoration))
430436
builder.Append("--simplify-by-decoration ");
431437

432-
var mode = GetHistoryFilterMode();
433-
if (mode == FilterMode.None)
434-
builder.Append("--branches --remotes --tags HEAD");
435-
else if (mode == FilterMode.Included)
436-
BuildHistoryParamsForIncluded(builder);
438+
if (FocusOnCurrentBranch)
439+
{
440+
builder.Append("HEAD");
441+
}
437442
else
438-
BuildHistoryParamsForExcluded(builder, gitDir);
443+
{
444+
var mode = GetHistoryFilterMode();
445+
if (mode == FilterMode.None)
446+
builder.Append("--branches --remotes --tags HEAD");
447+
else if (mode == FilterMode.Included)
448+
BuildHistoryParamsForIncluded(builder);
449+
else
450+
BuildHistoryParamsForExcluded(builder, gitDir);
451+
}
439452

440453
return builder.ToString();
441454
}

‎src/Resources/Icons.axaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
<StreamGeometry x:Key="Icons.Local">M976 0h-928A48 48 0 000 48v652a48 48 0 0048 48h416V928H200a48 48 0 000 96h624a48 48 0 000-96H560v-180h416a48 48 0 0048-48V48A48 48 0 00976 0zM928 652H96V96h832v556z</StreamGeometry>
9494
<StreamGeometry x:Key="Icons.Lock">M832 464h-68V240a128 128 0 00-128-128h-248a128 128 0 00-128 128v224H192c-18 0-32 14-32 32v384c0 18 14 32 32 32h640c18 0 32-14 32-32v-384c0-18-14-32-32-32zm-292 237v53a8 8 0 01-8 8h-40a8 8 0 01-8-8v-53a48 48 0 1156 0zm152-237H332V240a56 56 0 0156-56h248a56 56 0 0156 56v224z</StreamGeometry>
9595
<StreamGeometry x:Key="Icons.Logs">M908 366h-25V248a18 18 0 00-0-2 20 20 0 00-5-13L681 7 681 7a19 19 0 00-4-3c-0-0-1-1-1-1a29 29 0 00-4-2L671 1a24 24 0 00-5-1H181a40 40 0 00-40 40v326h-25c-32 0-57 26-57 57v298c0 32 26 57 57 57h25v204c0 22 18 40 40 40H843a40 40 0 0040-40v-204h25c32 0 57-26 57-57V424a57 57 0 00-57-57zM181 40h465v205c0 11 9 20 20 20h177v101H181V40zm413 527c0 89-54 143-134 143-81 0-128-61-128-138 0-82 52-143 132-143 84 0 129 63 129 138zm-440 139V433h62v220h108v52h-170zm690 267H181v-193H843l0 193zm18-280a305 305 0 01-91 15c-50 0-86-12-111-37-25-23-39-59-38-99 0-90 66-142 155-142 35 0 62 7 76 13l-13 49c-15-6-33-12-63-12-51 0-90 29-90 88 0 56 35 89 86 89 14 0 25-2 30-4v-57h-42v-48h101v143zM397 570c0 53 25 91 66 91 42 0 65-40 65-92 0-49-23-91-66-91-42 0-66 40-66 93z</StreamGeometry>
96+
<StreamGeometry x:Key="Icons.Magic">M650 662l-94 198a26 26 0 01-42 7l-151-160a26 26 0 00-15-8l-218-29a26 26 0 01-19-38l105-193a26 26 0 003-17L177 207a26 26 0 0130-30l216 40a26 26 0 0017-3l193-105a26 26 0 0138 19l29 218a26 26 0 008 15l160 151a26 26 0 01-7 42l-198 94a26 26 0 00-12 12zm34 82 60-60 181 181-60 60-181-181z</StreamGeometry>
9697
<StreamGeometry x:Key="Icons.Menu">M192 192m-64 0a64 64 0 1 0 128 0 64 64 0 1 0-128 0ZM192 512m-64 0a64 64 0 1 0 128 0 64 64 0 1 0-128 0ZM192 832m-64 0a64 64 0 1 0 128 0 64 64 0 1 0-128 0ZM864 160H352c-17.7 0-32 14.3-32 32s14.3 32 32 32h512c17.7 0 32-14.3 32-32s-14.3-32-32-32zM864 480H352c-17.7 0-32 14.3-32 32s14.3 32 32 32h512c17.7 0 32-14.3 32-32s-14.3-32-32-32zM864 800H352c-17.7 0-32 14.3-32 32s14.3 32 32 32h512c17.7 0 32-14.3 32-32s-14.3-32-32-32z</StreamGeometry>
9798
<StreamGeometry x:Key="Icons.Merge">M824 645V307c0-56-46-102-102-102h-102V102l-154 154 154 154V307h102v338c-46 20-82 67-82 123 0 72 61 133 133 133 72 0 133-61 133-133 0-56-36-102-82-123zm-51 195c-41 0-72-31-72-72s31-72 72-72c41 0 72 31 72 72s-31 72-72 72zM384 256c0-72-61-133-133-133-72 0-133 61-133 133 0 56 36 102 82 123v266C154 666 118 712 118 768c0 72 61 133 133 133 72 0 133-61 133-133 0-56-36-102-82-123V379C348 358 384 312 384 256zM323 768c0 41-31 72-72 72-41 0-72-31-72-72s31-72 72-72c41 0 72 31 72 72zM251 328c-41 0-72-31-72-72s31-72 72-72c41 0 72 31 72 72s-31 72-72 72z</StreamGeometry>
9899
<StreamGeometry x:Key="Icons.Message">M688 544a48 48 0 110-96 48 48 0 010 96M512 544a48 48 0 110-96 48 48 0 010 96m-176 0a48 48 0 11-0-96A48 48 0 01336 544M805 192H219C186 192 160 219 160 253v471c0 34 26 61 59 61h189c6 0 16 6 18 11l38 72 3 5c11 14 27 23 44 23h0c17 0 33-8 45-23l41-77c2-5 12-11 18-11h190c32 0 59-27 59-61V253C864 219 838 192 805 192</StreamGeometry>

‎src/Resources/Locales/en_US.axaml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,11 @@
830830
<x:String x:Key="Text.Repository.FilterCommits.Expand" xml:space="preserve">Expand Filters</x:String>
831831
<x:String x:Key="Text.Repository.FilterCommits.Include" xml:space="preserve">Filter in commit graph</x:String>
832832
<x:String x:Key="Text.Repository.FilterCommits.Summary" xml:space="preserve">filter(s) enabled</x:String>
833+
<x:String x:Key="Text.Repository.FocusOnCurrentBranch" xml:space="preserve">Focus on Current Branch
834+
835+
When this is toggled, all history filters will be cleared. And only commits belongs to the current branch will be listed in `Dashboard` page.
836+
837+
Manually add a branch/tag history filter will disable this feature automatically.</x:String>
833838
<x:String x:Key="Text.Repository.HistoriesLayout" xml:space="preserve">LAYOUT</x:String>
834839
<x:String x:Key="Text.Repository.HistoriesLayout.Horizontal" xml:space="preserve">Horizontal</x:String>
835840
<x:String x:Key="Text.Repository.HistoriesLayout.Vertical" xml:space="preserve">Vertical</x:String>

‎src/Resources/Locales/zh_CN.axaml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,11 @@
834834
<x:String x:Key="Text.Repository.FilterCommits.Expand" xml:space="preserve">展开过滤项列表</x:String>
835835
<x:String x:Key="Text.Repository.FilterCommits.Include" xml:space="preserve">使用其对提交列表过滤</x:String>
836836
<x:String x:Key="Text.Repository.FilterCommits.Summary" xml:space="preserve">个过滤项已被启用</x:String>
837+
<x:String x:Key="Text.Repository.FocusOnCurrentBranch" xml:space="preserve">专注模式
838+
839+
进入该模式后,历史提交列表将仅显示属于当前分支的提交,并且自动清空已设置的过滤条件。
840+
841+
用户手动添加新的分支或标签过滤条件后,自动退出该模式。</x:String>
837842
<x:String x:Key="Text.Repository.HistoriesLayout" xml:space="preserve">布局方式</x:String>
838843
<x:String x:Key="Text.Repository.HistoriesLayout.Horizontal" xml:space="preserve">水平排布</x:String>
839844
<x:String x:Key="Text.Repository.HistoriesLayout.Vertical" xml:space="preserve">竖直排布</x:String>

‎src/ViewModels/Repository.cs‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@ public Models.GitFlow GitFlow
4545
set;
4646
} = new();
4747

48+
public bool FocusOnCurrentBranch
49+
{
50+
get => _uiStates.FocusOnCurrentBranch;
51+
set
52+
{
53+
if (value != _uiStates.FocusOnCurrentBranch)
54+
{
55+
_uiStates.FocusOnCurrentBranch = value;
56+
OnPropertyChanged();
57+
58+
if (value && _historyFilterMode != Models.FilterMode.None)
59+
ClearHistoryFilters();
60+
else
61+
RefreshCommits();
62+
}
63+
}
64+
}
65+
4866
public Models.FilterMode HistoryFilterMode
4967
{
5068
get => _historyFilterMode;
@@ -990,6 +1008,13 @@ public void UpdateBranchNodeIsExpanded(BranchTreeNode node)
9901008

9911009
public void SetTagFilterMode(Models.Tag tag, Models.FilterMode mode)
9921010
{
1011+
// Auto turn off `FocusOnCurrentBranch` when user set a tag filter manually.
1012+
if (_uiStates.FocusOnCurrentBranch)
1013+
{
1014+
_uiStates.FocusOnCurrentBranch = false;
1015+
OnPropertyChanged(nameof(FocusOnCurrentBranch));
1016+
}
1017+
9931018
var changed = _uiStates.UpdateHistoryFilters(tag.Name, Models.FilterType.Tag, mode);
9941019
if (changed)
9951020
RefreshHistoryFilters(true);
@@ -1004,6 +1029,13 @@ public void SetBranchFilterMode(Models.Branch branch, Models.FilterMode mode, bo
10041029

10051030
public void SetBranchFilterMode(BranchTreeNode node, Models.FilterMode mode, bool clearExists, bool refresh)
10061031
{
1032+
// Auto turn off `FocusOnCurrentBranch` when user set a branch filter manually.
1033+
if (_uiStates.FocusOnCurrentBranch)
1034+
{
1035+
_uiStates.FocusOnCurrentBranch = false;
1036+
OnPropertyChanged(nameof(FocusOnCurrentBranch));
1037+
}
1038+
10071039
var isLocal = node.Path.StartsWith("refs/heads/", StringComparison.Ordinal);
10081040
var tree = isLocal ? _localBranchTrees : _remoteBranchTrees;
10091041

@@ -1224,7 +1256,9 @@ public void RefreshCommits()
12241256

12251257
var builder = new StringBuilder();
12261258
builder
1227-
.Append('-').Append(Preferences.Instance.MaxHistoryCommits).Append(' ')
1259+
.Append('-')
1260+
.Append(Preferences.Instance.MaxHistoryCommits)
1261+
.Append(' ')
12281262
.Append(_uiStates.BuildHistoryParams(GitDir));
12291263

12301264
var commits = await new Commands.QueryCommits(FullPath, builder.ToString())

‎src/Views/RepositoryToolbar.axaml‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,14 @@
127127
<Button Width="0" Height="0" Click="FetchDirectlyByHotKey" IsVisible="False" HotKey="{OnPlatform Ctrl+Down, macOS=⌘+Down}"/>
128128
</StackPanel>
129129

130-
<Grid Grid.Column="3" HorizontalAlignment="Right" ColumnDefinitions="Auto,*,32">
130+
<Grid Grid.Column="3" HorizontalAlignment="Right" ColumnDefinitions="Auto,*,Auto,Auto,6">
131131
<Path Grid.Column="0"
132132
Width="13" Height="13"
133133
Margin="18,0,0,0"
134134
Data="{StaticResource Icons.Branch}"/>
135135

136136
<Border Grid.Column="1"
137-
Margin="6,0,0,0"
137+
Margin="6,0"
138138
Background="Transparent"
139139
ToolTip.Tip="{Binding CurrentBranch?.Name, TargetNullValue='--', Mode=OneWay}">
140140
<TextBlock Text="{Binding CurrentBranch?.Name, TargetNullValue='--', Mode=OneWay}"
@@ -143,13 +143,28 @@
143143

144144
<Button Grid.Column="2"
145145
Classes="icon_button"
146-
Width="32"
146+
Width="28"
147147
Click="NavigateToHead"
148148
ToolTip.Tip="{DynamicResource Text.Repository.NavigateToCurrentHead}">
149149
<Path Width="13" Height="13"
150150
Margin="0,2,0,0"
151151
Data="{StaticResource Icons.Target}"/>
152152
</Button>
153+
154+
<ToggleButton Grid.Column="3"
155+
Classes="line_path"
156+
Width="28"
157+
IsChecked="{Binding FocusOnCurrentBranch, Mode=TwoWay}"
158+
ToolTip.Tip="{DynamicResource Text.Repository.FocusOnCurrentBranch}">
159+
<ToggleButton.Styles>
160+
<Style Selector="ToolTip">
161+
<Setter Property="MaxWidth" Value="400"/>
162+
</Style>
163+
</ToggleButton.Styles>
164+
165+
<Path Width="13" Height="13"
166+
Data="{StaticResource Icons.Magic}"/>
167+
</ToggleButton>
153168
</Grid>
154169
</Grid>
155170
</UserControl>

0 commit comments

Comments
 (0)