1111using RevitDBExplorer . Augmentations ;
1212using RevitDBExplorer . Domain ;
1313using RevitDBExplorer . Domain . RevitDatabaseQuery ;
14- using RevitDBExplorer . Domain . RevitDatabaseQuery . Autocompletion ;
1514using RevitDBExplorer . Domain . RevitDatabaseScripting ;
1615using RevitDBExplorer . Domain . Selectors ;
1716using RevitDBExplorer . Properties ;
1817using RevitDBExplorer . UIComponents . Breadcrumbs ;
1918using RevitDBExplorer . UIComponents . List ;
19+ using RevitDBExplorer . UIComponents . QueryEditor ;
2020using RevitDBExplorer . UIComponents . QueryVisualization ;
2121using RevitDBExplorer . UIComponents . Trees . Base ;
2222using RevitDBExplorer . UIComponents . Trees . Base . Items ;
2323using RevitDBExplorer . UIComponents . Trees . Explorer ;
2424using RevitDBExplorer . UIComponents . Trees . Utility ;
2525using RevitDBExplorer . Utils ;
2626using RevitDBExplorer . WPF ;
27- using RevitDBExplorer . WPF . Controls ;
28- using RDQCommand = RevitDBExplorer . Domain . RevitDatabaseQuery . Parser . Command ;
2927
3028// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md
3129
3230namespace RevitDBExplorer
3331{
3432 internal enum RightView { None , List , CommandAndControl , CompareAndPinToolInfo }
3533
36- internal partial class MainWindow : Window , IAmWindowOpener , IAmQueryExecutor , INotifyPropertyChanged
34+ internal partial class MainWindow : Window , IAmWindowOpener , INotifyPropertyChanged
3735 {
38- private readonly ExplorerTreeViewModel explorerTreeViewModel = new ( ) ;
39- private readonly UtilityTreeViewModel utilityTreeViewModel = new ( ) ;
40- private readonly ListVM listVM ;
41- private readonly QueryVisualizationVM queryVisualizationVM = new ( ) ;
42- private readonly BreadcrumbsVM breadcrumbs ;
43- private RightView rightView ;
44- private string databaseQuery = string . Empty ;
45- private string databaseQueryToolTip = string . Empty ;
46- private bool isPopupOpen ;
36+ private readonly QueryEditorViewModel queryEditorVM ;
37+ private readonly QueryVisualizationVM queryVisualizationVM = new ( ) ;
38+ private readonly ExplorerTreeViewModel explorerTreeVM = new ( ) ;
39+ private readonly UtilityTreeViewModel utilityTreeVM = new ( ) ;
40+ private readonly ListVM listVM ;
41+ private readonly BreadcrumbsVM breadcrumbsVM ;
42+ private readonly DispatcherTimer isRevitBusyDispatcher ;
43+ private readonly IRDV3DController rdvController ;
44+ private RightView rightView ;
4745 private bool isRevitBusy ;
4846 private bool isNewVerAvailable ;
4947 private string newVersionLink ;
5048 private bool isWiderThan800px ;
5149 private string mouseStatus ;
52- private readonly DispatcherTimer isRevitBusyDispatcher ;
53- private readonly IAutocompleteItemProvider databaseQueryAutocompleteItemProvider = new AutocompleteItemProvider ( ) ;
54- private readonly IRDV3DController rdvController ;
50+ private string rdqGeneratedCSharpSyntax ;
5551
5652
57- public ExplorerTreeViewModel ExplorerTree => explorerTreeViewModel ;
58- public UtilityTreeViewModel UtilityTree => utilityTreeViewModel ;
53+ public QueryEditorViewModel QueryEditor => queryEditorVM ;
54+ public ExplorerTreeViewModel ExplorerTree => explorerTreeVM ;
55+ public UtilityTreeViewModel UtilityTree => utilityTreeVM ;
5956 public ListVM List => listVM ;
6057 public QueryVisualizationVM QueryVisualization => queryVisualizationVM ;
61- public BreadcrumbsVM Breadcrumbs => breadcrumbs ;
58+ public BreadcrumbsVM Breadcrumbs => breadcrumbsVM ;
6259 public RightView RightView
6360 {
6461 get
@@ -71,46 +68,6 @@ public RightView RightView
7168 OnPropertyChanged ( ) ;
7269 }
7370 }
74- public string DatabaseQuery
75- {
76- get
77- {
78- return databaseQuery ;
79- }
80- set
81- {
82- databaseQuery = value ;
83- if ( IsPopupOpen == false )
84- {
85- TryQueryDatabase ( value ) ;
86- }
87- OnPropertyChanged ( ) ;
88- }
89- }
90- public string DatabaseQueryToolTip
91- {
92- get
93- {
94- return databaseQueryToolTip ;
95- }
96- set
97- {
98- databaseQueryToolTip = value ;
99- OnPropertyChanged ( ) ;
100- }
101- }
102- public bool IsPopupOpen
103- {
104- get
105- {
106- return isPopupOpen ;
107- }
108- set
109- {
110- isPopupOpen = value ;
111- OnPropertyChanged ( ) ;
112- }
113- }
11471 public bool IsRevitBusy
11572 {
11673 get
@@ -173,15 +130,8 @@ public string MouseStatus
173130 mouseStatus = value ;
174131 OnPropertyChanged ( ) ;
175132 }
176- }
177- public IAutocompleteItemProvider DatabaseQueryAutocompleteItemProvider
178- {
179- get
180- {
181- return databaseQueryAutocompleteItemProvider ;
182- }
183- }
184- public bool IsBoundingBoxVisualizerEnabled
133+ }
134+ public bool IsRDVEnabled
185135 {
186136 get
187137 {
@@ -194,9 +144,7 @@ public bool IsBoundingBoxVisualizerEnabled
194144 OnPropertyChanged ( ) ;
195145 }
196146 }
197- public RelayCommand OpenScriptingWithQueryCommand { get ; }
198- public RelayCommand SaveQueryAsFavoriteCommand { get ; }
199-
147+
200148
201149 public MainWindow ( SourceOfObjects sourceOfObjects , IntPtr ? parentWindowHandle = null ) : this ( )
202150 {
@@ -209,25 +157,22 @@ public MainWindow(SourceOfObjects sourceOfObjects, IntPtr? parentWindowHandle =
209157 public MainWindow ( )
210158 {
211159 Dispatcher . UnhandledException += Dispatcher_UnhandledException ;
212- listVM = new ListVM ( this , this ) ;
213- breadcrumbs = new BreadcrumbsVM ( ) ;
160+ queryEditorVM = new QueryEditorViewModel ( TryQueryDatabase , GenerateScriptForQueryAndOpenRDS ) ;
161+ listVM = new ListVM ( this , queryEditorVM ) ;
162+ breadcrumbsVM = new BreadcrumbsVM ( ) ;
214163
215164 InitializeComponent ( ) ;
216165 InitializeAsync ( ) . Forget ( ) ;
217-
218166 this . DataContext = this ;
219167
220168 Title = WindowTitleGenerator . Get ( ) ;
221-
222169 isRevitBusyDispatcher = new DispatcherTimer ( TimeSpan . FromMilliseconds ( 500 ) , DispatcherPriority . Background , IsRevitBusyDispatcher_Tick , Dispatcher . CurrentDispatcher ) ;
223170
224171 ExplorerTree . SelectedItemChanged += Tree_SelectedItemChanged ;
225172 ExplorerTree . ScriptWasGenerated += OpenRDSWithGivenScript ;
226173 UtilityTree . SelectedItemChanged += Tree_SelectedItemChanged ;
227174 UtilityTree . ScriptWasGenerated += OpenRDSWithGivenScript ;
228-
229- OpenScriptingWithQueryCommand = new RelayCommand ( GenerateScriptForQueryAndOpenRDS ) ;
230- SaveQueryAsFavoriteCommand = new RelayCommand ( SaveQueryAsFavorite , x => ! string . IsNullOrEmpty ( DatabaseQuery ) ) ;
175+
231176 rdvController = RevitDatabaseVisualizationFactory . CreateController ( ) ;
232177 }
233178 private async Task InitializeAsync ( )
@@ -356,15 +301,11 @@ private async void TryQueryDatabase(string query)
356301 return result ;
357302 } ) ;
358303
359- DatabaseQueryToolTip = rdqResult . GeneratedCSharpSyntax ;
304+ rdqGeneratedCSharpSyntax = rdqResult . GeneratedCSharpSyntax ;
360305 QueryVisualization . Update ( rdqResult . Commands ) . Forget ( ) ;
361306 ExplorerTree . PopulateTreeView ( rdqResult . SourceOfObjects ) ;
362307 }
363- void IAmQueryExecutor . Query ( string query )
364- {
365- DatabaseQuery = query ;
366- }
367-
308+
368309
369310 private void PopulateExplorerTree ( SourceOfObjects sourceOfObjects )
370311 {
@@ -373,16 +314,11 @@ private void PopulateExplorerTree(SourceOfObjects sourceOfObjects)
373314 }
374315 private void ResetDatabaseQuery ( )
375316 {
376- databaseQuery = "" ;
377- OnPropertyChanged ( nameof ( DatabaseQuery ) ) ;
378- DatabaseQueryToolTip = "" ;
379- QueryVisualization . Update ( Enumerable . Empty < RDQCommand > ( ) ) . Forget ( ) ;
380- }
381- private void SaveQueryAsFavorite ( )
382- {
383- FavoritesManager . Add ( DatabaseQuery ) ;
317+ QueryEditor . ResetDatabaseQuery ( ) ;
318+ rdqGeneratedCSharpSyntax = "" ;
319+ QueryVisualization . Reset ( ) . Forget ( ) ;
384320 }
385-
321+
386322
387323 private void UpdateRDV ( )
388324 {
@@ -401,9 +337,9 @@ private void UpdateRDV()
401337
402338 private void GenerateScriptForQueryAndOpenRDS ( )
403339 {
404- var scriptText = CodeGenerator . GenerateQueryFor ( DatabaseQueryToolTip ) ;
340+ var scriptText = CodeGenerator . GenerateQueryFor ( rdqGeneratedCSharpSyntax ) ;
405341 OpenRDSWithGivenScript ( scriptText ) ;
406- }
342+ }
407343 private void OpenRDSWithGivenScript ( string scriptText )
408344 {
409345 OpenRDS ( ) ;
0 commit comments