1616using RevitDBExplorer . Domain . Selectors ;
1717using RevitDBExplorer . Properties ;
1818using RevitDBExplorer . UIComponents . Breadcrumbs ;
19- using RevitDBExplorer . UIComponents . CommandAndControl ;
2019using RevitDBExplorer . UIComponents . List ;
2120using RevitDBExplorer . UIComponents . QueryVisualization ;
22- using RevitDBExplorer . UIComponents . Scripting ;
2321using RevitDBExplorer . UIComponents . Trees . Base ;
2422using RevitDBExplorer . UIComponents . Trees . Base . Items ;
2523using RevitDBExplorer . UIComponents . Trees . Explorer ;
@@ -39,10 +37,8 @@ internal partial class MainWindow : Window, IAmWindowOpener, IAmQueryExecutor, I
3937 {
4038 private readonly ExplorerTreeViewModel explorerTreeViewModel = new ( ) ;
4139 private readonly UtilityTreeViewModel utilityTreeViewModel = new ( ) ;
42- private readonly ListVM listVM ;
43- private readonly CommandAndControlVM commandAndControlVM = new ( ) ;
44- private readonly QueryVisualizationVM queryVisualizationVM = new ( ) ;
45- private readonly RDScriptingVM rdscriptingVM ;
40+ private readonly ListVM listVM ;
41+ private readonly QueryVisualizationVM queryVisualizationVM = new ( ) ;
4642 private readonly BreadcrumbsVM breadcrumbs ;
4743 private RightView rightView ;
4844 private string databaseQuery = string . Empty ;
@@ -60,10 +56,8 @@ internal partial class MainWindow : Window, IAmWindowOpener, IAmQueryExecutor, I
6056
6157 public ExplorerTreeViewModel ExplorerTree => explorerTreeViewModel ;
6258 public UtilityTreeViewModel UtilityTree => utilityTreeViewModel ;
63- public ListVM List => listVM ;
64- public CommandAndControlVM CommandAndControl => commandAndControlVM ;
65- public QueryVisualizationVM QueryVisualization => queryVisualizationVM ;
66- public RDScriptingVM Scripting => rdscriptingVM ;
59+ public ListVM List => listVM ;
60+ public QueryVisualizationVM QueryVisualization => queryVisualizationVM ;
6761 public BreadcrumbsVM Breadcrumbs => breadcrumbs ;
6862 public RightView RightView
6963 {
@@ -196,6 +190,7 @@ public bool IsBoundingBoxVisualizerEnabled
196190 set
197191 {
198192 rdvController . IsEnabled = value ;
193+ UpdateRDV ( ) ;
199194 OnPropertyChanged ( ) ;
200195 }
201196 }
@@ -215,24 +210,23 @@ public MainWindow()
215210 {
216211 Dispatcher . UnhandledException += Dispatcher_UnhandledException ;
217212 listVM = new ListVM ( this , this ) ;
213+ breadcrumbs = new BreadcrumbsVM ( ) ;
218214
219215 InitializeComponent ( ) ;
220216 InitializeAsync ( ) . Forget ( ) ;
221217
222- this . DataContext = this ;
223- rdscriptingVM = new RDScriptingVM ( ) ;
224- breadcrumbs = new BreadcrumbsVM ( ) ;
218+ this . DataContext = this ;
225219
226220 Title = WindowTitleGenerator . Get ( ) ;
227221
228222 isRevitBusyDispatcher = new DispatcherTimer ( TimeSpan . FromMilliseconds ( 500 ) , DispatcherPriority . Background , IsRevitBusyDispatcher_Tick , Dispatcher . CurrentDispatcher ) ;
229223
230224 ExplorerTree . SelectedItemChanged += Tree_SelectedItemChanged ;
231- ExplorerTree . ScriptWasGenerated += RDSOpenWithCommand ;
225+ ExplorerTree . ScriptWasGenerated += OpenRDSWithGivenScript ;
232226 UtilityTree . SelectedItemChanged += Tree_SelectedItemChanged ;
233- UtilityTree . ScriptWasGenerated += RDSOpenWithCommand ;
227+ UtilityTree . ScriptWasGenerated += OpenRDSWithGivenScript ;
234228
235- OpenScriptingWithQueryCommand = new RelayCommand ( RDSOpenWithQuery ) ;
229+ OpenScriptingWithQueryCommand = new RelayCommand ( GenerateScriptForQueryAndOpenRDS ) ;
236230 SaveQueryAsFavoriteCommand = new RelayCommand ( SaveQueryAsFavorite , x => ! string . IsNullOrEmpty ( DatabaseQuery ) ) ;
237231 rdvController = RevitDatabaseVisualizationFactory . CreateController ( ) ;
238232 }
@@ -311,9 +305,9 @@ private async void Tree_SelectedItemChanged(SelectedItemChangedEventArgs eventAr
311305
312306 if ( eventArgs . NewOne is SnoopableObjectTreeItem snoopableObjectTreeItem )
313307 {
314- RightView = RightView . List ;
315- await List . PopulateListView ( snoopableObjectTreeItem ) ;
316- rdvController . AddDrawingVisuals ( snoopableObjectTreeItem . Object . GetVisualization ( ) ) ;
308+ RightView = RightView . List ;
309+ UpdateRDV ( ) ;
310+ await List . PopulateListView ( snoopableObjectTreeItem ) ;
317311 return ;
318312 }
319313 rdvController . RemoveAll ( ) ;
@@ -384,23 +378,45 @@ private void ResetDatabaseQuery()
384378 DatabaseQueryToolTip = "" ;
385379 QueryVisualization . Update ( Enumerable . Empty < RDQCommand > ( ) ) . Forget ( ) ;
386380 }
381+ private void SaveQueryAsFavorite ( )
382+ {
383+ FavoritesManager . Add ( DatabaseQuery ) ;
384+ }
385+
387386
388-
389- private void RDSOpenWithQuery ( object parameter )
387+ private void UpdateRDV ( )
390388 {
391- var scriptText = CodeGenerator . GenerateQueryFor ( DatabaseQueryToolTip ) ;
392- OpenRDS ( ) ;
393- Application . RDSController . SetText ( scriptText ) ;
389+ rdvController . RemoveAll ( ) ;
390+ if ( rdvController . IsEnabled )
391+ {
392+ var snoopableObjectTreeItem = ExplorerTree . SelectedItem as SnoopableObjectTreeItem ;
393+ snoopableObjectTreeItem ??= UtilityTree . SelectedItem as SnoopableObjectTreeItem ;
394+ if ( snoopableObjectTreeItem != null )
395+ {
396+ rdvController . AddDrawingVisuals ( snoopableObjectTreeItem . Object . GetVisualization ( ) ) ;
397+ }
398+ }
399+ }
400+
401+
402+ private void GenerateScriptForQueryAndOpenRDS ( )
403+ {
404+ var scriptText = CodeGenerator . GenerateQueryFor ( DatabaseQueryToolTip ) ;
405+ OpenRDSWithGivenScript ( scriptText ) ;
394406 }
395- private void RDSOpenWithCommand ( string scriptText )
407+ private void OpenRDSWithGivenScript ( string scriptText )
396408 {
397409 OpenRDS ( ) ;
398410 Application . RDSController . SetText ( scriptText ) ;
399411 }
400- private void SaveQueryAsFavorite ( object parameter )
412+ private void RDSButton_Click ( object sender , RoutedEventArgs e )
401413 {
402- FavoritesManager . Add ( DatabaseQuery ) ;
414+ OpenRDS ( ) ;
403415 }
416+ private void OpenRDS ( )
417+ {
418+ Application . RDSController . Open ( this . Left , this . Top + this . ActualHeight ) ;
419+ }
404420
405421
406422 private void Window_Closed ( object sender , EventArgs e )
@@ -410,9 +426,9 @@ private void Window_Closed(object sender, EventArgs e)
410426 Dispatcher . UnhandledException -= Dispatcher_UnhandledException ;
411427 isRevitBusyDispatcher . Tick -= IsRevitBusyDispatcher_Tick ;
412428 ExplorerTree . SelectedItemChanged -= Tree_SelectedItemChanged ;
413- ExplorerTree . ScriptWasGenerated -= RDSOpenWithCommand ;
429+ ExplorerTree . ScriptWasGenerated -= OpenRDSWithGivenScript ;
414430 UtilityTree . SelectedItemChanged -= Tree_SelectedItemChanged ;
415- UtilityTree . ScriptWasGenerated -= RDSOpenWithCommand ;
431+ UtilityTree . ScriptWasGenerated -= OpenRDSWithGivenScript ;
416432 }
417433 private void Window_Closing ( object sender , EventArgs e )
418434 {
@@ -436,7 +452,7 @@ private void Window_KeyDown(object sender, KeyEventArgs e)
436452 private void Window_SizeChanged ( object sender , SizeChangedEventArgs e )
437453 {
438454 IsWiderThan800px = this . Width > 848 ;
439- window_SizeChanged_Debouncer = window_SizeChanged_Debouncer . Debounce ( TimeSpan . FromSeconds ( 1 ) , SaveUserSettings ) ;
455+ window_SizeChanged_Debouncer = window_SizeChanged_Debouncer . Debounce ( TimeSpan . FromSeconds ( 4 ) , SaveUserSettings ) ;
440456 }
441457 private void SaveUserSettings ( )
442458 {
@@ -445,28 +461,15 @@ private void SaveUserSettings()
445461 AppSettings . Default . FirstColumnWidth = cFirstColumnDefinition . Width . Value ;
446462 AppSettings . Default . Save ( ) ;
447463 }
448- private void Window_MenuItem_ConfigurationClick ( object sender , RoutedEventArgs e )
464+ private void ConfigurationButton_Click ( object sender , RoutedEventArgs e )
449465 {
450466 var window = new ConfigWindow ( ) ;
451467 window . Owner = this ;
452468 window . ShowDialog ( ) ;
453- foreach ( ResourceDictionary dict in Resources . MergedDictionaries )
454- {
455- if ( dict is ThemeResourceDictionary skinDict )
456- skinDict . UpdateSource ( ) ;
457- }
469+ ThemeResourceDictionary . Update ( Resources ) ;
458470 }
459471
460472
461- private void RDS_Click ( object sender , RoutedEventArgs e )
462- {
463- OpenRDS ( ) ;
464- }
465- private void OpenRDS ( )
466- {
467- Application . RDSController . Open ( this . Left , this . Top + this . ActualHeight ) ;
468- }
469-
470473 #region INotifyPropertyChanged
471474
472475 public event PropertyChangedEventHandler PropertyChanged ;
0 commit comments