Skip to content

Commit

Permalink
Merge pull request #8995 from ivangrek/fix-5797
Browse files Browse the repository at this point in the history
Resolve PluginSettings key names issue
  • Loading branch information
ivangrek committed Mar 26, 2021
2 parents 643c033 + 7c901fb commit c9b8c73
Show file tree
Hide file tree
Showing 34 changed files with 266 additions and 209 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void InitDashboardLayout()
foreach (var gitHoster in PluginRegistry.GitHosters)
{
lastControl = CreateLink(panel, string.Format(_cloneFork.Text, gitHoster.Description), Images.CloneRepoGitHub,
lastControl = CreateLink(panel, string.Format(_cloneFork.Text, gitHoster.Name), Images.CloneRepoGitHub,
(repoSender, eventArgs) => UICommands.StartCloneForkFromHoster(this, gitHoster, GitModuleChanged));
}
Expand Down
4 changes: 2 additions & 2 deletions GitUI/CommandsDialogs/FormBrowse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ private void RegisterPlugins()

var item = new ToolStripMenuItem
{
Text = plugin.Description,
Text = plugin.Name,
Image = plugin.Icon,
Tag = plugin
};
Expand Down Expand Up @@ -990,7 +990,7 @@ private void RegisterPlugins()
_repositoryHostsToolStripMenuItem.Visible = PluginRegistry.GitHosters.Count > 0;
if (PluginRegistry.GitHosters.Count == 1)
{
_repositoryHostsToolStripMenuItem.Text = PluginRegistry.GitHosters[0].Description;
_repositoryHostsToolStripMenuItem.Text = PluginRegistry.GitHosters[0].Name;
}

UpdatePluginMenu(Module.IsValidGitWorkingDir());
Expand Down
4 changes: 2 additions & 2 deletions GitUI/CommandsDialogs/RepoHosting/ForkAndCloneForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private void Init()
});
}

Text = _gitHoster.Description + ": " + Text;
Text = $"{_gitHoster.Name}: {Text}";

UpdateCloneInfo();
UpdateMyRepos();
Expand Down Expand Up @@ -134,7 +134,7 @@ private void UpdateMyRepos()
await this.SwitchToMainThreadAsync();
myReposLV.Items.Clear();
helpTextLbl.Text = string.Format(_strFailedToGetRepos.Text, _gitHoster.Description) +
helpTextLbl.Text = string.Format(_strFailedToGetRepos.Text, _gitHoster.Name) +
"\r\n\r\nException: " + ex.Message + "\r\n\r\n" + helpTextLbl.Text;
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ private void CreateSettingsControls()

private void Init(IGitPlugin gitPlugin)
{
Validates.NotNull(gitPlugin.Name);
Validates.NotNull(gitPlugin.Description);

_gitPlugin = gitPlugin;
_settingsContainer = new GitPluginSettingsContainer(gitPlugin.Name);

// Description for old plugin setting processing as key
_settingsContainer = new GitPluginSettingsContainer(gitPlugin.Id, gitPlugin.Description);
CreateSettingsControls();
InitializeComplete();
}
Expand All @@ -52,7 +54,7 @@ protected override ISettingsSource GetCurrentSettings()

public override string GetTitle()
{
return _gitPlugin?.Description ?? string.Empty;
return _gitPlugin?.Name ?? string.Empty;
}

private IEnumerable<ISetting> GetSettings()
Expand Down
29 changes: 26 additions & 3 deletions GitUI/Plugin/GitPluginSettingsContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ namespace GitUI
{
public class GitPluginSettingsContainer : ISettingsSource, IGitPluginSettingsContainer
{
private readonly Guid _pluginId;
private readonly string _pluginName;
private ISettingsSource? _settingsSource;

public GitPluginSettingsContainer(string pluginName)
public GitPluginSettingsContainer(Guid pluginId, string pluginName)
{
_pluginId = pluginId;
_pluginName = pluginName;
}

Expand All @@ -34,12 +36,33 @@ public override SettingLevel SettingLevel

public override T GetValue<T>(string name, T defaultValue, Func<string, T> decode)
{
return ExternalSettings.GetValue(_pluginName + name, defaultValue, decode);
// for old plugin setting processing
if (_pluginId == Guid.Empty)
{
return ExternalSettings.GetValue($"{_pluginName}{name}", defaultValue, decode);
}

var value = ExternalSettings.GetValue($"{_pluginId}.{name}", defaultValue, decode);

// for old plugin setting processing
if (value is null || value.Equals(defaultValue))
{
value = ExternalSettings.GetValue($"{_pluginName}{name}", defaultValue, decode);
}

return value;
}

public override void SetValue<T>(string name, T value, Func<T, string?> encode)
{
ExternalSettings.SetValue(_pluginName + name, value, encode);
if (_pluginId == Guid.Empty)
{
ExternalSettings.SetValue($"{_pluginName}{name}", value, encode);
}
else
{
ExternalSettings.SetValue($"{_pluginId}.{name}", value, encode);
}
}
}
}
6 changes: 4 additions & 2 deletions GitUI/Plugin/PluginRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ public static void Initialize()

foreach (var plugin in ManagedExtensibility.GetExports<IGitPlugin>().Select(lazy => lazy.Value))
{
Validates.NotNull(plugin.Name);
plugin.SettingsContainer = new GitPluginSettingsContainer(plugin.Name);
Validates.NotNull(plugin.Description);

// Description for old plugin setting processing as key
plugin.SettingsContainer = new GitPluginSettingsContainer(plugin.Id, plugin.Description);

if (plugin is IRepositoryHostPlugin repositoryHostPlugin)
{
Expand Down
2 changes: 1 addition & 1 deletion GitUI/Script/ScriptRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private static CommandStatus RunScriptInternal(IWin32Window owner, IGitModule mo
{
foreach (var plugin in PluginRegistry.Plugins)
{
if (string.Equals(plugin.Description, command, StringComparison.CurrentCultureIgnoreCase))
if (string.Equals(plugin.Name, command, StringComparison.CurrentCultureIgnoreCase))
{
var eventArgs = new GitUIEventArgs(owner, uiCommands);
return new CommandStatus(executed: true, needsGridRefresh: plugin.Execute(eventArgs));
Expand Down
30 changes: 15 additions & 15 deletions GitUI/Translation/Czech.Plugins.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</file>
<file datatype="plaintext" original="AutoCompileSubModulesPlugin" source-language="en" target-language="cs">
<body>
<trans-unit id="Description.Text">
<trans-unit id="Name.Text">
<source>Auto compile SubModules</source>
<target>Automaticky přeložit podmoduly</target>

Expand Down Expand Up @@ -48,7 +48,7 @@
</file>
<file datatype="plaintext" original="BackgroundFetchPlugin" source-language="en" target-language="cs">
<body>
<trans-unit id="Description.Text">
<trans-unit id="Name.Text">
<source>Periodic background fetch</source>
<target>Pravidelné přenášení na pozadí</target>

Expand Down Expand Up @@ -97,7 +97,7 @@
<target>Uživatelské jméno na Bitbucket</target>

</trans-unit>
<trans-unit id="Description.Text">
<trans-unit id="Name.Text">
<source>Bitbucket Server</source>
<target>Bitbucket server</target>

Expand Down Expand Up @@ -296,7 +296,7 @@
</file>
<file datatype="plaintext" original="CreateLocalBranchesPlugin" source-language="en" target-language="cs">
<body>
<trans-unit id="Description.Text">
<trans-unit id="Name.Text">
<source>Create local tracking branches</source>
<target>Vytvořit místní sledovací větve</target>

Expand Down Expand Up @@ -458,7 +458,7 @@ Opravdu chcete pokračovat?</target>
</file>
<file datatype="plaintext" original="DeleteUnusedBranchesPlugin" source-language="en" target-language="cs">
<body>
<trans-unit id="Description.Text">
<trans-unit id="Name.Text">
<source>Delete obsolete branches</source>
<target>Smazat zastaralé větve</target>

Expand Down Expand Up @@ -577,7 +577,7 @@ Opravdu chcete pokračovat?</target>
</file>
<file datatype="plaintext" original="FindLargeFilesPlugin" source-language="en" target-language="cs">
<body>
<trans-unit id="Description.Text">
<trans-unit id="Name.Text">
<source>Find large files</source>
<target>Najít velké soubory</target>

Expand Down Expand Up @@ -1022,7 +1022,7 @@ To enable Gerrit support for a repository, a .gitreview file must be created. Th
</file>
<file datatype="plaintext" original="GerritPlugin" source-language="en" target-language="cs">
<body>
<trans-unit id="Description.Text">
<trans-unit id="Name.Text">
<source>Gerrit Code Review</source>
<target>Gerrit - Revize kódu</target>

Expand Down Expand Up @@ -1230,7 +1230,7 @@ To enable Gerrit support for a repository, a .gitreview file must be created. Th
</file>
<file datatype="plaintext" original="GitFlowPlugin" source-language="en" target-language="cs">
<body>
<trans-unit id="Description.Text">
<trans-unit id="Name.Text">
<source>GitFlow</source>
<target>GitFlow</target>

Expand All @@ -1239,7 +1239,7 @@ To enable Gerrit support for a repository, a .gitreview file must be created. Th
</file>
<file datatype="plaintext" original="GitHub3Plugin" source-language="en" target-language="cs">
<body>
<trans-unit id="Description.Text">
<trans-unit id="Name.Text">
<source>GitHub</source>
<target>GitHub</target>

Expand All @@ -1265,7 +1265,7 @@ To enable Gerrit support for a repository, a .gitreview file must be created. Th
</file>
<file datatype="plaintext" original="GitImpactPlugin" source-language="en" target-language="cs">
<body>
<trans-unit id="Description.Text">
<trans-unit id="Name.Text">
<source>Impact Graph</source>
<target>Graf vlivu</target>

Expand All @@ -1274,7 +1274,7 @@ To enable Gerrit support for a repository, a .gitreview file must be created. Th
</file>
<file datatype="plaintext" original="GitStatisticsPlugin" source-language="en" target-language="cs">
<body>
<trans-unit id="Description.Text">
<trans-unit id="Name.Text">
<source>Statistics</source>
<target>Statistiky</target>

Expand All @@ -1298,7 +1298,7 @@ To enable Gerrit support for a repository, a .gitreview file must be created. Th
</file>
<file datatype="plaintext" original="GourcePlugin" source-language="en" target-language="cs">
<body>
<trans-unit id="Description.Text">
<trans-unit id="Name.Text">
<source>Gource</source>
<target>Gource</target>

Expand Down Expand Up @@ -1445,7 +1445,7 @@ Chcete znovu nastavit cestu?</target>
</file>
<file datatype="plaintext" original="JiraCommitHintPlugin" source-language="en" target-language="cs">
<body>
<trans-unit id="Description.Text">
<trans-unit id="Name.Text">
<source>Jira Commit Hint</source>

</trans-unit>
Expand Down Expand Up @@ -1553,7 +1553,7 @@ Chcete znovu nastavit cestu?</target>
</file>
<file datatype="plaintext" original="ProxySwitcherPlugin" source-language="en" target-language="cs">
<body>
<trans-unit id="Description.Text">
<trans-unit id="Name.Text">
<source>Proxy Switcher</source>
<target>Přepínač proxy serverů</target>

Expand Down Expand Up @@ -1708,7 +1708,7 @@ název větve, nebo značky)</target>
</file>
<file datatype="plaintext" original="ReleaseNotesGeneratorPlugin" source-language="en" target-language="cs">
<body>
<trans-unit id="Description.Text">
<trans-unit id="Name.Text">
<source>Release Notes Generator</source>
<target>Generátor poznámek k vydání</target>

Expand Down
Loading

0 comments on commit c9b8c73

Please sign in to comment.