make sure menus are initialized when a new window is opened

Thu, 11 Jun 2026 20:27:11 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 11 Jun 2026 20:27:11 +0200
changeset 1189
6efc3994e8dd
parent 1188
92841501de20
child 1190
7dcd5994c9a5

make sure menus are initialized when a new window is opened

ui/cocoa/AppDelegate.m file | annotate | diff | comparison | revisions
ui/cocoa/menu.m file | annotate | diff | comparison | revisions
ui/cocoa/window.m file | annotate | diff | comparison | revisions
ui/common/app.c file | annotate | diff | comparison | revisions
ui/common/app.h file | annotate | diff | comparison | revisions
--- a/ui/cocoa/AppDelegate.m	Wed Jun 10 18:04:30 2026 +0200
+++ b/ui/cocoa/AppDelegate.m	Thu Jun 11 20:27:11 2026 +0200
@@ -38,9 +38,15 @@
 
 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
     NSLog(@"toolkit applicationDidFinishLaunching");
-    uic_application_init(NULL);
     ui_menu_init();
     uic_application_startup(NULL);
+    // run ui_menu_init again, because it is possible, that the startup func
+    // added menus (which is probably true when using other language bindings)
+    // the menu init func can be called multiple times and is also called
+    // when a new window is created
+    // The only usecase for calling init here is, that an application might not
+    // open a window on startup, but wants a working menubar
+    ui_menu_init();
 }
 
 - (void)applicationWillTerminate:(NSNotification *)aNotification {
--- a/ui/cocoa/menu.m	Wed Jun 10 18:04:30 2026 +0200
+++ b/ui/cocoa/menu.m	Thu Jun 11 20:27:11 2026 +0200
@@ -186,7 +186,14 @@
 }
 
 
+static BOOL menu_is_initialized = NO;
+
 void ui_menu_init(void) {
+    if(menu_is_initialized) {
+        return;
+    }
+    menu_is_initialized = YES;
+    
     bindingItems = [[NSMutableArray alloc] init];
     
     UiMenu *menus_begin = uic_get_menu_list();
--- a/ui/cocoa/window.m	Wed Jun 10 18:04:30 2026 +0200
+++ b/ui/cocoa/window.m	Thu Jun 11 20:27:11 2026 +0200
@@ -32,6 +32,7 @@
 #import "WindowManager.h"
 #import "BoxContainer.h"
 #import "EventData.h"
+#import "menu.h"
 
 #import <objc/runtime.h>
 
@@ -58,6 +59,7 @@
 }
 
 static UiObject* create_window(const char *title, BOOL simple, BOOL sidebar, BOOL splitview) {
+    ui_menu_init();
     UiObject *obj = uic_object_new_toplevel();
     
     int width = window_default_width;
--- a/ui/common/app.c	Wed Jun 10 18:04:30 2026 +0200
+++ b/ui/common/app.c	Thu Jun 11 20:27:11 2026 +0200
@@ -28,8 +28,6 @@
 
 #include "app.h"
 
-static ui_callback   init_func;
-static void          *init_data;
 static ui_callback   startup_func;
 static void          *startup_data;
 static ui_callback   newwindow_func;
@@ -40,11 +38,6 @@
 void                 *exit_data;
 
 
-void ui_oninit(ui_callback f, void *userdata) {
-    init_func = f;
-    init_data = userdata;
-}
-
 void ui_onstartup(ui_callback f, void *userdata) {
     startup_func = f;
     startup_data = userdata;
@@ -65,12 +58,6 @@
     exit_data = userdata;
 }
 
-void uic_application_init(UiEvent *event) {
-    if(init_func) {
-        init_func(event, init_data);
-    }
-}
-
 void uic_application_startup(UiEvent *event) {
     if(startup_func) {
         startup_func(event, startup_data);
--- a/ui/common/app.h	Wed Jun 10 18:04:30 2026 +0200
+++ b/ui/common/app.h	Thu Jun 11 20:27:11 2026 +0200
@@ -35,7 +35,6 @@
 extern "C" {
 #endif
 
-void uic_application_init(UiEvent *event);
 void uic_application_startup(UiEvent *event);
 void uic_application_newwindow(UiEvent *event);
 void uic_application_open(UiEvent *event);

mercurial