MdiWorkspace differs with SmartPartClosing

Topics: CAB & Smart Client Software Factory
Mar 3, 2006 at 1:56 PM
originally posted by: JaredBienz

WindowWorkpace uses WindowForm.WindowFormClosing to fire its SmartPartClosing event. When the SmartPart is shown in an MdiWorkspace, SmartPartClosing happens when the MdiParent is closing (usually when the application is shutting down).

Other workspaces like DeckWorkspace and ZoneWorkspace do not fire SmartPartClosing when the application is shutting down. If a SmartPart cancels the closing in an MdiWorkspace, it can keep the entire application from exiting. This is not true for a Deck or Zone Workspace.

I would like to propose two solutions:

1. WindowForm could override OnFormClosing (instead of the simpler OnClosing) and pass the CloseReason on to the WindowWorkspace. WindowWorkspace could examine the CloseReason and not raise the SmartPartClosing event unless the reason is UserClosing. This would be consistent with other workspaces but could allow for a SmartPart to be closed without the framework knowing about it.

2. Option two is similar to option one but WorkspaceCancelEventArgs would be modified to include an optional CloseReason in the constructor. CloseReason would default to CloseReason.UserClosing so all existing workspaces wouldn’t have to be rewritten. This approach would allow better handling of the SmartPartClosing event, taking into consideration the reason why the SmartPart is being closed.


I also want to mention that I’m using CloseReason loosely. CloseReason should be a CAB enumeration with whichever values the team thinks are pertinent. We should not simply forward the System.Windows.Forms.CloseReason on through the WorkspaceCancelEventArgs as that would bind all modules to WinForms dependencies.