Skip to content

Commit 923de8c

Browse files
committed
extract QueryEditor as a separate component
1 parent e85bf8c commit 923de8c

File tree

6 files changed

+231
-138
lines changed

6 files changed

+231
-138
lines changed

sources/RevitDBExplorer/MainWindow.xaml

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
7+
xmlns:componentQueryEditor="clr-namespace:RevitDBExplorer.UIComponents.QueryEditor"
78
xmlns:componentQueryVisualization="clr-namespace:RevitDBExplorer.UIComponents.QueryVisualization"
89
xmlns:componentBusyIndicator="clr-namespace:RevitDBExplorer.UIComponents.BusyIndicator"
910
xmlns:componentList="clr-namespace:RevitDBExplorer.UIComponents.List"
@@ -12,8 +13,7 @@
1213
xmlns:componentCAndC="clr-namespace:RevitDBExplorer.UIComponents.CommandAndControl"
1314
xmlns:componentScripting="clr-namespace:RevitDBExplorer.UIComponents.Scripting"
1415
xmlns:componentBreadcrumbs="clr-namespace:RevitDBExplorer.UIComponents.Breadcrumbs"
15-
xmlns:converters="clr-namespace:RevitDBExplorer.WPF.Converters"
16-
xmlns:controls="clr-namespace:RevitDBExplorer.WPF.Controls"
16+
xmlns:converters="clr-namespace:RevitDBExplorer.WPF.Converters"
1717
xmlns:ext="clr-namespace:RevitDBExplorer.WPF.MarkupExtensions"
1818
xmlns:wpf="clr-namespace:RevitDBExplorer.WPF"
1919
xmlns:ap="clr-namespace:RevitDBExplorer.WPF.AttachedProperties"
@@ -47,11 +47,6 @@
4747
</ResourceDictionary>
4848
</Window.Resources>
4949

50-
<!--<Window.ContextMenu>
51-
<ContextMenu>
52-
<MenuItem Header="Configuration" Click="Window_MenuItem_ConfigurationClick" />
53-
</ContextMenu>
54-
</Window.ContextMenu>-->
5550
<Grid>
5651
<Grid.RowDefinitions>
5752
<RowDefinition Height="1*" MinHeight="200"/>
@@ -207,40 +202,11 @@
207202
<Grid.RowDefinitions>
208203
<RowDefinition/>
209204
<RowDefinition/>
210-
</Grid.RowDefinitions>
211-
<Grid.ColumnDefinitions>
212-
<ColumnDefinition/>
213-
<ColumnDefinition Width="auto"/>
214-
<ColumnDefinition Width="auto"/>
215-
</Grid.ColumnDefinitions>
216-
217-
<controls:TextBoxWithPlaceholder Text="{Binding DatabaseQuery, Mode=TwoWay, Delay=1000, UpdateSourceTrigger=PropertyChanged}"
218-
AutocompleteItemProvider="{Binding DatabaseQueryAutocompleteItemProvider}"
219-
IsPopupOpen="{Binding IsPopupOpen}"
220-
Placeholder="Query Revit database with RDQ">
221-
<!--ToolTip="{Binding DatabaseQueryToolTip}"
222-
ToolTipService.ShowDuration="50000"-->
223-
224-
<!--<controls:TextBoxWithPlaceholder.ContextMenu>
225-
<ContextMenu>
226-
<MenuItem Command="ApplicationCommands.Copy" />
227-
<MenuItem Command="ApplicationCommands.Cut" />
228-
<MenuItem Command="ApplicationCommands.Paste" />
229-
<Separator/>
230-
<MenuItem Header ="Copy generated C# syntax" Tag="Default" Click="TextBox_MenuItem_CopyFilteredElementCollector"/>
231-
</ContextMenu>
232-
</controls:TextBoxWithPlaceholder.ContextMenu>-->
233-
</controls:TextBoxWithPlaceholder>
234-
235-
<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}">
236-
<Path Style="{StaticResource IconFavorite}" Width="18"/>
237-
</Button>
238-
239-
<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}">
240-
<Path Style="{StaticResource IconQuery}" Width="12" />
241-
</Button>
205+
</Grid.RowDefinitions>
242206

243-
<componentQueryVisualization:QueryVisualizationView Grid.Row="1" Grid.ColumnSpan="2" Margin="0 1 0 0" DataContext="{Binding QueryVisualization}"/>
207+
<componentQueryEditor:QueryEditorView DataContext="{Binding QueryEditor}" />
208+
209+
<componentQueryVisualization:QueryVisualizationView Grid.Row="1" Margin="0 1 0 0" DataContext="{Binding QueryVisualization}"/>
244210
</Grid>
245211

246212
<DockPanel Grid.Row="2" Grid.Column="0" Margin="0 0 2 0" SizeChanged="Window_SizeChanged">
@@ -297,13 +263,13 @@
297263
<StackPanel Orientation="Horizontal" Grid.Column="1" Background="{DynamicResource StatusBar.Background}">
298264
<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}}"/>
299265

300-
<ToggleButton Style="{StaticResource ToolTooggle}" IsChecked="{Binding IsBoundingBoxVisualizerEnabled}" Padding="0" Background="red" ToolTip="Show visualization for the selected object in the Tree">
266+
<ToggleButton Style="{StaticResource ToolTooggle}" IsChecked="{Binding IsRDVEnabled}" Padding="0" Background="red" ToolTip="Show visualization for the selected object in the Tree">
301267
<Grid Background="#FEFCF7" Height="19" Width="38" >
302268
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
303269
<TextBlock Text="V" Foreground="#1434CB" FontWeight="Heavy" FontFamily="Arial" FontSize="15"/>
304270
<Grid>
305-
<TextBlock Text=":on " Visibility="{Binding IsBoundingBoxVisualizerEnabled, Converter={StaticResource BoolToVisibilityConverterHidden}}" Foreground="Black" VerticalAlignment="Bottom"/>
306-
<TextBlock Text=":off " Visibility="{Binding IsBoundingBoxVisualizerEnabled, Converter={StaticResource BoolToVisibilityConverterHiddenInverted}}" Foreground="Black" VerticalAlignment="Bottom"/>
271+
<TextBlock Text=":on " Visibility="{Binding IsRDVEnabled, Converter={StaticResource BoolToVisibilityConverterHidden}}" Foreground="Black" VerticalAlignment="Bottom"/>
272+
<TextBlock Text=":off " Visibility="{Binding IsRDVEnabled, Converter={StaticResource BoolToVisibilityConverterHiddenInverted}}" Foreground="Black" VerticalAlignment="Bottom"/>
307273
</Grid>
308274
</StackPanel>
309275
</Grid>

sources/RevitDBExplorer/MainWindow.xaml.cs

Lines changed: 31 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -11,54 +11,51 @@
1111
using RevitDBExplorer.Augmentations;
1212
using RevitDBExplorer.Domain;
1313
using RevitDBExplorer.Domain.RevitDatabaseQuery;
14-
using RevitDBExplorer.Domain.RevitDatabaseQuery.Autocompletion;
1514
using RevitDBExplorer.Domain.RevitDatabaseScripting;
1615
using RevitDBExplorer.Domain.Selectors;
1716
using RevitDBExplorer.Properties;
1817
using RevitDBExplorer.UIComponents.Breadcrumbs;
1918
using RevitDBExplorer.UIComponents.List;
19+
using RevitDBExplorer.UIComponents.QueryEditor;
2020
using RevitDBExplorer.UIComponents.QueryVisualization;
2121
using RevitDBExplorer.UIComponents.Trees.Base;
2222
using RevitDBExplorer.UIComponents.Trees.Base.Items;
2323
using RevitDBExplorer.UIComponents.Trees.Explorer;
2424
using RevitDBExplorer.UIComponents.Trees.Utility;
2525
using RevitDBExplorer.Utils;
2626
using 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

3230
namespace 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();
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<UserControl x:Class="RevitDBExplorer.UIComponents.QueryEditor.QueryEditorView"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:RevitDBExplorer.UIComponents.QueryEditor"
7+
xmlns:wpf="clr-namespace:RevitDBExplorer.WPF"
8+
xmlns:controls="clr-namespace:RevitDBExplorer.WPF.Controls"
9+
mc:Ignorable="d"
10+
d:DesignHeight="450" d:DesignWidth="800">
11+
<UserControl.Resources>
12+
<ResourceDictionary>
13+
<ResourceDictionary.MergedDictionaries>
14+
<ResourceDictionary Source="../../Resources/Templates/All.xaml"/>
15+
<wpf:ThemeResourceDictionary Name="Colors"/>
16+
<ResourceDictionary Source="../../Resources/VectorGraphic.xaml"/>
17+
</ResourceDictionary.MergedDictionaries>
18+
19+
</ResourceDictionary>
20+
</UserControl.Resources>
21+
22+
<Grid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Margin="0 3 0 3" >
23+
<Grid.RowDefinitions>
24+
<RowDefinition/>
25+
</Grid.RowDefinitions>
26+
<Grid.ColumnDefinitions>
27+
<ColumnDefinition/>
28+
<ColumnDefinition Width="auto"/>
29+
<ColumnDefinition Width="auto"/>
30+
</Grid.ColumnDefinitions>
31+
32+
<controls:TextBoxWithPlaceholder Text="{Binding DatabaseQuery, Mode=TwoWay, Delay=1000, UpdateSourceTrigger=PropertyChanged}"
33+
AutocompleteItemProvider="{Binding DatabaseQueryAutocompleteItemProvider}"
34+
IsPopupOpen="{Binding IsPopupOpen}"
35+
Placeholder="Query Revit database with RDQ">
36+
<!--ToolTip="{Binding DatabaseQueryToolTip}"
37+
ToolTipService.ShowDuration="50000"-->
38+
39+
<!--<controls:TextBoxWithPlaceholder.ContextMenu>
40+
<ContextMenu>
41+
<MenuItem Command="ApplicationCommands.Copy" />
42+
<MenuItem Command="ApplicationCommands.Cut" />
43+
<MenuItem Command="ApplicationCommands.Paste" />
44+
<Separator/>
45+
<MenuItem Header ="Copy generated C# syntax" Tag="Default" Click="TextBox_MenuItem_CopyFilteredElementCollector"/>
46+
</ContextMenu>
47+
</controls:TextBoxWithPlaceholder.ContextMenu>-->
48+
</controls:TextBoxWithPlaceholder>
49+
50+
<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}">
51+
<Path Style="{StaticResource IconFavorite}" Width="18"/>
52+
</Button>
53+
54+
<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}">
55+
<Path Style="{StaticResource IconQuery}" Width="12" />
56+
</Button>
57+
</Grid>
58+
</UserControl>

0 commit comments

Comments
 (0)