Skip to content

Commit 2d3f038

Browse files
committed
refactoring : remove obsolete code and fix a memory leak
1 parent ad2e69a commit 2d3f038

File tree

8 files changed

+27
-115
lines changed

8 files changed

+27
-115
lines changed

sources/RevitDBExplorer/Command.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme
2929
if (numberOfWindowsInMemory > 3)
3030
{
3131
#if DEBUG
32-
//throw new Exception("There is probably a memory leak.");
32+
GC.Collect();
33+
if (numberOfWindowsInMemory > 4)
34+
{
35+
//throw new Exception("There is probably a memory leak.");
36+
}
3337
#endif
3438
}
3539

sources/RevitDBExplorer/MainWindow.xaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
77
xmlns:componentQueryEditor="clr-namespace:RevitDBExplorer.UIComponents.QueryEditor"
88
xmlns:componentQueryVisualization="clr-namespace:RevitDBExplorer.UIComponents.QueryVisualization"
9-
xmlns:componentBusyIndicator="clr-namespace:RevitDBExplorer.UIComponents.BusyIndicator"
10-
xmlns:componentBreadcrumbs="clr-namespace:RevitDBExplorer.UIComponents.Breadcrumbs"
9+
xmlns:componentBusyIndicator="clr-namespace:RevitDBExplorer.UIComponents.BusyIndicator"
1110
xmlns:componentWorkspaces="clr-namespace:RevitDBExplorer.UIComponents.Workspaces"
1211
xmlns:converters="clr-namespace:RevitDBExplorer.WPF.Converters"
1312
xmlns:ext="clr-namespace:RevitDBExplorer.WPF.MarkupExtensions"
@@ -235,7 +234,7 @@
235234
</Grid.ColumnDefinitions>
236235

237236
<Grid Grid.Column="0" ClipToBounds="False" Visibility="Collapsed">
238-
<componentBreadcrumbs:BreadcrumbsView DataContext="{Binding Breadcrumbs}" Margin="7 0 0 0"/>
237+
239238
</Grid>
240239

241240
<StackPanel Orientation="Horizontal" Grid.Column="1" Background="{DynamicResource StatusBar.Background}">

sources/RevitDBExplorer/MainWindow.xaml.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
using RevitDBExplorer.Domain.RevitDatabaseScripting;
1818
using RevitDBExplorer.Domain.Selectors;
1919
using RevitDBExplorer.Properties;
20-
using RevitDBExplorer.UIComponents.Breadcrumbs;
2120
using RevitDBExplorer.UIComponents.List;
2221
using RevitDBExplorer.UIComponents.List.ViewModels;
2322
using RevitDBExplorer.UIComponents.QueryEditor;
@@ -36,7 +35,6 @@ internal partial class MainWindow : Window, IAmWindowOpener, INotifyPropertyChan
3635
private readonly QueryEditorViewModel queryEditorVM;
3736
private readonly QueryVisualizationVM queryVisualizationVM;
3837
private readonly WorkspacesViewModel workspacesVM;
39-
private readonly BreadcrumbsVM breadcrumbsVM;
4038
private readonly DispatcherTimer isRevitBusyDispatcher;
4139
private readonly IRDV3DController rdvController;
4240
private bool isRevitBusy;
@@ -49,8 +47,7 @@ internal partial class MainWindow : Window, IAmWindowOpener, INotifyPropertyChan
4947

5048
public QueryEditorViewModel QueryEditor => queryEditorVM;
5149
public QueryVisualizationVM QueryVisualization => queryVisualizationVM;
52-
public WorkspacesViewModel Workspaces => workspacesVM;
53-
public BreadcrumbsVM Breadcrumbs => breadcrumbsVM;
50+
public WorkspacesViewModel Workspaces => workspacesVM;
5451
public bool IsRevitBusy
5552
{
5653
get
@@ -144,7 +141,6 @@ public MainWindow()
144141
queryEditorVM = new QueryEditorViewModel(TryQueryDatabase, GenerateScriptForQueryAndOpenRDS);
145142
queryVisualizationVM = new QueryVisualizationVM();
146143
workspacesVM = new WorkspacesViewModel(this, queryEditorVM, OpenRDSWithGivenScript);
147-
breadcrumbsVM = new BreadcrumbsVM();
148144

149145
rdvController = RevitDatabaseVisualizationFactory.CreateController();
150146

@@ -216,6 +212,7 @@ private void Workspaces_SelectedItemChanged(SelectedItemChangedEventArgs obj)
216212
}
217213
void IAmWindowOpener.Open(SourceOfObjects sourceOfObjects)
218214
{
215+
SaveUserSettings();
219216
var window = new MainWindow(sourceOfObjects);
220217
window.Owner = this;
221218
window.Show();
@@ -300,6 +297,7 @@ private void Window_Closed(object sender, EventArgs e)
300297
Dispatcher.UnhandledException -= Dispatcher_UnhandledException;
301298
isRevitBusyDispatcher.Tick -= IsRevitBusyDispatcher_Tick;
302299
Workspaces.SelectedItemChanged -= Workspaces_SelectedItemChanged;
300+
Workspaces.Unbind();
303301
}
304302
private void Window_Closing(object sender, EventArgs e)
305303
{

sources/RevitDBExplorer/UIComponents/Breadcrumbs/BreadcrumbsVM.cs

Lines changed: 0 additions & 38 deletions
This file was deleted.

sources/RevitDBExplorer/UIComponents/Breadcrumbs/BreadcrumbsView.xaml

Lines changed: 0 additions & 35 deletions
This file was deleted.

sources/RevitDBExplorer/UIComponents/Breadcrumbs/BreadcrumbsView.xaml.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.

sources/RevitDBExplorer/UIComponents/Trees/Utility/UtilityTreeViewModel.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Linq;
32
using System.Collections.ObjectModel;
43
using System.Windows;
54
using RevitDBExplorer.Domain.DataModel;

sources/RevitDBExplorer/UIComponents/Workspaces/WorkspacesViewModel.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
44
using System.Linq;
5+
using System.Threading.Tasks;
56
using System.Windows;
67
using RevitDBExplorer.Domain;
78
using RevitDBExplorer.Domain.DataModel;
@@ -75,6 +76,10 @@ public IEnumerable<object> GetSelectedItems()
7576
{
7677
return Workspaces.First().GetSelectedItems();
7778
}
79+
public void Unbind()
80+
{
81+
Workspaces.First().Unbind();
82+
}
7883

7984

8085
private WorkspaceViewModel CreateNewWorkspace()
@@ -175,7 +180,7 @@ public WorkspaceViewModel(IAmWindowOpener windowOpener, IAmQueryExecutor queryEx
175180
List.SelectedItemChanged += List_SelectedItemChanged;
176181
ExplorerTree.ScriptWasGenerated += OpenRDSWithGivenScript;
177182
UtilityTree.ScriptWasGenerated += OpenRDSWithGivenScript;
178-
Title = "Workspace";
183+
Title = "";
179184
}
180185

181186

@@ -187,7 +192,7 @@ private async void Tree_SelectedItemChanged(TreeSelectedItemChangedEventArgs eve
187192

188193
if (eventArgs.Sender == ExplorerTree)
189194
{
190-
UtilityTree.RemoveSelection();
195+
UtilityTree?.RemoveSelection();
191196
}
192197
if (eventArgs.Sender == UtilityTree)
193198
{
@@ -201,7 +206,7 @@ private async void Tree_SelectedItemChanged(TreeSelectedItemChangedEventArgs eve
201206
if (eventArgs.NewOne is SnoopableObjectTreeItem snoopableObjectTreeItem)
202207
{
203208
chosenView = RightView.List;
204-
await List.PopulateListView(snoopableObjectTreeItem);
209+
List.PopulateListView(snoopableObjectTreeItem).Forget();
205210
}
206211

207212
if (eventArgs.NewOne is UtilityGroupTreeItem utilityGroupTreeItem)
@@ -260,10 +265,18 @@ public IEnumerable<object> GetSelectedItems()
260265
{
261266
yield return ExplorerTree.SelectedItem;
262267
}
263-
if (UtilityTree.SelectedItem != null)
268+
if (UtilityTree?.SelectedItem != null)
264269
{
265270
yield return UtilityTree.SelectedItem;
266271
}
267272
}
273+
public void Unbind()
274+
{
275+
ExplorerTree.SelectedItemChanged -= Tree_SelectedItemChanged;
276+
UtilityTree.SelectedItemChanged -= Tree_SelectedItemChanged;
277+
List.SelectedItemChanged -= List_SelectedItemChanged;
278+
ExplorerTree.ScriptWasGenerated -= OpenRDSWithGivenScript;
279+
UtilityTree.ScriptWasGenerated -= OpenRDSWithGivenScript;
280+
}
268281
}
269282
}

0 commit comments

Comments
 (0)