From cffd333342d1f0d559cb0db355e35f555ae567a7 Mon Sep 17 00:00:00 2001 From: Gianluigi Conti Date: Sun, 5 Feb 2017 15:05:22 +0100 Subject: [PATCH] Add icon to toggle whitespaces ignoring --- GitDiffMargin/GitDiffMargin.csproj | 4 ++++ GitDiffMargin/GitDiffMargin.vsct | 16 ++++++++++++- GitDiffMargin/GitDiffMarginCommand.cs | 1 + GitDiffMargin/GitDiffMarginCommandHandler.cs | 21 ++++++++++++++++++ .../Resources/Ignore_whitespaces.png | Bin 0 -> 409 bytes .../ViewModel/DiffMarginViewModelBase.cs | 13 ++++++++++- .../ViewModel/EditorDiffMarginViewModel.cs | 18 +++++++++++++++ 7 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 GitDiffMargin/Resources/Ignore_whitespaces.png diff --git a/GitDiffMargin/GitDiffMargin.csproj b/GitDiffMargin/GitDiffMargin.csproj index 7f90ea8..3c9c68c 100644 --- a/GitDiffMargin/GitDiffMargin.csproj +++ b/GitDiffMargin/GitDiffMargin.csproj @@ -275,6 +275,10 @@ LICENSE.md true + + + source.extension.vsixmanifest + Designer diff --git a/GitDiffMargin/GitDiffMargin.vsct b/GitDiffMargin/GitDiffMargin.vsct index 25c61dc..75a0024 100644 --- a/GitDiffMargin/GitDiffMargin.vsct +++ b/GitDiffMargin/GitDiffMargin.vsct @@ -80,6 +80,17 @@ Copy Old Text + + @@ -88,6 +99,7 @@ + @@ -100,6 +112,7 @@ + @@ -110,5 +123,6 @@ + - + \ No newline at end of file diff --git a/GitDiffMargin/GitDiffMarginCommand.cs b/GitDiffMargin/GitDiffMarginCommand.cs index 0d89fae..9c895de 100644 --- a/GitDiffMargin/GitDiffMarginCommand.cs +++ b/GitDiffMargin/GitDiffMarginCommand.cs @@ -10,6 +10,7 @@ public enum GitDiffMarginCommand RollbackChange = 2, ShowDiff = 3, CopyOldText = 4, + IgnoreWhiteSpaces = 5, GitDiffToolbar = 100, diff --git a/GitDiffMargin/GitDiffMarginCommandHandler.cs b/GitDiffMargin/GitDiffMarginCommandHandler.cs index aacd5dd..25fb882 100644 --- a/GitDiffMargin/GitDiffMarginCommandHandler.cs +++ b/GitDiffMargin/GitDiffMarginCommandHandler.cs @@ -98,6 +98,19 @@ protected override OLECMDF QueryCommandStatus(ref Guid commandGroup, uint comman // these aren't actually commands, but IDs of the command bars and groups break; + case GitDiffMarginCommand.IgnoreWhiteSpaces: + { + EditorDiffMarginViewModel viewModel; + if (!TryGetMarginViewModel(out viewModel) || !viewModel.HasDiffs) + return 0; + + if (viewModel.IgnoreWhiteSpaces) + return OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_LATCHED; + else + return OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED; + } + break; + default: break; } @@ -166,6 +179,14 @@ protected override bool HandlePreExec(ref Guid commandGroup, uint commandId, OLE // these aren't actually commands, but IDs of the command bars and groups break; + case GitDiffMarginCommand.IgnoreWhiteSpaces: + { + ICommand command = viewModel.ToggleIgnoreWhiteSpacesCommand; + command.Execute(null); + return true; + } + break; + default: break; } diff --git a/GitDiffMargin/Resources/Ignore_whitespaces.png b/GitDiffMargin/Resources/Ignore_whitespaces.png new file mode 100644 index 0000000000000000000000000000000000000000..a1a18bd8d4c5883dc3c60a2c4dbdc861162f9de3 GIT binary patch literal 409 zcmV;K0cQS*P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vG&=l}pD=mCOb1snhX0WL{IK~y+T&62T> zf2yM#=U6NjFin$k;1_VB zC}OMCifuNVFKa%Z4+_STBw@O)lU5)-t^t00000NkvXXu0mjf D+m)z| literal 0 HcmV?d00001 diff --git a/GitDiffMargin/ViewModel/DiffMarginViewModelBase.cs b/GitDiffMargin/ViewModel/DiffMarginViewModelBase.cs index 3f53261..39331eb 100644 --- a/GitDiffMargin/ViewModel/DiffMarginViewModelBase.cs +++ b/GitDiffMargin/ViewModel/DiffMarginViewModelBase.cs @@ -24,6 +24,8 @@ protected DiffMarginViewModelBase(IMarginCore marginCore) MarginCore.HunksChanged += HandleHunksChanged; } + public bool HasDiffs { get; private set; } + public ObservableCollection DiffViewModels { get; private set; } public void RefreshDiffViewModelPositions() @@ -38,7 +40,16 @@ protected virtual void HandleHunksChanged(object sender, HunksChangedEventArgs e { DiffViewModels.Clear(); - foreach (var diffViewModel in e.Hunks.Select(CreateDiffViewModel)) + HasDiffs = e.Hunks.Any(); + + var hunks = e.Hunks; + + if (MarginCore.IgnoreWhiteSpaces) + { + hunks = hunks.Where(hunk => !hunk.IsWhiteSpaceChange); + } + + foreach (var diffViewModel in hunks.Select(CreateDiffViewModel)) { DiffViewModels.Add(diffViewModel); } diff --git a/GitDiffMargin/ViewModel/EditorDiffMarginViewModel.cs b/GitDiffMargin/ViewModel/EditorDiffMarginViewModel.cs index 05486bb..09730a4 100644 --- a/GitDiffMargin/ViewModel/EditorDiffMarginViewModel.cs +++ b/GitDiffMargin/ViewModel/EditorDiffMarginViewModel.cs @@ -15,6 +15,7 @@ internal class EditorDiffMarginViewModel : DiffMarginViewModelBase private readonly Action _updateDiffDimensions; private RelayCommand _previousChangeCommand; private RelayCommand _nextChangeCommand; + private RelayCommand _toggleIgnoreWhiteSpacesCommand; internal EditorDiffMarginViewModel(IMarginCore marginCore, Action updateDiffDimensions) : base(marginCore) @@ -25,6 +26,8 @@ internal EditorDiffMarginViewModel(IMarginCore marginCore, Action MarginCore.IgnoreWhiteSpaces; + public RelayCommand PreviousChangeCommand { get { return _previousChangeCommand ?? (_previousChangeCommand = new RelayCommand(PreviousChange, PreviousChangeCanExecute)); } @@ -35,6 +38,11 @@ public RelayCommand NextChangeCommand get { return _nextChangeCommand ?? (_nextChangeCommand = new RelayCommand(NextChange, NextChangeCanExecute)); } } + public RelayCommand ToggleIgnoreWhiteSpacesCommand + { + get { return _toggleIgnoreWhiteSpacesCommand ?? (_toggleIgnoreWhiteSpacesCommand = new RelayCommand(ToggleIgnoreWhiteSpaces, CanExecuteToggleIgnoreWhiteSpaces)); } + } + private bool PreviousChangeCanExecute(DiffViewModel currentEditorDiffViewModel) { return DiffViewModels.IndexOf(currentEditorDiffViewModel) > 0; @@ -55,6 +63,16 @@ private void NextChange(DiffViewModel currentEditorDiffViewModel) MoveToChange(currentEditorDiffViewModel, +1); } + private void ToggleIgnoreWhiteSpaces() + { + MarginCore.ToggleIgnoreWhiteSpace(); + } + + private bool CanExecuteToggleIgnoreWhiteSpaces() + { + return true; + } + public void MoveToChange(DiffViewModel currentDiffViewModel, int indexModifier) { var diffViewModelIndex = DiffViewModels.IndexOf(currentDiffViewModel) + indexModifier;