Skip to content

Commit

Permalink
Make DiffMarginControl the primary FrameworkElement for the margin
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Feb 6, 2013
1 parent ecc2f4a commit 0cb6542
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
22 changes: 4 additions & 18 deletions Diff/DiffMargin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Editor.OptionsExtensionMethods;

public class DiffMargin : Canvas, IWpfTextViewMargin
public class DiffMargin : IWpfTextViewMargin
{
public const string MarginName = "GitDiffMargin";

Expand All @@ -34,7 +34,6 @@ public class DiffMargin : Canvas, IWpfTextViewMargin
/// <param name="textView"> The <see cref="IWpfTextView" /> to attach the margin to. </param>
public DiffMargin(IWpfTextView textView, ITextDocumentFactoryService textDocumentFactoryService, IEditorFormatMapService editorFormatMapService)
{
Width = MarginWidth;
_textView = textView;
_editorFormatMap = editorFormatMapService.GetEditorFormatMap(textView);

Expand All @@ -45,17 +44,9 @@ public DiffMargin(IWpfTextView textView, ITextDocumentFactoryService textDocumen
HandleOptionChanged(null, null);
_textView.Options.OptionChanged += HandleOptionChanged;

IsVisibleChanged += (sender, e) =>
{
if ((bool)e.NewValue)
_textView.LayoutChanged += HandleLayoutChanged;
else
_textView.LayoutChanged -= HandleLayoutChanged;
};

_gitDiffBarControl = new DiffMarginControl();
_gitDiffBarControl.DataContext = new DiffMarginViewModel(this, _textView, textDocumentFactoryService, new GitCommands());
Children.Add(_gitDiffBarControl);
_gitDiffBarControl.Width = MarginWidth;
}

/// <summary>
Expand All @@ -66,7 +57,7 @@ public System.Windows.FrameworkElement VisualElement
get
{
ThrowIfDisposed();
return this;
return _gitDiffBarControl;
}
}

Expand All @@ -75,7 +66,7 @@ public double MarginSize
get
{
ThrowIfDisposed();
return this.ActualWidth;
return _gitDiffBarControl.ActualWidth;
}
}

Expand Down Expand Up @@ -141,11 +132,6 @@ private void HandleOptionChanged(object sender, EditorOptionChangedEventArgs e)
{
}

private void HandleLayoutChanged(object sender, TextViewLayoutChangedEventArgs e)
{
InvalidateVisual();
}

private void UpdateBrushes()
{
_additionBrush = GetBrush(_editorFormatMap.GetProperties(DiffFormatNames.Addition));
Expand Down
2 changes: 1 addition & 1 deletion Diff/ViewModel/DiffMarginViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private void RefreshDiffViewModelPositions()

private void HandleParseComplete(object sender, ParseResultEventArgs e)
{
_margin.Dispatcher.BeginInvoke((Action)(() =>
_margin.VisualElement.Dispatcher.BeginInvoke((Action)(() =>
{
DiffViewModels.Clear();

Expand Down

0 comments on commit 0cb6542

Please sign in to comment.