Skip to content

Commit ec74c6d

Browse files
committed
refactor: commit refs presenter
- Add `Use compact branch names in commit graph` setting in `Preferences` window - Compact branch names should only be used in commit graph Signed-off-by: leo <longshuang@msn.cn>
1 parent 5bbef39 commit ec74c6d

7 files changed

Lines changed: 32 additions & 5 deletions

File tree

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@
672672
<x:String x:Key="Text.Preferences.General.ShowTagsInGraph" xml:space="preserve">Show tags in commit graph</x:String>
673673
<x:String x:Key="Text.Preferences.General.SubjectGuideLength" xml:space="preserve">Subject Guide Length</x:String>
674674
<x:String x:Key="Text.Preferences.General.Use24Hours" xml:space="preserve">24-Hours</x:String>
675+
<x:String x:Key="Text.Preferences.General.UseCompactBranchNames" xml:space="preserve">Use compact branch names in commit graph</x:String>
675676
<x:String x:Key="Text.Preferences.General.UseGitHubStyleAvatar" xml:space="preserve">Generate Github style default avatar</x:String>
676677
<x:String x:Key="Text.Preferences.Git" xml:space="preserve">GIT</x:String>
677678
<x:String x:Key="Text.Preferences.Git.CRLF" xml:space="preserve">Enable Auto CRLF</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@
676676
<x:String x:Key="Text.Preferences.General.ShowTagsInGraph" xml:space="preserve">在提交路线图中显示标签</x:String>
677677
<x:String x:Key="Text.Preferences.General.SubjectGuideLength" xml:space="preserve">SUBJECT字数检测</x:String>
678678
<x:String x:Key="Text.Preferences.General.Use24Hours" xml:space="preserve">24小时制</x:String>
679+
<x:String x:Key="Text.Preferences.General.UseCompactBranchNames" xml:space="preserve">在提交路线图中使用精简分支名</x:String>
679680
<x:String x:Key="Text.Preferences.General.UseGitHubStyleAvatar" xml:space="preserve">生成GitHub风格的默认头像</x:String>
680681
<x:String x:Key="Text.Preferences.Git" xml:space="preserve">GIT配置</x:String>
681682
<x:String x:Key="Text.Preferences.Git.CRLF" 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
@@ -676,6 +676,7 @@
676676
<x:String x:Key="Text.Preferences.General.ShowTagsInGraph" xml:space="preserve">在路線圖中顯示標籤</x:String>
677677
<x:String x:Key="Text.Preferences.General.SubjectGuideLength" xml:space="preserve">提交標題字數偵測</x:String>
678678
<x:String x:Key="Text.Preferences.General.Use24Hours" xml:space="preserve">24 小時制</x:String>
679+
<x:String x:Key="Text.Preferences.General.UseCompactBranchNames" xml:space="preserve">在提交路線圖中使用簡潔的分支標籤</x:String>
679680
<x:String x:Key="Text.Preferences.General.UseGitHubStyleAvatar" xml:space="preserve">產生 GitHub 風格的預設頭貼</x:String>
680681
<x:String x:Key="Text.Preferences.Git" xml:space="preserve">Git 設定</x:String>
681682
<x:String x:Key="Text.Preferences.Git.CRLF" xml:space="preserve">自動換行轉換</x:String>

src/ViewModels/Preferences.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ public bool ShowTagsInGraph
217217
set => SetProperty(ref _showTagsInGraph, value);
218218
}
219219

220+
public bool UseCompactBranchNamesInGraph
221+
{
222+
get => _useCompactBranchNamesInGraph;
223+
set => SetProperty(ref _useCompactBranchNamesInGraph, value);
224+
}
225+
220226
public bool UseTwoColumnsLayoutInHistories
221227
{
222228
get => _useTwoColumnsLayoutInHistories;
@@ -827,6 +833,7 @@ private bool RemoveInvalidRepositoriesRecursive(List<RepositoryNode> collection)
827833
private bool _useGitHubStyleAvatar = true;
828834
private bool _showAuthorTimeInGraph = false;
829835
private bool _showChildren = false;
836+
private bool _useCompactBranchNamesInGraph = true;
830837

831838
private bool _check4UpdatesOnStartup = true;
832839
private double _lastCheckUpdateTime = 0;

src/Views/CommitRefsPresenter.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ public IBrush Foreground
5757
set => SetValue(ForegroundProperty, value);
5858
}
5959

60+
public static readonly StyledProperty<bool> UseCompactBranchNamesProperty =
61+
AvaloniaProperty.Register<CommitRefsPresenter, bool>(nameof(UseCompactBranchNames));
62+
63+
public bool UseCompactBranchNames
64+
{
65+
get => GetValue(UseCompactBranchNamesProperty);
66+
set => SetValue(UseCompactBranchNamesProperty, value);
67+
}
68+
6069
public static readonly StyledProperty<bool> UseGraphColorProperty =
6170
AvaloniaProperty.Register<CommitRefsPresenter, bool>(nameof(UseGraphColor));
6271

@@ -91,6 +100,7 @@ static CommitRefsPresenter()
91100
FontSizeProperty,
92101
ForegroundProperty,
93102
UseGraphColorProperty,
103+
UseCompactBranchNamesProperty,
94104
BackgroundProperty,
95105
ShowTagsProperty);
96106
}
@@ -195,6 +205,7 @@ protected override Size MeasureOverride(Size availableSize)
195205
return new Size(0, 0);
196206
}
197207

208+
var useCompactBranchNames = UseCompactBranchNames;
198209
var typeface = new Typeface(FontFamily);
199210
var typefaceHead = new Typeface(FontFamily, FontStyle.Normal, FontWeight.Bold);
200211
var typefaceRemote = new Typeface(FontFamily, FontStyle.Italic, FontWeight.Bold);
@@ -264,7 +275,7 @@ protected override Size MeasureOverride(Size availableSize)
264275

265276
item.Width = item.Label.Width + 24;
266277

267-
if (findRemotes)
278+
if (findRemotes && useCompactBranchNames)
268279
{
269280
for (var j = i + 1; j < count; j++)
270281
{

src/Views/Histories.axaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@
125125
ShowTags="{Binding Source={x:Static vm:Preferences.Instance}, Path=ShowTagsInGraph}"
126126
FontSize="12"
127127
VerticalAlignment="Center"
128-
UseGraphColor="{Binding IsHighlightedInGraph, Mode=OneWay}"/>
128+
UseGraphColor="{Binding IsHighlightedInGraph, Mode=OneWay}"
129+
UseCompactBranchNames="{Binding Source={x:Static vm:Preferences.Instance}, Path=UseCompactBranchNamesInGraph}"/>
129130

130131
<v:CommitSubjectPresenter Grid.Column="3"
131132
Height="26"

src/Views/Preferences.axaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<TabItem.Header>
4848
<TextBlock Classes="tab_header" Text="{DynamicResource Text.Preferences.General}"/>
4949
</TabItem.Header>
50-
<Grid Margin="8" RowDefinitions="32,32,32,32,32,32,32,32,32,32,32,32,32,Auto" ColumnDefinitions="Auto,*">
50+
<Grid Margin="8" RowDefinitions="32,32,32,32,32,32,32,32,32,32,32,32,32,32,Auto" ColumnDefinitions="Auto,*">
5151
<TextBlock Grid.Row="0" Grid.Column="0"
5252
Text="{DynamicResource Text.Preferences.General.Locale}"
5353
HorizontalAlignment="Right"
@@ -172,16 +172,21 @@
172172
IsChecked="{Binding ShowChildren, Mode=TwoWay}"/>
173173

174174
<CheckBox Grid.Row="11" Grid.Column="1"
175+
Height="32"
176+
Content="{DynamicResource Text.Preferences.General.UseCompactBranchNames}"
177+
IsChecked="{Binding UseCompactBranchNamesInGraph, Mode=TwoWay}"/>
178+
179+
<CheckBox Grid.Row="12" Grid.Column="1"
175180
Height="32"
176181
Content="{DynamicResource Text.Preferences.General.EnableCompactFolders}"
177182
IsChecked="{Binding EnableCompactFoldersInChangesTree, Mode=TwoWay}"/>
178183

179-
<CheckBox Grid.Row="12" Grid.Column="1"
184+
<CheckBox Grid.Row="13" Grid.Column="1"
180185
Height="32"
181186
Content="{DynamicResource Text.Preferences.General.UseGitHubStyleAvatar}"
182187
IsChecked="{Binding UseGitHubStyleAvatar, Mode=TwoWay}"/>
183188

184-
<CheckBox Grid.Row="13" Grid.Column="1"
189+
<CheckBox Grid.Row="14" Grid.Column="1"
185190
Height="32"
186191
Content="{DynamicResource Text.Preferences.General.Check4UpdatesOnStartup}"
187192
IsVisible="{x:Static s:App.IsCheckForUpdateCommandVisible}"

0 commit comments

Comments
 (0)