Skip to content

Commit

Permalink
Correct IScriptsManager resolution in Settings dialog (#11254)
Browse files Browse the repository at this point in the history
Resolves #11253
  • Loading branch information
RussKie committed Oct 9, 2023
1 parent 44cf233 commit 8ec3ae8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 32 deletions.
19 changes: 5 additions & 14 deletions GitUI/CommandsDialogs/SettingsDialog/Pages/HotkeysSettingsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,20 @@ namespace GitUI.CommandsDialogs.SettingsDialog.Pages
{
public partial class HotkeysSettingsPage : SettingsPageWithHeader
{
private readonly IScriptsManager _scriptsManager;

public HotkeysSettingsPage(IServiceProvider serviceProvider)
: base(serviceProvider)
{
_scriptsManager = serviceProvider.GetRequiredService<IScriptsManager>();

InitializeComponent();
InitializeComplete();
}

private IScriptsManager ScriptsManager
{
get
{
if (!TryGetUICommands(out IGitUICommands commands))
{
throw new InvalidOperationException("IGitUICommands should have been assigned");
}

return commands.GetRequiredService<IScriptsManager>();
}
}

protected override void SettingsToPage()
{
controlHotkeys.ReloadSettings(ScriptsManager);
controlHotkeys.ReloadSettings(_scriptsManager);

base.SettingsToPage();
}
Expand Down
23 changes: 7 additions & 16 deletions GitUI/CommandsDialogs/SettingsDialog/Pages/ScriptsSettingsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ public partial class ScriptsSettingsPage : SettingsPageWithHeader
{
ColorDepth = ColorDepth.Depth32Bit
};

private readonly BindingList<ScriptInfoProxy> _scripts = new();
private readonly IScriptsManager _scriptsManager;
private SimpleHelpDisplayDialog? _argumentsCheatSheet;
private bool _handlingCheck;

Expand All @@ -89,6 +91,8 @@ public partial class ScriptsSettingsPage : SettingsPageWithHeader
public ScriptsSettingsPage(IServiceProvider serviceProvider)
: base(serviceProvider)
{
_scriptsManager = serviceProvider.GetRequiredService<IScriptsManager>();

InitializeComponent();

// stop the localisation of the propertygrid
Expand All @@ -115,19 +119,6 @@ public ScriptsSettingsPage(IServiceProvider serviceProvider)
};
}

private IScriptsManager ScriptsManager
{
get
{
if (!TryGetUICommands(out IGitUICommands commands))
{
throw new InvalidOperationException("IGitUICommands should have been assigned");
}

return commands.GetRequiredService<IScriptsManager>();
}
}

private ScriptInfoProxy? SelectedScript { get; set; }

protected override void OnParentChanged(EventArgs e)
Expand Down Expand Up @@ -174,7 +165,7 @@ protected override void SettingsToPage()
{
_scripts.Clear();

foreach (var script in ScriptsManager.GetScripts())
foreach (var script in _scriptsManager.GetScripts())
{
_scripts.Add(script);
}
Expand All @@ -191,15 +182,15 @@ protected override void PageToSettings()
{
// TODO: this is an abomination, the whole script persistence must be scorched and rewritten

List<ScriptInfo> scripts = new(ScriptsManager.GetScripts());
BindingList<ScriptInfo> scripts = _scriptsManager.GetScripts();
scripts.Clear();

foreach (ScriptInfoProxy proxy in _scripts)
{
scripts.Add(proxy);
}

AppSettings.OwnScripts = ScriptsManager.SerializeIntoXml();
AppSettings.OwnScripts = _scriptsManager.SerializeIntoXml();

base.PageToSettings();
}
Expand Down
2 changes: 1 addition & 1 deletion GitUI/Editor/FileViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ protected override void Dispose(bool disposing)
_async.Dispose();
components?.Dispose();

if (TryGetUICommands(out var uiCommands))
if (TryGetUICommandsDirect(out var uiCommands))
{
uiCommands.PostSettings -= UICommands_PostSettings;
}
Expand Down
2 changes: 1 addition & 1 deletion GitUI/GitModuleControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public IGitUICommandsSource UICommandsSource
/// <para>By contrast, the <see cref="UICommands"/> property attempts to initialise
/// the value if not previously initialised.</para>
/// </remarks>
public bool TryGetUICommands([NotNullWhen(returnValue: true)] out GitUICommands? commands)
internal bool TryGetUICommandsDirect([NotNullWhen(returnValue: true)] out GitUICommands? commands)
{
commands = _uiCommandsSource?.UICommands;
return commands is not null;
Expand Down

0 comments on commit 8ec3ae8

Please sign in to comment.