LibGUI: Make MenuBar a Core::Object

This makes it show up in Inspector with all the menus inside it. :^)
This commit is contained in:
Andreas Kling 2020-04-21 16:01:00 +02:00
parent a19690170f
commit 52a250cb61
Notes: sideshowbarker 2024-07-19 07:25:03 +09:00
28 changed files with 36 additions and 38 deletions

View file

@ -228,7 +228,7 @@ int main(int argc, char** argv)
statusbar.set_text(String::format("Loading (%d pending resources...)", Web::ResourceLoader::the().pending_loads()));
};
auto menubar = make<GUI::MenuBar>();
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Browser");
app_menu.add_action(GUI::Action::create("Reload", { Mod_None, Key_F5 }, Gfx::Bitmap::load_from_file("/res/icons/16x16/reload.png"), [&](auto&) {

View file

@ -65,7 +65,7 @@ int main(int argc, char** argv)
window->show();
window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-calculator.png"));
auto menubar = make<GUI::MenuBar>();
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Calculator");
app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {

View file

@ -65,7 +65,7 @@ int main(int argc, char** argv)
window->show();
window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-calendar.png"));
auto menubar = make<GUI::MenuBar>();
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Calendar");
app_menu.add_action(GUI::Action::create("Add Event", { Mod_Ctrl | Mod_Shift, Key_E },

View file

@ -92,7 +92,7 @@ int main(int argc, char** argv)
window->show();
auto menubar = make<GUI::MenuBar>();
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("ChanViewer");
app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {

View file

@ -60,7 +60,7 @@ int main(int argc, char** argv)
window->set_main_widget(instance.root_widget());
window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-display-properties.png"));
auto menubar = make<GUI::MenuBar>();
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Display Properties");
app_menu.add_action(GUI::CommonActions::make_quit_action([&](const GUI::Action&) {

View file

@ -534,7 +534,7 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
},
window);
auto menubar = make<GUI::MenuBar>();
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("File Manager");
app_menu.add_action(mkdir_action);

View file

@ -74,7 +74,7 @@ int main(int argc, char** argv)
window->show();
window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-font-editor.png"));
auto menubar = make<GUI::MenuBar>();
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Font Editor");
app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {

View file

@ -177,7 +177,7 @@ int main(int argc, char* argv[])
toolbar.add_action(*go_back_action);
toolbar.add_action(*go_forward_action);
auto menubar = make<GUI::MenuBar>();
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Help");
app_menu.add_action(GUI::Action::create("About", [&](const GUI::Action&) {

View file

@ -132,7 +132,7 @@ HexEditorWidget::HexEditorWidget()
dbg() << "Wrote document to " << save_path.value();
});
auto menubar = make<GUI::MenuBar>();
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Hex Editor");
app_menu.add_action(*m_new_action);
app_menu.add_action(*m_open_action);

View file

@ -259,7 +259,7 @@ void IRCAppWindow::setup_actions()
void IRCAppWindow::setup_menus()
{
auto menubar = make<GUI::MenuBar>();
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("IRC Client");
app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {
dbgprintf("Terminal: Quit menu activated!\n");

View file

@ -74,7 +74,7 @@ int main(int argc, char** argv)
window->show();
auto menubar = make<GUI::MenuBar>();
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("PaintBrush");
app_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) {

View file

@ -92,7 +92,7 @@ int main(int argc, char** argv)
});
audio_thread.start();
auto menubar = make<GUI::MenuBar>();
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Piano");
app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {

View file

@ -234,7 +234,7 @@ int main(int argc, char** argv)
main_toolbar.add_action(zoom_in_action);
main_toolbar.add_action(zoom_out_action);
auto menubar = make<GUI::MenuBar>();
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("QuickShow");
app_menu.add_action(open_action);

View file

@ -64,7 +64,7 @@ int main(int argc, char** argv)
window->set_rect(300, 300, 350, 140);
window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-sound-player.png"));
auto menubar = make<GUI::MenuBar>();
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("SoundPlayer");
auto& player = window->set_main_widget<SoundPlayerWidget>(window, audio_client);

View file

@ -174,7 +174,7 @@ int main(int argc, char** argv)
toolbar.add_action(stop_action);
toolbar.add_action(continue_action);
auto menubar = make<GUI::MenuBar>();
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("System Monitor");
app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {
GUI::Application::the().quit(0);

View file

@ -243,7 +243,7 @@ int main(int argc, char** argv)
terminal.set_opacity(new_opacity);
window->set_has_alpha_channel(new_opacity < 255);
auto menubar = make<GUI::MenuBar>();
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Terminal");
app_menu.add_action(GUI::Action::create("Open new terminal", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/app-terminal.png"), [&](auto&) {

View file

@ -341,7 +341,7 @@ TextEditorWidget::TextEditorWidget()
m_line_wrapping_setting_action->set_checkable(true);
m_line_wrapping_setting_action->set_checked(m_editor->is_line_wrapping_enabled());
auto menubar = make<GUI::MenuBar>();
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Text Editor");
app_menu.add_action(*m_new_action);
app_menu.add_action(*m_open_action);

View file

@ -491,7 +491,7 @@ int main(int argc, char** argv)
locator.open();
});
auto menubar = make<GUI::MenuBar>();
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("HackStudio");
app_menu.add_action(open_action);
app_menu.add_action(save_action);

View file

@ -80,7 +80,7 @@ int main(int argc, char** argv)
disassembly_view.set_model(profile->disassembly_model());
};
auto menubar = make<GUI::MenuBar>();
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("ProfileViewer");
app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app.quit(); }));

View file

@ -56,7 +56,7 @@ int main(int argc, char** argv)
propbox->table_view().set_model(widget ? &widget->property_model() : nullptr);
};
auto menubar = make<GUI::MenuBar>();
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Visual Builder");
app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {
GUI::Application::the().quit(0);

View file

@ -80,7 +80,7 @@ int main(int argc, char** argv)
window->resize(size);
});
auto menubar = make<GUI::MenuBar>();
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Minesweeper");

View file

@ -57,7 +57,7 @@ int main(int argc, char** argv)
auto& game = window->set_main_widget<SnakeGame>();
auto menubar = make<GUI::MenuBar>();
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Snake");

View file

@ -51,7 +51,7 @@ int main(int argc, char** argv)
window->set_title(String::format("Score: %u - Solitaire", score));
});
auto menubar = make<GUI::MenuBar>();
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Solitaire");
app_menu.add_action(GUI::Action::create("Restart game", [&](auto&) { widget->setup(); }));

View file

@ -79,7 +79,7 @@ void Application::quit(int exit_code)
m_event_loop->quit(exit_code);
}
void Application::set_menubar(OwnPtr<MenuBar>&& menubar)
void Application::set_menubar(RefPtr<MenuBar> menubar)
{
if (m_menubar)
m_menubar->notify_removed_from_application({});

View file

@ -45,7 +45,7 @@ public:
int exec();
void quit(int = 0);
void set_menubar(OwnPtr<MenuBar>&&);
void set_menubar(RefPtr<MenuBar>);
Action* action_for_key_event(const KeyEvent&);
void register_global_shortcut_action(Badge<Action>, Action&);
@ -70,7 +70,7 @@ public:
private:
OwnPtr<Core::EventLoop> m_event_loop;
OwnPtr<MenuBar> m_menubar;
RefPtr<MenuBar> m_menubar;
RefPtr<Gfx::PaletteImpl> m_palette;
RefPtr<Gfx::PaletteImpl> m_system_palette;
HashMap<Shortcut, Action*> m_global_shortcut_actions;

View file

@ -43,14 +43,9 @@ MenuBar::~MenuBar()
Menu& MenuBar::add_menu(String name)
{
auto menu = Menu::construct(move(name));
append_menu(menu);
return *menu;
}
void MenuBar::append_menu(NonnullRefPtr<Menu> menu)
{
m_menus.append(move(menu));
auto& menu = add<Menu>(move(name));
m_menus.append(menu);
return menu;
}
int MenuBar::realize_menubar()

View file

@ -28,22 +28,25 @@
#include <AK/Forward.h>
#include <AK/NonnullRefPtrVector.h>
#include <LibCore/Object.h>
#include <LibGUI/Forward.h>
namespace GUI {
class MenuBar {
class MenuBar : public Core::Object {
C_OBJECT(MenuBar);
public:
MenuBar();
~MenuBar();
Menu& add_menu(String name);
void append_menu(NonnullRefPtr<Menu>);
void notify_added_to_application(Badge<Application>);
void notify_removed_from_application(Badge<Application>);
private:
MenuBar();
int realize_menubar();
void unrealize_menubar();

View file

@ -72,7 +72,7 @@ int main(int argc, char** argv)
window->set_title("HTML");
window->show();
auto menubar = make<GUI::MenuBar>();
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("HTML");
app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) {