Skip to content

Commit bb9cb71

Browse files
committed
Cleanup and preparation for refactoring menu in advanced search
1 parent 3051de8 commit bb9cb71

File tree

3 files changed

+44
-23
lines changed

3 files changed

+44
-23
lines changed

CSharpCodeAnalyst/Areas/AdvancedSearchArea/AdvancedSearchControl.xaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
<ResourceDictionary Source="/Styles/DataGridStyles.xaml" />
1717
<ResourceDictionary Source="/Styles/ImageStyles.xaml" />
1818
</ResourceDictionary.MergedDictionaries>
19-
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
2019

2120
</ResourceDictionary>
2221
</UserControl.Resources>
@@ -76,7 +75,7 @@
7675

7776
<MenuItem Header="{x:Static resources:Strings.CopyFullQualifiedNameToClipboard}"
7877
Command="{Binding CopyToClipboardCommand}"
79-
CommandParameter="{Binding PlacementTarget.SelectedItem, RelativeSource={RelativeSource AncestorType=ContextMenu}}">
78+
CommandParameter="{Binding PlacementTarget.SelectedItems, RelativeSource={RelativeSource AncestorType=ContextMenu}}">
8079
<MenuItem.Icon>
8180
<Image Source="/Resources/copy_fqn_16.png" />
8281
</MenuItem.Icon>

CSharpCodeAnalyst/Areas/AdvancedSearchArea/AdvancedSearchViewModel.cs

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,11 @@ public AdvancedSearchViewModel(MessageBus messaging)
3838
ExecuteSearchInternal();
3939
};
4040

41-
SearchCommand = new WpfCommand(ExecuteSearch);
4241
ClearSearchCommand = new WpfCommand(ClearSearch);
4342
AddSelectedToGraphCommand = new WpfCommand<object>(AddSelectedToGraph);
4443
AddSelectedToGraphCollapsedCommand = new WpfCommand<object>(AddSelectedToGraphCollapsed);
4544
PartitionCommand = new WpfCommand<SearchItemViewModel>(OnPartition, CanPartition);
46-
CopyToClipboardCommand = new WpfCommand<SearchItemViewModel>(OnCopyToClipboard);
45+
CopyToClipboardCommand = new WpfCommand<object>(OnCopyToClipboard);
4746
}
4847

4948
public ObservableCollection<SearchItemViewModel> AllItems
@@ -79,7 +78,6 @@ public string SearchText
7978
}
8079
}
8180

82-
public ICommand SearchCommand { get; }
8381
public ICommand ClearSearchCommand { get; }
8482
public ICommand AddSelectedToGraphCommand { get; }
8583
public ICommand AddSelectedToGraphCollapsedCommand { get; }
@@ -88,9 +86,11 @@ public string SearchText
8886

8987
public event PropertyChangedEventHandler? PropertyChanged;
9088

91-
private static void OnCopyToClipboard(SearchItemViewModel vm)
89+
private static void OnCopyToClipboard(object? items)
9290
{
93-
var text = vm?.CodeElement?.FullName;
91+
var elements = GetSelectedCodeElements(items);
92+
93+
var text = string.Join(Environment.NewLine, elements.Select(e => e.FullName));
9494
if (string.IsNullOrEmpty(text))
9595
{
9696
return;
@@ -111,13 +111,13 @@ private void OnPartition(SearchItemViewModel? vm)
111111
_messaging.Publish(new ShowPartitionsRequest(vm.CodeElement, false));
112112
}
113113
}
114-
114+
115115
public void HandleCodeGraphRefactored(CodeGraphRefactored message)
116116
{
117117
// This operation is not that expensive
118118
LoadCodeGraph(message.Graph);
119119
}
120-
120+
121121

122122
public void LoadCodeGraph(CodeGraph codeGraph)
123123
{
@@ -187,18 +187,40 @@ private void AddSelectedToGraphCollapsed(object? selectedItems)
187187

188188
private void AddSelectedToGraphInternal(object? selectedItems, bool addCollapsed)
189189
{
190+
var codeElements = GetSelectedCodeElements(selectedItems);
191+
192+
if (codeElements.Count > 0)
193+
{
194+
_messaging.Publish(new AddNodeToGraphRequest(codeElements, addCollapsed));
195+
}
196+
}
197+
198+
private static List<CodeElement> GetSelectedCodeElements(object? selectedItems)
199+
{
200+
var elements = new List<CodeElement>();
201+
202+
if (selectedItems is null)
203+
{
204+
return elements;
205+
}
206+
207+
if (selectedItems is SearchItemViewModel { CodeElement: not null } item)
208+
{
209+
elements.Add(item.CodeElement);
210+
return elements;
211+
}
212+
190213
if (selectedItems is IList list)
191214
{
192-
var codeElements = list.Cast<SearchItemViewModel>()
193-
.Where(item => item.CodeElement != null)
194-
.Select(item => item.CodeElement!)
215+
var codeElements = list.OfType<SearchItemViewModel>()
216+
.Where(i => i.CodeElement != null)
217+
.Select(i => i.CodeElement!)
195218
.ToList();
196219

197-
if (codeElements.Count > 0)
198-
{
199-
_messaging.Publish(new AddNodeToGraphRequest(codeElements, addCollapsed));
200-
}
220+
elements.AddRange(codeElements);
201221
}
222+
223+
return elements;
202224
}
203225

204226
private void OnPropertyChanged(string propertyName)

CSharpCodeAnalyst/Shared/UI/ToastManager.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public enum ToastType
1111

1212
public static class ToastManager
1313
{
14-
private static readonly List<ToastNotification> _activeToasts = new();
14+
private static readonly List<ToastNotification> ActiveToasts = new();
1515
private static readonly double ToastSpacing = 10; // Spacing between stacked toasts
1616
private static readonly double RightMargin = 20;
1717
private static readonly double TopMargin = 100;
@@ -48,12 +48,12 @@ private static void ShowToast(string message, int durationMs, ToastType type = T
4848
};
4949

5050
// Track active toasts
51-
_activeToasts.Add(toast);
51+
ActiveToasts.Add(toast);
5252

5353
// Remove from tracking when closed
5454
toast.Closed += (s, e) =>
5555
{
56-
_activeToasts.Remove(toast);
56+
ActiveToasts.Remove(toast);
5757
RepositionToasts(workingArea);
5858
};
5959

@@ -67,12 +67,12 @@ private static void PositionToast(ToastNotification toast, Rect workingArea)
6767
// Calculate vertical offset based on number of existing toasts
6868
double topOffset = TopMargin;
6969

70-
int index = _activeToasts.IndexOf(toast);
70+
int index = ActiveToasts.IndexOf(toast);
7171
for (int i = 0; i < index; i++)
7272
{
73-
if (_activeToasts[i].IsLoaded)
73+
if (ActiveToasts[i].IsLoaded)
7474
{
75-
topOffset += _activeToasts[i].ActualHeight + ToastSpacing;
75+
topOffset += ActiveToasts[i].ActualHeight + ToastSpacing;
7676
}
7777
}
7878

@@ -86,7 +86,7 @@ private static void RepositionToasts(Rect workingArea)
8686
// Reposition all active toasts to fill gaps
8787
double topOffset = TopMargin;
8888

89-
foreach (var toast in _activeToasts)
89+
foreach (var toast in ActiveToasts)
9090
{
9191
if (toast.IsLoaded)
9292
{

0 commit comments

Comments
 (0)