33using Nice3point . Revit . Toolkit . Decorators ;
44using Nice3point . Revit . Toolkit . External ;
55using RevitDevTool . View ;
6+ using RevitDevTool . ViewModel ;
67
78namespace 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 }
0 commit comments