diff --git a/sources/RevitDBExplorer/MainWindow.xaml b/sources/RevitDBExplorer/MainWindow.xaml index 15cee72..cc94c21 100644 --- a/sources/RevitDBExplorer/MainWindow.xaml +++ b/sources/RevitDBExplorer/MainWindow.xaml @@ -56,7 +56,7 @@ - + @@ -256,7 +256,7 @@ - + @@ -309,11 +309,11 @@ - - @@ -329,8 +329,8 @@ - + - + \ No newline at end of file diff --git a/sources/RevitDBExplorer/MainWindow.xaml.cs b/sources/RevitDBExplorer/MainWindow.xaml.cs index 44f7132..48c48be 100644 --- a/sources/RevitDBExplorer/MainWindow.xaml.cs +++ b/sources/RevitDBExplorer/MainWindow.xaml.cs @@ -16,10 +16,8 @@ using RevitDBExplorer.Domain.Selectors; using RevitDBExplorer.Properties; using RevitDBExplorer.UIComponents.Breadcrumbs; -using RevitDBExplorer.UIComponents.CommandAndControl; using RevitDBExplorer.UIComponents.List; using RevitDBExplorer.UIComponents.QueryVisualization; -using RevitDBExplorer.UIComponents.Scripting; using RevitDBExplorer.UIComponents.Trees.Base; using RevitDBExplorer.UIComponents.Trees.Base.Items; using RevitDBExplorer.UIComponents.Trees.Explorer; @@ -39,10 +37,8 @@ internal partial class MainWindow : Window, IAmWindowOpener, IAmQueryExecutor, I { private readonly ExplorerTreeViewModel explorerTreeViewModel = new(); private readonly UtilityTreeViewModel utilityTreeViewModel = new(); - private readonly ListVM listVM; - private readonly CommandAndControlVM commandAndControlVM = new(); - private readonly QueryVisualizationVM queryVisualizationVM = new(); - private readonly RDScriptingVM rdscriptingVM; + private readonly ListVM listVM; + private readonly QueryVisualizationVM queryVisualizationVM = new(); private readonly BreadcrumbsVM breadcrumbs; private RightView rightView; private string databaseQuery = string.Empty; @@ -60,10 +56,8 @@ internal partial class MainWindow : Window, IAmWindowOpener, IAmQueryExecutor, I public ExplorerTreeViewModel ExplorerTree => explorerTreeViewModel; public UtilityTreeViewModel UtilityTree => utilityTreeViewModel; - public ListVM List => listVM; - public CommandAndControlVM CommandAndControl => commandAndControlVM; - public QueryVisualizationVM QueryVisualization => queryVisualizationVM; - public RDScriptingVM Scripting => rdscriptingVM; + public ListVM List => listVM; + public QueryVisualizationVM QueryVisualization => queryVisualizationVM; public BreadcrumbsVM Breadcrumbs => breadcrumbs; public RightView RightView { @@ -196,6 +190,7 @@ public bool IsBoundingBoxVisualizerEnabled set { rdvController.IsEnabled = value; + UpdateRDV(); OnPropertyChanged(); } } @@ -215,24 +210,23 @@ public MainWindow() { Dispatcher.UnhandledException += Dispatcher_UnhandledException; listVM = new ListVM(this, this); + breadcrumbs = new BreadcrumbsVM(); InitializeComponent(); InitializeAsync().Forget(); - this.DataContext = this; - rdscriptingVM = new RDScriptingVM(); - breadcrumbs = new BreadcrumbsVM(); + this.DataContext = this; Title = WindowTitleGenerator.Get(); isRevitBusyDispatcher = new DispatcherTimer(TimeSpan.FromMilliseconds(500), DispatcherPriority.Background, IsRevitBusyDispatcher_Tick, Dispatcher.CurrentDispatcher); ExplorerTree.SelectedItemChanged += Tree_SelectedItemChanged; - ExplorerTree.ScriptWasGenerated += RDSOpenWithCommand; + ExplorerTree.ScriptWasGenerated += OpenRDSWithGivenScript; UtilityTree.SelectedItemChanged += Tree_SelectedItemChanged; - UtilityTree.ScriptWasGenerated += RDSOpenWithCommand; + UtilityTree.ScriptWasGenerated += OpenRDSWithGivenScript; - OpenScriptingWithQueryCommand = new RelayCommand(RDSOpenWithQuery); + OpenScriptingWithQueryCommand = new RelayCommand(GenerateScriptForQueryAndOpenRDS); SaveQueryAsFavoriteCommand = new RelayCommand(SaveQueryAsFavorite, x => !string.IsNullOrEmpty(DatabaseQuery) ); rdvController = RevitDatabaseVisualizationFactory.CreateController(); } @@ -311,9 +305,9 @@ private async void Tree_SelectedItemChanged(SelectedItemChangedEventArgs eventAr if (eventArgs.NewOne is SnoopableObjectTreeItem snoopableObjectTreeItem) { - RightView = RightView.List; - await List.PopulateListView(snoopableObjectTreeItem); - rdvController.AddDrawingVisuals(snoopableObjectTreeItem.Object.GetVisualization()); + RightView = RightView.List; + UpdateRDV(); + await List.PopulateListView(snoopableObjectTreeItem); return; } rdvController.RemoveAll(); @@ -384,23 +378,45 @@ private void ResetDatabaseQuery() DatabaseQueryToolTip = ""; QueryVisualization.Update(Enumerable.Empty()).Forget(); } + private void SaveQueryAsFavorite() + { + FavoritesManager.Add(DatabaseQuery); + } + - - private void RDSOpenWithQuery(object parameter) + private void UpdateRDV() { - var scriptText = CodeGenerator.GenerateQueryFor(DatabaseQueryToolTip); - OpenRDS(); - Application.RDSController.SetText(scriptText); + rdvController.RemoveAll(); + if (rdvController.IsEnabled) + { + var snoopableObjectTreeItem = ExplorerTree.SelectedItem as SnoopableObjectTreeItem; + snoopableObjectTreeItem ??= UtilityTree.SelectedItem as SnoopableObjectTreeItem; + if (snoopableObjectTreeItem != null) + { + rdvController.AddDrawingVisuals(snoopableObjectTreeItem.Object.GetVisualization()); + } + } + } + + + private void GenerateScriptForQueryAndOpenRDS() + { + var scriptText = CodeGenerator.GenerateQueryFor(DatabaseQueryToolTip); + OpenRDSWithGivenScript(scriptText); } - private void RDSOpenWithCommand(string scriptText) + private void OpenRDSWithGivenScript(string scriptText) { OpenRDS(); Application.RDSController.SetText(scriptText); } - private void SaveQueryAsFavorite(object parameter) + private void RDSButton_Click(object sender, RoutedEventArgs e) { - FavoritesManager.Add(DatabaseQuery); + OpenRDS(); } + private void OpenRDS() + { + Application.RDSController.Open(this.Left, this.Top + this.ActualHeight); + } private void Window_Closed(object sender, EventArgs e) @@ -410,9 +426,9 @@ private void Window_Closed(object sender, EventArgs e) Dispatcher.UnhandledException -= Dispatcher_UnhandledException; isRevitBusyDispatcher.Tick -= IsRevitBusyDispatcher_Tick; ExplorerTree.SelectedItemChanged -= Tree_SelectedItemChanged; - ExplorerTree.ScriptWasGenerated -= RDSOpenWithCommand; + ExplorerTree.ScriptWasGenerated -= OpenRDSWithGivenScript; UtilityTree.SelectedItemChanged -= Tree_SelectedItemChanged; - UtilityTree.ScriptWasGenerated -= RDSOpenWithCommand; + UtilityTree.ScriptWasGenerated -= OpenRDSWithGivenScript; } private void Window_Closing(object sender, EventArgs e) { @@ -436,7 +452,7 @@ private void Window_KeyDown(object sender, KeyEventArgs e) private void Window_SizeChanged(object sender, SizeChangedEventArgs e) { IsWiderThan800px = this.Width > 848; - window_SizeChanged_Debouncer = window_SizeChanged_Debouncer.Debounce(TimeSpan.FromSeconds(1), SaveUserSettings); + window_SizeChanged_Debouncer = window_SizeChanged_Debouncer.Debounce(TimeSpan.FromSeconds(4), SaveUserSettings); } private void SaveUserSettings() { @@ -445,28 +461,15 @@ private void SaveUserSettings() AppSettings.Default.FirstColumnWidth = cFirstColumnDefinition.Width.Value; AppSettings.Default.Save(); } - private void Window_MenuItem_ConfigurationClick(object sender, RoutedEventArgs e) + private void ConfigurationButton_Click(object sender, RoutedEventArgs e) { var window = new ConfigWindow(); window.Owner = this; window.ShowDialog(); - foreach (ResourceDictionary dict in Resources.MergedDictionaries) - { - if (dict is ThemeResourceDictionary skinDict) - skinDict.UpdateSource(); - } + ThemeResourceDictionary.Update(Resources); } - private void RDS_Click(object sender, RoutedEventArgs e) - { - OpenRDS(); - } - private void OpenRDS() - { - Application.RDSController.Open(this.Left, this.Top + this.ActualHeight); - } - #region INotifyPropertyChanged public event PropertyChangedEventHandler PropertyChanged; diff --git a/sources/RevitDBExplorer/UIComponents/CommandAndControl/CommandAndControlVM.cs b/sources/RevitDBExplorer/UIComponents/CommandAndControl/CommandAndControlVM.cs index c40faf6..d15078f 100644 --- a/sources/RevitDBExplorer/UIComponents/CommandAndControl/CommandAndControlVM.cs +++ b/sources/RevitDBExplorer/UIComponents/CommandAndControl/CommandAndControlVM.cs @@ -1,12 +1,4 @@ -using System.Collections.ObjectModel; -using System.Linq; -using System.Threading.Tasks; -using System.Windows.Controls; -using Autodesk.Revit.DB; -using RevitDBExplorer.Domain; -using RevitDBExplorer.UIComponents.Trees.Base.Items; -using RevitDBExplorer.WPF; -using Binding = System.Windows.Data.Binding; +using RevitDBExplorer.WPF; // (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md @@ -14,38 +6,14 @@ namespace RevitDBExplorer.UIComponents.CommandAndControl { internal class CommandAndControlVM : BaseViewModel { - private GroupTreeItem selectedGroup; - private int itemsCount; - - - public int ItemsCount - { - get - { - return itemsCount; - } - set - { - itemsCount = value; - OnPropertyChanged(); - } - } + - public CommandAndControlVM() { } - public async Task SetInput(GroupTreeItem groupTreeItemVM) - { - selectedGroup = groupTreeItemVM; - ItemsCount = selectedGroup.GetAllSnoopableObjects().Select(x => x.Object).OfType().Count(); - var elements = selectedGroup.GetAllSnoopableObjects().Select(x => x.Object).OfType().Take(100).ToArray(); - - - } } } \ No newline at end of file diff --git a/sources/RevitDBExplorer/UIComponents/Scripting/RDScriptingVM.cs b/sources/RevitDBExplorer/UIComponents/Scripting/RDScriptingVM.cs index 0d4e244..3a07eeb 100644 --- a/sources/RevitDBExplorer/UIComponents/Scripting/RDScriptingVM.cs +++ b/sources/RevitDBExplorer/UIComponents/Scripting/RDScriptingVM.cs @@ -1,13 +1,5 @@ using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; using System.Windows; -using System.Windows.Documents; -using System.Windows.Media; -using RevitDBExplorer.Domain; -using RevitDBExplorer.Domain.RevitDatabaseScripting; using RevitDBExplorer.WPF; // (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md @@ -18,11 +10,7 @@ internal class RDScriptingVM : BaseViewModel { private bool isPanelOpen = false; private GridLength height; - private IEnumerable output; - private FlowDocument outputDocument; - private IEnumerable input; - private int selectedTabIndex; - private IEnumerable inputs = Enumerable.Empty(); + public bool IsOpen { @@ -51,65 +39,14 @@ public GridLength Height public RelayCommand CloseCommand { get; } - public RelayCommand RunCommand { get; } - public IEnumerable Output - { - get - { - return output; - } - set - { - output = value; - OnPropertyChanged(); - } - } - public FlowDocument OutputDocument - { - get - { - return outputDocument; - } - set - { - outputDocument = value; - OnPropertyChanged(); - } - } - public IEnumerable Input - { - get - { - return input; - } - set - { - input = value; - OnPropertyChanged(); - } - } - public int SelectedTabIndex - { - get - { - return selectedTabIndex; - } - set - { - selectedTabIndex = value; - OnPropertyChanged(); - } - } - public int InputsCount - { - get => inputs.Count(); - } - + + + public RDScriptingVM() { CloseCommand = new RelayCommand(Close); - RunCommand = new RelayCommand(Run); + } @@ -117,46 +54,14 @@ public void Open() { IsOpen = true; Height = new GridLength(Math.Max(Height.Value, 198)); - SelectedTabIndex = 1; - PrintInputs(); + + } private void Close(object parameter) { IsOpen = false; Height = new GridLength(0, GridUnitType.Auto); } - private async void Run(object parameter) - { - - - } - - public void SetScript(string scriptText) - { - - } - public void SetInput(IEnumerable inputs) - { - this.inputs = inputs; - //SelectedTabIndex = 0; - OnPropertyChanged(nameof(InputsCount)); - PrintInputs(); - } - - private readonly SolidColorBrush typeBrush = (SolidColorBrush)new BrushConverter().ConvertFrom("#008080"); - private void PrintInputs() - { - var input = new List() - { - new Run("Parameters that can be used in the method header:"), - new LineBreak(), - new Run(" Document ") {Foreground=typeBrush }, new Run("document"), - new LineBreak(), - new Run(" UIApplication ") {Foreground=typeBrush }, new Run("uia"), - new LineBreak(), - new Run(" IEnumerable") {Foreground=typeBrush }, new Run("") {Foreground=typeBrush }, new Run(" objects - which contains curently "), new Run($"{inputs.Count()}"){Foreground=Brushes.Blue, FontWeight=FontWeights.Bold }, new Run(" objects"), - }; - Input = input; - } + } } \ No newline at end of file diff --git a/sources/RevitDBExplorer/WPF/ThemeResourceDictionary.cs b/sources/RevitDBExplorer/WPF/ThemeResourceDictionary.cs index 57563ad..d56775d 100644 --- a/sources/RevitDBExplorer/WPF/ThemeResourceDictionary.cs +++ b/sources/RevitDBExplorer/WPF/ThemeResourceDictionary.cs @@ -29,5 +29,15 @@ public void UpdateSource() var path = new Uri($"pack://application:,,,/RevitDBExplorer;component/Resources/Themes/{themeName}.{dictionaryName}.xaml", UriKind.RelativeOrAbsolute); base.Source = path; } + + + public static void Update(ResourceDictionary resources) + { + foreach (ResourceDictionary dict in resources.MergedDictionaries) + { + if (dict is ThemeResourceDictionary skinDict) + skinDict.UpdateSource(); + } + } } } \ No newline at end of file