Skip to content

Commit 5412396

Browse files
committed
Refactor Commandhelper
1 parent f9e5bf5 commit 5412396

File tree

6 files changed

+39
-124
lines changed

6 files changed

+39
-124
lines changed

TGit/Commands/GitFlowMenuCommands.cs

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,43 +29,24 @@ public void AddCommands()
2929
{
3030
//GitFlow Commands
3131
//Start/Finish Feature
32-
var startFeature = CommandHelper.CreateCommand(StartFeatureCommand, PkgCmdIDList.StartFeature);
33-
startFeature.BeforeQueryStatus += CommandHelper.GitFlow_BeforeQueryStatus;
34-
CommandHelper.AddCommand(_mcs, startFeature);
35-
36-
var finishFeature = CommandHelper.CreateCommand(FinishFeatureCommand, PkgCmdIDList.FinishFeature);
37-
finishFeature.BeforeQueryStatus += CommandHelper.Feature_BeforeQueryStatus;
38-
CommandHelper.AddCommand(_mcs, finishFeature);
32+
CommandHelper.AddCommand(_mcs, StartFeatureCommand, PkgCmdIDList.StartFeature, CommandHelper.GitFlow_BeforeQueryStatus);
33+
CommandHelper.AddCommand(_mcs, FinishFeatureCommand, PkgCmdIDList.FinishFeature, CommandHelper.Feature_BeforeQueryStatus);
3934

4035
//Start/Finish Release
41-
var startRelease = CommandHelper.CreateCommand(StartReleaseCommand, PkgCmdIDList.StartRelease);
42-
startRelease.BeforeQueryStatus += CommandHelper.GitFlow_BeforeQueryStatus;
43-
CommandHelper.AddCommand(_mcs, startRelease);
44-
45-
var finishRelease = CommandHelper.CreateCommand(FinishReleaseCommand, PkgCmdIDList.FinishRelease);
46-
finishRelease.BeforeQueryStatus += CommandHelper.Release_BeforeQueryStatus;
47-
CommandHelper.AddCommand(_mcs, finishRelease);
36+
CommandHelper.AddCommand(_mcs, StartReleaseCommand, PkgCmdIDList.StartRelease, CommandHelper.GitFlow_BeforeQueryStatus);
37+
CommandHelper.AddCommand(_mcs, FinishReleaseCommand, PkgCmdIDList.FinishRelease, CommandHelper.Release_BeforeQueryStatus);
4838

4939
//Start/Finish Hotfix
50-
var startHotfix = CommandHelper.CreateCommand(StartHotfixCommand, PkgCmdIDList.StartHotfix);
51-
startHotfix.BeforeQueryStatus += CommandHelper.GitFlow_BeforeQueryStatus;
52-
CommandHelper.AddCommand(_mcs, startHotfix);
53-
54-
var finishHotfix = CommandHelper.CreateCommand(FinishHotfixCommand, PkgCmdIDList.FinishHotfix);
55-
finishHotfix.BeforeQueryStatus += CommandHelper.Hotfix_BeforeQueryStatus;
56-
CommandHelper.AddCommand(_mcs, finishHotfix);
40+
CommandHelper.AddCommand(_mcs, StartHotfixCommand, PkgCmdIDList.StartHotfix, CommandHelper.GitFlow_BeforeQueryStatus);
41+
CommandHelper.AddCommand(_mcs, FinishHotfixCommand, PkgCmdIDList.FinishHotfix, CommandHelper.Hotfix_BeforeQueryStatus);
5742

5843
//Init
59-
var init = CommandHelper.CreateCommand(InitCommand, PkgCmdIDList.Init);
60-
init.BeforeQueryStatus += CommandHelper.GitHubFlow_BeforeQueryStatus;
61-
CommandHelper.AddCommand(_mcs, init);
44+
CommandHelper.AddCommand(_mcs, InitCommand, PkgCmdIDList.Init, CommandHelper.GitHubFlow_BeforeQueryStatus);
6245

6346
//GitHubFlow Commands
6447
//Start/Finish Feature
6548
CommandHelper.AddCommand(_mcs, StartFeatureGitHubCommand, PkgCmdIDList.StartFeatureGitHub);
66-
var finishFeatureGitHub = CommandHelper.CreateCommand(FinishFeatureGitHubCommand, PkgCmdIDList.FinishFeatureGitHub);
67-
finishFeatureGitHub.BeforeQueryStatus += CommandHelper.Feature_BeforeQueryStatus;
68-
CommandHelper.AddCommand(_mcs, finishFeatureGitHub);
49+
CommandHelper.AddCommand(_mcs, FinishFeatureGitHubCommand, PkgCmdIDList.FinishFeatureGitHub, CommandHelper.Feature_BeforeQueryStatus);
6950
}
7051

7152
private void InitCommand(object sender, EventArgs e)

TGit/Commands/MainMenuCommands.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ public void AddCommands()
3333
CommandHelper.AddCommand(_mcs, RepoBrowserCommand, PkgCmdIDList.RepoBrowser);
3434

3535
CommandHelper.AddCommand(_mcs, CreateStashCommand, PkgCmdIDList.CreateStash);
36-
var applyStash = CommandHelper.CreateCommand(ApplyStashCommand, PkgCmdIDList.ApplyStash);
37-
applyStash.BeforeQueryStatus += CommandHelper.ApplyStash_BeforeQueryStatus;
38-
CommandHelper.AddCommand(_mcs, applyStash);
36+
CommandHelper.AddCommand(_mcs, ApplyStashCommand, PkgCmdIDList.ApplyStash, CommandHelper.ApplyStash_BeforeQueryStatus);
3937

4038
CommandHelper.AddCommand(_mcs, BranchCommand, PkgCmdIDList.Branch);
4139
CommandHelper.AddCommand(_mcs, SwitchCommand, PkgCmdIDList.Switch);

TGit/Helpers/CommandHelper.cs

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,24 @@ public static class CommandHelper
88
{
99
public static EnvHelper EnvHelper;
1010

11-
public static void AddCommand(OleMenuCommandService mcs, EventHandler handler, uint commandId, EventHandler eventHandler)
12-
{
13-
mcs.AddCommand(CreateCommand(handler, commandId, eventHandler));
14-
}
15-
16-
public static void AddCommand(OleMenuCommandService mcs, EventHandler handler, uint commandId)
17-
{
18-
mcs.AddCommand(CreateCommand(handler, commandId));
19-
}
20-
21-
public static void AddCommand(OleMenuCommandService mcs, MenuCommand command)
22-
{
23-
mcs.AddCommand(command);
24-
}
25-
26-
public static OleMenuCommand CreateCommand(EventHandler handler, uint commandId, EventHandler eventHandler = null)
11+
public static void AddCommand(OleMenuCommandService mcs, EventHandler handler, uint commandId,
12+
EventHandler eventHandler = null, string text = null)
2713
{
2814
var menuCommandId = new CommandID(GuidList.GuidTgitCmdSet, (int)commandId);
29-
var menuItem = new OleMenuCommand(handler, menuCommandId);
15+
var menuItem = new OleMenuCommand(handler, menuCommandId, text);
3016

3117
if (eventHandler != null)
3218
{
3319
menuItem.BeforeQueryStatus += eventHandler;
3420
}
35-
36-
return menuItem;
37-
}
3821

39-
public static OleMenuCommand CreateCommand(uint commandId)
40-
{
41-
return CreateCommand(null, commandId);
22+
mcs.AddCommand(menuItem);
4223
}
4324

44-
public static void ApplyStash_BeforeQueryStatus(object sender, EventArgs e)
45-
{
46-
((OleMenuCommand) sender).Enabled = EnvHelper.HasStash();
47-
}
25+
#region Eventhandlers
26+
27+
public static void ApplyStash_BeforeQueryStatus(object sender, EventArgs e)
28+
=> ((OleMenuCommand)sender).Enabled = EnvHelper.HasStash();
4829

4930
public static void Feature_BeforeQueryStatus(object sender, EventArgs e)
5031
{
@@ -67,22 +48,18 @@ public static void Release_BeforeQueryStatus(object sender, EventArgs e)
6748
((OleMenuCommand)sender).Enabled = EnvHelper.HasGitRoot() && EnvHelper.BranchNameStartsWith(gitConfig.ReleasePrefix);
6849
}
6950

70-
public static void SolutionVisibility_BeforeQueryStatus(object sender, EventArgs e)
71-
{
72-
((OleMenuCommand) sender).Visible = EnvHelper.HasGitRoot();
73-
}
51+
public static void SolutionVisibility_BeforeQueryStatus(object sender, EventArgs e)
52+
=> ((OleMenuCommand)sender).Visible = EnvHelper.HasGitRoot();
7453

75-
public static void GitFlow_BeforeQueryStatus(object sender, EventArgs e)
76-
{
77-
((OleMenuCommand) sender).Visible = EnvHelper.HasGitRoot() && EnvHelper.IsGitFlow();
78-
}
54+
public static void GitFlow_BeforeQueryStatus(object sender, EventArgs e)
55+
=> ((OleMenuCommand)sender).Visible = EnvHelper.HasGitRoot() && EnvHelper.IsGitFlow();
7956

80-
public static void GitHubFlow_BeforeQueryStatus(object sender, EventArgs e)
81-
{
82-
((OleMenuCommand) sender).Visible = EnvHelper.HasGitRoot() && !EnvHelper.IsGitFlow();
83-
}
57+
public static void GitHubFlow_BeforeQueryStatus(object sender, EventArgs e)
58+
=> ((OleMenuCommand)sender).Visible = EnvHelper.HasGitRoot() && !EnvHelper.IsGitFlow();
8459

8560
public static void GitSvn_BeforeQueryStatus(object sender, EventArgs e)
8661
=> ((OleMenuCommand)sender).Visible = EnvHelper.HasGitRoot() && EnvHelper.IsGitSvn();
62+
63+
#endregion
8764
}
8865
}

TGit/PkgCmdID.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ static class PkgCmdIDList
5252
public const uint TGitGitFlowMenu = 0x2000;
5353
public const uint TGitGitHubFlowMenu = 0x3000;
5454
public const uint TGitSvnMenu = 0x4000;
55+
public const uint Toolbar = 0x1000;
5556

5657
public const uint Resolve = 0x137;
5758
public const uint Sync = 0x138;

0 commit comments

Comments
 (0)