1- using System . Collections ;
21using System . Collections . ObjectModel ;
32using System . ComponentModel ;
43using System . Windows ;
76using Contracts . Graph ;
87using CSharpCodeAnalyst . Common ;
98using CSharpCodeAnalyst . Messages ;
9+ using CSharpCodeAnalyst . Refactoring ;
1010using CSharpCodeAnalyst . Wpf ;
1111
1212namespace CSharpCodeAnalyst . Areas . AdvancedSearchArea ;
1313
1414public sealed class AdvancedSearchViewModel : INotifyPropertyChanged
1515{
1616 private readonly MessageBus _messaging ;
17+ private readonly RefactoringService _refactoringService ;
1718 private readonly DispatcherTimer _searchTimer ;
1819 private ObservableCollection < SearchItemViewModel > _allItems ;
1920 private CodeGraph ? _codeGraph ;
2021 private ObservableCollection < SearchItemViewModel > _filteredItems ;
2122 private string _searchText ;
2223
23- public AdvancedSearchViewModel ( MessageBus messaging )
24+ public AdvancedSearchViewModel ( MessageBus messaging , RefactoringService refactoringService )
2425 {
2526 _messaging = messaging ;
27+ _refactoringService = refactoringService ;
2628 _searchText = string . Empty ;
2729 _allItems = [ ] ;
2830 _filteredItems = [ ] ;
@@ -45,8 +47,12 @@ public AdvancedSearchViewModel(MessageBus messaging)
4547 CopyToClipboardCommand = new WpfCommand < SearchItemViewModel > ( OnCopyToClipboard ) ;
4648 SelectAllCommand = new WpfCommand ( SelectAll ) ;
4749 DeselectAllCommand = new WpfCommand ( DeselectAll ) ;
50+
51+ SetMovementTargetCommand = new WpfCommand < SearchItemViewModel > ( RefactoringSetMovementTarget , RefactoringCanSetMovementTarget ) ;
52+ MoveSelectedCommand = new WpfCommand ( RefactoringMoveCodeElement , RefactoringCanMoveCodeElement ) ;
4853 }
4954
55+
5056 public ObservableCollection < SearchItemViewModel > AllItems
5157 {
5258 get => _allItems ;
@@ -87,9 +93,43 @@ public string SearchText
8793 public ICommand CopyToClipboardCommand { get ; }
8894 public ICommand SelectAllCommand { get ; }
8995 public ICommand DeselectAllCommand { get ; }
96+ public ICommand SetMovementTargetCommand { get ; }
97+ public ICommand MoveSelectedCommand { get ; }
9098
9199 public event PropertyChangedEventHandler ? PropertyChanged ;
92100
101+ private bool RefactoringCanSetMovementTarget ( SearchItemViewModel vm )
102+ {
103+ return _refactoringService . CanSetMovementTarget ( vm . CodeElement ? . Id ) ;
104+ }
105+
106+ private bool RefactoringCanMoveCodeElement ( )
107+ {
108+ var ids = GetSelectedCodeElements ( ) . Select ( e => e . Id ) . ToHashSet ( ) ;
109+ return _refactoringService . CanMoveCodeElements ( ids ) ;
110+ }
111+
112+ private void RefactoringMoveCodeElement ( )
113+ {
114+ var elementIds = GetSelectedCodeElements ( ) . Select ( e => e . Id ) . ToHashSet ( ) ;
115+ if ( elementIds . Any ( ) )
116+ {
117+ _refactoringService . MoveCodeElements ( elementIds ) ;
118+ }
119+ }
120+
121+ public string GetRefactoringNewMoveParent ( )
122+ {
123+ var target = _refactoringService . GetMovementTarget ( ) ;
124+ return target ? . Name != null ? target . Name : string . Empty ;
125+ }
126+
127+
128+ private void RefactoringSetMovementTarget ( SearchItemViewModel vm )
129+ {
130+ _refactoringService . SetMovementTarget ( vm . CodeElement ? . Id ) ;
131+ }
132+
93133 private void OnCopyToClipboard ( SearchItemViewModel item )
94134 {
95135 var text = item . CodeElement ? . FullName ;
@@ -214,8 +254,8 @@ private void AddSelectedToGraphInternal(bool addCollapsed)
214254 }
215255
216256 /// <summary>
217- /// Gets selected code elements from all items, including the
218- /// currently non-visible.
257+ /// Gets selected code elements from all items, including the
258+ /// currently non-visible.
219259 /// </summary>
220260 private List < CodeElement > GetSelectedCodeElements ( )
221261 {
0 commit comments