mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibGUI: Make MenuBar a Core::Object
This makes it show up in Inspector with all the menus inside it. :^)
This commit is contained in:
parent
a19690170f
commit
52a250cb61
Notes:
sideshowbarker
2024-07-19 07:25:03 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/52a250cb614
28 changed files with 36 additions and 38 deletions
|
@ -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&) {
|
||||
|
|
|
@ -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&) {
|
||||
|
|
|
@ -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 },
|
||||
|
|
|
@ -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&) {
|
||||
|
|
|
@ -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&) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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&) {
|
||||
|
|
|
@ -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&) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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&) {
|
||||
|
|
|
@ -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&) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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&) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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(); }));
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -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(); }));
|
||||
|
|
|
@ -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({});
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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&) {
|
||||
|
|
Loading…
Reference in a new issue