Skip to content

Commit d4efbbf

Browse files
committed
Add ability to hide normal push button (#27)
1 parent 3d118ec commit d4efbbf

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/GitExtensions.GerritPlugin/GerritPlugin.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class GerritPlugin : GitPluginBase, IGitPluginForRepository
3838
private readonly BoolSetting _gerritEnabled = new("Gerrit plugin enabled", true);
3939
private readonly ChoiceSetting _predefinedGerritVersion = new("Treat Gerrit as having version",
4040
new[] { DefaultGerritVersion, "Older then 2.15" }, DefaultGerritVersion);
41+
private readonly BoolSetting _hidePushButton = new("Hide Push button", false);
4142

4243
private static readonly Dictionary<string, bool> _validatedHooks = new(StringComparer.OrdinalIgnoreCase);
4344
private static readonly object _syncRoot = new();
@@ -51,6 +52,7 @@ public class GerritPlugin : GitPluginBase, IGitPluginForRepository
5152
private Form _mainForm;
5253
private IGitUICommands _gitUiCommands;
5354
private ToolStripButton _installCommitMsgMenuItem;
55+
private ToolStripButton _pushMenuItem;
5456

5557
// public only because of FormTranslate
5658
public GerritPlugin() : base(true)
@@ -84,17 +86,18 @@ private void UpdateGerritMenuItems(object sender, GitUIEventArgs e)
8486
// Correct enabled/visibility of our menu/tool strip items.
8587

8688
var gitModule = e.GitModule;
87-
bool validWorkingDir = gitModule.IsValidGitWorkingDir();
89+
bool isValidWorkingDir = gitModule.IsValidGitWorkingDir();
8890

89-
_gitReviewMenuItem.Enabled = validWorkingDir;
91+
_gitReviewMenuItem.Enabled = isValidWorkingDir;
9092

9193
bool isEnabled = _gerritEnabled.ValueOrDefault(Settings);
92-
bool showGerritItems = isEnabled && validWorkingDir && File.Exists(gitModule.WorkingDir + ".gitreview");
94+
bool hasGitreviewFile = File.Exists(gitModule.WorkingDir + ".gitreview");
95+
bool showGerritItems = isEnabled && isValidWorkingDir && hasGitreviewFile;
9396
bool hasValidCommitMsgHook = HasValidCommitMsgHook(gitModule, true);
9497

95-
if (gitModule.IsValidGitWorkingDir())
98+
if (isValidWorkingDir)
9699
{
97-
if (isEnabled && !hasValidCommitMsgHook)
100+
if (isEnabled && !hasValidCommitMsgHook && hasGitreviewFile)
98101
{
99102
installCommitMsgMenuItem_Click(sender, e);
100103
}
@@ -112,6 +115,7 @@ private void UpdateGerritMenuItems(object sender, GitUIEventArgs e)
112115
_installCommitMsgMenuItem.Visible =
113116
showGerritItems &&
114117
!hasValidCommitMsgHook;
118+
_pushMenuItem.Visible = !showGerritItems || !_hidePushButton.ValueOrDefault(Settings);
115119
}
116120

117121
private static bool HasValidCommitMsgHook([NotNull] IGitModule gitModule, bool force = false)
@@ -217,13 +221,13 @@ private void Initialize(Form form)
217221

218222
// Create the tool strip items.
219223

220-
var pushMenuItem = toolStrip.Items.Cast<ToolStripItem>().SingleOrDefault(p => p.Name == "toolStripButtonPush");
221-
if (pushMenuItem == null)
224+
_pushMenuItem = (ToolStripButton)toolStrip.Items.Cast<ToolStripItem>().SingleOrDefault(p => p.Name == "toolStripButtonPush");
225+
if (_pushMenuItem == null)
222226
{
223227
throw new Exception("Cannot find push menu item");
224228
}
225229

226-
int nextIndex = toolStrip.Items.IndexOf(pushMenuItem) + 1;
230+
int nextIndex = toolStrip.Items.IndexOf(_pushMenuItem) + 1;
227231

228232
var separator = new ToolStripSeparator();
229233

@@ -475,6 +479,7 @@ public override IEnumerable<ISetting> GetSettings()
475479
{
476480
yield return _gerritEnabled;
477481
yield return _predefinedGerritVersion;
482+
yield return _hidePushButton;
478483
}
479484
}
480485
}

0 commit comments

Comments
 (0)