Skip to content

Commit

Permalink
extract QueryEditor as a separate component
Browse files Browse the repository at this point in the history
  • Loading branch information
NeVeSpl committed Oct 30, 2023
1 parent e85bf8c commit 923de8c
Show file tree
Hide file tree
Showing 6 changed files with 231 additions and 138 deletions.
52 changes: 9 additions & 43 deletions sources/RevitDBExplorer/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:componentQueryEditor="clr-namespace:RevitDBExplorer.UIComponents.QueryEditor"
xmlns:componentQueryVisualization="clr-namespace:RevitDBExplorer.UIComponents.QueryVisualization"
xmlns:componentBusyIndicator="clr-namespace:RevitDBExplorer.UIComponents.BusyIndicator"
xmlns:componentList="clr-namespace:RevitDBExplorer.UIComponents.List"
Expand All @@ -12,8 +13,7 @@
xmlns:componentCAndC="clr-namespace:RevitDBExplorer.UIComponents.CommandAndControl"
xmlns:componentScripting="clr-namespace:RevitDBExplorer.UIComponents.Scripting"
xmlns:componentBreadcrumbs="clr-namespace:RevitDBExplorer.UIComponents.Breadcrumbs"
xmlns:converters="clr-namespace:RevitDBExplorer.WPF.Converters"
xmlns:controls="clr-namespace:RevitDBExplorer.WPF.Controls"
xmlns:converters="clr-namespace:RevitDBExplorer.WPF.Converters"
xmlns:ext="clr-namespace:RevitDBExplorer.WPF.MarkupExtensions"
xmlns:wpf="clr-namespace:RevitDBExplorer.WPF"
xmlns:ap="clr-namespace:RevitDBExplorer.WPF.AttachedProperties"
Expand Down Expand Up @@ -47,11 +47,6 @@
</ResourceDictionary>
</Window.Resources>

<!--<Window.ContextMenu>
<ContextMenu>
<MenuItem Header="Configuration" Click="Window_MenuItem_ConfigurationClick" />
</ContextMenu>
</Window.ContextMenu>-->
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1*" MinHeight="200"/>
Expand Down Expand Up @@ -207,40 +202,11 @@
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>

<controls:TextBoxWithPlaceholder Text="{Binding DatabaseQuery, Mode=TwoWay, Delay=1000, UpdateSourceTrigger=PropertyChanged}"
AutocompleteItemProvider="{Binding DatabaseQueryAutocompleteItemProvider}"
IsPopupOpen="{Binding IsPopupOpen}"
Placeholder="Query Revit database with RDQ">
<!--ToolTip="{Binding DatabaseQueryToolTip}"
ToolTipService.ShowDuration="50000"-->

<!--<controls:TextBoxWithPlaceholder.ContextMenu>
<ContextMenu>
<MenuItem Command="ApplicationCommands.Copy" />
<MenuItem Command="ApplicationCommands.Cut" />
<MenuItem Command="ApplicationCommands.Paste" />
<Separator/>
<MenuItem Header ="Copy generated C# syntax" Tag="Default" Click="TextBox_MenuItem_CopyFilteredElementCollector"/>
</ContextMenu>
</controls:TextBoxWithPlaceholder.ContextMenu>-->
</controls:TextBoxWithPlaceholder>

<Button Grid.Column="1" BorderBrush="Transparent" Margin="2 0 0 0" MinWidth="21" MinHeight="21" Padding="2 0 1 1" ToolTip="Save query as favorite" Background="Transparent" Command="{Binding SaveQueryAsFavoriteCommand}">
<Path Style="{StaticResource IconFavorite}" Width="18"/>
</Button>

<Button Grid.Column="2" BorderBrush="Transparent" Margin="2 0 0 0" MinWidth="21" MinHeight="21" Padding="2 0 1 1" ToolTip="Generate C# code for this SELECT query (RDS)" Background="Transparent" Command="{Binding OpenScriptingWithQueryCommand}">
<Path Style="{StaticResource IconQuery}" Width="12" />
</Button>
</Grid.RowDefinitions>

<componentQueryVisualization:QueryVisualizationView Grid.Row="1" Grid.ColumnSpan="2" Margin="0 1 0 0" DataContext="{Binding QueryVisualization}"/>
<componentQueryEditor:QueryEditorView DataContext="{Binding QueryEditor}" />

<componentQueryVisualization:QueryVisualizationView Grid.Row="1" Margin="0 1 0 0" DataContext="{Binding QueryVisualization}"/>
</Grid>

<DockPanel Grid.Row="2" Grid.Column="0" Margin="0 0 2 0" SizeChanged="Window_SizeChanged">
Expand Down Expand Up @@ -297,13 +263,13 @@
<StackPanel Orientation="Horizontal" Grid.Column="1" Background="{DynamicResource StatusBar.Background}">
<TextBlock Text="{Binding MouseStatus}" Margin="0 0 2 0" Foreground="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" ToolTip="Mouse cursor position in the Revit Model Coordinates (imperial), &#x0a;&#x0a; it does not work when a direction of a Revit view is not aligned with any of directions of a Revit model" HorizontalAlignment="Left" VerticalAlignment="Center" Visibility="{Binding IsNewVerAvailable, Converter={StaticResource BoolToVisibilityConverterCollapsedInverted}}"/>

<ToggleButton Style="{StaticResource ToolTooggle}" IsChecked="{Binding IsBoundingBoxVisualizerEnabled}" Padding="0" Background="red" ToolTip="Show visualization for the selected object in the Tree">
<ToggleButton Style="{StaticResource ToolTooggle}" IsChecked="{Binding IsRDVEnabled}" Padding="0" Background="red" ToolTip="Show visualization for the selected object in the Tree">
<Grid Background="#FEFCF7" Height="19" Width="38" >
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
<TextBlock Text="V" Foreground="#1434CB" FontWeight="Heavy" FontFamily="Arial" FontSize="15"/>
<Grid>
<TextBlock Text=":on " Visibility="{Binding IsBoundingBoxVisualizerEnabled, Converter={StaticResource BoolToVisibilityConverterHidden}}" Foreground="Black" VerticalAlignment="Bottom"/>
<TextBlock Text=":off " Visibility="{Binding IsBoundingBoxVisualizerEnabled, Converter={StaticResource BoolToVisibilityConverterHiddenInverted}}" Foreground="Black" VerticalAlignment="Bottom"/>
<TextBlock Text=":on " Visibility="{Binding IsRDVEnabled, Converter={StaticResource BoolToVisibilityConverterHidden}}" Foreground="Black" VerticalAlignment="Bottom"/>
<TextBlock Text=":off " Visibility="{Binding IsRDVEnabled, Converter={StaticResource BoolToVisibilityConverterHiddenInverted}}" Foreground="Black" VerticalAlignment="Bottom"/>
</Grid>
</StackPanel>
</Grid>
Expand Down
126 changes: 31 additions & 95 deletions sources/RevitDBExplorer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,54 +11,51 @@
using RevitDBExplorer.Augmentations;
using RevitDBExplorer.Domain;
using RevitDBExplorer.Domain.RevitDatabaseQuery;
using RevitDBExplorer.Domain.RevitDatabaseQuery.Autocompletion;
using RevitDBExplorer.Domain.RevitDatabaseScripting;
using RevitDBExplorer.Domain.Selectors;
using RevitDBExplorer.Properties;
using RevitDBExplorer.UIComponents.Breadcrumbs;
using RevitDBExplorer.UIComponents.List;
using RevitDBExplorer.UIComponents.QueryEditor;
using RevitDBExplorer.UIComponents.QueryVisualization;
using RevitDBExplorer.UIComponents.Trees.Base;
using RevitDBExplorer.UIComponents.Trees.Base.Items;
using RevitDBExplorer.UIComponents.Trees.Explorer;
using RevitDBExplorer.UIComponents.Trees.Utility;
using RevitDBExplorer.Utils;
using RevitDBExplorer.WPF;
using RevitDBExplorer.WPF.Controls;
using RDQCommand = RevitDBExplorer.Domain.RevitDatabaseQuery.Parser.Command;

// (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md

namespace RevitDBExplorer
{
internal enum RightView { None, List, CommandAndControl, CompareAndPinToolInfo }

internal partial class MainWindow : Window, IAmWindowOpener, IAmQueryExecutor, INotifyPropertyChanged
internal partial class MainWindow : Window, IAmWindowOpener, INotifyPropertyChanged
{
private readonly ExplorerTreeViewModel explorerTreeViewModel = new();
private readonly UtilityTreeViewModel utilityTreeViewModel = new();
private readonly ListVM listVM;
private readonly QueryVisualizationVM queryVisualizationVM = new();
private readonly BreadcrumbsVM breadcrumbs;
private RightView rightView;
private string databaseQuery = string.Empty;
private string databaseQueryToolTip = string.Empty;
private bool isPopupOpen;
private readonly QueryEditorViewModel queryEditorVM;
private readonly QueryVisualizationVM queryVisualizationVM = new();
private readonly ExplorerTreeViewModel explorerTreeVM = new();
private readonly UtilityTreeViewModel utilityTreeVM = new();
private readonly ListVM listVM;
private readonly BreadcrumbsVM breadcrumbsVM;
private readonly DispatcherTimer isRevitBusyDispatcher;
private readonly IRDV3DController rdvController;
private RightView rightView;
private bool isRevitBusy;
private bool isNewVerAvailable;
private string newVersionLink;
private bool isWiderThan800px;
private string mouseStatus;
private readonly DispatcherTimer isRevitBusyDispatcher;
private readonly IAutocompleteItemProvider databaseQueryAutocompleteItemProvider = new AutocompleteItemProvider();
private readonly IRDV3DController rdvController;
private string rdqGeneratedCSharpSyntax;


public ExplorerTreeViewModel ExplorerTree => explorerTreeViewModel;
public UtilityTreeViewModel UtilityTree => utilityTreeViewModel;
public QueryEditorViewModel QueryEditor => queryEditorVM;
public ExplorerTreeViewModel ExplorerTree => explorerTreeVM;
public UtilityTreeViewModel UtilityTree => utilityTreeVM;
public ListVM List => listVM;
public QueryVisualizationVM QueryVisualization => queryVisualizationVM;
public BreadcrumbsVM Breadcrumbs => breadcrumbs;
public BreadcrumbsVM Breadcrumbs => breadcrumbsVM;
public RightView RightView
{
get
Expand All @@ -71,46 +68,6 @@ public RightView RightView
OnPropertyChanged();
}
}
public string DatabaseQuery
{
get
{
return databaseQuery;
}
set
{
databaseQuery = value;
if (IsPopupOpen == false)
{
TryQueryDatabase(value);
}
OnPropertyChanged();
}
}
public string DatabaseQueryToolTip
{
get
{
return databaseQueryToolTip;
}
set
{
databaseQueryToolTip = value;
OnPropertyChanged();
}
}
public bool IsPopupOpen
{
get
{
return isPopupOpen;
}
set
{
isPopupOpen = value;
OnPropertyChanged();
}
}
public bool IsRevitBusy
{
get
Expand Down Expand Up @@ -173,15 +130,8 @@ public string MouseStatus
mouseStatus = value;
OnPropertyChanged();
}
}
public IAutocompleteItemProvider DatabaseQueryAutocompleteItemProvider
{
get
{
return databaseQueryAutocompleteItemProvider;
}
}
public bool IsBoundingBoxVisualizerEnabled
}
public bool IsRDVEnabled
{
get
{
Expand All @@ -194,9 +144,7 @@ public bool IsBoundingBoxVisualizerEnabled
OnPropertyChanged();
}
}
public RelayCommand OpenScriptingWithQueryCommand { get; }
public RelayCommand SaveQueryAsFavoriteCommand { get; }



public MainWindow(SourceOfObjects sourceOfObjects, IntPtr? parentWindowHandle = null) : this()
{
Expand All @@ -209,25 +157,22 @@ public MainWindow(SourceOfObjects sourceOfObjects, IntPtr? parentWindowHandle =
public MainWindow()
{
Dispatcher.UnhandledException += Dispatcher_UnhandledException;
listVM = new ListVM(this, this);
breadcrumbs = new BreadcrumbsVM();
queryEditorVM = new QueryEditorViewModel(TryQueryDatabase, GenerateScriptForQueryAndOpenRDS);
listVM = new ListVM(this, queryEditorVM);
breadcrumbsVM = new BreadcrumbsVM();

InitializeComponent();
InitializeAsync().Forget();

this.DataContext = this;

Title = WindowTitleGenerator.Get();

isRevitBusyDispatcher = new DispatcherTimer(TimeSpan.FromMilliseconds(500), DispatcherPriority.Background, IsRevitBusyDispatcher_Tick, Dispatcher.CurrentDispatcher);

ExplorerTree.SelectedItemChanged += Tree_SelectedItemChanged;
ExplorerTree.ScriptWasGenerated += OpenRDSWithGivenScript;
UtilityTree.SelectedItemChanged += Tree_SelectedItemChanged;
UtilityTree.ScriptWasGenerated += OpenRDSWithGivenScript;

OpenScriptingWithQueryCommand = new RelayCommand(GenerateScriptForQueryAndOpenRDS);
SaveQueryAsFavoriteCommand = new RelayCommand(SaveQueryAsFavorite, x => !string.IsNullOrEmpty(DatabaseQuery) );

rdvController = RevitDatabaseVisualizationFactory.CreateController();
}
private async Task InitializeAsync()
Expand Down Expand Up @@ -356,15 +301,11 @@ private async void TryQueryDatabase(string query)
return result;
});

DatabaseQueryToolTip = rdqResult.GeneratedCSharpSyntax;
rdqGeneratedCSharpSyntax = rdqResult.GeneratedCSharpSyntax;
QueryVisualization.Update(rdqResult.Commands).Forget();
ExplorerTree.PopulateTreeView(rdqResult.SourceOfObjects);
}
void IAmQueryExecutor.Query(string query)
{
DatabaseQuery = query;
}



private void PopulateExplorerTree(SourceOfObjects sourceOfObjects)
{
Expand All @@ -373,16 +314,11 @@ private void PopulateExplorerTree(SourceOfObjects sourceOfObjects)
}
private void ResetDatabaseQuery()
{
databaseQuery = "";
OnPropertyChanged(nameof(DatabaseQuery));
DatabaseQueryToolTip = "";
QueryVisualization.Update(Enumerable.Empty<RDQCommand>()).Forget();
}
private void SaveQueryAsFavorite()
{
FavoritesManager.Add(DatabaseQuery);
QueryEditor.ResetDatabaseQuery();
rdqGeneratedCSharpSyntax = "";
QueryVisualization.Reset().Forget();
}


private void UpdateRDV()
{
Expand All @@ -401,9 +337,9 @@ private void UpdateRDV()

private void GenerateScriptForQueryAndOpenRDS()
{
var scriptText = CodeGenerator.GenerateQueryFor(DatabaseQueryToolTip);
var scriptText = CodeGenerator.GenerateQueryFor(rdqGeneratedCSharpSyntax);
OpenRDSWithGivenScript(scriptText);
}
}
private void OpenRDSWithGivenScript(string scriptText)
{
OpenRDS();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<UserControl x:Class="RevitDBExplorer.UIComponents.QueryEditor.QueryEditorView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:RevitDBExplorer.UIComponents.QueryEditor"
xmlns:wpf="clr-namespace:RevitDBExplorer.WPF"
xmlns:controls="clr-namespace:RevitDBExplorer.WPF.Controls"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../../Resources/Templates/All.xaml"/>
<wpf:ThemeResourceDictionary Name="Colors"/>
<ResourceDictionary Source="../../Resources/VectorGraphic.xaml"/>
</ResourceDictionary.MergedDictionaries>

</ResourceDictionary>
</UserControl.Resources>

<Grid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Margin="0 3 0 3" >
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>

<controls:TextBoxWithPlaceholder Text="{Binding DatabaseQuery, Mode=TwoWay, Delay=1000, UpdateSourceTrigger=PropertyChanged}"
AutocompleteItemProvider="{Binding DatabaseQueryAutocompleteItemProvider}"
IsPopupOpen="{Binding IsPopupOpen}"
Placeholder="Query Revit database with RDQ">
<!--ToolTip="{Binding DatabaseQueryToolTip}"
ToolTipService.ShowDuration="50000"-->

<!--<controls:TextBoxWithPlaceholder.ContextMenu>
<ContextMenu>
<MenuItem Command="ApplicationCommands.Copy" />
<MenuItem Command="ApplicationCommands.Cut" />
<MenuItem Command="ApplicationCommands.Paste" />
<Separator/>
<MenuItem Header ="Copy generated C# syntax" Tag="Default" Click="TextBox_MenuItem_CopyFilteredElementCollector"/>
</ContextMenu>
</controls:TextBoxWithPlaceholder.ContextMenu>-->
</controls:TextBoxWithPlaceholder>

<Button Grid.Column="1" BorderBrush="Transparent" Margin="2 0 0 0" MinWidth="21" MinHeight="21" Padding="2 0 1 1" ToolTip="Save query as favorite" Background="Transparent" Command="{Binding SaveQueryAsFavoriteCommand}">
<Path Style="{StaticResource IconFavorite}" Width="18"/>
</Button>

<Button Grid.Column="2" BorderBrush="Transparent" Margin="2 0 0 0" MinWidth="21" MinHeight="21" Padding="2 0 1 1" ToolTip="Generate C# code for this SELECT query (RDS)" Background="Transparent" Command="{Binding OpenScriptingWithQueryCommand}">
<Path Style="{StaticResource IconQuery}" Width="12" />
</Button>
</Grid>
</UserControl>
Loading

0 comments on commit 923de8c

Please sign in to comment.