8000 Duplicate Quit buttons · Issue #130 · jwdj/EasyABC · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Duplicate Quit buttons #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lutzhamel opened this issue May 10, 2025 · 1 comment
Open

Duplicate Quit buttons #130

lutzhamel opened this issue May 10, 2025 · 1 comment

Comments

@lutzhamel
Copy link

In the EasyABC version I just installed on MacOS (1.3.8.7) there are two Quit buttons available:

  1. under the File menu
  2. under the EasyABC menu

Here is the problem, the Quit button under the File menu behaves correctly asking you if you want to save your file if your file has unsaved modifications in it. On the other hand, the Quit button under the EasyABC menu does not have this behavior and just quits the program without saving your work! This risks loosing all your work if you are not careful when shutting down your editor.

@bomm
Copy link
bomm commented May 26, 2025

@lutzhamel This EasyABC menu is MacOS specific. It does not exist on Linux or Windows.

A Google search for "wxwidgets macos application menu quit" returned this AI generated information. Maybe it is relevant.

On macOS, wxWidgets applications typically have a standard Apple menu (obtained via wxMenuBar::OSXGetAppleMenu()) which includes a "Quit" item (usually wxID_EXIT) and its corresponding keyboard shortcut (Cmd+Q). This "Quit" item's default action, by default, is to terminate the application without closing any windows, according to a GitHub issue.
To properly quit your wxWidgets application when the "Quit" menu item or Cmd+Q is used, you might need to explicitly handle the wxEVT_COMMAND_MENU_SELECTED event for wxID_EXIT in your application code and call wxGetApp().ExitMainLoop(). This ensures the application exits gracefully, and that any necessary cleanup or application state is handled before termination, according to Stack Overflow.
Here's how you can handle the "Quit" event in your wxWidgets code:

1. Connect the event handler:
In your application class (usually wxApp), use wxApp::OnCommand() to handle the wxEVT_COMMAND_MENU_SELECTED event.
2. Check for wxID_EXIT:
Inside your event handler, check if the event's ID is wxID_EXIT.
3. Call ExitMainLoop():
If it's wxID_EXIT, call wxGetApp().ExitMainLoop() to terminate the application's main loop.
4. Perform Cleanup:
You can perform any necessary cleanup before calling ExitMainLoop(). For example, you might want to save application data or release resources.

And a search for "wxwidgets macos duplicate quit" returns

On macOS, wxWidgets applications may exhibit a "duplicate quit" issue, where the application might attempt to close multiple times, potentially leading to unexpected behavior or crashes. This can occur when the application's default quit action is used in conjunction with the Cmd+Q shortcut or other methods of quitting, such as from the Dock. A workaround is to handle the wxID_EXIT event, which is associated with the quit action in the Apple menu, to prevent the default action and allow the application to handle the quit event properly.
Explanation:

Default Quit Action:
The macOS default application menu, accessed through wxMenuBar::OSXGetAppleMenu(), contains a "Quit" item (wxID_EXIT) with the Cmd+Q shortcut. By default, this item triggers the application to exit without calling Close() on windows, potentially bypassing any checks for unsaved changes. 

Duplicate Quit:
If the application's own code also attempts to handle quitting (e.g., by responding to the Close event), it might trigger the quit action again, resulting in a duplicate quit.
Modal Dialogs and Dock:
Applications running with modal dialogs can also experience issues. Quitting from the Dock while a modal dialog is open can still trigger the application to exit, even though the dialog is blocking the application from fully closing.
Workaround: Handling wxID_EXIT:
To avoid the duplicate quit or other unwanted behavior, you can handle the wxID_EXIT event in your wxWidgets application. This prevents the default quit action from being triggered and allows you to control the application's closing process more effectively.

To handle wxID_EXIT:

Get the Apple menu: Obtain the Apple menu using wxMenuBar::OSXGetAppleMenu().
Find the Quit item: Locate the item with ID wxID_EXIT.
Attach an event handler: Connect an event handler to the wxID_EXIT item. This handler will be executed when the user selects the Quit option from the Apple menu or uses Cmd+Q.
Implement custom quit logic: In the event handler, implement the desired logic for quitting your application, including closing windows, saving data, and potentially prompting the user for unsaved changes. 

I don't know if all this is correct, but it looks reasonable as a starting point for further research.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0