Skip to content

Commit 5940e3a

Browse files
committed
Add icon to toggle whitespaces ignoring
1 parent 1bfe1a4 commit 5940e3a

File tree

7 files changed

+68
-2
lines changed

7 files changed

+68
-2
lines changed

GitDiffMargin/GitDiffMargin.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@
271271
<Link>LICENSE.md</Link>
272272
<IncludeInVSIX>true</IncludeInVSIX>
273273
</Content>
274+
<Content Include="Resources\Ignore_whitespaces.png" />
274275
<None Include="packages.config">
275276
<SubType>Designer</SubType>
276277
</None>

GitDiffMargin/GitDiffMargin.vsct

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@
8080
<ToolTipText>Copy Old Text</ToolTipText>
8181
</Strings>
8282
</Button>
83+
84+
<Button guid="GitDiffMarginCommand" id="IgnoreWhitespaces" priority="0x106" type="Button">
85+
<Parent guid="GitDiffMarginCommand" id="GitDiffToolbarGroup" />
86+
<Icon guid="IgnoreWhitespaces" id="1" />
87+
<CommandFlag>DefaultDisabled</CommandFlag>
88+
<Strings>
89+
<ButtonText>Ignore whitespaces</ButtonText>
90+
<MenuText>Ignore whitespaces</MenuText>
91+
<ToolTipText>Ignore whitespaces</ToolTipText>
92+
</Strings>
93+
</Button>
8394
</Buttons>
8495

8596
<Bitmaps>
@@ -88,6 +99,7 @@
8899
<Bitmap guid="IconRollback" href="Resources\Rollback.png"/>
89100
<Bitmap guid="IconShowDifference" href="Resources\ShowDifference.png"/>
90101
<Bitmap guid="IconCopyOldText" href="Resources\CopyOldText.png"/>
102+
<Bitmap guid="IgnoreWhitespaces" href="Resources\Ignore_whitespaces.png" />
91103
</Bitmaps>
92104
</Commands>
93105

@@ -100,6 +112,7 @@
100112
<IDSymbol name="RollbackChange" value="2" />
101113
<IDSymbol name="ShowDiff" value="3" />
102114
<IDSymbol name="CopyOldText" value="4" />
115+
<IDSymbol name="IgnoreWhitespaces" value="5" />
103116

104117
<IDSymbol name="GitDiffToolbar" value="100"/>
105118
<IDSymbol name="GitDiffToolbarGroup" value="150"/>
@@ -110,5 +123,6 @@
110123
<GuidSymbol name="IconRollback" value="{E4584E6D-3BB3-4141-80A7-9E22D028C41E}" />
111124
<GuidSymbol name="IconShowDifference" value="{E8011DB3-8E2C-4EEA-8C3D-0D33FB66EB12}" />
112125
<GuidSymbol name="IconCopyOldText" value="{269FF401-0A36-4E4B-8301-66FB58AA9835}" />
126+
<GuidSymbol name="IgnoreWhitespaces" value="{72992790-BB19-4EC3-A4CE-7C2E6D9E539D}" />
113127
</Symbols>
114-
</CommandTable>
128+
</CommandTable>

GitDiffMargin/GitDiffMarginCommand.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public enum GitDiffMarginCommand
1010
RollbackChange = 2,
1111
ShowDiff = 3,
1212
CopyOldText = 4,
13+
IgnoreWhiteSpaces = 5,
1314

1415
GitDiffToolbar = 100,
1516

GitDiffMargin/GitDiffMarginCommandHandler.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,19 @@ protected override OLECMDF QueryCommandStatus(ref Guid commandGroup, uint comman
9898
// these aren't actually commands, but IDs of the command bars and groups
9999
break;
100100

101+
case GitDiffMarginCommand.IgnoreWhiteSpaces:
102+
{
103+
EditorDiffMarginViewModel viewModel;
104+
if (!TryGetMarginViewModel(out viewModel) || !viewModel.HasDiffs)
105+
return 0;
106+
107+
if (viewModel.IgnoreWhiteSpaces)
108+
return OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED | OLECMDF.OLECMDF_LATCHED;
109+
else
110+
return OLECMDF.OLECMDF_SUPPORTED | OLECMDF.OLECMDF_ENABLED;
111+
}
112+
break;
113+
101114
default:
102115
break;
103116
}
@@ -166,6 +179,14 @@ protected override bool HandlePreExec(ref Guid commandGroup, uint commandId, OLE
166179
// these aren't actually commands, but IDs of the command bars and groups
167180
break;
168181

182+
case GitDiffMarginCommand.IgnoreWhiteSpaces:
183+
{
184+
ICommand command = viewModel.ToggleIgnoreWhiteSpacesCommand;
185+
command.Execute(null);
186+
return true;
187+
}
188+
break;
189+
169190
default:
170191
break;
171192
}
188 Bytes
Loading

GitDiffMargin/ViewModel/DiffMarginViewModelBase.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ protected DiffMarginViewModelBase(IMarginCore marginCore)
2424
MarginCore.HunksChanged += HandleHunksChanged;
2525
}
2626

27+
public bool HasDiffs { get; private set; }
28+
2729
public ObservableCollection<DiffViewModel> DiffViewModels { get; private set; }
2830

2931
public void RefreshDiffViewModelPositions()
@@ -38,7 +40,16 @@ protected virtual void HandleHunksChanged(object sender, HunksChangedEventArgs e
3840
{
3941
DiffViewModels.Clear();
4042

41-
foreach (var diffViewModel in e.Hunks.Select(CreateDiffViewModel))
43+
HasDiffs = e.Hunks.Any();
44+
45+
var hunks = e.Hunks;
46+
47+
if (MarginCore.IgnoreWhiteSpaces)
48+
{
49+
hunks = hunks.Where(hunk => !hunk.IsWhiteSpaceChange);
50+
}
51+
52+
foreach (var diffViewModel in hunks.Select(CreateDiffViewModel))
4253
{
4354
DiffViewModels.Add(diffViewModel);
4455
}

GitDiffMargin/ViewModel/EditorDiffMarginViewModel.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ internal class EditorDiffMarginViewModel : DiffMarginViewModelBase
1515
private readonly Action<DiffViewModel, HunkRangeInfo> _updateDiffDimensions;
1616
private RelayCommand<DiffViewModel> _previousChangeCommand;
1717
private RelayCommand<DiffViewModel> _nextChangeCommand;
18+
private RelayCommand _toggleIgnoreWhiteSpacesCommand;
1819

1920
internal EditorDiffMarginViewModel(IMarginCore marginCore, Action<DiffViewModel, HunkRangeInfo> updateDiffDimensions) :
2021
base(marginCore)
@@ -25,6 +26,8 @@ internal EditorDiffMarginViewModel(IMarginCore marginCore, Action<DiffViewModel,
2526
_updateDiffDimensions = updateDiffDimensions;
2627
}
2728

29+
public bool IgnoreWhiteSpaces => MarginCore.IgnoreWhiteSpaces;
30+
2831
public RelayCommand<DiffViewModel> PreviousChangeCommand
2932
{
3033
get { return _previousChangeCommand ?? (_previousChangeCommand = new RelayCommand<DiffViewModel>(PreviousChange, PreviousChangeCanExecute)); }
@@ -35,6 +38,11 @@ public RelayCommand<DiffViewModel> NextChangeCommand
3538
get { return _nextChangeCommand ?? (_nextChangeCommand = new RelayCommand<DiffViewModel>(NextChange, NextChangeCanExecute)); }
3639
}
3740

41+
public RelayCommand ToggleIgnoreWhiteSpacesCommand
42+
{
43+
get { return _toggleIgnoreWhiteSpacesCommand ?? (_toggleIgnoreWhiteSpacesCommand = new RelayCommand(ToggleIgnoreWhiteSpaces, CanExecuteToggleIgnoreWhiteSpaces)); }
44+
}
45+
3846
private bool PreviousChangeCanExecute(DiffViewModel currentEditorDiffViewModel)
3947
{
4048
return DiffViewModels.IndexOf(currentEditorDiffViewModel) > 0;
@@ -55,6 +63,16 @@ private void NextChange(DiffViewModel currentEditorDiffViewModel)
5563
MoveToChange(currentEditorDiffViewModel, +1);
5664
}
5765

66+
private void ToggleIgnoreWhiteSpaces()
67+
{
68+
MarginCore.ToggleIgnoreWhiteSpace();
69+
}
70+
71+
private bool CanExecuteToggleIgnoreWhiteSpaces()
72+
{
73+
return true;
74+
}
75+
5876
public void MoveToChange(DiffViewModel currentDiffViewModel, int indexModifier)
5977
{
6078
var diffViewModelIndex = DiffViewModels.IndexOf(currentDiffViewModel) + indexModifier;

0 commit comments

Comments
 (0)