@@ -38,6 +38,7 @@ public class GerritPlugin : GitPluginBase, IGitPluginForRepository
38
38
private readonly BoolSetting _gerritEnabled = new ( "Gerrit plugin enabled" , true ) ;
39
39
private readonly ChoiceSetting _predefinedGerritVersion = new ( "Treat Gerrit as having version" ,
40
40
new [ ] { DefaultGerritVersion , "Older then 2.15" } , DefaultGerritVersion ) ;
41
+ private readonly BoolSetting _hidePushButton = new ( "Hide Push button" , false ) ;
41
42
42
43
private static readonly Dictionary < string , bool > _validatedHooks = new ( StringComparer . OrdinalIgnoreCase ) ;
43
44
private static readonly object _syncRoot = new ( ) ;
@@ -51,6 +52,7 @@ public class GerritPlugin : GitPluginBase, IGitPluginForRepository
51
52
private Form _mainForm ;
52
53
private IGitUICommands _gitUiCommands ;
53
54
private ToolStripButton _installCommitMsgMenuItem ;
55
+ private ToolStripButton _pushMenuItem ;
54
56
55
57
// public only because of FormTranslate
56
58
public GerritPlugin ( ) : base ( true )
@@ -84,17 +86,18 @@ private void UpdateGerritMenuItems(object sender, GitUIEventArgs e)
84
86
// Correct enabled/visibility of our menu/tool strip items.
85
87
86
88
var gitModule = e . GitModule ;
87
- bool validWorkingDir = gitModule . IsValidGitWorkingDir ( ) ;
89
+ bool isValidWorkingDir = gitModule . IsValidGitWorkingDir ( ) ;
88
90
89
- _gitReviewMenuItem . Enabled = validWorkingDir ;
91
+ _gitReviewMenuItem . Enabled = isValidWorkingDir ;
90
92
91
93
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 ;
93
96
bool hasValidCommitMsgHook = HasValidCommitMsgHook ( gitModule , true ) ;
94
97
95
- if ( gitModule . IsValidGitWorkingDir ( ) )
98
+ if ( isValidWorkingDir )
96
99
{
97
- if ( isEnabled && ! hasValidCommitMsgHook )
100
+ if ( isEnabled && ! hasValidCommitMsgHook && hasGitreviewFile )
98
101
{
99
102
installCommitMsgMenuItem_Click ( sender , e ) ;
100
103
}
@@ -112,6 +115,7 @@ private void UpdateGerritMenuItems(object sender, GitUIEventArgs e)
112
115
_installCommitMsgMenuItem . Visible =
113
116
showGerritItems &&
114
117
! hasValidCommitMsgHook ;
118
+ _pushMenuItem . Visible = ! showGerritItems || ! _hidePushButton . ValueOrDefault ( Settings ) ;
115
119
}
116
120
117
121
private static bool HasValidCommitMsgHook ( [ NotNull ] IGitModule gitModule , bool force = false )
@@ -217,13 +221,13 @@ private void Initialize(Form form)
217
221
218
222
// Create the tool strip items.
219
223
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 )
222
226
{
223
227
throw new Exception ( "Cannot find push menu item" ) ;
224
228
}
225
229
226
- int nextIndex = toolStrip . Items . IndexOf ( pushMenuItem ) + 1 ;
230
+ int nextIndex = toolStrip . Items . IndexOf ( _pushMenuItem ) + 1 ;
227
231
228
232
var separator = new ToolStripSeparator ( ) ;
229
233
@@ -475,6 +479,7 @@ public override IEnumerable<ISetting> GetSettings()
475
479
{
476
480
yield return _gerritEnabled ;
477
481
yield return _predefinedGerritVersion ;
482
+ yield return _hidePushButton ;
478
483
}
479
484
}
480
485
}
0 commit comments