diff options
author | Thomas Goyne <plorkyeran@aegisub.org> | 2016-03-13 12:04:17 -0700 |
---|---|---|
committer | Andrej Shadura <andrewsh@debian.org> | 2022-07-20 16:13:45 +0200 |
commit | 46ce428af3f1a8403394534239cfcb1457785102 (patch) | |
tree | e7b682662bb7d543523858d894944c6ce07e32ae | |
parent | 7bc91ce9dbfa138ea5d83b3846f4289d923fe1fb (diff) |
[PATCH] Add the standard OS X "Window" menu
Gbp-Pq: Name osx-menu.patch
-rw-r--r-- | src/menu.cpp | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/src/menu.cpp b/src/menu.cpp index 4c3848e..13e054b 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -27,6 +27,7 @@ #include "format.h" #include "libresrc/libresrc.h" #include "options.h" +#include "utils.h" #include <libaegisub/cajun/reader.h> #include <libaegisub/hotkey.h> @@ -170,6 +171,10 @@ public: { } + void SetContext(agi::Context *c) { + context = c; + } + int AddCommand(cmd::Command *co, wxMenu *parent, std::string const& text = "") { return AddCommand(co, parent, text.empty() ? co->StrMenu(context) : _(to_wx(text))); } @@ -229,6 +234,8 @@ public: } void OnMenuOpen(wxMenuEvent &) { + if (!context) + return; for (auto const& item : dynamic_items) UpdateItem(item); for (auto item : mru) item->Update(); } @@ -237,7 +244,7 @@ public: // This also gets clicks on unrelated things such as the toolbar, so // the window ID ranges really need to be unique size_t id = static_cast<size_t>(evt.GetId() - MENU_ID_BASE); - if (id < items.size()) + if (id < items.size() && context) cmd::call(items[id], context); #ifdef __WXMAC__ @@ -336,6 +343,11 @@ void process_menu_item(wxMenu *parent, agi::Context *c, json::Object const& ele, std::string submenu, recent, command, text, special; read_entry(ele, "special", &special); +#ifdef __WXMAC__ + if (special == "window") + osx::make_windows_menu(parent); +#endif + if (read_entry(ele, "submenu", &submenu) && read_entry(ele, "text", &text)) { wxString tl_text = _(to_wx(text)); parent->AppendSubMenu(build_menu(submenu, c, cm), tl_text); @@ -487,6 +499,21 @@ public: namespace menu { void GetMenuBar(std::string const& name, wxFrame *window, agi::Context *c) { +#ifdef __WXMAC__ + auto bind_events = [&](CommandMenuBar *menu) { + window->Bind(wxEVT_ACTIVATE, [=](wxActivateEvent&) { menu->cm.SetContext(c); }); + window->Bind(wxEVT_DESTROY, [=](wxWindowDestroyEvent&) { + if (!osx::activate_top_window_other_than(window)) + menu->cm.SetContext(nullptr); + }); + }; + + if (wxMenuBar *menu = wxMenuBar::MacGetCommonMenuBar()) { + bind_events(static_cast<CommandMenuBar *>(menu)); + return; + } +#endif + auto menu = agi::make_unique<CommandMenuBar>(c); for (auto const& item : get_menu(name)) { std::string submenu, disp; @@ -502,9 +529,15 @@ namespace menu { } } - window->Bind(wxEVT_MENU_OPEN, &CommandManager::OnMenuOpen, &menu->cm); - window->Bind(wxEVT_MENU, &CommandManager::OnMenuClick, &menu->cm); + menu->Bind(wxEVT_MENU_OPEN, &CommandManager::OnMenuOpen, &menu->cm); + menu->Bind(wxEVT_MENU, &CommandManager::OnMenuClick, &menu->cm); + +#ifdef __WXMAC__ + bind_events(menu.get()); + wxMenuBar::MacSetCommonMenuBar(menu.get()); +#else window->SetMenuBar(menu.get()); +#endif menu.release(); } |