I'm sorry if my words didn't convey my exact meaning, I'm trying my best to convey my thoughts as English is not my first language. I didn't say that ShowModal() was non-blocking. It was ShowWindowModal() that doesn't block the entire application and I can see why. Let me quote some documentation.
Unlike ShowModal(), dialogs shown with this function only prevent the user from interacting with their parent frame only but not with the rest of the application. They also don't block the program execution but instead return immediately, as Show(), and generate a wxEVT_WINDOW_MODAL_DIALOG_CLOSED event (wxWindowModalDialogEvent) later when the dialog is closed.
I got to know that this was the case, and because we have to wait for an event to generate, it is not made a blocking call. The design for sheets seems to be this way, as they are never a blocking calls in Cocoa on OSX and now on macOS. And then, my application is a code editor with tabs support (I use wxAuiNotebook to provide tabbed editing), and hence I had this high level psuedocode to handle the case of close clicked on a tab.
- User clicked on close button on tab
- If the current tab is not modified, delete the tab page.
- Or else if the current tab is modified:
- Ask user to save the file. Options YES / NO / CANCEL are given.
- If the user selected YES:
- Show the save file dialog (assuming the case of new file)
- If the user proceeds to save the file, then delete the tab page.
- If the user clicks on cancel in the save file dialog, veto the event.
- If the user selected NO, then delete the tab page.
- If the user selected CANCEL, then veto the event.
Now it looks fine, but I want to refactor out. I want to finish stuff in as much less lines as possible. (I know the line
if it ain't broke, don't fix it, but am doing it for the sake of learning. Another cause for my love of tidy code might be that I'm a Haskell programmer at work.). Now looking at this, I already handle the 3(b) case in my OnMenuSave event. I want to reuse it.
If the code is synchronous (and it is when I was using ShowModal()) then I could have simply called the OnMenuSave handler that I defined. I also avoid code duplication that way. You might ask me why not use CPS (continuation passing style) and pass callbacks to create the flow, and I'm doing it already.
I'm just asking if there is any alternative that both shows the dialog as sheet and blocks the execution till the dialog result is recorded and returned. If that is the case, the code looks much more tidy in my opinion.
Thanks for your time, and sorry if I didn't make it clear in the first post itself.