diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-03-28 07:55:21 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-03-28 07:55:21 +0300 |
commit | 9d66bec7f60a9767b7ec0acac747dbfecc87899c (patch) | |
tree | 8ee2c768f4db81a2bf877efa4992387f686f4d18 | |
parent | ea7cc3847d1e4101478137779ecd43cca2218cd7 (diff) |
macOS: Recreate menus after language changes
IssueID #192
-rw-r--r-- | src/macos.h | 1 | ||||
-rw-r--r-- | src/macos.m | 6 | ||||
-rw-r--r-- | src/ui/window.c | 30 |
3 files changed, 31 insertions, 6 deletions
diff --git a/src/macos.h b/src/macos.h index a59351e6..0d3f097a 100644 --- a/src/macos.h +++ b/src/macos.h | |||
@@ -32,6 +32,7 @@ void enableMomentumScroll_MacOS (void); | |||
32 | void registerURLHandler_MacOS (void); | 32 | void registerURLHandler_MacOS (void); |
33 | void setupApplication_MacOS (void); | 33 | void setupApplication_MacOS (void); |
34 | void insertMenuItems_MacOS (const char *menuLabel, int atIndex, const iMenuItem *items, size_t count); | 34 | void insertMenuItems_MacOS (const char *menuLabel, int atIndex, const iMenuItem *items, size_t count); |
35 | void removeMenu_MacOS (int atIndex); | ||
35 | void enableMenu_MacOS (const char *menuLabel, iBool enable); | 36 | void enableMenu_MacOS (const char *menuLabel, iBool enable); |
36 | void enableMenuItem_MacOS (const char *menuItemCommand, iBool enable); | 37 | void enableMenuItem_MacOS (const char *menuItemCommand, iBool enable); |
37 | void enableMenuItemsByKey_MacOS (int key, int kmods, iBool enable); | 38 | void enableMenuItemsByKey_MacOS (int key, int kmods, iBool enable); |
diff --git a/src/macos.m b/src/macos.m index 019533bd..0dcc3ef5 100644 --- a/src/macos.m +++ b/src/macos.m | |||
@@ -460,6 +460,12 @@ static void setShortcut_NSMenuItem_(NSMenuItem *item, int key, int kmods) { | |||
460 | delete_String(str); | 460 | delete_String(str); |
461 | } | 461 | } |
462 | 462 | ||
463 | void removeMenu_MacOS(int atIndex) { | ||
464 | NSApplication *app = [NSApplication sharedApplication]; | ||
465 | NSMenu *appMenu = [app mainMenu]; | ||
466 | [appMenu removeItemAtIndex:atIndex]; | ||
467 | } | ||
468 | |||
463 | void insertMenuItems_MacOS(const char *menuLabel, int atIndex, const iMenuItem *items, size_t count) { | 469 | void insertMenuItems_MacOS(const char *menuLabel, int atIndex, const iMenuItem *items, size_t count) { |
464 | NSApplication *app = [NSApplication sharedApplication]; | 470 | NSApplication *app = [NSApplication sharedApplication]; |
465 | MyDelegate *myDel = (MyDelegate *) app.delegate; | 471 | MyDelegate *myDel = (MyDelegate *) app.delegate; |
diff --git a/src/ui/window.c b/src/ui/window.c index 9b132da1..a3675ae5 100644 --- a/src/ui/window.c +++ b/src/ui/window.c | |||
@@ -320,6 +320,24 @@ static const iMenuItem helpMenuItems_[] = { | |||
320 | { "${menu.aboutpages}", 0, 0, "!open url:about:about" }, | 320 | { "${menu.aboutpages}", 0, 0, "!open url:about:about" }, |
321 | { "${menu.debug}", 0, 0, "!open url:about:debug" }, | 321 | { "${menu.debug}", 0, 0, "!open url:about:debug" }, |
322 | }; | 322 | }; |
323 | |||
324 | static void insertMacMenus_(void) { | ||
325 | insertMenuItems_MacOS("${menu.title.file}", 1, fileMenuItems_, iElemCount(fileMenuItems_)); | ||
326 | insertMenuItems_MacOS("${menu.title.edit}", 2, editMenuItems_, iElemCount(editMenuItems_)); | ||
327 | insertMenuItems_MacOS("${menu.title.view}", 3, viewMenuItems_, iElemCount(viewMenuItems_)); | ||
328 | insertMenuItems_MacOS("${menu.title.bookmarks}", 4, bookmarksMenuItems_, iElemCount(bookmarksMenuItems_)); | ||
329 | insertMenuItems_MacOS("${menu.title.identity}", 5, identityMenuItems_, iElemCount(identityMenuItems_)); | ||
330 | insertMenuItems_MacOS("${menu.title.help}", 7, helpMenuItems_, iElemCount(helpMenuItems_)); | ||
331 | } | ||
332 | |||
333 | static void removeMacMenus_(void) { | ||
334 | removeMenu_MacOS(7); | ||
335 | removeMenu_MacOS(5); | ||
336 | removeMenu_MacOS(4); | ||
337 | removeMenu_MacOS(3); | ||
338 | removeMenu_MacOS(2); | ||
339 | removeMenu_MacOS(1); | ||
340 | } | ||
323 | #endif | 341 | #endif |
324 | 342 | ||
325 | #if defined (iPlatformAppleMobile) | 343 | #if defined (iPlatformAppleMobile) |
@@ -1055,12 +1073,7 @@ static void setupUserInterface_Window(iWindow *d) { | |||
1055 | setAlignVisually_LabelWidget(navMenu, iTrue); | 1073 | setAlignVisually_LabelWidget(navMenu, iTrue); |
1056 | setId_Widget(addChildFlags_Widget(navBar, iClob(navMenu), collapse_WidgetFlag), "navbar.menu"); | 1074 | setId_Widget(addChildFlags_Widget(navBar, iClob(navMenu), collapse_WidgetFlag), "navbar.menu"); |
1057 | #else | 1075 | #else |
1058 | insertMenuItems_MacOS("${menu.title.file}", 1, fileMenuItems_, iElemCount(fileMenuItems_)); | 1076 | insertMacMenus_(); |
1059 | insertMenuItems_MacOS("${menu.title.edit}", 2, editMenuItems_, iElemCount(editMenuItems_)); | ||
1060 | insertMenuItems_MacOS("${menu.title.view}", 3, viewMenuItems_, iElemCount(viewMenuItems_)); | ||
1061 | insertMenuItems_MacOS("${menu.title.bookmarks}", 4, bookmarksMenuItems_, iElemCount(bookmarksMenuItems_)); | ||
1062 | insertMenuItems_MacOS("${menu.title.identity}", 5, identityMenuItems_, iElemCount(identityMenuItems_)); | ||
1063 | insertMenuItems_MacOS("${menu.title.help}", 7, helpMenuItems_, iElemCount(helpMenuItems_)); | ||
1064 | #endif | 1077 | #endif |
1065 | } | 1078 | } |
1066 | /* Tab bar. */ { | 1079 | /* Tab bar. */ { |
@@ -1821,6 +1834,11 @@ iBool processEvent_Window(iWindow *d, const SDL_Event *ev) { | |||
1821 | updateMetrics_Window_(d); | 1834 | updateMetrics_Window_(d); |
1822 | } | 1835 | } |
1823 | if (isCommand_UserEvent(&event, "lang.changed")) { | 1836 | if (isCommand_UserEvent(&event, "lang.changed")) { |
1837 | #if defined (iPlatformAppleDesktop) | ||
1838 | /* Retranslate the menus. */ | ||
1839 | removeMacMenus_(); | ||
1840 | insertMacMenus_(); | ||
1841 | #endif | ||
1824 | invalidate_Window_(d); | 1842 | invalidate_Window_(d); |
1825 | arrange_Widget(d->root); | 1843 | arrange_Widget(d->root); |
1826 | } | 1844 | } |