Skip to content

Commit

Permalink
VisualStudio will freeze at frequently. #22
Browse files Browse the repository at this point in the history
  • Loading branch information
sboulema committed Aug 16, 2016
1 parent d773fda commit b3a7666
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
31 changes: 14 additions & 17 deletions TGit/Helpers/CommandHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ namespace SamirBoulema.TGit.Helpers
public class CommandHelper
{
private readonly ProcessHelper _processHelper;
private readonly FileHelper _fileHelper;
private readonly GitHelper _gitHelper;
private readonly OleMenuCommandService _mcs;
private readonly TGitPackage _package;

public CommandHelper(ProcessHelper processHelper, FileHelper fileHelper, GitHelper gitHelper, OleMenuCommandService mcs)
public CommandHelper(ProcessHelper processHelper, GitHelper gitHelper, OleMenuCommandService mcs, TGitPackage package)
{
_processHelper = processHelper;
_fileHelper = fileHelper;
_gitHelper = gitHelper;
_mcs = mcs;
_package = package;
}

public void AddCommand(EventHandler handler, uint commandId)
Expand Down Expand Up @@ -48,44 +48,41 @@ private void Diff_BeforeQueryStatus(object sender, EventArgs e)
}

public void Feature_BeforeQueryStatus(object sender, EventArgs e)
{
var hasSolution = !string.IsNullOrEmpty(_fileHelper.GetSolutionDir());
((OleMenuCommand)sender).Visible = hasSolution && _gitHelper.IsGitFlow();
((OleMenuCommand)sender).Enabled = hasSolution && _gitHelper.IsFeatureBranch();
{
((OleMenuCommand)sender).Visible = _package.HasSolutionDir() && _package.IsGitFlow;
((OleMenuCommand)sender).Enabled = _package.HasSolutionDir() && _gitHelper.IsFeatureBranch();
}

public void Hotfix_BeforeQueryStatus(object sender, EventArgs e)
{
var hasSolution = !string.IsNullOrEmpty(_fileHelper.GetSolutionDir());
((OleMenuCommand)sender).Visible = hasSolution && _gitHelper.IsGitFlow();
((OleMenuCommand)sender).Enabled = hasSolution && _gitHelper.IsHotfixBranch();
((OleMenuCommand)sender).Visible = _package.HasSolutionDir() && _package.IsGitFlow;
((OleMenuCommand)sender).Enabled = _package.HasSolutionDir() && _gitHelper.IsHotfixBranch();
}

public void Release_BeforeQueryStatus(object sender, EventArgs e)
{
var hasSolution = !string.IsNullOrEmpty(_fileHelper.GetSolutionDir());
((OleMenuCommand)sender).Visible = hasSolution && _gitHelper.IsGitFlow();
((OleMenuCommand)sender).Enabled = hasSolution && _gitHelper.IsReleaseBranch();
((OleMenuCommand)sender).Visible = _package.HasSolutionDir() && _package.IsGitFlow;
((OleMenuCommand)sender).Enabled = _package.HasSolutionDir() && _gitHelper.IsReleaseBranch();
}

public void Solution_BeforeQueryStatus(object sender, EventArgs e)
{
((OleMenuCommand) sender).Enabled = !string.IsNullOrEmpty(_fileHelper.GetSolutionDir());
((OleMenuCommand) sender).Enabled = _package.HasSolutionDir();
}

public void SolutionVisibility_BeforeQueryStatus(object sender, EventArgs e)
{
((OleMenuCommand) sender).Visible = !string.IsNullOrEmpty(_fileHelper.GetSolutionDir());
((OleMenuCommand) sender).Visible = _package.HasSolutionDir();
}

public void GitFlow_BeforeQueryStatus(object sender, EventArgs e)
{
((OleMenuCommand) sender).Visible = !string.IsNullOrEmpty(_fileHelper.GetSolutionDir()) && _gitHelper.IsGitFlow();
((OleMenuCommand) sender).Visible = _package.HasSolutionDir() && _package.IsGitFlow;
}

public void GitHubFlow_BeforeQueryStatus(object sender, EventArgs e)
{
((OleMenuCommand) sender).Visible = !string.IsNullOrEmpty(_fileHelper.GetSolutionDir()) && _gitHelper.IsGitHubFlow();
((OleMenuCommand) sender).Visible = _package.HasSolutionDir() && !_package.IsGitFlow;
}
}
}
20 changes: 19 additions & 1 deletion TGit/TGITPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public sealed class TGitPackage : Package
private CommandHelper _commandHelper;
private GitHelper _gitHelper;

private SolutionEvents _events;
public string SolutionDir;
public bool IsGitFlow;

/// <summary>
/// Initialization of the package; this method is called right after the package is sited, so this is the place
/// where you can put all the initialization code that rely on services provided by VisualStudio.
Expand All @@ -37,11 +41,14 @@ protected override void Initialize()
_processHelper = new ProcessHelper(_dte);
_gitHelper = new GitHelper(_fileHelper, _processHelper);

_events = _dte.Events.SolutionEvents;
_events.Opened += SolutionEvents_Opened;

// Add our command handlers for menu (commands must exist in the .vsct file)
var mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
if (null == mcs) return;

_commandHelper = new CommandHelper(_processHelper, _fileHelper, _gitHelper, mcs);
_commandHelper = new CommandHelper(_processHelper, _gitHelper, mcs, this);

new MainMenuCommands(_processHelper, _commandHelper, _gitHelper, _fileHelper, _dte, generalOptions, mcs).AddCommands();

Expand Down Expand Up @@ -75,5 +82,16 @@ protected override void Initialize()
tgitGitHubFlowMenu.BeforeQueryStatus += _commandHelper.GitHubFlow_BeforeQueryStatus;
mcs.AddCommand(tgitGitHubFlowMenu);
}

private void SolutionEvents_Opened()
{
SolutionDir = _fileHelper.GetSolutionDir();
IsGitFlow = _processHelper.StartProcessGit("config --get gitflow.branch.master", false);
}

public bool HasSolutionDir()
{
return !string.IsNullOrEmpty(SolutionDir);
}
}
}
2 changes: 1 addition & 1 deletion TGit/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="2eb0e74d-a27d-4c41-bca4-7e9e9befaa18" Version="3.6" Language="en-US" Publisher="Samir L. Boulema" />
<Identity Id="2eb0e74d-a27d-4c41-bca4-7e9e9befaa18" Version="3.6.1" Language="en-US" Publisher="Samir L. Boulema" />
<DisplayName>TGit</DisplayName>
<Description xml:space="preserve">Control TortoiseGit from within Visual Studio</Description>
<MoreInfo>https://github.com/sboulema/TGit</MoreInfo>
Expand Down

0 comments on commit b3a7666

Please sign in to comment.