Skip to content

Commit

Permalink
Add icon to toggle whitespaces ignoring
Browse files Browse the repository at this point in the history
  • Loading branch information
glconti committed Feb 8, 2017
1 parent 46232a3 commit 3456f44
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 2 deletions.
1 change: 1 addition & 0 deletions GitDiffMargin/GitDiffMargin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@
<Link>LICENSE.md</Link>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Content Include="Resources\Ignore_whitespaces.png" />
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
Expand Down
16 changes: 15 additions & 1 deletion GitDiffMargin/GitDiffMargin.vsct
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@
<ToolTipText>Copy Old Text</ToolTipText>
</Strings>
</Button>

<Button guid="GitDiffMarginCommand" id="IgnoreWhitespaces" priority="0x106" type="Button">
<Parent guid="GitDiffMarginCommand" id="GitDiffToolbarGroup" />
<Icon guid="IgnoreWhitespaces" id="1" />
<CommandFlag>DefaultDisabled</CommandFlag>
<Strings>
<ButtonText>Ignore whitespaces</ButtonText>
<MenuText>Ignore whitespaces</MenuText>
<ToolTipText>Ignore whitespaces</ToolTipText>
</Strings>
</Button>
</Buttons>

<Bitmaps>
Expand All @@ -88,6 +99,7 @@
<Bitmap guid="IconRollback" href="Resources\Rollback.png"/>
<Bitmap guid="IconShowDifference" href="Resources\ShowDifference.png"/>
<Bitmap guid="IconCopyOldText" href="Resources\CopyOldText.png"/>
<Bitmap guid="IgnoreWhitespaces" href="Resources\Ignore_whitespaces.png" />
</Bitmaps>
</Commands>

Expand All @@ -100,6 +112,7 @@
<IDSymbol name="RollbackChange" value="2" />
<IDSymbol name="ShowDiff" value="3" />
<IDSymbol name="CopyOldText" value="4" />
<IDSymbol name="IgnoreWhitespaces" value="5" />

<IDSymbol name="GitDiffToolbar" value="100"/>
<IDSymbol name="GitDiffToolbarGroup" value="150"/>
Expand All @@ -110,5 +123,6 @@
<GuidSymbol name="IconRollback" value="{E4584E6D-3BB3-4141-80A7-9E22D028C41E}" />
<GuidSymbol name="IconShowDifference" value="{E8011DB3-8E2C-4EEA-8C3D-0D33FB66EB12}" />
<GuidSymbol name="IconCopyOldText" value="{269FF401-0A36-4E4B-8301-66FB58AA9835}" />
<GuidSymbol name="IgnoreWhitespaces" value="{72992790-BB19-4EC3-A4CE-7C2E6D9E539D}" />
</Symbols>
</CommandTable>
</CommandTable>
1 change: 1 addition & 0 deletions GitDiffMargin/GitDiffMarginCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public enum GitDiffMarginCommand
RollbackChange = 2,
ShowDiff = 3,
CopyOldText = 4,
IgnoreWhiteSpaces = 5,

GitDiffToolbar = 100,

Expand Down
21 changes: 21 additions & 0 deletions GitDiffMargin/GitDiffMarginCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
Binary file added GitDiffMargin/Resources/Ignore_whitespaces.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 12 additions & 1 deletion GitDiffMargin/ViewModel/DiffMarginViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ protected DiffMarginViewModelBase(IMarginCore marginCore)
MarginCore.HunksChanged += HandleHunksChanged;
}

public bool HasDiffs { get; private set; }

public ObservableCollection<DiffViewModel> DiffViewModels { get; private set; }

public void RefreshDiffViewModelPositions()
Expand All @@ -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);
}
Expand Down
18 changes: 18 additions & 0 deletions GitDiffMargin/ViewModel/EditorDiffMarginViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ internal class EditorDiffMarginViewModel : DiffMarginViewModelBase
private readonly Action<DiffViewModel, HunkRangeInfo> _updateDiffDimensions;
private RelayCommand<DiffViewModel> _previousChangeCommand;
private RelayCommand<DiffViewModel> _nextChangeCommand;
private RelayCommand _toggleIgnoreWhiteSpacesCommand;

internal EditorDiffMarginViewModel(IMarginCore marginCore, Action<DiffViewModel, HunkRangeInfo> updateDiffDimensions) :
base(marginCore)
Expand All @@ -25,6 +26,8 @@ internal EditorDiffMarginViewModel(IMarginCore marginCore, Action<DiffViewModel,
_updateDiffDimensions = updateDiffDimensions;
}

public bool IgnoreWhiteSpaces => MarginCore.IgnoreWhiteSpaces;

public RelayCommand<DiffViewModel> PreviousChangeCommand
{
get { return _previousChangeCommand ?? (_previousChangeCommand = new RelayCommand<DiffViewModel>(PreviousChange, PreviousChangeCanExecute)); }
Expand All @@ -35,6 +38,11 @@ public RelayCommand<DiffViewModel> NextChangeCommand
get { return _nextChangeCommand ?? (_nextChangeCommand = new RelayCommand<DiffViewModel>(NextChange, NextChangeCanExecute)); }
}

public RelayCommand ToggleIgnoreWhiteSpacesCommand
{
get { return _toggleIgnoreWhiteSpacesCommand ?? (_toggleIgnoreWhiteSpacesCommand = new RelayCommand(ToggleIgnoreWhiteSpaces, CanExecuteToggleIgnoreWhiteSpaces)); }
}

private bool PreviousChangeCanExecute(DiffViewModel currentEditorDiffViewModel)
{
return DiffViewModels.IndexOf(currentEditorDiffViewModel) > 0;
Expand All @@ -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;
Expand Down

0 comments on commit 3456f44

Please sign in to comment.