Skip to content

Commit

Permalink
3.4: Gitflow ouput improved UI
Browse files Browse the repository at this point in the history
  • Loading branch information
sboulema committed Jul 11, 2016
1 parent d569b7d commit 142d575
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 51 deletions.
83 changes: 47 additions & 36 deletions GitFlow/Helpers/ProcessHelper.cs
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
using EnvDTE;
using System;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using Process = System.Diagnostics.Process;

namespace SamirBoulema.TGIT.Helpers
{
public class ProcessHelper
{
private readonly FileHelper fileHelper;
private string solutionDir;
private readonly string tortoiseGitProc, git;
private readonly DTE dte;
private OutputBox outputBox;
private readonly Stopwatch stopwatch;
private readonly FileHelper _fileHelper;
private string _solutionDir;
private readonly string _tortoiseGitProc, _git;
private readonly DTE _dte;
private OutputBox _outputBox;
private readonly Stopwatch _stopwatch;

public ProcessHelper(DTE dte)
{
this.dte = dte;
fileHelper = new FileHelper(dte);
tortoiseGitProc = fileHelper.GetTortoiseGitProc();
git = fileHelper.GetMSysGit();
stopwatch = new Stopwatch();
_dte = dte;
_fileHelper = new FileHelper(dte);
_tortoiseGitProc = _fileHelper.GetTortoiseGitProc();
_git = _fileHelper.GetMSysGit();
_stopwatch = new Stopwatch();
}

public bool StartProcessGit(string commands, bool showAlert = true)
{
solutionDir = fileHelper.GetSolutionDir();
if (string.IsNullOrEmpty(solutionDir)) return false;
_solutionDir = _fileHelper.GetSolutionDir();
if (string.IsNullOrEmpty(_solutionDir)) return false;

string output = string.Empty;
string error = string.Empty;
var output = string.Empty;
var error = string.Empty;
var proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = $"/c cd /D \"{solutionDir}\" && \"{git}\" {commands}",
Arguments = $"/c cd /D \"{_solutionDir}\" && \"{_git}\" {commands}",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
Expand Down Expand Up @@ -67,18 +68,18 @@ public void StartTortoiseGitProc(string args)
{
try
{
Process.Start(tortoiseGitProc, args);
Process.Start(_tortoiseGitProc, args);
}
catch (Exception e)
{
MessageBox.Show(e.Message, $"{tortoiseGitProc} not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show(e.Message, $"{_tortoiseGitProc} not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

public string StartProcessGitResult(string commands)
{
solutionDir = fileHelper.GetSolutionDir();
if (string.IsNullOrEmpty(solutionDir)) return string.Empty;
_solutionDir = _fileHelper.GetSolutionDir();
if (string.IsNullOrEmpty(_solutionDir)) return string.Empty;

string output = string.Empty;
string error = string.Empty;
Expand All @@ -87,7 +88,7 @@ public string StartProcessGitResult(string commands)
StartInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = $"/c cd /D \"{solutionDir}\" && \"{git}\" {commands}",
Arguments = $"/c cd /D \"{_solutionDir}\" && \"{_git}\" {commands}",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
Expand Down Expand Up @@ -116,7 +117,7 @@ public string GitResult(string workingDir, string commands)
StartInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = $"/c cd /D \"{workingDir}\" && \"{git}\" {commands}",
Arguments = $"/c cd /D \"{workingDir}\" && \"{_git}\" {commands}",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
Expand Down Expand Up @@ -146,14 +147,14 @@ public void StartProcessGui(string application, string args, string title)
var dialogResult = DialogResult.OK;
if (!StartProcessGit("config user.name") || !StartProcessGit("config user.email"))
{
dialogResult = new Credentials(dte).ShowDialog();
dialogResult = new Credentials(_dte).ShowDialog();
}

if (dialogResult == DialogResult.OK)
{
try
{
Process process = new Process();
var process = new Process();
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
Expand All @@ -165,18 +166,18 @@ public void StartProcessGui(string application, string args, string title)
process.ErrorDataReceived += OutputDataHandler;
process.StartInfo.FileName = application;
process.StartInfo.Arguments = args;
process.StartInfo.WorkingDirectory = solutionDir;
process.StartInfo.WorkingDirectory = _solutionDir;

outputBox = new OutputBox(dte);
_outputBox = new OutputBox(_dte);

stopwatch.Reset();
stopwatch.Start();
_stopwatch.Reset();
_stopwatch.Start();
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();

outputBox.Text = title;
outputBox.Show();
_outputBox.Text = title;
_outputBox.Show();
}
catch (Exception e)
{
Expand All @@ -191,20 +192,30 @@ private void OutputDataHandler(object sendingProcess, DataReceivedEventArgs outL
var process = sendingProcess as Process;
if (process == null) return;

outputBox.BeginInvoke((Action)(() => outputBox.textBox.AppendText(outLine.Data + "\n")));
outputBox.BeginInvoke((Action)(() => outputBox.textBox.Select(0, 0)));
var text = outLine.Data + Environment.NewLine;

_outputBox.BeginInvoke((Action) (() => _outputBox.richTextBox1.AppendText(text, text.StartsWith(">"))));
_outputBox.BeginInvoke((Action) (() => _outputBox.richTextBox1.Select(_outputBox.richTextBox1.TextLength - text.Length + 1, 0)));
_outputBox.BeginInvoke((Action) (() => _outputBox.richTextBox1.ScrollToCaret()));
}

private void process_Exited(object sender, EventArgs e)
{
var process = sender as Process;
if (process == null) return;

stopwatch.Stop();
var exitCodeText = process.ExitCode == 0 ? "Succes" : "Error";
_stopwatch.Stop();

outputBox.BeginInvoke((Action)(() => outputBox.textBox.AppendText($"{Environment.NewLine}{exitCodeText} ({stopwatch.ElapsedMilliseconds} ms @ {process.StartTime})")));
outputBox.BeginInvoke((Action)(() => outputBox.okButton.Enabled = true));
var exitCodeText = process.ExitCode == 0 ? "Succes" : "Error";
var summaryText = $"{Environment.NewLine}{exitCodeText} ({_stopwatch.ElapsedMilliseconds} ms @ {process.StartTime})";

_outputBox.BeginInvoke((Action) (() => _outputBox.richTextBox1.AppendText(
summaryText,
process.ExitCode == 0 ? Color.Blue : Color.Red,
true)));
_outputBox.BeginInvoke((Action) (() => _outputBox.richTextBox1.Select(_outputBox.richTextBox1.TextLength - summaryText.Length + Environment.NewLine.Length, 0)));
_outputBox.BeginInvoke((Action) (() => _outputBox.richTextBox1.ScrollToCaret()));
_outputBox.BeginInvoke((Action) (() => _outputBox.okButton.Enabled = true));
}
}
}
16 changes: 16 additions & 0 deletions GitFlow/OutputBox.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 20 additions & 14 deletions GitFlow/OutputBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ namespace SamirBoulema.TGIT
{
public sealed partial class OutputBox : Form
{
private DTE dte;
private readonly FileHelper _fileHelper;
private readonly ProcessHelper _processHelper;

public OutputBox(DTE dte)
{
InitializeComponent();
this.dte = dte;
_fileHelper = new FileHelper(dte);
_processHelper = new ProcessHelper(dte);
}

private void okButton_Click(object sender, EventArgs e)
Expand All @@ -26,17 +28,17 @@ private void okButton_Click(object sender, EventArgs e)
private void ResolveButton_Click(object sender, EventArgs e)
{
okButton_Click(null, null);
string solutionDir = new FileHelper(dte).GetSolutionDir();
var solutionDir = _fileHelper.GetSolutionDir();
if (string.IsNullOrEmpty(solutionDir)) return;
new ProcessHelper(dte).StartTortoiseGitProc(string.Format("/command:resolve /path:\"{0}\"", solutionDir));
_processHelper.StartTortoiseGitProc($"/command:resolve /path:\"{solutionDir}\"");
}

private void StashButton_Click(object sender, EventArgs e)
{
okButton_Click(null, null);
string solutionDir = new FileHelper(dte).GetSolutionDir();
var solutionDir = _fileHelper.GetSolutionDir();
if (string.IsNullOrEmpty(solutionDir)) return;
new ProcessHelper(dte).StartTortoiseGitProc(string.Format("/command:repostatus /path:\"{0}\"", solutionDir));
_processHelper.StartTortoiseGitProc($"/command:repostatus /path:\"{solutionDir}\"");
}

private void textBox_TextChanged(object sender, EventArgs e)
Expand All @@ -45,20 +47,24 @@ private void textBox_TextChanged(object sender, EventArgs e)

if (textBox.Text.ToLower().Contains("fix conflicts") && !flowLayoutPanel1.Controls.Find("Resolve", true).Any())
{
var resolveButton = new Button();
resolveButton.Text = "Resolve";
resolveButton.Name = "Resolve";
resolveButton.AutoSize = true;
var resolveButton = new Button
{
Text = "Resolve",
Name = "Resolve",
AutoSize = true
};
resolveButton.Click += ResolveButton_Click;
flowLayoutPanel1.Controls.Add(resolveButton);
}

if (textBox.Text.ToLower().Contains("stash") && !flowLayoutPanel1.Controls.Find("Stash", true).Any())
{
var stashButton = new Button();
stashButton.Text = "Show changes";
stashButton.Name = "Stash";
stashButton.AutoSize = true;
var stashButton = new Button
{
Text = "Show changes",
Name = "Stash",
AutoSize = true
};
stashButton.Click += StashButton_Click;
flowLayoutPanel1.Controls.Add(stashButton);
}
Expand Down
30 changes: 30 additions & 0 deletions GitFlow/RichTextBoxExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Drawing;
using System.Windows.Forms;

namespace SamirBoulema.TGIT
{
public static class RichTextBoxExtension
{
public static void AppendText(this RichTextBox box, string text, Color color, bool bold)
{
box.SelectionStart = box.TextLength;
box.SelectionLength = 0;

box.SelectionColor = color;
box.SelectionFont = new Font(box.Font, bold ? FontStyle.Bold : FontStyle.Regular);
box.AppendText(text);
box.SelectionColor = box.ForeColor;
}

public static void AppendText(this RichTextBox box, string text, bool bold)
{
box.SelectionStart = box.TextLength;
box.SelectionLength = 0;

box.SelectionColor = box.ForeColor;
box.SelectionFont = new Font(box.Font, bold ? FontStyle.Bold : FontStyle.Regular);
box.AppendText(text);
box.SelectionColor = box.ForeColor;
}
}
}
1 change: 1 addition & 0 deletions GitFlow/TGIT.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="RichTextBoxExtension.cs" />
<Compile Include="TGITPackage.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PkgCmdID.cs" />
Expand Down
2 changes: 1 addition & 1 deletion GitFlow/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.3" Language="en-US" Publisher="Samir L. Boulema" />
<Identity Id="2eb0e74d-a27d-4c41-bca4-7e9e9befaa18" Version="3.4" Language="en-US" Publisher="Samir L. Boulema" />
<DisplayName>TGIT</DisplayName>
<Description xml:space="preserve">Control TortoiseGIT from within Visual Studio</Description>
<MoreInfo>http://visualstudiogallery.msdn.microsoft.com/be8a61ca-9358-4f43-80e3-4fc73b09dff3</MoreInfo>
Expand Down

0 comments on commit 142d575

Please sign in to comment.