Skip to content

Commit cfe1124

Browse files
authored
Merge branch 'next' into next
2 parents 4c2d089 + c7dc9b3 commit cfe1124

File tree

5 files changed

+71
-25
lines changed

5 files changed

+71
-25
lines changed

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
4+
using System.Diagnostics.CodeAnalysis;
45
using System.Globalization;
56
using System.Linq;
67
using NLog;
@@ -21,6 +22,7 @@
2122
using System.Windows;
2223

2324
// ReSharper disable CanBeReplacedWithTryCastAndCheckForNull
25+
// ReSharper disable ExplicitCallerInfoArgument
2426

2527
namespace Rubberduck.Navigation.CodeExplorer
2628
{
@@ -99,54 +101,45 @@ public CodeExplorerViewModel(FolderHelper folderHelper, RubberduckParserState st
99101

100102
SetNameSortCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), param =>
101103
{
102-
if ((bool)param == true)
104+
if ((bool)param)
103105
{
104106
SortByName = (bool)param;
105107
SortByCodeOrder = !(bool)param;
106108
}
107-
}, param =>
108-
{
109-
return SortByName ? false : true;
110-
});
109+
}, param => !SortByName);
111110

112111
SetCodeOrderSortCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), param =>
113112
{
114-
if ((bool)param == true)
113+
if ((bool)param)
115114
{
116115
SortByCodeOrder = (bool)param;
117116
SortByName = !(bool)param;
118-
};
119-
}, param =>
120-
{
121-
return SortByCodeOrder ? false : true;
122-
});
117+
}
118+
}, param => !SortByCodeOrder);
123119
}
124120

125121
private CodeExplorerItemViewModel _selectedItem;
126122
public CodeExplorerItemViewModel SelectedItem
127123
{
128-
get { return _selectedItem; }
124+
get => _selectedItem;
129125
set
130126
{
131127
_selectedItem = value;
132128
OnPropertyChanged();
133129

134-
// ReSharper disable ExplicitCallerInfoArgument
135130
OnPropertyChanged("CanExecuteIndenterCommand");
136131
OnPropertyChanged("CanExecuteRenameCommand");
137132
OnPropertyChanged("CanExecuteFindAllReferencesCommand");
138133
OnPropertyChanged("ExportVisibility");
139134
OnPropertyChanged("ExportAllVisibility");
140135
OnPropertyChanged("PanelTitle");
141136
OnPropertyChanged("Description");
142-
143-
// ReSharper restore ExplicitCallerInfoArgument
144137
}
145138
}
146139

147140
public bool SortByName
148141
{
149-
get { return _windowSettings.CodeExplorer_SortByName; }
142+
get => _windowSettings.CodeExplorer_SortByName;
150143
set
151144
{
152145
if (_windowSettings.CodeExplorer_SortByName == value)
@@ -166,7 +159,7 @@ public bool SortByName
166159

167160
public bool SortByCodeOrder
168161
{
169-
get { return _windowSettings.CodeExplorer_SortByCodeOrder; }
162+
get => _windowSettings.CodeExplorer_SortByCodeOrder;
170163
set
171164
{
172165
if (_windowSettings.CodeExplorer_SortByCodeOrder == value)
@@ -192,7 +185,7 @@ public bool SortByCodeOrder
192185

193186
public bool GroupByType
194187
{
195-
get { return _windowSettings.CodeExplorer_GroupByType; }
188+
get => _windowSettings.CodeExplorer_GroupByType;
196189
set
197190
{
198191
if (_windowSettings.CodeExplorer_GroupByType != value)
@@ -207,10 +200,22 @@ public bool GroupByType
207200
}
208201
}
209202

203+
private bool _canSearch;
204+
205+
public bool CanSearch
206+
{
207+
get => _canSearch;
208+
set
209+
{
210+
_canSearch = value;
211+
OnPropertyChanged();
212+
}
213+
}
214+
210215
private bool _isBusy;
211216
public bool IsBusy
212217
{
213-
get { return _isBusy; }
218+
get => _isBusy;
214219
set
215220
{
216221
_isBusy = value;
@@ -277,15 +282,17 @@ public string Description
277282
private ObservableCollection<CodeExplorerItemViewModel> _projects;
278283
public ObservableCollection<CodeExplorerItemViewModel> Projects
279284
{
280-
get { return _projects; }
285+
get => _projects;
281286
set
282287
{
283288
ReorderChildNodes(value);
284289
_projects = new ObservableCollection<CodeExplorerItemViewModel>(value.OrderBy(o => o.NameWithSignature));
285-
290+
CanSearch = _projects.Any();
291+
286292
OnPropertyChanged();
287293
// Once a Project has been set, show the TreeView
288294
OnPropertyChanged("TreeViewVisibility");
295+
OnPropertyChanged("CanSearch");
289296
}
290297
}
291298

RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@
291291

292292
<Style x:Key="XButtonStyle" TargetType="Button">
293293
<Setter Property="Background" Value="Transparent"/>
294+
<Setter Property="Content" Value=""/>
294295
<Setter Property="BorderThickness" Value="0"/>
295296
<Setter Property="HorizontalContentAlignment" Value="Center"/>
296297
<Setter Property="VerticalContentAlignment" Value="Center"/>
@@ -490,10 +491,32 @@
490491
</ToolBar>
491492
</ToolBarTray>
492493

493-
<TextBox Grid.Row="1" TextChanged="SearchBox_OnTextChanged" VerticalContentAlignment="Center" Name="SearchBox"></TextBox>
494-
<Image Grid.Row="1" Source="{StaticResource SearchImage}" HorizontalAlignment="Right" VerticalAlignment="Center" MaxHeight="16" Margin="0,0,1,0" MouseDown="SearchIcon_OnMouseDown" Visibility="{Binding ElementName=SearchBox, Path=Text.Length, Converter={StaticResource StringHasValueToVisibility}}" />
495-
<Button Grid.Row="1" Style="{StaticResource XButtonStyle}" HorizontalAlignment="Right" VerticalAlignment="Center" Height="18" Width="18" Margin="0,1,1,0" Visibility="{Binding ElementName=SearchBox, Path=Text.Length, Converter={StaticResource StringHasNoValueToVisibility}}" Click="ButtonBase_OnClick">✕</Button>
494+
<Border Grid.Row="1"
495+
BorderBrush="{StaticResource {x:Static SystemColors.ControlBrushKey}}"
496+
BorderThickness="1">
497+
<Grid>
498+
<TextBox x:Name="SearchBox"
499+
VerticalContentAlignment="Center"
500+
IsEnabled="{Binding CanSearch}"
501+
MinHeight="20"
502+
PreviewKeyDown="SearchBox_OnPreviewKeyDown"
503+
TextChanged="SearchBox_OnTextChanged" />
496504

505+
<Image Source="{StaticResource SearchImage}"
506+
HorizontalAlignment="Right" VerticalAlignment="Center"
507+
MaxHeight="16" Margin="0,0,1,0"
508+
IsEnabled="{Binding CanSearch}"
509+
Visibility="{Binding ElementName=SearchBox, Path=Text.Length, Converter={StaticResource StringHasValueToVisibility}}"
510+
MouseDown="SearchIcon_OnMouseDown" />
511+
512+
<Button Style="{StaticResource XButtonStyle}"
513+
HorizontalAlignment="Right" VerticalAlignment="Center"
514+
Height="18" Width="18" Margin="0,1,1,0"
515+
IsEnabled="{Binding CanSearch}"
516+
Visibility="{Binding ElementName=SearchBox, Path=Text.Length, Converter={StaticResource StringHasNoValueToVisibility}}"
517+
Click="ButtonBase_OnClick" />
518+
</Grid>
519+
</Border>
497520
<controls:EmptyUIRefresh Grid.Row="2" />
498521

499522
<TreeView x:Name="ProjectTree"

RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,22 @@ private void SearchIcon_OnMouseDown(object sender, MouseButtonEventArgs e)
4343
}
4444

4545
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
46+
{
47+
ClearSearchBox();
48+
}
49+
50+
private void ClearSearchBox()
4651
{
4752
SearchBox.Text = string.Empty;
4853
SearchBox.Focus();
4954
}
55+
56+
private void SearchBox_OnPreviewKeyDown(object sender, KeyEventArgs e)
57+
{
58+
if (e.Key == Key.Escape)
59+
{
60+
ClearSearchBox();
61+
}
62+
}
5063
}
5164
}

RetailCoder.VBE/UI/Command/MenuItems/CodeExplorerCommandMenuItem.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Rubberduck.Parsing.VBA;
12
using Rubberduck.UI.Command.MenuItems.ParentMenus;
23

34
namespace Rubberduck.UI.Command.MenuItems
@@ -9,6 +10,8 @@ public CodeExplorerCommandMenuItem(CommandBase command)
910
{
1011
}
1112

13+
public override bool EvaluateCanExecute(RubberduckParserState state) => true;
14+
1215
public override string Key => "RubberduckMenu_CodeExplorer";
1316
public override int DisplayOrder => (int)NavigationMenuItemDisplayOrder.CodeExplorer;
1417
}

RetailCoder.VBE/UI/Command/MenuItems/CommandMenuItemBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public virtual Func<string> ToolTipText
4747
/// <remarks>Returns <c>true</c> if not overridden.</remarks>
4848
public virtual bool EvaluateCanExecute(RubberduckParserState state)
4949
{
50-
return state != null && _command.CanExecute(state);
50+
return state != null && (_command?.CanExecute(state) ?? false);
5151
}
5252

5353
public virtual ButtonStyle ButtonStyle => ButtonStyle.IconAndCaption;

0 commit comments

Comments
 (0)