@@ -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 )
0 commit comments