Skip to content

Commit

Permalink
Merge pull request #1925 from feinstaub/feature/goto_plugin_settings
Browse files Browse the repository at this point in the history
Open corresponding SettingsPage directly from Plugin
  • Loading branch information
KindDragon committed Jun 24, 2013
2 parents 5e5cddb + 63d816b commit 3424440
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 66 deletions.
16 changes: 15 additions & 1 deletion GitUI/CommandsDialogs/SettingsDialog/SettingsPageReference.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using GitUIPluginInterfaces;
using System;

namespace GitUI.CommandsDialogs.SettingsDialog
{
Expand All @@ -11,6 +12,9 @@ public abstract class SettingsPageReference
{
}

/// <summary>
/// Type may be a SettingsPage type or a IGitPlugin subclass type
/// </summary>
public class SettingsPageReferenceByType : SettingsPageReference
{
private readonly Type _settingsPageType;
Expand All @@ -37,4 +41,14 @@ public override string ToString()
return SettingsPageType.ToString();
}
}

public class SettingsPageReferenceByPlugin : SettingsPageReferenceByType
{
private readonly IGitPlugin _gitPlugin;

public SettingsPageReferenceByPlugin(IGitPlugin gitPlugin)
: base(gitPlugin.GetType())
{
}
}
}
6 changes: 6 additions & 0 deletions GitUI/GitUICommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,12 @@ public bool StartSettingsDialog()
return StartSettingsDialog(null);
}

public bool StartSettingsDialog(IGitPlugin gitPlugin)
{
// TODO: how to pass the main dialog as owner of the SettingsDialog (first parameter):
return StartSettingsDialog(null, new SettingsPageReferenceByPlugin(gitPlugin));
}

public bool StartArchiveDialog(IWin32Window owner = null, GitRevision revision = null, string path = null)
{
return DoActionOnRepo(owner, true, false, PreArchive, PostArchive, () =>
Expand Down
3 changes: 2 additions & 1 deletion Plugins/BackgroundFetch/BackgroundFetchPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ public override void Unregister(IGitUICommands gitUiCommands)
base.Unregister(gitUiCommands);
}

public override bool Execute(GitUIBaseEventArgs gitUiCommands)
public override bool Execute(GitUIBaseEventArgs gitUiArgs)
{
gitUiArgs.GitUICommands.StartSettingsDialog(this);
return false;
}
}
Expand Down
133 changes: 74 additions & 59 deletions Plugins/DeleteUnusedBranches/DeleteUnusedBranchesForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion Plugins/DeleteUnusedBranches/DeleteUnusedBranchesForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ public sealed partial class DeleteUnusedBranchesForm : Form
private readonly int days;
private readonly string referenceBranch;
private readonly IGitModule gitCommands;
private readonly IGitUICommands _gitUICommands;
private readonly IGitPlugin _gitPlugin;

public DeleteUnusedBranchesForm(int days, string referenceBranch, IGitModule gitCommands)
public DeleteUnusedBranchesForm(int days, string referenceBranch, IGitModule gitCommands, IGitUICommands gitUICommands, IGitPlugin gitPlugin)
{
InitializeComponent();

this.referenceBranch = referenceBranch;
this.days = days;
this.gitCommands = gitCommands;
_gitUICommands = gitUICommands;
_gitPlugin = gitPlugin;
instructionLabel.Text = "Choose branches to delete. Only branches that are fully merged in '" + referenceBranch + "' will be deleted.";
}

Expand Down Expand Up @@ -70,5 +74,12 @@ private void Delete_Click(object sender, EventArgs e)
BranchesGrid.Refresh();
}
}

private void buttonSettings_Click(object sender, EventArgs e)
{
Hide();
Close();
_gitUICommands.StartSettingsDialog(_gitPlugin);
}
}
}
11 changes: 7 additions & 4 deletions Plugins/DeleteUnusedBranches/DeleteUnusedBranchesPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ protected override void RegisterSettings()
{
base.RegisterSettings();
Settings.AddSetting("Delete obsolete branches older than (days)", "30");
Settings.AddSetting("Branch where all branches should be merged in", "HEAD");
Settings.AddSetting("Branch where all branches should be merged in", "HEAD");
}

public override bool Execute(GitUIBaseEventArgs gitUiCommands)
public override bool Execute(GitUIBaseEventArgs gitUiArgs)
{
int days;
if (!int.TryParse(Settings.GetSetting("Delete obsolete branches older than (days)"), out days))
days = 30;

string referenceBranch = Settings.GetSetting("Branch where all branches should be merged in");
using (var frm = new DeleteUnusedBranchesForm(days, referenceBranch, gitUiCommands.GitModule)) frm.ShowDialog(gitUiCommands.OwnerForm as IWin32Window);
string referenceBranch = Settings.GetSetting("Branch where all branches should be merged in");
using (var frm = new DeleteUnusedBranchesForm(days, referenceBranch, gitUiArgs.GitModule, gitUiArgs.GitUICommands, this))
{
frm.ShowDialog(gitUiArgs.OwnerForm as IWin32Window);
}

return true;
}
Expand Down
1 change: 1 addition & 0 deletions Plugins/GitUIPluginInterfaces/IGitUICommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public interface IGitUICommands
bool StartRemotesDialog();
bool StartResolveConflictsDialog();
bool StartSettingsDialog();
bool StartSettingsDialog(IGitPlugin gitPlugin);
bool StartStashDialog();
bool StartSvnCloneDialog();
bool StartSvnDcommitDialog();
Expand Down

0 comments on commit 3424440

Please sign in to comment.