Skip to content

Commit ed1351b

Browse files
committed
feature: supports to show submodules as tree or list (#1307)
Signed-off-by: leo <[email protected]>
1 parent d299469 commit ed1351b

File tree

10 files changed

+299
-149
lines changed

10 files changed

+299
-149
lines changed

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,7 @@
617617
<x:String x:Key="Text.Repository.Search.ByMessage" xml:space="preserve">Message</x:String>
618618
<x:String x:Key="Text.Repository.Search.BySHA" xml:space="preserve">SHA</x:String>
619619
<x:String x:Key="Text.Repository.Search.InCurrentBranch" xml:space="preserve">Current Branch</x:String>
620+
<x:String x:Key="Text.Repository.ShowSubmodulesAsTree" xml:space="preserve">Show Submodules as Tree</x:String>
620621
<x:String x:Key="Text.Repository.ShowTagsAsTree" xml:space="preserve">Show Tags as Tree</x:String>
621622
<x:String x:Key="Text.Repository.Skip" xml:space="preserve">SKIP</x:String>
622623
<x:String x:Key="Text.Repository.Statistics" xml:space="preserve">Statistics</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@
621621
<x:String x:Key="Text.Repository.Search.ByMessage" xml:space="preserve">提交信息</x:String>
622622
<x:String x:Key="Text.Repository.Search.BySHA" xml:space="preserve">提交指纹</x:String>
623623
<x:String x:Key="Text.Repository.Search.InCurrentBranch" xml:space="preserve">仅在当前分支中查找</x:String>
624+
<x:String x:Key="Text.Repository.ShowSubmodulesAsTree" xml:space="preserve">以树型结构展示</x:String>
624625
<x:String x:Key="Text.Repository.ShowTagsAsTree" xml:space="preserve">以树型结构展示</x:String>
625626
<x:String x:Key="Text.Repository.Skip" xml:space="preserve">跳过此提交</x:String>
626627
<x:String x:Key="Text.Repository.Statistics" 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
@@ -621,6 +621,7 @@
621621
<x:String x:Key="Text.Repository.Search.ByMessage" xml:space="preserve">提交訊息</x:String>
622622
<x:String x:Key="Text.Repository.Search.BySHA" xml:space="preserve">提交編號</x:String>
623623
<x:String x:Key="Text.Repository.Search.InCurrentBranch" xml:space="preserve">僅搜尋目前分支</x:String>
624+
<x:String x:Key="Text.Repository.ShowSubmodulesAsTree" xml:space="preserve">以樹型結構展示</x:String>
624625
<x:String x:Key="Text.Repository.ShowTagsAsTree" xml:space="preserve">以樹型結構展示</x:String>
625626
<x:String x:Key="Text.Repository.Skip" xml:space="preserve">跳過此提交</x:String>
626627
<x:String x:Key="Text.Repository.Statistics" xml:space="preserve">提交統計</x:String>

src/Resources/Styles.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@
12351235
<Setter Property="Opacity" Value="1"/>
12361236
</Style>
12371237

1238-
<Style Selector="ToggleButton.tag_display_mode">
1238+
<Style Selector="ToggleButton.show_as_tree">
12391239
<Setter Property="Margin" Value="0" />
12401240
<Setter Property="Background" Value="Transparent"/>
12411241
<Setter Property="Template">

src/ViewModels/Preferences.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ public bool ShowTagsInGraph
188188
set => SetProperty(ref _showTagsInGraph, value);
189189
}
190190

191+
public bool ShowSubmodulesAsTree
192+
{
193+
get;
194+
set;
195+
} = false;
196+
191197
public bool UseTwoColumnsLayoutInHistories
192198
{
193199
get => _useTwoColumnsLayoutInHistories;

src/ViewModels/Repository.cs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,21 @@ public List<Models.Submodule> Submodules
210210
private set => SetProperty(ref _submodules, value);
211211
}
212212

213-
public SubmoduleCollection VisibleSubmodules
213+
public bool ShowSubmodulesAsTree
214+
{
215+
get => Preferences.Instance.ShowSubmodulesAsTree;
216+
set
217+
{
218+
if (value != Preferences.Instance.ShowSubmodulesAsTree)
219+
{
220+
Preferences.Instance.ShowSubmodulesAsTree = value;
221+
VisibleSubmodules = BuildVisibleSubmodules();
222+
OnPropertyChanged();
223+
}
224+
}
225+
}
226+
227+
public object VisibleSubmodules
214228
{
215229
get => _visibleSubmodules;
216230
private set => SetProperty(ref _visibleSubmodules, value);
@@ -536,7 +550,7 @@ public void Close()
536550
_tags.Clear();
537551
_visibleTags.Clear();
538552
_submodules.Clear();
539-
_visibleSubmodules.Clear();
553+
_visibleSubmodules = null;
540554
_searchedCommits.Clear();
541555
_selectedSearchedCommit = null;
542556

@@ -2512,7 +2526,7 @@ private BranchTreeNode.Builder BuildBranchTree(List<Models.Branch> branches, Lis
25122526
return visible;
25132527
}
25142528

2515-
private SubmoduleCollection BuildVisibleSubmodules()
2529+
private object BuildVisibleSubmodules()
25162530
{
25172531
var visible = new List<Models.Submodule>();
25182532
if (string.IsNullOrEmpty(_filter))
@@ -2528,7 +2542,10 @@ private SubmoduleCollection BuildVisibleSubmodules()
25282542
}
25292543
}
25302544

2531-
return SubmoduleCollection.Build(visible, _visibleSubmodules);
2545+
if (Preferences.Instance.ShowSubmodulesAsTree)
2546+
return SubmoduleCollectionAsTree.Build(visible, _visibleSubmodules as SubmoduleCollectionAsTree);
2547+
else
2548+
return new SubmoduleCollectionAsList() { Submodules = visible };
25322549
}
25332550

25342551
private void RefreshHistoriesFilters(bool refresh)
@@ -2760,7 +2777,7 @@ private void AutoFetchImpl(object sender)
27602777
private List<Models.Tag> _tags = new List<Models.Tag>();
27612778
private List<Models.Tag> _visibleTags = new List<Models.Tag>();
27622779
private List<Models.Submodule> _submodules = new List<Models.Submodule>();
2763-
private SubmoduleCollection _visibleSubmodules = new SubmoduleCollection();
2780+
private object _visibleSubmodules = null;
27642781

27652782
private bool _isAutoFetching = false;
27662783
private Timer _autoFetchTimer = null;

src/ViewModels/SubmoduleTreeNode.cs renamed to src/ViewModels/SubmoduleCollection.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private static void InsertFolder(List<SubmoduleTreeNode> collection, SubmoduleTr
120120
private bool _isExpanded = false;
121121
}
122122

123-
public class SubmoduleCollection
123+
public class SubmoduleCollectionAsTree
124124
{
125125
public List<SubmoduleTreeNode> Tree
126126
{
@@ -134,16 +134,19 @@ public AvaloniaList<SubmoduleTreeNode> Rows
134134
set;
135135
} = [];
136136

137-
public static SubmoduleCollection Build(List<Models.Submodule> submodules, SubmoduleCollection old)
137+
public static SubmoduleCollectionAsTree Build(List<Models.Submodule> submodules, SubmoduleCollectionAsTree old)
138138
{
139139
var oldExpanded = new HashSet<string>();
140-
foreach (var row in old.Rows)
140+
if (old != null)
141141
{
142-
if (row.IsFolder && row.IsExpanded)
143-
oldExpanded.Add(row.FullPath);
142+
foreach (var row in old.Rows)
143+
{
144+
if (row.IsFolder && row.IsExpanded)
145+
oldExpanded.Add(row.FullPath);
146+
}
144147
}
145148

146-
var collection = new SubmoduleCollection();
149+
var collection = new SubmoduleCollectionAsTree();
147150
collection.Tree = SubmoduleTreeNode.Build(submodules, oldExpanded);
148151

149152
var rows = new List<SubmoduleTreeNode>();
@@ -203,4 +206,13 @@ private void MakeTreeRows(List<SubmoduleTreeNode> rows, List<SubmoduleTreeNode>
203206
}
204207
}
205208
}
209+
210+
public class SubmoduleCollectionAsList
211+
{
212+
public List<Models.Submodule> Submodules
213+
{
214+
get;
215+
set;
216+
} = [];
217+
}
206218
}

src/Views/Repository.axaml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@
269269
<Run Text="{Binding Tags, Converter={x:Static c:ListConverters.ToCount}}"/>
270270
</TextBlock>
271271
<ToggleButton Grid.Column="2"
272-
Classes="tag_display_mode"
272+
Classes="show_as_tree"
273273
Width="14"
274274
IsChecked="{Binding Source={x:Static vm:Preferences.Instance}, Path=ShowTagsAsTree, Mode=TwoWay}"
275275
ToolTip.Tip="{DynamicResource Text.Repository.ShowTagsAsTree}"/>
@@ -305,13 +305,19 @@
305305

306306
<!-- Submodules -->
307307
<ToggleButton Grid.Row="6" Classes="group_expander" IsChecked="{Binding IsSubmoduleGroupExpanded, Mode=TwoWay}">
308-
<Grid ColumnDefinitions="16,*,Auto,Auto">
308+
<Grid ColumnDefinitions="16,*,Auto,Auto,Auto">
309309
<Path Grid.Column="0" Width="10" Height="10" Margin="2,0,0,0" HorizontalAlignment="Left" Data="{StaticResource Icons.Submodules}" Fill="{DynamicResource Brush.FG2}"/>
310310
<TextBlock Grid.Column="1" Classes="group_header_label" Margin="0">
311311
<Run Text="{DynamicResource Text.Repository.Submodules}"/>
312312
<Run Text="{Binding Submodules, Converter={x:Static c:ListConverters.ToCount}}"/>
313313
</TextBlock>
314-
<Button Grid.Column="2"
314+
<ToggleButton Grid.Column="2"
315+
Classes="show_as_tree"
316+
Width="14"
317+
IsChecked="{Binding ShowSubmodulesAsTree, Mode=TwoWay}"
318+
IsVisible="{Binding Submodules, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}"
319+
ToolTip.Tip="{DynamicResource Text.Repository.ShowSubmodulesAsTree}"/>
320+
<Button Grid.Column="3"
315321
Classes="icon_button"
316322
Width="14"
317323
Margin="8,0"
@@ -320,7 +326,7 @@
320326
ToolTip.Tip="{DynamicResource Text.Repository.Submodules.Update}">
321327
<Path Width="12" Height="12" Data="{StaticResource Icons.Loading}"/>
322328
</Button>
323-
<Button Grid.Column="3"
329+
<Button Grid.Column="4"
324330
Classes="icon_button"
325331
Width="14"
326332
Margin="0,0,8,0"
@@ -334,7 +340,7 @@
334340
x:Name="SubmoduleList"
335341
Height="0"
336342
Margin="8,0,4,0"
337-
Submodules="{Binding VisibleSubmodules}"
343+
Content="{Binding VisibleSubmodules}"
338344
RowsChanged="OnSubmodulesRowsChanged"
339345
Focusable="False"
340346
IsVisible="{Binding IsSubmoduleGroupExpanded, Mode=OneWay}"/>

0 commit comments

Comments
 (0)