Skip to content

Commit

Permalink
Fixed hotkey execution for RevisionGrid. Closes #1939
Browse files Browse the repository at this point in the history
  • Loading branch information
KindDragon committed Jul 4, 2013
1 parent ae39d0e commit b90acb1
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 66 deletions.
28 changes: 14 additions & 14 deletions GitUI/GitModuleControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,31 @@ public class GitModuleControl : GitExtensionsControl

[Browsable(false)]
public event GitUICommandsSourceSetEventHandler GitUICommandsSourceSet;
private IGitUICommandsSource _UICommandsSource;
private IGitUICommandsSource _uiCommandsSource;

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[Browsable(false)]
public IGitUICommandsSource UICommandsSource
{
get
{
if (_UICommandsSource == null)
if (_uiCommandsSource == null)
SearchForUICommandsSource();
if (_UICommandsSource == null)
if (_uiCommandsSource == null)
throw new NullReferenceException("UICommandsSource");
return _UICommandsSource;
return _uiCommandsSource;
}
set
{
if (value == null)
throw new ArgumentException("Can not assign null value to UICommandsSource");
if (_UICommandsSource != null)
if (_uiCommandsSource != null)
throw new ArgumentException("UICommandsSource is already set");

_UICommandsSource = value;
_uiCommandsSource = value;

if (GitUICommandsSourceSet != null)
GitUICommandsSourceSet(this, _UICommandsSource);
GitUICommandsSourceSet(this, _uiCommandsSource);
}

}
Expand Down Expand Up @@ -65,15 +66,15 @@ public GitModuleControl()

protected override void Dispose(bool disposing)
{
if (_UICommandsSource != null)
if (_uiCommandsSource != null)
DisposeUICommandsSource();

base.Dispose(disposing);
}

protected virtual void DisposeUICommandsSource()
{
_UICommandsSource = null;
_uiCommandsSource = null;
}

private void SearchForUICommandsSource()
Expand All @@ -83,7 +84,7 @@ private void SearchForUICommandsSource()

lock (this)
{
if (_UICommandsSource != null)
if (_uiCommandsSource != null)
return;

IGitUICommandsSource cs = null;
Expand All @@ -104,13 +105,12 @@ protected override bool ExecuteCommand(int command)
{
if (ExecuteScriptCommand(command))
return true;
else
return base.ExecuteCommand(command);
return base.ExecuteCommand(command);
}

protected virtual bool ExecuteScriptCommand(int command)
protected bool ExecuteScriptCommand(int command)
{
return GitUI.Script.ScriptRunner.ExecuteScriptCommand(Module, command);
return Script.ScriptRunner.ExecuteScriptCommand(Module, command, this as RevisionGrid);
}
}
}
20 changes: 9 additions & 11 deletions GitUI/GitModuleForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ namespace GitUI
{
public class GitModuleForm : GitExtensionsForm, IGitUICommandsSource
{
private GitUICommands _UICommands;
private GitUICommands _uiCommands;
[Browsable(false)]
public GitUICommands UICommands
{
get
{
if (_UICommands == null)
if (_uiCommands == null)
throw new NullReferenceException("Commands");

return _UICommands;
return _uiCommands;
}

protected set
{
GitUICommands oldCommands = _UICommands;
_UICommands = value;
GitUICommands oldCommands = _uiCommands;
_uiCommands = value;
if (GitUICommandsChanged != null)
GitUICommandsChanged(this, oldCommands);
}
Expand All @@ -31,7 +31,7 @@ public bool IsUICommandsInitialized
{
get
{
return _UICommands != null;
return _uiCommands != null;
}
}

Expand All @@ -58,14 +58,12 @@ protected override bool ExecuteCommand(int command)
{
if (ExecuteScriptCommand(command))
return true;
else
return base.ExecuteCommand(command);
return base.ExecuteCommand(command);
}

protected virtual bool ExecuteScriptCommand(int command)
protected bool ExecuteScriptCommand(int command)
{
return GitUI.Script.ScriptRunner.ExecuteScriptCommand(Module, command);
return Script.ScriptRunner.ExecuteScriptCommand(Module, command);
}

}
}
21 changes: 10 additions & 11 deletions GitUI/Script/ScriptRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace GitUI.Script
{
public static class ScriptRunner
{
public static bool ExecuteScriptCommand(GitModule aModule, int command)
public static bool ExecuteScriptCommand(GitModule aModule, int command, RevisionGrid revisionGrid = null)
{
var curScripts = ScriptManager.GetScripts();
bool anyScriptExecuted = false;
Expand All @@ -17,15 +17,14 @@ public static bool ExecuteScriptCommand(GitModule aModule, int command)
{
if (s.HotkeyCommandIdentifier == command)
{
RunScript(aModule, s.Name, null);
RunScript(aModule, s.Name, revisionGrid);
anyScriptExecuted = true;
}
}
return anyScriptExecuted;
}


public static void RunScript(GitModule aModule, string script, RevisionGrid RevisionGrid)
public static void RunScript(GitModule aModule, string script, RevisionGrid revisionGrid)
{
if (string.IsNullOrEmpty(script))
return;
Expand All @@ -48,17 +47,17 @@ public static void RunScript(GitModule aModule, string script, RevisionGrid Revi
continue;
if (!option.StartsWith("{s"))
continue;
if (RevisionGrid != null)
if (revisionGrid != null)
continue;
MessageBox.Show(
string.Format("Option {0} is only supported when started from revision grid.", option),
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
RunScript(aModule, scriptInfo, RevisionGrid);
RunScript(aModule, scriptInfo, revisionGrid);
}

internal static void RunScript(GitModule aModule, ScriptInfo scriptInfo, RevisionGrid RevisionGrid)
internal static void RunScript(GitModule aModule, ScriptInfo scriptInfo, RevisionGrid revisionGrid)
{
string command = scriptInfo.Command;
string argument = scriptInfo.Arguments;
Expand All @@ -84,11 +83,11 @@ internal static void RunScript(GitModule aModule, ScriptInfo scriptInfo, Revisio
continue;
if (!option.StartsWith("{s") || selectedRevision != null)
{
currentRevision = GetCurrentRevision(aModule, RevisionGrid, currentTags, currentLocalBranches, currentRemoteBranches, currentBranches, currentRevision, option);
currentRevision = GetCurrentRevision(aModule, revisionGrid, currentTags, currentLocalBranches, currentRemoteBranches, currentBranches, currentRevision, option);
}
else
{
selectedRevision = CalculateSelectedRevision(RevisionGrid, selectedRemoteBranches, selectedRemotes, selectedLocalBranches, selectedBranches, selectedTags);
selectedRevision = CalculateSelectedRevision(revisionGrid, selectedRemoteBranches, selectedRemotes, selectedLocalBranches, selectedBranches, selectedTags);
}

switch (option)
Expand Down Expand Up @@ -241,11 +240,11 @@ internal static void RunScript(GitModule aModule, ScriptInfo scriptInfo, Revisio
FormProcess.ShowDialog(null, command, argument, aModule.WorkingDir, null, true);
}

private static GitRevision CalculateSelectedRevision(RevisionGrid RevisionGrid, List<GitRef> selectedRemoteBranches,
private static GitRevision CalculateSelectedRevision(RevisionGrid revisionGrid, List<GitRef> selectedRemoteBranches,
List<string> selectedRemotes, List<GitRef> selectedLocalBranches,
List<GitRef> selectedBranches, List<GitRef> selectedTags)
{
GitRevision selectedRevision = RevisionGrid.GetRevision(RevisionGrid.LastRow);
GitRevision selectedRevision = revisionGrid.GetRevision(revisionGrid.LastRow);
foreach (GitRef head in selectedRevision.Refs)
{
if (head.IsTag)
Expand Down
18 changes: 9 additions & 9 deletions GitUI/UserControls/RevisionGrid.Designer.cs

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

0 comments on commit b90acb1

Please sign in to comment.