Skip to content

Commit 3db91ed

Browse files
committed
feature: supports to choose group and bookmark when cloning remote repository
Signed-off-by: leo <longshuang@msn.cn>
1 parent 52b51ff commit 3db91ed

File tree

5 files changed

+94
-3
lines changed

5 files changed

+94
-3
lines changed

src/Resources/Locales/en_US.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@
130130
<x:String x:Key="Text.Clone" xml:space="preserve">Clone Remote Repository</x:String>
131131
<x:String x:Key="Text.Clone.AdditionalParam" xml:space="preserve">Extra Parameters:</x:String>
132132
<x:String x:Key="Text.Clone.AdditionalParam.Placeholder" xml:space="preserve">Additional arguments to clone repository. Optional.</x:String>
133+
<x:String x:Key="Text.Clone.Bookmark" xml:space="preserve">Bookmark:</x:String>
134+
<x:String x:Key="Text.Clone.Group" xml:space="preserve">Group:</x:String>
133135
<x:String x:Key="Text.Clone.LocalName" xml:space="preserve">Local Name:</x:String>
134136
<x:String x:Key="Text.Clone.LocalName.Placeholder" xml:space="preserve">Repository name. Optional.</x:String>
135137
<x:String x:Key="Text.Clone.ParentFolder" xml:space="preserve">Parent Folder:</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@
134134
<x:String x:Key="Text.Clone" xml:space="preserve">克隆远程仓库</x:String>
135135
<x:String x:Key="Text.Clone.AdditionalParam" xml:space="preserve">额外参数 :</x:String>
136136
<x:String x:Key="Text.Clone.AdditionalParam.Placeholder" xml:space="preserve">其他克隆参数,选填。</x:String>
137+
<x:String x:Key="Text.Clone.Bookmark" xml:space="preserve">书签 :</x:String>
138+
<x:String x:Key="Text.Clone.Group" xml:space="preserve">自定义分组 :</x:String>
137139
<x:String x:Key="Text.Clone.LocalName" xml:space="preserve">本地仓库名 :</x:String>
138140
<x:String x:Key="Text.Clone.LocalName.Placeholder" xml:space="preserve">本地仓库目录的名字,选填。</x:String>
139141
<x:String x:Key="Text.Clone.ParentFolder" xml:space="preserve">父级目录 :</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@
134134
<x:String x:Key="Text.Clone" xml:space="preserve">複製 (clone) 遠端存放庫</x:String>
135135
<x:String x:Key="Text.Clone.AdditionalParam" xml:space="preserve">額外參數:</x:String>
136136
<x:String x:Key="Text.Clone.AdditionalParam.Placeholder" xml:space="preserve">其他複製參數,選填。</x:String>
137+
<x:String x:Key="Text.Clone.Bookmark" xml:space="preserve">書籤:</x:String>
138+
<x:String x:Key="Text.Clone.Group" xml:space="preserve">群組:</x:String>
137139
<x:String x:Key="Text.Clone.LocalName" xml:space="preserve">本機存放庫名稱:</x:String>
138140
<x:String x:Key="Text.Clone.LocalName.Placeholder" xml:space="preserve">本機存放庫目錄的名稱,選填。</x:String>
139141
<x:String x:Key="Text.Clone.ParentFolder" xml:space="preserve">上層目錄:</x:String>

src/ViewModels/Clone.cs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.ComponentModel.DataAnnotations;
34
using System.IO;
45
using System.Threading.Tasks;
@@ -45,6 +46,28 @@ public string Local
4546
set => SetProperty(ref _local, value);
4647
}
4748

49+
public List<RepositoryNode> Groups
50+
{
51+
get;
52+
}
53+
54+
public RepositoryNode SelectedGroup
55+
{
56+
get => _selectedGroup;
57+
set => SetProperty(ref _selectedGroup, value);
58+
}
59+
60+
public List<int> Bookmarks
61+
{
62+
get;
63+
}
64+
65+
public int Bookmark
66+
{
67+
get => _bookmark;
68+
set => SetProperty(ref _bookmark, value);
69+
}
70+
4871
public string ExtraArgs
4972
{
5073
get => _extraArgs;
@@ -61,6 +84,15 @@ public Clone(string pageId)
6184
{
6285
_pageId = pageId;
6386

87+
Groups = new List<RepositoryNode>();
88+
CollectGroups(Groups, Preferences.Instance.RepositoryNodes);
89+
if (Groups.Count > 0)
90+
SelectedGroup = Groups[0];
91+
92+
Bookmarks = new List<int>();
93+
for (var i = 0; i < Models.Bookmarks.Brushes.Length; i++)
94+
Bookmarks.Add(i);
95+
6496
var activeWorkspace = Preferences.Instance.GetActiveWorkspace();
6597
_parentFolder = activeWorkspace?.DefaultCloneDir;
6698
if (string.IsNullOrEmpty(ParentFolder))
@@ -134,7 +166,8 @@ public override async Task<bool> Sure()
134166

135167
log.Complete();
136168

137-
var node = Preferences.Instance.FindOrAddNodeByRepositoryPath(path, null, true);
169+
var node = Preferences.Instance.FindOrAddNodeByRepositoryPath(path, _selectedGroup, true);
170+
node.Bookmark = _bookmark;
138171
await node.UpdateStatusAsync(false, null);
139172

140173
var launcher = App.GetLauncher();
@@ -153,12 +186,26 @@ public override async Task<bool> Sure()
153186
return true;
154187
}
155188

189+
private void CollectGroups(List<RepositoryNode> outs, List<RepositoryNode> collections)
190+
{
191+
foreach (var node in collections)
192+
{
193+
if (!node.IsRepository)
194+
{
195+
outs.Add(node);
196+
CollectGroups(outs, node.SubNodes);
197+
}
198+
}
199+
}
200+
156201
private string _pageId = string.Empty;
157202
private string _remote = string.Empty;
158203
private bool _useSSH = false;
159204
private string _sshKey = string.Empty;
160205
private string _parentFolder = string.Empty;
161206
private string _local = string.Empty;
162207
private string _extraArgs = string.Empty;
208+
private RepositoryNode _selectedGroup = null;
209+
private int _bookmark = 0;
163210
}
164211
}

src/Views/Clone.axaml

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55
xmlns:vm="using:SourceGit.ViewModels"
66
xmlns:v="using:SourceGit.Views"
7+
xmlns:c="using:SourceGit.Converters"
78
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
89
x:Class="SourceGit.Views.Clone"
910
x:DataType="vm:Clone">
@@ -19,7 +20,7 @@
1920
Text="{DynamicResource Text.Clone}"/>
2021
</StackPanel>
2122

22-
<Grid Margin="8,16,0,0" RowDefinitions="32,Auto,32,32,32,32" ColumnDefinitions="Auto,*">
23+
<Grid Margin="8,16,0,0" RowDefinitions="32,Auto,32,32,32,32,32,32" ColumnDefinitions="Auto,*">
2324
<TextBlock Grid.Row="0" Grid.Column="0"
2425
HorizontalAlignment="Right"
2526
Margin="0,0,8,0"
@@ -102,7 +103,44 @@
102103
Watermark="{DynamicResource Text.Clone.AdditionalParam.Placeholder}"
103104
Text="{Binding ExtraArgs, Mode=TwoWay}"/>
104105

105-
<CheckBox Grid.Row="5" Grid.Column="1"
106+
<TextBlock Grid.Row="5" Grid.Column="0"
107+
HorizontalAlignment="Right"
108+
Margin="0,0,8,0"
109+
Text="{DynamicResource Text.Clone.Group}"/>
110+
<ComboBox Grid.Row="5" Grid.Column="1"
111+
Height="28" Padding="8,0"
112+
VerticalAlignment="Center" HorizontalAlignment="Stretch"
113+
ItemsSource="{Binding Groups}"
114+
SelectedItem="{Binding SelectedGroup, Mode=TwoWay}">
115+
<ComboBox.ItemTemplate>
116+
<DataTemplate DataType="vm:RepositoryNode">
117+
<TextBlock Text="{Binding Name, Mode=OneWay}"/>
118+
</DataTemplate>
119+
</ComboBox.ItemTemplate>
120+
</ComboBox>
121+
122+
<TextBlock Grid.Row="6" Grid.Column="0"
123+
HorizontalAlignment="Right"
124+
Margin="0,0,8,0"
125+
Text="{DynamicResource Text.Clone.Bookmark}"/>
126+
<ComboBox Grid.Row="6" Grid.Column="1"
127+
Height="28" Padding="8,0"
128+
VerticalAlignment="Center"
129+
ItemsSource="{Binding Bookmarks}"
130+
SelectedItem="{Binding Bookmark, Mode=TwoWay}">
131+
<ComboBox.ItemTemplate>
132+
<DataTemplate>
133+
<Grid Height="20">
134+
<Path Width="12" Height="12"
135+
Fill="{Binding Converter={x:Static c:IntConverters.ToBookmarkBrush}}"
136+
HorizontalAlignment="Center" VerticalAlignment="Center"
137+
Data="{StaticResource Icons.Bookmark}"/>
138+
</Grid>
139+
</DataTemplate>
140+
</ComboBox.ItemTemplate>
141+
</ComboBox>
142+
143+
<CheckBox Grid.Row="7" Grid.Column="1"
106144
Content="{DynamicResource Text.Clone.RecurseSubmodules}"
107145
IsChecked="{Binding InitAndUpdateSubmodules, Mode=TwoWay}"
108146
ToolTip.Tip="--recurse-submodules"/>

0 commit comments

Comments
 (0)