Skip to content

Commit

Permalink
WIP - Registering plugin when opening commit dialog from startup para…
Browse files Browse the repository at this point in the history
…meter.
  • Loading branch information
maraf committed Jan 10, 2019
1 parent f7e97be commit 3b51b28
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
3 changes: 3 additions & 0 deletions GitUI/CommandsDialogs/FormBrowse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,7 @@ private void RegisterPlugins()
}

UpdatePluginMenu(Module.IsValidGitWorkingDir());
PluginRegistry.ArePluginsRegistered = true;
}

private void UnregisterPlugins()
Expand All @@ -698,6 +699,8 @@ private void UnregisterPlugins()
{
plugin.Unregister(UICommands);
}

PluginRegistry.ArePluginsRegistered = false;
}

/// <summary>
Expand Down
52 changes: 52 additions & 0 deletions GitUI/GitUICommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,57 @@ public bool DoActionOnRepo(Func<bool> action)
return DoActionOnRepo(null, false, true, null, null, action);
}

#region Plugins

private IDisposable RegisterPlugins(IWin32Window owner)
{
if (PluginRegistry.ArePluginsRegistered)
{
return EmptyDiposable.Instance;
}

return new RegisterDisposable(owner, this);
}

private class RegisterDisposable : IDisposable
{
private readonly GitUICommands _commands;

public RegisterDisposable(IWin32Window owner, GitUICommands commands)
{
_commands = commands;

foreach (IGitPlugin plugin in PluginRegistry.Plugins)
{
plugin.Register(_commands);
}

PluginRegistry.ArePluginsRegistered = true;
commands.RaisePostRegisterPlugin(owner);
}

public void Dispose()
{
foreach (IGitPlugin plugin in PluginRegistry.Plugins)
{
plugin.Unregister(_commands);
}

PluginRegistry.ArePluginsRegistered = false;
}
}

private class EmptyDiposable : IDisposable
{
public static readonly EmptyDiposable Instance = new EmptyDiposable();

public void Dispose()
{
}
}

#endregion

#region Checkout

public bool StartCheckoutBranch([CanBeNull] IWin32Window owner, string branch = "", bool remote = false, IReadOnlyList<ObjectId> containRevisions = null)
Expand Down Expand Up @@ -441,6 +492,7 @@ public bool StartCommitDialog(IWin32Window owner, bool showOnlyWhenChanges = fal
bool Action()
{
using (var form = new FormCommit(this))
using (RegisterPlugins(owner))
{
if (showOnlyWhenChanges)
{
Expand Down
2 changes: 2 additions & 0 deletions GitUI/Plugin/PluginRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public static class PluginRegistry

public static List<IRepositoryHostPlugin> GitHosters { get; } = new List<IRepositoryHostPlugin>();

public static bool ArePluginsRegistered { get; set; }

public static void Initialize()
{
lock (Plugins)
Expand Down

0 comments on commit 3b51b28

Please sign in to comment.