Skip to content

Commit 48dab52

Browse files
committed
Fix the way Settings are now managed in GitExtensions
1 parent 0beb13f commit 48dab52

File tree

3 files changed

+17
-47
lines changed

3 files changed

+17
-47
lines changed

GitTfsPlugin.cs

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,9 @@
77

88
namespace GitTfs.GitExtensions.Plugin
99
{
10-
public class GitTfsPlugin : IGitPlugin
10+
public class GitTfsPlugin : GitPluginBase
1111
{
12-
public IEnumerable<ISetting> GetSettings()
13-
{
14-
return new List<ISetting>();
15-
}
16-
17-
public void Register(IGitUICommands gitUiCommands)
18-
{
19-
var existingKeys = Settings.GetAvailableSettings();
20-
21-
var settingsToAdd = from field in typeof(SettingKeys).GetFields(BindingFlags.Public | BindingFlags.Static)
22-
let key = (string)field.GetValue(null)
23-
where !existingKeys.Contains(key)
24-
select key;
25-
26-
foreach (var settingToAdd in settingsToAdd)
27-
{
28-
Settings.AddSetting(settingToAdd, string.Empty);
29-
}
30-
}
31-
32-
public void Unregister(IGitUICommands gitUiCommands)
33-
{
34-
}
35-
36-
public bool Execute(GitUIBaseEventArgs gitUiCommands)
12+
public override bool Execute(GitUIBaseEventArgs gitUiCommands)
3713
{
3814
if (string.IsNullOrEmpty(gitUiCommands.GitModule.WorkingDir))
3915
{
@@ -62,15 +38,11 @@ private static IEnumerable<string> GetTfsRemotes(IGitUICommands commands)
6238
: Enumerable.Empty<string>();
6339
}
6440

65-
public string Description
41+
public override string Description
6642
{
67-
get { return "git-tfs"; }
43+
get { return "Git-Tfs"; }
6844
}
6945

70-
ISettingsSource IGitPlugin.Settings { get; set; }
71-
72-
public IGitPluginSettingsContainer Settings { get; set; }
73-
7446
public SettingsContainer PluginSettings
7547
{
7648
get { return new SettingsContainer(Settings); }

SettingsContainer.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ namespace GitTfs.GitExtensions.Plugin
66
{
77
public class SettingsContainer
88
{
9-
private readonly IGitPluginSettingsContainer _container;
9+
private readonly ISettingsSource _container;
1010

11-
public SettingsContainer(IGitPluginSettingsContainer container)
11+
public SettingsContainer(ISettingsSource container)
1212
{
1313
_container = container;
1414
}
1515

1616
public string TfsRemote
1717
{
18-
get { return _container.GetSetting(SettingKeys.TfsRemote); }
19-
set { _container.SetSetting(SettingKeys.TfsRemote, value); }
18+
get { return _container.GetValue(SettingKeys.TfsRemote, null , x => x); }
19+
set { _container.SetValue(SettingKeys.TfsRemote, value, x => x); }
2020
}
2121

2222
public PullSetting? PullSetting
@@ -40,17 +40,15 @@ public ShelveSettingsContainer ShelveSettings
4040
where T : struct
4141
{
4242
var type = typeof (T);
43-
var value = _container.GetSetting(key);
44-
45-
return (from name in Enum.GetNames(type)
46-
where name == value
47-
select (T?) Enum.Parse(type, name)).FirstOrDefault();
43+
return _container.GetValue(key, default(T), x => (from name in Enum.GetNames(type)
44+
where name == x
45+
select (T?) Enum.Parse(type, name)).FirstOrDefault());
4846
}
4947

5048
private void SetEnumSettingValue<T>(string key, T? value)
5149
where T : struct
5250
{
53-
_container.SetSetting(key, value.HasValue ? value.ToString() : string.Empty);
51+
_container.SetValue(key, value, x => x.HasValue ? x.ToString() : string.Empty);
5452
}
5553
}
5654
}

ShelveSettingsContainer.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ namespace GitTfs.GitExtensions.Plugin
44
{
55
public class ShelveSettingsContainer
66
{
7-
private readonly IGitPluginSettingsContainer _container;
7+
private readonly ISettingsSource _container;
88

9-
public ShelveSettingsContainer(IGitPluginSettingsContainer container)
9+
public ShelveSettingsContainer(ISettingsSource container)
1010
{
1111
_container = container;
1212
}
1313

1414
public string Name
1515
{
16-
get { return _container.GetSetting(SettingKeys.ShelvesetName); }
17-
set { _container.SetSetting(SettingKeys.ShelvesetName, value); }
16+
get { return _container.GetValue(SettingKeys.ShelvesetName, string.Empty, x => x); }
17+
set { _container.SetValue(SettingKeys.ShelvesetName, value, x => x); }
1818
}
1919

2020
public bool Overwrite
@@ -26,7 +26,7 @@ public bool Overwrite
2626
}
2727
set
2828
{
29-
_container.SetSetting(SettingKeys.OverwriteShelveset, value.ToString());
29+
_container.SetValue(SettingKeys.OverwriteShelveset, value, x => x.ToString());
3030
}
3131
}
3232
}

0 commit comments

Comments
 (0)