From b6cc5a4e7f68819f1b0b39608203759d073de393 Mon Sep 17 00:00:00 2001 From: NeVeSpl Date: Tue, 31 Oct 2023 08:23:22 +0100 Subject: [PATCH] refactoring --- readme.md | 2 +- sources/RevitDBExplorer/Application.cs | 12 ++++----- sources/RevitDBExplorer/Command.cs | 4 +-- sources/RevitDBExplorer/ConfigWindow.xaml.cs | 1 + sources/RevitDBExplorer/MainWindow.xaml.cs | 26 +++++++++++++++++-- .../UIComponents/List/ListVM.cs | 12 +++++++-- .../{ => Utils}/ApplicationModifyTab.cs | 8 +++--- 7 files changed, 48 insertions(+), 17 deletions(-) rename sources/RevitDBExplorer/{ => Utils}/ApplicationModifyTab.cs (74%) diff --git a/readme.md b/readme.md index 6853c1d..9e850a8 100644 --- a/readme.md +++ b/readme.md @@ -4,7 +4,7 @@ Yet another [RevitLookup](https://github.com/jeremytammik/RevitLookup) like tool. RevitLookup was an indispensable tool to work with Revit API for many years. But now, there is a better tool for the job. Let me introduce you to Revit database explorer and its capabilities. It not only allows us to **explore** database but also to: - **edit**, any parameter value -- **query**, with intuitive syntax that is translated into a FilteredElementCollector +- **query**, database with intuitive syntax that is translated into a FilteredElementCollector - **script**, by running ad hoc scripts written in C# - **visualize**, geometrical features of elements diff --git a/sources/RevitDBExplorer/Application.cs b/sources/RevitDBExplorer/Application.cs index beb22a3..a82eb86 100644 --- a/sources/RevitDBExplorer/Application.cs +++ b/sources/RevitDBExplorer/Application.cs @@ -13,17 +13,19 @@ using RevitDBExplorer.Domain.DataModel.ValueContainers.Base; using RevitDBExplorer.Domain.RevitDatabaseQuery; using RevitDBExplorer.Properties; +using RevitDBExplorer.Utils; using RevitDBScripting; namespace RevitDBExplorer { public class Application : IExternalApplication, IScriptRunner { + private static UIView UIView; + private static View View; public static IntPtr RevitWindowHandle; public static UIApplication UIApplication; public static RDSController RDSController; - private static UIView UIView; - private static View View; + public Application() { @@ -59,10 +61,7 @@ public Result OnStartup(UIControlledApplication application) UIApplication.ViewActivated += UIApplication_ViewActivated; return Result.Succeeded; - } - - - + } public Result OnShutdown(UIControlledApplication application) { application.Idling -= Application_Idling; @@ -169,6 +168,7 @@ public static string GetMouseStatus() return ""; } + private static DateTime LastTimeWhenInCharge; private void Application_Idling(object sender, Autodesk.Revit.UI.Events.IdlingEventArgs e) { diff --git a/sources/RevitDBExplorer/Command.cs b/sources/RevitDBExplorer/Command.cs index 03a0440..d7bde2f 100644 --- a/sources/RevitDBExplorer/Command.cs +++ b/sources/RevitDBExplorer/Command.cs @@ -1,11 +1,11 @@ using System; -using System.Linq; using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; using Autodesk.Revit.Attributes; using Autodesk.Revit.DB; using Autodesk.Revit.UI; using RevitDBExplorer.Domain.Selectors; -using System.Diagnostics; namespace RevitDBExplorer { diff --git a/sources/RevitDBExplorer/ConfigWindow.xaml.cs b/sources/RevitDBExplorer/ConfigWindow.xaml.cs index 928fa61..2790d28 100644 --- a/sources/RevitDBExplorer/ConfigWindow.xaml.cs +++ b/sources/RevitDBExplorer/ConfigWindow.xaml.cs @@ -8,6 +8,7 @@ using System.Windows.Controls; using RevitDBExplorer.Domain.RevitDatabaseQuery.Autocompletion; using RevitDBExplorer.Properties; +using RevitDBExplorer.Utils; using RevitDBExplorer.WPF; // (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md diff --git a/sources/RevitDBExplorer/MainWindow.xaml.cs b/sources/RevitDBExplorer/MainWindow.xaml.cs index 16da421..39d80ee 100644 --- a/sources/RevitDBExplorer/MainWindow.xaml.cs +++ b/sources/RevitDBExplorer/MainWindow.xaml.cs @@ -10,12 +10,14 @@ using System.Windows.Threading; using RevitDBExplorer.Augmentations; using RevitDBExplorer.Domain; +using RevitDBExplorer.Domain.DataModel.ValueViewModels; using RevitDBExplorer.Domain.RevitDatabaseQuery; using RevitDBExplorer.Domain.RevitDatabaseScripting; using RevitDBExplorer.Domain.Selectors; using RevitDBExplorer.Properties; using RevitDBExplorer.UIComponents.Breadcrumbs; using RevitDBExplorer.UIComponents.List; +using RevitDBExplorer.UIComponents.List.ViewModels; using RevitDBExplorer.UIComponents.QueryEditor; using RevitDBExplorer.UIComponents.QueryVisualization; using RevitDBExplorer.UIComponents.Trees.Base; @@ -47,7 +49,7 @@ internal partial class MainWindow : Window, IAmWindowOpener, INotifyPropertyChan private string newVersionLink; private bool isWiderThan800px; private string mouseStatus; - private string rdqGeneratedCSharpSyntax; + private string rdqGeneratedCSharpSyntax = ""; public QueryEditorViewModel QueryEditor => queryEditorVM; @@ -172,9 +174,13 @@ public MainWindow() ExplorerTree.ScriptWasGenerated += OpenRDSWithGivenScript; UtilityTree.SelectedItemChanged += Tree_SelectedItemChanged; UtilityTree.ScriptWasGenerated += OpenRDSWithGivenScript; + List.SelectedItemChanged += List_SelectedItemChanged; rdvController = RevitDatabaseVisualizationFactory.CreateController(); } + + + private async Task InitializeAsync() { (IsNewVerAvailable, NewVersionLink) = await VersionChecker.CheckIfNewVersionIsAvailable(); @@ -280,6 +286,21 @@ private async void Tree_SelectedItemChanged(SelectedItemChangedEventArgs eventAr } RightView = RightView.None; } + private void List_SelectedItemChanged(ListSelectedItemChangedEventArgs args) + { + if (args.NewOne is ListItemForMember listItemForMember) + { + var leftOne = listItemForMember[0]; + var righttOne = listItemForMember[1]; + + if (leftOne?.ValueViewModel is DefaultPresenter { ValueContainer: { } } presenter) + { + var v = presenter.ValueContainer.GetVisualization(); + + //return Enumerable.Empty(); + } + } + } bool ignoreEvents = false; void IAmWindowOpener.Open(SourceOfObjects sourceOfObjects) { @@ -364,7 +385,8 @@ private void Window_Closed(object sender, EventArgs e) ExplorerTree.SelectedItemChanged -= Tree_SelectedItemChanged; ExplorerTree.ScriptWasGenerated -= OpenRDSWithGivenScript; UtilityTree.SelectedItemChanged -= Tree_SelectedItemChanged; - UtilityTree.ScriptWasGenerated -= OpenRDSWithGivenScript; + UtilityTree.ScriptWasGenerated -= OpenRDSWithGivenScript; + List.SelectedItemChanged -= List_SelectedItemChanged; } private void Window_Closing(object sender, EventArgs e) { diff --git a/sources/RevitDBExplorer/UIComponents/List/ListVM.cs b/sources/RevitDBExplorer/UIComponents/List/ListVM.cs index 04f9e1e..e3aedaf 100644 --- a/sources/RevitDBExplorer/UIComponents/List/ListVM.cs +++ b/sources/RevitDBExplorer/UIComponents/List/ListVM.cs @@ -11,6 +11,7 @@ using RevitDBExplorer.Domain.DataModel.ValueViewModels.Base; using RevitDBExplorer.UIComponents.List.ViewModels; using RevitDBExplorer.UIComponents.List.WPF; +using RevitDBExplorer.UIComponents.Trees.Base; using RevitDBExplorer.UIComponents.Trees.Base.Items; using RevitDBExplorer.WPF; @@ -64,11 +65,17 @@ public IListItem ListSelectedItem return listSelectedItem; } set - { - listSelectedItem = value; + { + if (listSelectedItem != value) + { + var oldOne = listSelectedItem; + listSelectedItem = value; + SelectedItemChanged?.Invoke(new ListSelectedItemChangedEventArgs(oldOne, listSelectedItem)); + } OnPropertyChanged(); } } + public event Action SelectedItemChanged; public RelayCommand KeyDown_Enter_Command { get; } public RelayCommand ListItem_Click_Command { get; } public RelayCommand ReloadCommand { get; } @@ -381,6 +388,7 @@ private async void Reload() } } + internal record class ListSelectedItemChangedEventArgs(IListItem OldOne, IListItem NewOne); internal interface IAmWindowOpener { void Open(SourceOfObjects sourceOfObjects); diff --git a/sources/RevitDBExplorer/ApplicationModifyTab.cs b/sources/RevitDBExplorer/Utils/ApplicationModifyTab.cs similarity index 74% rename from sources/RevitDBExplorer/ApplicationModifyTab.cs rename to sources/RevitDBExplorer/Utils/ApplicationModifyTab.cs index 0e4ef5b..1bff66a 100644 --- a/sources/RevitDBExplorer/ApplicationModifyTab.cs +++ b/sources/RevitDBExplorer/Utils/ApplicationModifyTab.cs @@ -1,14 +1,14 @@ using Autodesk.Windows; using RevitDBExplorer.Domain; -namespace RevitDBExplorer +namespace RevitDBExplorer.Utils { public static class ApplicationModifyTab { - private static Autodesk.Windows.RibbonPanel ribbonPanel; + private static RibbonPanel ribbonPanel; - public static void Init(Autodesk.Windows.RibbonPanel ribbonPanel, bool visible = false) + public static void Init(RibbonPanel ribbonPanel, bool visible = false) { ApplicationModifyTab.ribbonPanel = ribbonPanel.Clone(); UpdateInternal(visible); @@ -21,7 +21,7 @@ public static void Update(bool visible) private static void UpdateInternal(bool visible) { - if (ApplicationModifyTab.ribbonPanel is null) return; + if (ribbonPanel is null) return; var tab = ComponentManager.Ribbon.FindTab("Modify"); if (tab is null) return;