Skip to content

Commit 7dbfd20

Browse files
committed
Make quick fix scope options visible on general applicability for the fix
E.g. is a fix does not allow fixing for an entire module, that option will not be shown. However, if the scope is unavailable because of other reasons, e.g. the fix is not applicable to all selected result, it will only be deactivated.
1 parent 8d1aaeb commit 7dbfd20

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

Rubberduck.Core/UI/Inspections/InspectionResultsControl.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
</Setter.Value>
3636
</Setter>
3737
<Setter Property="Command" Value="{Binding Command}"/>
38+
<Setter Property="Visibility" Value="{Binding IsVisible, Converter={StaticResource BoolToVisibility}}"/>
3839
</Style>
3940

4041
<Style TargetType="MenuItem" x:Key="QuickFixItemStyle">

Rubberduck.Core/UI/Inspections/InspectionResultsViewModel.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,18 @@ public class QuickFixCommandViewModel : ViewModelBase
7272
public IQuickFix Fix { get; }
7373
public string Key { get; }
7474
public ICommand Command { get; }
75+
public bool IsVisible { get; }
7576

7677
public QuickFixCommandViewModel(
7778
IQuickFix fix,
7879
string key,
79-
ICommand command)
80+
ICommand command,
81+
bool isVisible)
8082
{
8183
Fix = fix;
8284
Key = key;
8385
Command = command;
86+
IsVisible = isVisible;
8487
}
8588
}
8689

@@ -142,14 +145,14 @@ public InspectionResultsViewModel(
142145
CollapseAllCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteCollapseAll);
143146
ExpandAllCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteExpandAll);
144147

145-
QuickFixCommands = new List<(ICommand command, string key)>
148+
QuickFixCommands = new List<(ICommand command, string key, Func<IQuickFix, bool> visibility)>
146149
{
147-
(QuickFixCommand,"QuickFix_Instance"),
148-
(QuickFixSelectedItemsCommand,"QuickFix_Selection"),
149-
(QuickFixInProcedureCommand,"QuickFix_ThisProcedure"),
150-
(QuickFixInModuleCommand,"QuickFix_ThisModule"),
151-
(QuickFixInProjectCommand,"QuickFix_ThisProject"),
152-
(QuickFixInAllProjectsCommand,"QuickFix_All")
150+
(QuickFixCommand,"QuickFix_Instance", quickFix => true),
151+
(QuickFixSelectedItemsCommand,"QuickFix_Selection", quickFix => quickFix.CanFixMultiple),
152+
(QuickFixInProcedureCommand,"QuickFix_ThisProcedure", quickFix => quickFix.CanFixInProcedure),
153+
(QuickFixInModuleCommand,"QuickFix_ThisModule", quickFix => quickFix.CanFixInModule),
154+
(QuickFixInProjectCommand,"QuickFix_ThisProject", quickFix => quickFix.CanFixInProject),
155+
(QuickFixInAllProjectsCommand,"QuickFix_All", quickFix => quickFix.CanFixAll)
153156
};
154157

155158
_configService.SettingsChanged += _configService_SettingsChanged;
@@ -239,11 +242,11 @@ public IEnumerable<QuickFixViewModel> QuickFixes
239242
}
240243
}
241244

242-
private List<(ICommand command, string key)> QuickFixCommands { get; }
245+
private List<(ICommand command, string key, Func<IQuickFix,bool> visibility)> QuickFixCommands { get; }
243246

244247
private QuickFixViewModel DisplayQuickFix(IQuickFix quickFix, IInspectionResult result)
245248
{
246-
var commands = QuickFixCommands.Select(tpl => new QuickFixCommandViewModel(quickFix, tpl.key, tpl.command));
249+
var commands = QuickFixCommands.Select(tpl => new QuickFixCommandViewModel(quickFix, tpl.key, tpl.command, tpl.visibility(quickFix)));
247250
return new QuickFixViewModel(quickFix, result, commands);
248251
}
249252

0 commit comments

Comments
 (0)