Permalink
Browse files

Rework look and feel and the way

  • Loading branch information...
1 parent 39dd90b commit fb7c8b7eab9ce7045d01690d4781f259f1ef1ee5 @laurentkempe committed Feb 6, 2013
@@ -158,7 +158,7 @@ public void Parse_EmptyGitDiff_Expect0HunkRangeInfos()
var gitDiffParser = new GitDiffParser(EmptyGitDiff);
//Act
- var hunkRangeInfos = gitDiffParser.Parse().ToList();
+ var hunkRangeInfos = gitDiffParser.Parse(null).ToList();
//Assert
hunkRangeInfos.Count.ShouldBe(0);
@@ -171,7 +171,7 @@ public void Parse_WithOneHunk_ExpectHunkRanges()
var gitDiffParser = new GitDiffParser(FirstGitDiff);
//Act
- var hunkRanges = gitDiffParser.Parse().ToList();
+ var hunkRanges = gitDiffParser.Parse(null).ToList();
//Assert
hunkRanges[0].OriginalHunkRange.StartingLineNumber.ShouldBe(40);
@@ -187,7 +187,7 @@ public void Parse_WithOneHunkWithoutLineCount_ExpectHunkRanges()
var gitDiffParser = new GitDiffParser(ThirdGitDiff);
//Act
- var hunkRanges = gitDiffParser.Parse().ToList();
+ var hunkRanges = gitDiffParser.Parse(null).ToList();
//Assert
hunkRanges[0].OriginalHunkRange.StartingLineNumber.ShouldBe(0);
@@ -203,7 +203,7 @@ public void Parse_WithThreeHunk_ExpectHunkRanges()
var gitDiffParser = new GitDiffParser(SecondGitDiff);
//Act
- var hunkRanges = gitDiffParser.Parse().ToList();
+ var hunkRanges = gitDiffParser.Parse(null).ToList();
//Assert
hunkRanges[0].OriginalHunkRange.StartingLineNumber.ShouldBe(67);
@@ -18,7 +18,7 @@ public class HunkRangeInfoTests
public void IsAddition_AllDiffLinesWithStartsWithPlusSign_ExpectedTrue()
{
//Arrange
- var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-41,0"), new HunkRange("+42,20"), new List<string> { "+ ", "+ " }.ToArray());
+ var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-41,0"), new HunkRange("+42,20"), new List<string> { "+ ", "+ " }.ToArray(), null);
//Act
bool isAddition = hunkRangeInfo.IsAddition;
@@ -31,7 +31,7 @@ public void IsAddition_AllDiffLinesWithStartsWithPlusSign_ExpectedTrue()
public void IsAddition_NotAllDiffLinesStartsWithPlusSign_ExpectedFalse()
{
//Arrange
- var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-41,0"), new HunkRange("+42,20"), new List<string> { "+ ", "- " }.ToArray());
+ var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-41,0"), new HunkRange("+42,20"), new List<string> { "+ ", "- " }.ToArray(), null);
//Act
bool isAddition = hunkRangeInfo.IsAddition;
@@ -44,7 +44,7 @@ public void IsAddition_NotAllDiffLinesStartsWithPlusSign_ExpectedFalse()
public void IsModification_DiffLinesStartsWithPlusSignAndWithMinus_ExpectedTrue()
{
//Arrange
- var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-41,0"), new HunkRange("+42,20"), new List<string> { "+ ", "- " }.ToArray());
+ var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-41,0"), new HunkRange("+42,20"), new List<string> { "+ ", "- " }.ToArray(), null);
//Act
bool isModification = hunkRangeInfo.IsModification;
@@ -57,7 +57,7 @@ public void IsModification_DiffLinesStartsWithPlusSignAndWithMinus_ExpectedTrue(
public void OriginalText_1NewLineAnd1OriginalLine_ExpectedOriginalText()
{
//Arrange
- var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-41,0"), new HunkRange("+42,20"), new List<string> { "+New Text", "-Original Text" }.ToArray());
+ var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-41,0"), new HunkRange("+42,20"), new List<string> { "+New Text", "-Original Text" }.ToArray(), null);
//Act
string originalText = hunkRangeInfo.OriginalText[0];
@@ -70,7 +70,7 @@ public void OriginalText_1NewLineAnd1OriginalLine_ExpectedOriginalText()
public void OriginalText_1NewLineAnd1OriginalLineWithLeadingSpaces_ExpectedOriginalText()
{
//Arrange
- var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-41,0"), new HunkRange("+42,20"), new List<string> { "+ New Text", "- Original Text" }.ToArray());
+ var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-41,0"), new HunkRange("+42,20"), new List<string> { "+ New Text", "- Original Text" }.ToArray(), null);
//Act
string originalText = hunkRangeInfo.OriginalText[0];
@@ -83,7 +83,7 @@ public void OriginalText_1NewLineAnd1OriginalLineWithLeadingSpaces_ExpectedOrigi
public void OriginalText_1NewLineAnd1OriginalLineWithLeadingSpacesAndInvertedOrder_ExpectedOriginalText()
{
//Arrange
- var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-18"), new HunkRange("+18"), new List<string> { "- it++; // this is just a comment", "+ it--;" }.ToArray());
+ var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-18"), new HunkRange("+18"), new List<string> { "- it++; // this is just a comment", "+ it--;" }.ToArray(), null);
//Act
var originalText = hunkRangeInfo.OriginalText;
@@ -96,7 +96,7 @@ public void OriginalText_1NewLineAnd1OriginalLineWithLeadingSpacesAndInvertedOrd
public void IsDeletion_3DeletedLines_ExpectTrue()
{
//Arrange
- var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-7,3"), new HunkRange("+6,0"), new List<string> { "-using Microsoft.VisualStudio.Shell;", "-using Microsoft.VisualStudio.Text;", "-using Microsoft.VisualStudio.Text.Editor;" }.ToArray());
+ var hunkRangeInfo = new HunkRangeInfo(new HunkRange("-7,3"), new HunkRange("+6,0"), new List<string> { "-using Microsoft.VisualStudio.Shell;", "-using Microsoft.VisualStudio.Text;", "-using Microsoft.VisualStudio.Text.Editor;" }.ToArray(), null);
//Act
var isDeletion = hunkRangeInfo.IsDeletion;
@@ -36,6 +36,7 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="Microsoft.VisualStudio.Text.Data, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="nunit.framework">
<HintPath>..\packages\NUnit.2.6.0.12054\lib\nunit.framework.dll</HintPath>
</Reference>
@@ -2,6 +2,7 @@
<FileVersion>1</FileVersion>
<AutoEnableOnStartup>True</AutoEnableOnStartup>
<AllowParallelTestExecution>true</AllowParallelTestExecution>
+ <AllowTestsToRunInParallelWithThemselves>true</AllowTestsToRunInParallelWithThemselves>
<FrameworkUtilisationTypeForNUnit>UseDynamicAnalysis</FrameworkUtilisationTypeForNUnit>
<FrameworkUtilisationTypeForGallio>UseStaticAnalysis</FrameworkUtilisationTypeForGallio>
<FrameworkUtilisationTypeForMSpec>UseStaticAnalysis</FrameworkUtilisationTypeForMSpec>
@@ -0,0 +1,21 @@
+using System.ComponentModel.Composition;
+using System.Windows.Media;
+using GitDiffMargin.Git;
+using Microsoft.VisualStudio.Text.Classification;
+using Microsoft.VisualStudio.Utilities;
+
+namespace GitDiffMargin
+{
+ [Export(typeof(EditorFormatDefinition))]
+ [Name(DiffFormatNames.Addition)]
+ [UserVisible(true)]
+ internal sealed class DiffAdditionEditorFormatDefinition : EditorFormatDefinition
+ {
+ public DiffAdditionEditorFormatDefinition()
+ {
+ BackgroundColor = Color.FromRgb(180, 255, 180);
+ ForegroundCustomizable = false;
+ DisplayName = "Git Diff Addition";
+ }
+ }
+}
@@ -0,0 +1,21 @@
+using System.ComponentModel.Composition;
+using System.Windows.Media;
+using GitDiffMargin.Git;
+using Microsoft.VisualStudio.Text.Classification;
+using Microsoft.VisualStudio.Utilities;
+
+namespace GitDiffMargin
+{
+ [Export(typeof(EditorFormatDefinition))]
+ [Name(DiffFormatNames.Modification)]
+ [UserVisible(true)]
+ internal sealed class DiffModificationEditorFormatDefinition : EditorFormatDefinition
+ {
+ public DiffModificationEditorFormatDefinition()
+ {
+ BackgroundColor = Color.FromRgb(160, 200, 255);
+ ForegroundCustomizable = false;
+ DisplayName = "Git Diff Modification";
+ }
+ }
+}
@@ -0,0 +1,21 @@
+using GitDiffMargin.Git;
+using System.ComponentModel.Composition;
+using System.Windows.Media;
+using Microsoft.VisualStudio.Text.Classification;
+using Microsoft.VisualStudio.Utilities;
+
+namespace GitDiffMargin
+{
+ [Export(typeof(EditorFormatDefinition))]
+ [Name(DiffFormatNames.Removed)]
+ [UserVisible(true)]
+ internal sealed class DiffRemovedEditorFormatDefinition : EditorFormatDefinition
+ {
+ public DiffRemovedEditorFormatDefinition()
+ {
+ BackgroundColor = Color.FromRgb(255, 160, 180);
+ ForegroundCustomizable = false;
+ DisplayName = "Git Diff Removed";
+ }
+ }
+}
@@ -38,7 +38,7 @@ protected override void ReParseImpl()
{
textDocument = null;
}
- var diff = textDocument != null ? _commands.GetGitDiffFor(textDocument.FilePath) : Enumerable.Empty<HunkRangeInfo>();
+ var diff = textDocument != null ? _commands.GetGitDiffFor(textDocument.FilePath, snapshot) : Enumerable.Empty<HunkRangeInfo>();
var result = new DiffParseResultEventArgs(snapshot, stopwatch.Elapsed, diff.ToList());
OnParseComplete(result);
@@ -3,18 +3,17 @@
using System.Diagnostics;
using System.IO;
using Microsoft.VisualStudio.Shell;
+using Microsoft.VisualStudio.Text;
namespace GitDiffMargin.Git
{
public class GitCommands : IGitCommands
{
- public IEnumerable<HunkRangeInfo> GetGitDiffFor(string filename)
+ public IEnumerable<HunkRangeInfo> GetGitDiffFor(string filename, ITextSnapshot snapshot)
{
var p = GetProcess(filename);
p.StartInfo.Arguments = String.Format(@" diff --unified=0 {0}", filename);
- ActivityLog.LogInformation("GitDiffMargin", "Command:" + p.StartInfo.Arguments);
-
p.Start();
// Do not wait for the child process to exit before
// reading to the end of its redirected stream.
@@ -23,10 +22,8 @@ public IEnumerable<HunkRangeInfo> GetGitDiffFor(string filename)
var output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
- ActivityLog.LogInformation("GitDiffMargin", "Git Diff output:" + output);
-
var gitDiffParser = new GitDiffParser(output);
- return gitDiffParser.Parse();
+ return gitDiffParser.Parse(snapshot);
}
public void StartExternalDiff(string filename)
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using Microsoft.VisualStudio.Text;
namespace GitDiffMargin.Git
{
@@ -13,11 +14,11 @@ public GitDiffParser(string gitDiff)
_gitDiff = gitDiff;
}
- public IEnumerable<HunkRangeInfo> Parse()
+ public IEnumerable<HunkRangeInfo> Parse(ITextSnapshot snapshot)
{
return from hunkLine in GetUnifiedFormatHunkLines()
- where !string.IsNullOrEmpty(hunkLine.Item1)
- select new HunkRangeInfo(new HunkRange(GetHunkOriginalFile(hunkLine.Item1)), new HunkRange(GetHunkNewFile(hunkLine.Item1)), hunkLine.Item2);
+ where !string.IsNullOrEmpty(hunkLine.Item1)
+ select new HunkRangeInfo(new HunkRange(GetHunkOriginalFile(hunkLine.Item1)), new HunkRange(GetHunkNewFile(hunkLine.Item1)), hunkLine.Item2, snapshot);
}
public IEnumerable<Tuple<string, IEnumerable<string>>> GetUnifiedFormatHunkLines()
@@ -7,18 +7,18 @@ public HunkRange(string hunkRange)
if (hunkRange.Contains(","))
{
var hunkParts = hunkRange.Split(',');
- StartingLineNumber = long.Parse(hunkParts[0]) - 1;
- NumberOfLines = long.Parse(hunkParts[1]);
+ StartingLineNumber = int.Parse(hunkParts[0]) - 1;
+ NumberOfLines = int.Parse(hunkParts[1]);
}
else
{
- StartingLineNumber = long.Parse(hunkRange) - 1;
+ StartingLineNumber = int.Parse(hunkRange) - 1;
NumberOfLines = 1;
}
}
- public long StartingLineNumber { get; private set; }
- public long NumberOfLines { get; private set; }
+ public int StartingLineNumber { get; private set; }
+ public int NumberOfLines { get; private set; }
}
}
@@ -3,17 +3,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using Microsoft.VisualStudio.Text;
#endregion
namespace GitDiffMargin.Git
{
public class HunkRangeInfo
{
+ private readonly ITextSnapshot _snapshot;
private List<string> DiffLines { get; set; }
- public HunkRangeInfo(HunkRange originaleHunkRange, HunkRange newHunkRange, IEnumerable<string> diffLines)
+ public HunkRangeInfo(HunkRange originaleHunkRange, HunkRange newHunkRange, IEnumerable<string> diffLines, ITextSnapshot snapshot)
{
+ _snapshot = snapshot;
OriginalHunkRange = originaleHunkRange;
NewHunkRange = newHunkRange;
DiffLines = diffLines.ToList();
@@ -1,14 +1,15 @@
#region using
using System.Collections.Generic;
+using Microsoft.VisualStudio.Text;
#endregion
namespace GitDiffMargin.Git
{
public interface IGitCommands
{
- IEnumerable<HunkRangeInfo> GetGitDiffFor(string filename);
+ IEnumerable<HunkRangeInfo> GetGitDiffFor(string filename, ITextSnapshot snapshot);
void StartExternalDiff(string filename);
}
}
@@ -103,7 +103,10 @@
</ItemGroup>
<ItemGroup>
<Compile Include="BackgroundParser.cs" />
+ <Compile Include="DiffAdditionEditorFormatDefinition.cs" />
+ <Compile Include="DiffModificationEditorFormatDefinition.cs" />
<Compile Include="DiffParseResultEventArgs.cs" />
+ <Compile Include="DiffRemovedEditorFormatDefinition.cs" />
<Compile Include="DiffUpdateBackgroundParser.cs" />
<Compile Include="GitDiffMargin.cs" />
<Compile Include="GitDiffMarginFactory.cs" />
@@ -12,7 +12,7 @@ namespace GitDiffMargin
{
[Export(typeof (IWpfTextViewMarginProvider))]
[Name(GitDiffMargin.MarginName)]
- [Order(After = PredefinedMarginNames.Spacer)]
+ [Order(Before = PredefinedMarginNames.LineNumber)]
[MarginContainer(PredefinedMarginNames.LeftSelection)]
[ContentType("text")]
[TextViewRole(PredefinedTextViewRoles.Interactive)]
@@ -5,6 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ViewModel="clr-namespace:GitDiffMargin.ViewModel"
Cursor="Hand"
+ ClipToBounds="True"
d:DataContext="{d:DesignInstance ViewModel:DiffMarginViewModel}"
d:DesignHeight="300"
d:DesignWidth="9"
@@ -70,18 +71,15 @@
</Setter>
</Style>
<ControlTemplate x:Key="ChangeTemplate" d:DataContext="{d:DesignInstance ViewModel:DiffViewModel}">
- <Border Width="9"
- BorderBrush="#E0FFE0"
- BorderThickness="0,1,1,1">
- <Rectangle Fill="{Binding DiffBrush}">
- <Rectangle.ToolTip>
- <ToolTip Content="{Binding Coordinates, Mode=OneWay}" />
- </Rectangle.ToolTip>
- </Rectangle>
- </Border>
+ <Rectangle Width="{Binding Width, Mode=OneWay}" HorizontalAlignment="Left" Margin="{Binding Margin, Mode=OneWay}" Fill="{Binding DiffBrush}">
+ <Rectangle.ToolTip>
+ <ToolTip Content="{Binding Coordinates, Mode=OneWay}" />
+ </Rectangle.ToolTip>
+ </Rectangle>
+
</ControlTemplate>
<ControlTemplate x:Key="DeletionTemplate" d:DataContext="{d:DesignInstance ViewModel:DiffViewModel}">
- <Polygon Points="0,0 1,1 0,2 0,0" Fill="Gray" Width="9" Height="{Binding Height}" Stretch="Fill">
+ <Polygon Points="0,0 1,1 0,2 0,0" Fill="{Binding DiffBrush}" Width="9" Height="{Binding Height}" Stretch="Fill">
<Polygon.ToolTip>
<ToolTip Content="{Binding Coordinates, Mode=OneWay}" />
</Polygon.ToolTip>
@@ -95,7 +93,7 @@
<ItemsControl Grid.Column="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
- ItemsSource="{Binding DiffViewModels, Mode=TwoWay}">
+ ItemsSource="{Binding DiffViewModels, Mode=OneWay}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
@@ -116,7 +116,6 @@ private void HandleParseComplete(object sender, ParseResultEventArgs e)
var diffResult = e as DiffParseResultEventArgs;
if (diffResult == null) return;
-
foreach (var diffViewModel in diffResult.Diff.Select(hunkRangeInfo => new DiffViewModel(hunkRangeInfo, _textView)))
{
DiffViewModels.Add(diffViewModel);
Oops, something went wrong.

0 comments on commit fb7c8b7

Please sign in to comment.