Question

Differentiate between Close button being used to close a ToolWindow and other causes for it to close

Posted 10 months ago by Avatar Farris

In my application I have several different "Workspaces". Initially all the workspaces display the same ToolWindows, they are just arranged differently.

When a user goes from one workspace to another, the current layout is stored using DockSiteLayoutSerializer.SaveToString(), and the newly selected workspace is loaded using DockSiteLayoutSerializer.LoadFromString().

The issue that has arised, is that when calling DockSiteLayoutSerializer.LoadFromString(), the DockSite.WindowsClosed event is fired, closing all the ToolWindows, before openeing all the same windows again (given I have the same windows open in both workspaces).

This is rather unfortunate, since this is the same event that is fired when pressing the "X" on the ToolWindow to manually close it. When a user manually closes a window this way, I want to perform some extra logic (such as destroying the window and removing it from the DockSite). 

Is there some straightforward way to accomplish what I'm trying to do?

 

Thanks :) 


Comments (3)

Posted 10 months ago by Actipro Software Support - Cleveland, OH, USA

Hi Farris,

Since you know when you programmatically initiate a layout change, I would recommend setting a flag somewhere while doing the layout change, then clearing it when done.  That way your WindowsClosed handler can examine that flag and determine if you are in the one scenario or the other, and take appropriate action.


Actipro Software Support
Posted 7 months ago by Gordon Slysz

I'm having a related problem.

I want the user to close using the 'X'. And when the user does this, I tell the underlying viewModel to do something.

However, if the user floats the toolWindow and then clicks somewhere else in the app, the toolWindow close event gets triggered, and then bad things happen since it acts on the viewModel, when it is only supposed to do that when the user manually closes the toolWindow.

If I could only know if someone clicked that 'X', I would be all set. 

How can I know the window was closed manually?   This should be so easy  :(   I've even tried to overlay my own close button, but that ain't pretty.   Suggestions?

[Modified 7 months ago]

Posted 7 months ago by Actipro Software Support - Cleveland, OH, USA

Hi Gordon,

The UI is using various Close commands that effectively call the same Close method you can programmatically call.  That's why in the previous reply of this thread, we recommended that if you are programmatically closing something, you have the ability to set a flag somewhere that indicates you are in a programmatic close.  Then you can examine that flag in your WindowsClosed handler and adjust how you react.

Or please tell us more detail about your scenario if the above isn't an option.


Actipro Software Support
Information The latest build of this product (2018.1 build 0671) was released 1 month ago, which was after the last post in this thread.

Add a Comment

Please log in to a validated account to post comments.