Skip to content

Commit

Permalink
Merge pull request #33 from laurentkempe/feature/EnhancedScrollBar2
Browse files Browse the repository at this point in the history
Feature/enhanced scroll bar2
  • Loading branch information
laurentkempe committed Aug 28, 2014
2 parents 33fbd6d + a98e3dd commit e14b9e5
Show file tree
Hide file tree
Showing 45 changed files with 1,881 additions and 1,374 deletions.
2 changes: 1 addition & 1 deletion GitDiffMargin.Unit.Tests/Git/GitDiffParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace GitDiffMargin.Unit.Tests.Git
// ReSharper disable InconsistentNaming

[TestFixture]
public class Tests1
public class GitDiffParserTests
{
/*
git diff --unified=0 Sources/skyeEditor/Core/Model/Dependency/IModelDependency.cs
Expand Down
10 changes: 5 additions & 5 deletions GitDiffMargin.Unit.Tests/GitDiffMargin.Unit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.Text.Data, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="nunit.framework, Version=2.6.2.12296, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<Reference Include="nunit.framework, Version=2.6.3.13283, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\NUnit.2.6.2\lib\nunit.framework.dll</HintPath>
<HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="Shouldly">
<HintPath>..\packages\Shouldly.1.1.1.1\lib\35\Shouldly.dll</HintPath>
<Reference Include="Shouldly, Version=2.1.1.0, Culture=neutral, PublicKeyToken=6042cbcb05cbc941, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Shouldly.2.1.1\lib\net40\Shouldly.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -68,7 +69,6 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
4 changes: 2 additions & 2 deletions GitDiffMargin.Unit.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="2.6.2" targetFramework="net45" />
<package id="Shouldly" version="1.1.1.1" />
<package id="NUnit" version="2.6.3" targetFramework="net45" />
<package id="Shouldly" version="2.1.1" targetFramework="net45" />
</packages>
12 changes: 4 additions & 8 deletions GitDiffMargin.sln
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30501.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitDiffMargin", "GitDiffMargin\GitDiffMargin.csproj", "{233B6F13-7687-4823-870B-A8F44B79D4F0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitDiffMargin.Unit.Tests", "GitDiffMargin.Unit.Tests\GitDiffMargin.Unit.Tests.csproj", "{B954F515-AC6F-40D4-8169-03985AC62B06}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{0A0AF18B-6698-4A12-B5AB-C37929F583E4}"
ProjectSection(SolutionItems) = preProject
.nuget\NuGet.exe = .nuget\NuGet.exe
.nuget\NuGet.targets = .nuget\NuGet.targets
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Text;

namespace GitDiffMargin
namespace GitDiffMargin.Core
{
public abstract class BackgroundParser : IDisposable
{
Expand All @@ -45,7 +45,7 @@ public abstract class BackgroundParser : IDisposable

public event EventHandler<ParseResultEventArgs> ParseComplete;

public BackgroundParser(ITextBuffer textBuffer, TaskScheduler taskScheduler, ITextDocumentFactoryService textDocumentFactoryService)
protected BackgroundParser(ITextBuffer textBuffer, TaskScheduler taskScheduler, ITextDocumentFactoryService textDocumentFactoryService)
{
if (textBuffer == null)
throw new ArgumentNullException("textBuffer");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using GitDiffMargin.Git;
using Microsoft.VisualStudio.Text;

namespace GitDiffMargin
namespace GitDiffMargin.Core
{
public class DiffParseResultEventArgs : ParseResultEventArgs
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,120 +1,119 @@
using System.IO;
using System.Threading;
using GitDiffMargin.Git;
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.VisualStudio.Text;
using Stopwatch = System.Diagnostics.Stopwatch;
using Task = System.Threading.Tasks.Task;

namespace GitDiffMargin
{
public class DiffUpdateBackgroundParser : BackgroundParser
{
private readonly FileSystemWatcher _watcher;
private readonly IGitCommands _commands;
private readonly ITextDocument _textDocument;
private readonly ITextBuffer _documentBuffer;

public DiffUpdateBackgroundParser(ITextBuffer textBuffer, ITextBuffer documentBuffer, TaskScheduler taskScheduler, ITextDocumentFactoryService textDocumentFactoryService, IGitCommands commands)
: base(textBuffer, taskScheduler, textDocumentFactoryService)
{
_documentBuffer = documentBuffer;
_commands = commands;
ReparseDelay = TimeSpan.FromMilliseconds(500);

if (TextDocumentFactoryService.TryGetTextDocument(_documentBuffer, out _textDocument))
{
if (_commands.IsGitRepository(_textDocument.FilePath))
{
_textDocument.FileActionOccurred += OnFileActionOccurred;

var solutionDirectory = _commands.GetGitRepository(_textDocument.FilePath);

if (!string.IsNullOrWhiteSpace(solutionDirectory))
{
var gitDirectory = Path.Combine(solutionDirectory, ".git");
_watcher = new FileSystemWatcher(gitDirectory);
_watcher.Changed += HandleFileSystemChanged;
_watcher.Created += HandleFileSystemChanged;
_watcher.Deleted += HandleFileSystemChanged;
_watcher.Renamed += HandleFileSystemChanged;
_watcher.EnableRaisingEvents = true;
}
}
}
}

private void HandleFileSystemChanged(object sender, FileSystemEventArgs e)
{
Action action = () => ProcessFileSystemChange(e);
Task.Factory.StartNew(action, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default);
}

private void ProcessFileSystemChange(FileSystemEventArgs e)
{
if (e.ChangeType == WatcherChangeTypes.Changed && Directory.Exists(e.FullPath))
return;

if (string.Equals(Path.GetExtension(e.Name), ".lock", StringComparison.OrdinalIgnoreCase))
return;

MarkDirty(true);
}

private void OnFileActionOccurred(object sender, TextDocumentFileActionEventArgs e)
{
if ((e.FileActionType & FileActionTypes.ContentSavedToDisk) != 0)
{
MarkDirty(true);
}
}

public override string Name
{
get
{
return "Git Diff Analyzer";
}
}

protected override void ReParseImpl()
{
try
{
var stopwatch = Stopwatch.StartNew();

var snapshot = TextBuffer.CurrentSnapshot;
ITextDocument textDocument;
if (!TextDocumentFactoryService.TryGetTextDocument(_documentBuffer, out textDocument)) return;

var diff = _commands.GetGitDiffFor(textDocument, snapshot);
var result = new DiffParseResultEventArgs(snapshot, stopwatch.Elapsed, diff.ToList());
OnParseComplete(result);
}
catch (InvalidOperationException)
{
MarkDirty(true);
throw;
}
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);

if (disposing)
{
if (_textDocument != null)
{
_textDocument.FileActionOccurred -= OnFileActionOccurred;
}
if (_watcher != null)
{
_watcher.Dispose();
}
}
}
}
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using GitDiffMargin.Git;
using Microsoft.VisualStudio.Text;

namespace GitDiffMargin.Core
{
public class DiffUpdateBackgroundParser : BackgroundParser
{
private readonly FileSystemWatcher _watcher;
private readonly IGitCommands _commands;
private readonly ITextDocument _textDocument;
private readonly ITextBuffer _documentBuffer;

public DiffUpdateBackgroundParser(ITextBuffer textBuffer, ITextBuffer documentBuffer, TaskScheduler taskScheduler, ITextDocumentFactoryService textDocumentFactoryService, IGitCommands commands)
: base(textBuffer, taskScheduler, textDocumentFactoryService)
{
_documentBuffer = documentBuffer;
_commands = commands;
ReparseDelay = TimeSpan.FromMilliseconds(500);

if (TextDocumentFactoryService.TryGetTextDocument(_documentBuffer, out _textDocument))
{
if (_commands.IsGitRepository(_textDocument.FilePath))
{
_textDocument.FileActionOccurred += OnFileActionOccurred;

var solutionDirectory = _commands.GetGitRepository(_textDocument.FilePath);

if (!string.IsNullOrWhiteSpace(solutionDirectory))
{
var gitDirectory = Path.Combine(solutionDirectory, ".git");
_watcher = new FileSystemWatcher(gitDirectory);
_watcher.Changed += HandleFileSystemChanged;
_watcher.Created += HandleFileSystemChanged;
_watcher.Deleted += HandleFileSystemChanged;
_watcher.Renamed += HandleFileSystemChanged;
_watcher.EnableRaisingEvents = true;
}
}
}
}

private void HandleFileSystemChanged(object sender, FileSystemEventArgs e)
{
Action action = () => ProcessFileSystemChange(e);
Task.Factory.StartNew(action, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default);
}

private void ProcessFileSystemChange(FileSystemEventArgs e)
{
if (e.ChangeType == WatcherChangeTypes.Changed && Directory.Exists(e.FullPath))
return;

if (string.Equals(Path.GetExtension(e.Name), ".lock", StringComparison.OrdinalIgnoreCase))
return;

MarkDirty(true);
}

private void OnFileActionOccurred(object sender, TextDocumentFileActionEventArgs e)
{
if ((e.FileActionType & FileActionTypes.ContentSavedToDisk) != 0)
{
MarkDirty(true);
}
}

public override string Name
{
get
{
return "Git Diff Analyzer";
}
}

protected override void ReParseImpl()
{
try
{
var stopwatch = Stopwatch.StartNew();

var snapshot = TextBuffer.CurrentSnapshot;
ITextDocument textDocument;
if (!TextDocumentFactoryService.TryGetTextDocument(_documentBuffer, out textDocument)) return;

var diff = _commands.GetGitDiffFor(textDocument, snapshot);
var result = new DiffParseResultEventArgs(snapshot, stopwatch.Elapsed, diff.ToList());
OnParseComplete(result);
}
catch (InvalidOperationException)
{
MarkDirty(true);
throw;
}
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);

if (disposing)
{
if (_textDocument != null)
{
_textDocument.FileActionOccurred -= OnFileActionOccurred;
}
if (_watcher != null)
{
_watcher.Dispose();
}
}
}
}
}
34 changes: 34 additions & 0 deletions GitDiffMargin/Core/IMarginCore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media;
using GitDiffMargin.Git;
using Microsoft.VisualStudio.Text;

namespace GitDiffMargin.Core
{
internal interface IMarginCore
{
event EventHandler BrushesChanged;

event EventHandler<IEnumerable<HunkRangeInfo>> HunksChanged;

GitCommands GitCommands { get; }
FontFamily FontFamily { get; }
FontStretch FontStretch { get; }
FontStyle FontStyle { get; }
FontWeight FontWeight { get; }
double FontSize { get; }
Brush Background { get; }
Brush Foreground { get; }
Brush AdditionBrush { get; }
Brush ModificationBrush { get; }
Brush RemovedBrush { get; }
double EditorChangeLeft { get; }
double EditorChangeWidth { get; }
double ScrollChangeWidth { get; }
void MoveToChange(int lineNumber);
bool RollBack(HunkRangeInfo hunkRangeInfo);
ITextDocument GetTextDocument();
}
}
Loading

0 comments on commit e14b9e5

Please sign in to comment.