Skip to content

Commit

Permalink
VisualStudio will freeze at frequently. #22. Update values on window …
Browse files Browse the repository at this point in the history
…switch
  • Loading branch information
sboulema committed Aug 17, 2016
1 parent b3a7666 commit 21f682b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 59 deletions.
22 changes: 11 additions & 11 deletions TGit/Commands/ContextMenuCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,77 +46,77 @@ public void AddCommands()

private void ShowLogContextCommand(object sender, EventArgs e)
{
string currentFilePath = _dte.ActiveDocument.FullName;
var currentFilePath = _dte.ActiveDocument.FullName;
if (string.IsNullOrEmpty(currentFilePath)) return;
_dte.ActiveDocument.Save();
_processHelper.StartTortoiseGitProc($"/command:log /path:\"{currentFilePath}\" /closeonend:{_generalOptions.CloseOnEnd}");
}
private void DiskBrowserContextCommand(object sender, EventArgs e)
{
string currentFilePath = _dte.ActiveDocument.FullName;
var currentFilePath = _dte.ActiveDocument.FullName;
if (string.IsNullOrEmpty(currentFilePath)) return;
_processHelper.Start(currentFilePath);
}
private void RepoBrowserContextCommand(object sender, EventArgs e)
{
string currentFilePath = _dte.ActiveDocument.FullName;
var currentFilePath = _dte.ActiveDocument.FullName;
if (string.IsNullOrEmpty(currentFilePath)) return;
_processHelper.StartTortoiseGitProc($"/command:repobrowser /path:\"{currentFilePath}\"");
}
private void BlameContextCommand(object sender, EventArgs e)
{
string currentFilePath = _dte.ActiveDocument.FullName;
var currentFilePath = _dte.ActiveDocument.FullName;
int currentLineIndex = ((TextDocument)_dte.ActiveDocument.Object(string.Empty)).Selection.CurrentLine;
if (string.IsNullOrEmpty(currentFilePath)) return;
_dte.ActiveDocument.Save();
_processHelper.StartTortoiseGitProc($"/command:blame /path:\"{currentFilePath}\" /line:{currentLineIndex}");
}
private void MergeContextCommand(object sender, EventArgs e)
{
string currentFilePath = _dte.ActiveDocument.FullName;
var currentFilePath = _dte.ActiveDocument.FullName;
if (string.IsNullOrEmpty(currentFilePath)) return;
_dte.ActiveDocument.Save();
_processHelper.StartTortoiseGitProc($"/command:merge /path:\"{currentFilePath}\"");
}
private void PullContextCommand(object sender, EventArgs e)
{
string currentFilePath = _dte.ActiveDocument.FullName;
var currentFilePath = _dte.ActiveDocument.FullName;
if (string.IsNullOrEmpty(currentFilePath)) return;
_dte.ActiveDocument.Save();
_processHelper.StartTortoiseGitProc($"/command:pull /path:\"{currentFilePath}\"");
}
private void FetchContextCommand(object sender, EventArgs e)
{
string currentFilePath = _dte.ActiveDocument.FullName;
var currentFilePath = _dte.ActiveDocument.FullName;
if (string.IsNullOrEmpty(currentFilePath)) return;
_dte.ActiveDocument.Save();
_processHelper.StartTortoiseGitProc($"/command:fetch /path:\"{currentFilePath}\"");
}
private void CommitContextCommand(object sender, EventArgs e)
{
string currentFilePath = _dte.ActiveDocument.FullName;
var currentFilePath = _dte.ActiveDocument.FullName;
if (string.IsNullOrEmpty(currentFilePath)) return;
_dte.ActiveDocument.Save();
_processHelper.StartTortoiseGitProc($"/command:commit /path:\"{currentFilePath}\" /logmsg:\"{_gitHelper.GetCommitMessage(_generalOptions.CommitMessage, _dte)}\" /closeonend:{_generalOptions.CloseOnEnd}");
}
private void RevertContextCommand(object sender, EventArgs e)
{
string currentFilePath = _dte.ActiveDocument.FullName;
var currentFilePath = _dte.ActiveDocument.FullName;
if (string.IsNullOrEmpty(currentFilePath)) return;
_dte.ActiveDocument.Save();
_processHelper.StartTortoiseGitProc($"/command:revert /path:\"{currentFilePath}\"");
}
private void DiffContextCommand(object sender, EventArgs e)
{
string currentFilePath = _dte.ActiveDocument.FullName;
var currentFilePath = _dte.ActiveDocument.FullName;
if (string.IsNullOrEmpty(currentFilePath)) return;
_dte.ActiveDocument.Save();
_processHelper.StartTortoiseGitProc($"/command:diff /path:\"{currentFilePath}\"");
}

private void PrefDiffContextCommand(object sender, EventArgs e)
{
string currentFilePath = _dte.ActiveDocument.FullName;
var currentFilePath = _dte.ActiveDocument.FullName;
if (string.IsNullOrEmpty(currentFilePath)) return;
_dte.ActiveDocument.Save();

Expand Down
10 changes: 4 additions & 6 deletions TGit/Helpers/CommandHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ namespace SamirBoulema.TGit.Helpers
public class CommandHelper
{
private readonly ProcessHelper _processHelper;
private readonly GitHelper _gitHelper;
private readonly OleMenuCommandService _mcs;
private readonly TGitPackage _package;

public CommandHelper(ProcessHelper processHelper, GitHelper gitHelper, OleMenuCommandService mcs, TGitPackage package)
public CommandHelper(ProcessHelper processHelper, OleMenuCommandService mcs, TGitPackage package)
{
_processHelper = processHelper;
_gitHelper = gitHelper;
_mcs = mcs;
_package = package;
}
Expand Down Expand Up @@ -50,19 +48,19 @@ private void Diff_BeforeQueryStatus(object sender, EventArgs e)
public void Feature_BeforeQueryStatus(object sender, EventArgs e)
{
((OleMenuCommand)sender).Visible = _package.HasSolutionDir() && _package.IsGitFlow;
((OleMenuCommand)sender).Enabled = _package.HasSolutionDir() && _gitHelper.IsFeatureBranch();
((OleMenuCommand)sender).Enabled = _package.HasSolutionDir() && _package.BranchName.StartsWith(_package.FlowOptions.FeaturePrefix);
}

public void Hotfix_BeforeQueryStatus(object sender, EventArgs e)
{
((OleMenuCommand)sender).Visible = _package.HasSolutionDir() && _package.IsGitFlow;
((OleMenuCommand)sender).Enabled = _package.HasSolutionDir() && _gitHelper.IsHotfixBranch();
((OleMenuCommand)sender).Enabled = _package.HasSolutionDir() && _package.BranchName.StartsWith(_package.FlowOptions.HotfixPrefix);
}

public void Release_BeforeQueryStatus(object sender, EventArgs e)
{
((OleMenuCommand)sender).Visible = _package.HasSolutionDir() && _package.IsGitFlow;
((OleMenuCommand)sender).Enabled = _package.HasSolutionDir() && _gitHelper.IsReleaseBranch();
((OleMenuCommand)sender).Enabled = _package.HasSolutionDir() && _package.BranchName.StartsWith(_package.FlowOptions.ReleasePrefix);
}

public void Solution_BeforeQueryStatus(object sender, EventArgs e)
Expand Down
41 changes: 1 addition & 40 deletions TGit/Helpers/GitHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,11 @@ public GitHelper(FileHelper fileHelper, ProcessHelper processHelper)

public string GetCommitMessage(string commitMessageTemplate, DTE dte)
{
//var projectDir = _dte.Solution.Projects.Item(1).FullName;
//var projectFileName = _dte.Solution.Projects.Item(1).FileName;

string commitMessage = commitMessageTemplate;
var commitMessage = commitMessageTemplate;
commitMessage = commitMessage.Replace("$(BranchName)", GetCurrentBranchName(false));
commitMessage = commitMessage.Replace("$(FeatureName)", GetCurrentBranchName(true));
commitMessage = commitMessage.Replace("$(Configuration)", dte.Solution.SolutionBuild.ActiveConfiguration?.Name);
//commitMessage = commitMessage.Replace("$(Platform)", (string)_dte.Solution.Projects.Item(1).ConfigurationManager.PlatformNames);
commitMessage = commitMessage.Replace("$(DevEnvDir)", (string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7\\", dte.Version, ""));
//commitMessage = commitMessage.Replace("$(ProjectDir)", Path.GetDirectoryName(_dte.Solution.Projects.Item(1).FullName));
//commitMessage = commitMessage.Replace("$(ProjectPath)", Path.GetFullPath(_dte.Solution.Projects.Item(1).FullName));
//commitMessage = commitMessage.Replace("$(ProjectName)", _dte.Solution.Projects.Item(1).FullName);
//commitMessage = commitMessage.Replace("$(ProjectFileName)", _dte.Solution.Projects.Item(1).FileName);
//commitMessage = commitMessage.Replace("$(ProjectExt)", Path.GetExtension(_dte.Solution.Projects.Item(1).FileName));
commitMessage = commitMessage.Replace("$(SolutionDir)", Path.GetDirectoryName(dte.Solution.FullName));
commitMessage = commitMessage.Replace("$(SolutionPath)", Path.GetFullPath(dte.Solution.FullName));
commitMessage = commitMessage.Replace("$(SolutionName)", dte.Solution.FullName);
Expand Down Expand Up @@ -64,16 +55,6 @@ public string GetCurrentBranchName(bool trimPrefix)
return branchName;
}

public bool IsGitFlow()
{
return _processHelper.StartProcessGit("config --get gitflow.branch.master", false);
}

public bool IsGitHubFlow()
{
return !IsGitFlow();
}

public string GetSshSetup()
{
var remoteOriginPuttyKeyfile = _processHelper.StartProcessGitResult("config --get remote.origin.puttykeyfile");
Expand All @@ -95,26 +76,6 @@ public FlowOptions GetFlowOptions()
};
}

public string GetOption(string option)
{
return _processHelper.StartProcessGitResult($"config --get {option}");
}

public bool IsFeatureBranch()
{
return GetCurrentBranchName(false).StartsWith(GetOption("gitflow.prefix.feature"));
}

public bool IsHotfixBranch()
{
return GetCurrentBranchName(false).StartsWith(GetOption("gitflow.prefix.hotfix"));
}

public bool IsReleaseBranch()
{
return GetCurrentBranchName(false).StartsWith(GetOption("gitflow.prefix.release"));
}

public bool RemoteBranchExists(string branch)
{
return _processHelper.StartProcessGit($"show-ref refs/remotes/origin/{branch}");
Expand Down
23 changes: 22 additions & 1 deletion TGit/TGITPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ public sealed class TGitPackage : Package
private GitHelper _gitHelper;

private SolutionEvents _events;
private WindowEvents _windowEvents;
public string SolutionDir;
public bool IsGitFlow;
public FlowOptions FlowOptions;
public string BranchName;

/// <summary>
/// Initialization of the package; this method is called right after the package is sited, so this is the place
Expand All @@ -43,12 +46,16 @@ protected override void Initialize()

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

_windowEvents = _dte.Events.WindowEvents;
_windowEvents.WindowActivated += WindowEvents_WindowActivated;

// 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, _gitHelper, mcs, this);
_commandHelper = new CommandHelper(_processHelper, mcs, this);

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

Expand Down Expand Up @@ -83,10 +90,24 @@ protected override void Initialize()
mcs.AddCommand(tgitGitHubFlowMenu);
}

private void WindowEvents_WindowActivated(Window GotFocus, Window LostFocus)
{
SolutionEvents_Opened();
}

private void _events_AfterClosing()
{
SolutionDir = string.Empty;
BranchName = string.Empty;
IsGitFlow = false;
}

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

public bool HasSolutionDir()
Expand Down
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.1" Language="en-US" Publisher="Samir L. Boulema" />
<Identity Id="2eb0e74d-a27d-4c41-bca4-7e9e9befaa18" Version="3.6.2" 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 21f682b

Please sign in to comment.