Skip to content

Commit 87754c1

Browse files
committed
[Feature] Make default path configurable #54
1 parent 061a17f commit 87754c1

File tree

8 files changed

+70
-12
lines changed

8 files changed

+70
-12
lines changed

src/GitLab.VisualStudio.Shared/GitLab.VisualStudio.Shared.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@
186186
<Compile Include="IViewFactory.cs" />
187187
<Compile Include="IShellService.cs" />
188188
<Compile Include="IWebService.cs" />
189+
<Compile Include="Models\AppSettings.cs" />
189190
<Compile Include="Models\User.cs" />
190191
<Compile Include="Models\CreateSnippetResult.cs" />
191192
<Compile Include="Models\NamespacesPath.cs" />

src/GitLab.VisualStudio.Shared/IStorage.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public interface IStorage
99
User GetUser();
1010

1111
string Host { get; }
12-
12+
1313

1414
string GetPassword(string _host);
1515

@@ -26,5 +26,8 @@ public interface IStorage
2626
bool HaveHost(string host);
2727

2828
void AddHostVersionInfo(string host, ApiVersion apiVersion);
29+
void LoadConfig();
30+
void SaveConfig();
31+
AppSettings AppSettings { get; set; }
2932
}
3033
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace GitLab.VisualStudio.Shared.Models
8+
{
9+
public class AppSettings
10+
{
11+
public string BasePath { get; set; }
12+
}
13+
}

src/GitLab.VisualStudio.Shared/Strings.zh-Hans.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@
363363
<value>创建</value>
364364
</data>
365365
<data name="Visibility" xml:space="preserve">
366-
<value>可见度</value>
366+
<value>可见性级别</value>
367367
</data>
368368
<data name="Title" xml:space="preserve">
369369
<value>标题</value>

src/GitLab.VisualStudio.UI/ViewModels/CloneViewModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ private bool CanClone()
110110

111111
private void OnBrowse()
112112
{
113-
var browsed = _shell.BrowseFolder();
113+
var browsed = _shell.BrowseFolder(selectedPath: BaseRepositoryPath);
114114
if (browsed != null)
115115
{
116116
BaseRepositoryPath = browsed;
@@ -164,8 +164,9 @@ private void OnClone()
164164
Icon = SelectedRepository.Icon
165165
};
166166
_messenger.Send("OnClone", SelectedRepository.Url, repository);
167-
168167
_dialog.Close();
168+
_storage.AppSettings.BasePath = BaseRepositoryPath;
169+
_storage.SaveConfig();
169170
}
170171

171172
private void LoadRepositoriesAsync()

src/GitLab.VisualStudio.UI/ViewModels/CreateViewModel.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public string SelectedVisibilityLevels
188188

189189
private void OnBrowse()
190190
{
191-
var browsed = _shell.BrowseFolder();
191+
var browsed = _shell.BrowseFolder(selectedPath:Path);
192192
if (browsed != null)
193193
{
194194
Path = browsed;
@@ -202,6 +202,9 @@ private void OnSave()
202202
string clonePath = null;
203203
IsBusy = true;
204204
string giturl = null;
205+
_storage.AppSettings.BasePath = Path;
206+
_storage.SaveConfig();
207+
205208
Task.Run(() =>
206209
{
207210
try

src/GitLab.VisualStudio/Services/ShellService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public string BrowseFolder(string title = null, string selectedPath = null)
2121
{
2222
folderBrowser.RootFolder = System.Environment.SpecialFolder.Desktop;
2323
folderBrowser.SelectedPath = selectedPath;
24-
folderBrowser.ShowNewFolderButton = false;
24+
folderBrowser.ShowNewFolderButton = true;
2525

2626
if (title != null)
2727
{

src/GitLab.VisualStudio/Services/Storage.cs

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ namespace GitLab.VisualStudio.Services
1717
[PartCreationPolicy(CreationPolicy.Shared)]
1818
public class Storage : IStorage
1919
{
20+
public Storage()
21+
{
22+
LoadConfig();
23+
}
2024
public bool IsLogined
2125
{
2226
get
@@ -167,11 +171,44 @@ private static void EraseCredential(string key)
167171
}
168172
}
169173

170-
public string GetBaseRepositoryDirectory()
174+
public string GetBaseRepositoryDirectory() => AppSettings?.BasePath;
175+
176+
177+
public AppSettings AppSettings { get; set; }
178+
public void LoadConfig()
171179
{
172-
var user = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
173-
var _path = System.IO.Path.Combine(user, "Source", "Repos");
174-
return _path;
180+
try
181+
{
182+
var filename = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "gitlab4vs.cfg");
183+
if (System.IO.File.Exists(filename))
184+
{
185+
AppSettings = JsonConvert.DeserializeObject<AppSettings>(System.IO.File.ReadAllText(filename));
186+
}
187+
}
188+
catch (Exception)
189+
{
190+
}
191+
if (AppSettings==null)
192+
{
193+
AppSettings = new AppSettings();
194+
}
195+
if (string.IsNullOrEmpty(AppSettings.BasePath))
196+
{
197+
var user = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
198+
AppSettings.BasePath = System.IO.Path.Combine(user, "Source", "Repos");
199+
}
200+
}
201+
public void SaveConfig()
202+
{
203+
try
204+
{
205+
var filename = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "gitlab4vs.cfg");
206+
System.IO.File.WriteAllText(filename, JsonConvert.SerializeObject(AppSettings));
207+
}
208+
catch (Exception)
209+
{
210+
OutputWindowHelper.WarningWriteLine("Can't save config!");
211+
}
175212
}
176213

177214
private Dictionary<string, ApiVersion> HostVersionInfo { get; set; }
@@ -223,7 +260,7 @@ public void LoadHostVersionInfo()
223260
catch (Exception ex)
224261
{
225262
HostVersionInfo = new Dictionary<string, ApiVersion>();
226-
OutputWindowHelper.ExceptionWriteLine("LoadHostVersionInfo", ex);
263+
OutputWindowHelper.WarningWriteLine("Can't load host version infos");
227264
}
228265
if (HostVersionInfo == null) HostVersionInfo = new Dictionary<string, ApiVersion>();
229266
if (HostVersionInfo.Count == 0)
@@ -268,7 +305,7 @@ private void SaveHostVersion()
268305
}
269306
catch (Exception ex)
270307
{
271-
OutputWindowHelper.ExceptionWriteLine("SaveHostVersion", ex);
308+
OutputWindowHelper.WarningWriteLine("Can't save host version info");
272309
}
273310
}
274311
}

0 commit comments

Comments
 (0)