1 | // Aseprite |
---|---|
2 | // Copyright (C) 2020-2022 Igara Studio S.A |
3 | // Copyright (C) 2001-2015 David Capello |
4 | // |
5 | // This program is distributed under the terms of |
6 | // the End-User License Agreement for Aseprite. |
7 | |
8 | #ifdef HAVE_CONFIG_H |
9 | #include "config.h" |
10 | #endif |
11 | |
12 | #include "app/ui/main_menu_bar.h" |
13 | |
14 | #include "app/app.h" |
15 | #include "app/app_menus.h" |
16 | #include "app/extensions.h" |
17 | |
18 | namespace app { |
19 | |
20 | MainMenuBar::MainMenuBar() |
21 | // We process Alt+mnemonics with ShowMenu commands (instead of the |
22 | // integrated method in ui::MenuBox::onProcessMessage()). |
23 | : MenuBar(MenuBar::ProcessTopLevelShortcuts::kNo) |
24 | { |
25 | Extensions& extensions = App::instance()->extensions(); |
26 | |
27 | // Reload the main menu if there are changes in keyboard shortcuts |
28 | // or scripts when extensions are installed/uninstalled or |
29 | // enabled/disabled. |
30 | m_extKeys = extensions.KeysChange.connect( [this]{ reload(); }); |
31 | m_extScripts = extensions.ScriptsChange.connect( [this]{ reload(); }); |
32 | } |
33 | |
34 | void MainMenuBar::reload() |
35 | { |
36 | setMenu(nullptr); |
37 | |
38 | // Reload all menus. |
39 | AppMenus::instance()->reload(); |
40 | |
41 | setMenu(AppMenus::instance()->getRootMenu()); |
42 | if (auto p = parent()) |
43 | p->layout(); |
44 | } |
45 | |
46 | } // namespace app |
47 |