Skip to content

Commit 2295b29

Browse files
committed
update: enhance TraceLog functionality
- completely unsubcribe when panel not visible - change WindowStartupLocation to CenterOwner
1 parent aa84b09 commit 2295b29

File tree

6 files changed

+171
-134
lines changed

6 files changed

+171
-134
lines changed

source/RevitDevTool/Commands/TraceCommand.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Nice3point.Revit.Toolkit.Decorators;
44
using Nice3point.Revit.Toolkit.External;
55
using RevitDevTool.View;
6+
using RevitDevTool.ViewModel;
67

78
namespace RevitDevTool.Commands;
89

@@ -13,19 +14,19 @@ public class TraceCommand : ExternalCommand
1314
private const string CommandName = "TraceLog";
1415
private const string Guid = "43AE2B41-0BE6-425A-B27A-724B2CE17351";
1516
private static DockablePaneId PaneId { get; } = new(new Guid(Guid));
16-
private static bool IsForceHide { get; set; }
17+
private static bool IsForceHide { get; set; }
1718

1819
public override void Execute()
1920
{
2021
try
2122
{
2223
var dockableWindow = UiApplication.GetDockablePane(PaneId);
23-
if (dockableWindow.IsShown())
24+
if (dockableWindow.IsShown())
2425
{
2526
dockableWindow.Hide();
2627
IsForceHide = true;
2728
}
28-
else
29+
else
2930
{
3031
dockableWindow.Show();
3132
IsForceHide = false;
@@ -43,20 +44,33 @@ public static void RegisterDockablePane(UIControlledApplication application)
4344
.Register(application, new Guid(Guid), CommandName)
4445
.SetConfiguration(data =>
4546
{
46-
data.FrameworkElement = new TraceLog();
47+
var frameworkElement = new TraceLog();
48+
data.FrameworkElement = frameworkElement;
4749
data.InitialState = new DockablePaneState
4850
{
4951
MinimumWidth = 500,
5052
MinimumHeight = 400,
5153
DockPosition = DockPosition.Right,
5254
TabBehind = DockablePanes.BuiltInDockablePanes.PropertiesPalette
5355
};
56+
57+
application.DockableFrameVisibilityChanged += (_, args) =>
58+
{
59+
if (args.PaneId != PaneId) return;
60+
61+
if (frameworkElement.DataContext is not TraceLogViewModel vm) return;
62+
63+
if (args.DockableFrameShown)
64+
vm.Subcribe();
65+
else
66+
vm.Dispose();
67+
};
5468
});
5569

56-
application.ControlledApplication.DocumentOpened += ( _, _ ) =>
70+
application.ControlledApplication.DocumentOpened += (_, _) =>
5771
{
5872
var dockableWindow = application.GetDockablePane(PaneId);
59-
if (IsForceHide)
73+
if (IsForceHide)
6074
{
6175
dockableWindow.Hide();
6276
}
Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
using System.Collections;
21
using Nice3point.Revit.Toolkit.External.Handlers;
32

43
namespace RevitDevTool;
54

65
public static class ExternalEventController
76
{
87
private static ActionEventHandler? _actionEventHandler;
9-
private static AsyncEventHandler? _asyncEventHandler;
10-
private static AsyncEventHandler<IEnumerable>? _asyncCollectionEventHandler;
11-
private static IdlingEventHandler? _idlingEventHandler;
128

139
private const string HandlerNotSetMessage = "The handler was never set.";
1410

@@ -18,29 +14,8 @@ public static ActionEventHandler ActionEventHandler
1814
private set => _actionEventHandler = value;
1915
}
2016

21-
public static AsyncEventHandler AsyncEventHandler
22-
{
23-
get => _asyncEventHandler ?? throw new InvalidOperationException(HandlerNotSetMessage);
24-
private set => _asyncEventHandler = value;
25-
}
26-
27-
public static AsyncEventHandler<IEnumerable> AsyncCollectionEventHandler
28-
{
29-
get => _asyncCollectionEventHandler ?? throw new InvalidOperationException(HandlerNotSetMessage);
30-
private set => _asyncCollectionEventHandler = value;
31-
}
32-
33-
public static IdlingEventHandler IdlingEventHandler
34-
{
35-
get => _idlingEventHandler ?? throw new InvalidOperationException(HandlerNotSetMessage);
36-
private set => _idlingEventHandler = value;
37-
}
38-
3917
public static void Register()
4018
{
4119
ActionEventHandler = new ActionEventHandler();
42-
AsyncEventHandler = new AsyncEventHandler();
43-
AsyncCollectionEventHandler = new AsyncEventHandler<IEnumerable>();
44-
IdlingEventHandler = new IdlingEventHandler();
4520
}
4621
}

source/RevitDevTool/RevitDevTool.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
<PropertyGroup>
1818
<IsRepackable>true</IsRepackable>
19-
<RepackBinariesExcludes>$(AssemblyName).UI*.dll;System*.dll</RepackBinariesExcludes>
19+
<RepackBinariesExcludes>$(AssemblyName).UI*.dll</RepackBinariesExcludes>
2020
</PropertyGroup>
2121

2222
<!-- Revit Versions -->

source/RevitDevTool/View/SettingsView.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
1616
WindowBackdropType="Mica"
1717
WindowCornerPreference="Round"
18-
WindowStartupLocation="CenterScreen"
18+
WindowStartupLocation="CenterOwner"
1919
mc:Ignorable="d">
2020

2121
<Grid>

source/RevitDevTool/View/TraceLog.xaml.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,5 @@ public TraceLog()
1010
ThemeWatcher.Instance.Watch(this);
1111
InitializeComponent();
1212
DataContext = new TraceLogViewModel();
13-
Loaded += (_, _) =>
14-
{
15-
if (DataContext is TraceLogViewModel vm)
16-
vm.RefreshTheme();
17-
};
1813
}
1914
}

0 commit comments

Comments
 (0)