Skip to content

Commit

Permalink
#16: CloseOnEnd
Browse files Browse the repository at this point in the history
  • Loading branch information
sboulema committed Aug 9, 2016
1 parent 81fae92 commit 8078428
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 173 deletions.
114 changes: 57 additions & 57 deletions TGit/Commands/ContextMenuCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,126 +8,126 @@ namespace SamirBoulema.TGit.Commands
{
public class ContextMenuCommands
{
private readonly ProcessHelper processHelper;
private readonly CommandHelper commandHelper;
private readonly FileHelper fileHelper;
private readonly GitHelper gitHelper;
private readonly DTE dte;
private readonly OptionPageGrid options;
private readonly ProcessHelper _processHelper;
private readonly CommandHelper _commandHelper;
private readonly FileHelper _fileHelper;
private readonly GitHelper _gitHelper;
private readonly DTE _dte;
private readonly OptionPageGrid _generalOptions;

public ContextMenuCommands(ProcessHelper processHelper, CommandHelper commandHelper, GitHelper gitHelper, FileHelper fileHelper,
DTE dte, OptionPageGrid options)
DTE dte, OptionPageGrid generalOptions)
{
this.processHelper = processHelper;
this.commandHelper = commandHelper;
this.gitHelper = gitHelper;
this.fileHelper = fileHelper;
this.dte = dte;
this.options = options;
_processHelper = processHelper;
_commandHelper = commandHelper;
_gitHelper = gitHelper;
_fileHelper = fileHelper;
_dte = dte;
_generalOptions = generalOptions;
}

public void AddCommands()
{
commandHelper.AddCommand(ShowLogContextCommand, PkgCmdIDList.ShowLogContext);
commandHelper.AddCommand(DiskBrowserContextCommand, PkgCmdIDList.DiskBrowserContext);
commandHelper.AddCommand(RepoBrowserContextCommand, PkgCmdIDList.RepoBrowserContext);
_commandHelper.AddCommand(ShowLogContextCommand, PkgCmdIDList.ShowLogContext);
_commandHelper.AddCommand(DiskBrowserContextCommand, PkgCmdIDList.DiskBrowserContext);
_commandHelper.AddCommand(RepoBrowserContextCommand, PkgCmdIDList.RepoBrowserContext);

commandHelper.AddCommand(BlameContextCommand, PkgCmdIDList.BlameContext);
_commandHelper.AddCommand(BlameContextCommand, PkgCmdIDList.BlameContext);

commandHelper.AddCommand(MergeContextCommand, PkgCmdIDList.MergeContext);
_commandHelper.AddCommand(MergeContextCommand, PkgCmdIDList.MergeContext);

commandHelper.AddCommand(PullContextCommand, PkgCmdIDList.PullContext);
commandHelper.AddCommand(FetchContextCommand, PkgCmdIDList.FetchContext);
commandHelper.AddCommand(CommitContextCommand, PkgCmdIDList.CommitContext);
commandHelper.AddCommand(RevertContextCommand, PkgCmdIDList.RevertContext);
commandHelper.AddCommand(DiffContextCommand, PkgCmdIDList.DiffContext);
commandHelper.AddCommand(PrefDiffContextCommand, PkgCmdIDList.PrefDiffContext);
_commandHelper.AddCommand(PullContextCommand, PkgCmdIDList.PullContext);
_commandHelper.AddCommand(FetchContextCommand, PkgCmdIDList.FetchContext);
_commandHelper.AddCommand(CommitContextCommand, PkgCmdIDList.CommitContext);
_commandHelper.AddCommand(RevertContextCommand, PkgCmdIDList.RevertContext);
_commandHelper.AddCommand(DiffContextCommand, PkgCmdIDList.DiffContext);
_commandHelper.AddCommand(PrefDiffContextCommand, PkgCmdIDList.PrefDiffContext);
}

private void ShowLogContextCommand(object sender, EventArgs e)
{
string currentFilePath = dte.ActiveDocument.FullName;
string currentFilePath = _dte.ActiveDocument.FullName;
if (string.IsNullOrEmpty(currentFilePath)) return;
dte.ActiveDocument.Save();
processHelper.StartTortoiseGitProc($"/command:log /path:\"{currentFilePath}\" /closeonend:0");
_dte.ActiveDocument.Save();
_processHelper.StartTortoiseGitProc($"/command:log /path:\"{currentFilePath}\" /closeonend:{_generalOptions.CloseOnEnd}");
}
private void DiskBrowserContextCommand(object sender, EventArgs e)
{
string currentFilePath = dte.ActiveDocument.FullName;
string currentFilePath = _dte.ActiveDocument.FullName;
if (string.IsNullOrEmpty(currentFilePath)) return;
processHelper.Start(currentFilePath);
_processHelper.Start(currentFilePath);
}
private void RepoBrowserContextCommand(object sender, EventArgs e)
{
string currentFilePath = dte.ActiveDocument.FullName;
string currentFilePath = _dte.ActiveDocument.FullName;
if (string.IsNullOrEmpty(currentFilePath)) return;
processHelper.StartTortoiseGitProc($"/command:repobrowser /path:\"{currentFilePath}\"");
_processHelper.StartTortoiseGitProc($"/command:repobrowser /path:\"{currentFilePath}\"");
}
private void BlameContextCommand(object sender, EventArgs e)
{
string currentFilePath = dte.ActiveDocument.FullName;
int currentLineIndex = ((TextDocument)dte.ActiveDocument.Object(string.Empty)).Selection.CurrentLine;
string 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}");
_dte.ActiveDocument.Save();
_processHelper.StartTortoiseGitProc($"/command:blame /path:\"{currentFilePath}\" /line:{currentLineIndex}");
}
private void MergeContextCommand(object sender, EventArgs e)
{
string currentFilePath = dte.ActiveDocument.FullName;
string currentFilePath = _dte.ActiveDocument.FullName;
if (string.IsNullOrEmpty(currentFilePath)) return;
dte.ActiveDocument.Save();
processHelper.StartTortoiseGitProc($"/command:merge /path:\"{currentFilePath}\"");
_dte.ActiveDocument.Save();
_processHelper.StartTortoiseGitProc($"/command:merge /path:\"{currentFilePath}\"");
}
private void PullContextCommand(object sender, EventArgs e)
{
string currentFilePath = dte.ActiveDocument.FullName;
string currentFilePath = _dte.ActiveDocument.FullName;
if (string.IsNullOrEmpty(currentFilePath)) return;
dte.ActiveDocument.Save();
processHelper.StartTortoiseGitProc($"/command:pull /path:\"{currentFilePath}\"");
_dte.ActiveDocument.Save();
_processHelper.StartTortoiseGitProc($"/command:pull /path:\"{currentFilePath}\"");
}
private void FetchContextCommand(object sender, EventArgs e)
{
string currentFilePath = dte.ActiveDocument.FullName;
string currentFilePath = _dte.ActiveDocument.FullName;
if (string.IsNullOrEmpty(currentFilePath)) return;
dte.ActiveDocument.Save();
processHelper.StartTortoiseGitProc($"/command:fetch /path:\"{currentFilePath}\"");
_dte.ActiveDocument.Save();
_processHelper.StartTortoiseGitProc($"/command:fetch /path:\"{currentFilePath}\"");
}
private void CommitContextCommand(object sender, EventArgs e)
{
string currentFilePath = dte.ActiveDocument.FullName;
string currentFilePath = _dte.ActiveDocument.FullName;
if (string.IsNullOrEmpty(currentFilePath)) return;
dte.ActiveDocument.Save();
processHelper.StartTortoiseGitProc($"/command:commit /path:\"{currentFilePath}\" /logmsg:\"{gitHelper.GetCommitMessage(options.CommitMessage, dte)}\" /closeonend:0");
_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;
string currentFilePath = _dte.ActiveDocument.FullName;
if (string.IsNullOrEmpty(currentFilePath)) return;
dte.ActiveDocument.Save();
processHelper.StartTortoiseGitProc($"/command:revert /path:\"{currentFilePath}\"");
_dte.ActiveDocument.Save();
_processHelper.StartTortoiseGitProc($"/command:revert /path:\"{currentFilePath}\"");
}
private void DiffContextCommand(object sender, EventArgs e)
{
string currentFilePath = dte.ActiveDocument.FullName;
string currentFilePath = _dte.ActiveDocument.FullName;
if (string.IsNullOrEmpty(currentFilePath)) return;
dte.ActiveDocument.Save();
processHelper.StartTortoiseGitProc($"/command:diff /path:\"{currentFilePath}\"");
_dte.ActiveDocument.Save();
_processHelper.StartTortoiseGitProc($"/command:diff /path:\"{currentFilePath}\"");
}

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

var revisions = processHelper.GitResult(Path.GetDirectoryName(currentFilePath), $"log -2 --pretty=format:%h {fileHelper.GetExactFileName(currentFilePath)}");
var revisions = _processHelper.GitResult(Path.GetDirectoryName(currentFilePath), $"log -2 --pretty=format:%h {_fileHelper.GetExactFileName(currentFilePath)}");
if (!revisions.Contains(","))
{
MessageBox.Show("Could not determine the last committed revision!", "TGit", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
processHelper.StartTortoiseGitProc($"/command:diff /path:\"{fileHelper.GetExactPathName(currentFilePath)}\" /startrev:{revisions.Split(',')[0]} /endrev:{revisions.Split(',')[1]}");
_processHelper.StartTortoiseGitProc($"/command:diff /path:\"{_fileHelper.GetExactPathName(currentFilePath)}\" /startrev:{revisions.Split(',')[0]} /endrev:{revisions.Split(',')[1]}");
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions TGit/Commands/GitFlowCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ public class GitFlowCommands
private readonly CommandHelper _commandHelper;
private readonly FileHelper _fileHelper;
private readonly GitHelper _gitHelper;
private readonly OptionPageGrid _options;
private readonly OptionFlowPageGrid _options;
private readonly string _gitBin;
private readonly OleMenuCommandService _mcs;

public GitFlowCommands(ProcessHelper processHelper, CommandHelper commandHelper, GitHelper gitHelper, FileHelper fileHelper,
OptionPageGrid options, OleMenuCommandService mcs)
OptionFlowPageGrid options, OleMenuCommandService mcs)
{
_processHelper = processHelper;
_commandHelper = commandHelper;
Expand Down
Loading

0 comments on commit 8078428

Please sign in to comment.