Skip to content

Commit

Permalink
Use the DiffMargin view option to control the visibility of the diff …
Browse files Browse the repository at this point in the history
…margin (changes to the option for a text view are immediately applied)
  • Loading branch information
sharwell committed Feb 7, 2013
1 parent e37e0b0 commit 5d066f7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Diff/DiffMargin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ public DiffMargin(IWpfTextView textView, ITextDocumentFactoryService textDocumen
_textView.Closed += (sender, e) => _editorFormatMap.FormatMappingChanged -= HandleFormatMappingChanged;
UpdateBrushes();

HandleOptionChanged(null, null);
_textView.Options.OptionChanged += HandleOptionChanged;

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

/// <summary>
Expand Down Expand Up @@ -74,7 +74,7 @@ public bool Enabled
{
get
{
return _textView.Options.IsSelectionMarginEnabled();
return _textView.Options.GetOptionValue(GitTextViewOptions.DiffMarginId);
}
}

Expand Down Expand Up @@ -130,6 +130,8 @@ private void HandleFormatMappingChanged(object sender, FormatItemsEventArgs e)

private void HandleOptionChanged(object sender, EditorOptionChangedEventArgs e)
{
if (!_isDisposed && e.OptionId == GitTextViewOptions.DiffMarginName)
UpdateVisibility();
}

private void UpdateBrushes()
Expand All @@ -139,6 +141,12 @@ private void UpdateBrushes()
_removedBrush = GetBrush(_editorFormatMap.GetProperties(DiffFormatNames.Removed));
}

private void UpdateVisibility()
{
ThrowIfDisposed();
_gitDiffBarControl.Visibility = Enabled ? Visibility.Visible : Visibility.Collapsed;
}

private static Brush GetBrush(ResourceDictionary properties)
{
if (properties == null)
Expand Down

0 comments on commit 5d066f7

Please sign in to comment.