Userland: Turn all application menus into window menus :^)

This commit is contained in:
Andreas Kling 2021-03-25 21:41:39 +01:00
parent fcc8e3484f
commit 78b12e1521
Notes: sideshowbarker 2024-07-18 21:05:37 +09:00
47 changed files with 100 additions and 110 deletions

View file

@ -290,7 +290,7 @@ Tab::Tab(Type type)
m_menubar = GUI::MenuBar::construct();
auto& app_menu = m_menubar->add_menu("Browser");
auto& app_menu = m_menubar->add_menu("File");
app_menu.add_action(WindowActions::the().create_new_tab_action());
app_menu.add_action(GUI::Action::create(
"Close tab", { Mod_Ctrl, Key_W }, Gfx::Bitmap::load_from_file("/res/icons/16x16/close-tab.png"), [this](auto&) {
@ -568,7 +568,7 @@ void Tab::did_become_active()
m_toolbar_container->set_visible(!is_fullscreen);
m_statusbar->set_visible(!is_fullscreen);
GUI::Application::the()->set_menubar(m_menubar);
window()->set_menubar(m_menubar);
}
void Tab::context_menu_requested(const Gfx::IntPoint& screen_position)

View file

@ -71,10 +71,9 @@ int main(int argc, char** argv)
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Calculator");
auto& app_menu = menubar->add_menu("File");
app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {
GUI::Application::the()->quit();
return;
}));
auto& edit_menu = menubar->add_menu("Edit");
@ -93,8 +92,6 @@ int main(int argc, char** argv)
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::CommonActions::make_about_action("Calculator", app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
return app->exec();
}

View file

@ -159,7 +159,7 @@ int main(int argc, char** argv)
};
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Calendar");
auto& app_menu = menubar->add_menu("File");
app_menu.add_action(GUI::Action::create("Add Event", { Mod_Ctrl | Mod_Shift, Key_E }, Gfx::Bitmap::load_from_file("/res/icons/16x16/add-event.png"),
[&](const GUI::Action&) {
AddEventDialog::show(calendar_widget.selected_date(), window);
@ -176,7 +176,7 @@ int main(int argc, char** argv)
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::CommonActions::make_about_action("Calendar", app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
window->show();
app->exec();
}

View file

@ -68,7 +68,7 @@ int main(int argc, char** argv)
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Display Settings");
auto& app_menu = menubar->add_menu("File");
app_menu.add_action(GUI::CommonActions::make_quit_action([&](const GUI::Action&) {
app->quit();
}));
@ -76,7 +76,7 @@ int main(int argc, char** argv)
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::CommonActions::make_about_action("Display Settings", app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
window->show();
return app->exec();
}

View file

@ -755,7 +755,7 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("File Manager");
auto& app_menu = menubar->add_menu("File");
app_menu.add_action(mkdir_action);
app_menu.add_action(touch_action);
app_menu.add_action(copy_action);
@ -814,7 +814,7 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::CommonActions::make_about_action("File Manager", GUI::Icon::default_icon("app-file-manager"), window));
GUI::Application::the()->set_menubar(move(menubar));
window->set_menubar(menubar);
main_toolbar.add_action(go_back_action);
main_toolbar.add_action(go_forward_action);

View file

@ -106,7 +106,7 @@ int main(int argc, char** argv)
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Font Editor");
auto& app_menu = menubar->add_menu("File");
app_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) {
Optional<String> open_path = GUI::FilePicker::get_open_filepath(window);
if (!open_path.has_value())
@ -138,7 +138,6 @@ int main(int argc, char** argv)
app_menu.add_separator();
app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) {
app->quit();
return;
}));
auto& help_menu = menubar->add_menu("Help");
@ -148,8 +147,7 @@ int main(int argc, char** argv)
help_menu.add_action(GUI::CommonActions::make_about_action("Font Editor", app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
window->show();
return app->exec();

View file

@ -274,7 +274,7 @@ int main(int argc, char* argv[])
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Help");
auto& app_menu = menubar->add_menu("File");
app_menu.add_action(GUI::CommonActions::make_about_action("Help", app_icon, window));
app_menu.add_separator();
app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {
@ -286,7 +286,7 @@ int main(int argc, char* argv[])
go_menu.add_action(*go_forward_action);
go_menu.add_action(*go_home_action);
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
if (start_page) {
URL url = URL::create_with_url_or_path(start_page);

View file

@ -137,7 +137,7 @@ HexEditorWidget::~HexEditorWidget()
void HexEditorWidget::initialize_menubar(GUI::MenuBar& menubar)
{
auto& app_menu = menubar.add_menu("Hex Editor");
auto& app_menu = menubar.add_menu("File");
app_menu.add_action(*m_new_action);
app_menu.add_action(*m_open_action);
app_menu.add_action(*m_save_action);

View file

@ -61,8 +61,7 @@ int main(int argc, char** argv)
auto menubar = GUI::MenuBar::construct();
hex_editor_widget.initialize_menubar(menubar);
app->set_menubar(menubar);
window->set_menubar(menubar);
window->show();
window->set_icon(app_icon.bitmap_for_size(16));

View file

@ -258,7 +258,7 @@ void IRCAppWindow::setup_actions()
void IRCAppWindow::setup_menus()
{
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("IRC Client");
auto& app_menu = menubar->add_menu("File");
app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {
dbgln("Terminal: Quit menu activated!");
GUI::Application::the()->quit();
@ -297,7 +297,7 @@ void IRCAppWindow::setup_menus()
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::CommonActions::make_about_action("IRC Client", GUI::Icon::default_icon("app-irc-client"), this));
GUI::Application::the()->set_menubar(move(menubar));
set_menubar(move(menubar));
}
void IRCAppWindow::setup_widgets()

View file

@ -106,7 +106,7 @@ int main(int argc, char** argv)
// Menu
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Keyboard Mapper");
auto& app_menu = menubar->add_menu("File");
app_menu.add_action(open_action);
app_menu.add_action(save_action);
app_menu.add_action(save_as_action);
@ -116,7 +116,7 @@ int main(int argc, char** argv)
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::CommonActions::make_about_action("Keyboard Mapper", app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
return app->exec();
}

View file

@ -188,13 +188,13 @@ int main(int argc, char** argv)
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Keyboard Settings");
auto& app_menu = menubar->add_menu("File");
app_menu.add_action(quit_action);
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::CommonActions::make_about_action("Keyboard Settings", app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
window->show();

View file

@ -120,13 +120,13 @@ int main(int argc, char** argv)
};
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Mouse Settings");
auto& app_menu = menubar->add_menu("File");
app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) {
app->quit();
}));
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::CommonActions::make_about_action("Mouse Settings", app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
window->show();
return app->exec();

View file

@ -106,7 +106,7 @@ int main(int argc, char** argv)
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Piano");
auto& app_menu = menubar->add_menu("File");
app_menu.add_action(GUI::Action::create("Export", { Mod_Ctrl, Key_E }, [&](const GUI::Action&) {
save_path = GUI::FilePicker::get_save_filepath(window, "Untitled", "wav");
if (!save_path.has_value())
@ -131,7 +131,7 @@ int main(int argc, char** argv)
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::CommonActions::make_about_action("Piano", app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
return app->exec();
}

View file

@ -115,7 +115,7 @@ int main(int argc, char** argv)
window->show();
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("PixelPaint");
auto& app_menu = menubar->add_menu("File");
auto open_image_file = [&](auto& path) {
auto image = PixelPaint::Image::create_from_file(path);
@ -382,7 +382,7 @@ int main(int argc, char** argv)
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::CommonActions::make_about_action("PixelPaint", app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
image_editor.on_active_layer_change = [&](auto* layer) {
layer_list_widget.set_selected_layer(layer);

View file

@ -275,7 +275,7 @@ int main(int argc, char** argv)
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("QuickShow");
auto& app_menu = menubar->add_menu("File");
app_menu.add_action(open_action);
app_menu.add_action(delete_action);
app_menu.add_separator();
@ -310,7 +310,7 @@ int main(int argc, char** argv)
}));
help_menu.add_action(GUI::CommonActions::make_about_action("QuickShow", app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
if (path != nullptr) {
widget.load_from_file(path);

View file

@ -66,7 +66,7 @@ int main(int argc, char** argv)
window->set_icon(app_icon.bitmap_for_size(16));
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Sound Player");
auto& app_menu = menubar->add_menu("File");
auto& player = window->set_main_widget<SoundPlayerWidget>(window, audio_client);
if (argc > 1) {
@ -102,7 +102,7 @@ int main(int argc, char** argv)
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::CommonActions::make_about_action("Sound Player", app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
window->show();
return app->exec();

View file

@ -291,7 +291,7 @@ int main(int argc, char* argv[])
// Configure the menubar.
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu(APP_NAME);
auto& app_menu = menubar->add_menu("File");
app_menu.add_action(GUI::Action::create("Analyze", [&](auto&) {
analyze(tree, treemapwidget, statusbar);
}));
@ -300,7 +300,7 @@ int main(int argc, char* argv[])
}));
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::CommonActions::make_about_action(APP_NAME, app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
// Configure the nodes context menu.
auto open_folder_action = GUI::Action::create("Open Folder", { Mod_Ctrl, Key_O }, Gfx::Bitmap::load_from_file("/res/icons/16x16/open.png"), [&](auto&) {

View file

@ -111,7 +111,7 @@ int main(int argc, char* argv[])
spreadsheet_widget.load(filename);
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Spreadsheet");
auto& app_menu = menubar->add_menu("File");
app_menu.add_action(GUI::Action::create("Add New Sheet", Gfx::Bitmap::load_from_file("/res/icons/16x16/new-tab.png"), [&](auto&) {
spreadsheet_widget.add_sheet();
@ -270,7 +270,7 @@ int main(int argc, char* argv[])
help_menu.add_action(GUI::CommonActions::make_about_action("Spreadsheet", app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
window->show();

View file

@ -279,10 +279,9 @@ int main(int argc, char** argv)
});
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("System Monitor");
auto& app_menu = menubar->add_menu("File");
app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {
GUI::Application::the()->quit();
return;
}));
auto& process_menu = menubar->add_menu("Process");
@ -324,7 +323,7 @@ int main(int argc, char** argv)
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::CommonActions::make_about_action("System Monitor", app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
auto& process_tab_unused_widget = process_container_splitter->add<UnavailableProcessWidget>("No process selected");
process_tab_unused_widget.set_visible(true);

View file

@ -428,7 +428,7 @@ int main(int argc, char** argv)
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Terminal");
auto& app_menu = menubar->add_menu("File");
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&) {
pid_t child;
const char* argv[] = { "Terminal", nullptr };
@ -473,7 +473,8 @@ int main(int argc, char** argv)
}));
help_menu.add_action(GUI::CommonActions::make_about_action("Terminal", app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(menubar);
window->set_menubar(menubar);
if (unveil("/res", "r") < 0) {
perror("unveil");

View file

@ -361,7 +361,7 @@ TextEditorWidget::~TextEditorWidget()
void TextEditorWidget::initialize_menubar(GUI::MenuBar& menubar)
{
auto& app_menu = menubar.add_menu("Text Editor");
auto& app_menu = menubar.add_menu("File");
app_menu.add_action(*m_new_action);
app_menu.add_action(*m_open_action);
app_menu.add_action(*m_save_action);

View file

@ -87,7 +87,7 @@ int main(int argc, char** argv)
auto menubar = GUI::MenuBar::construct();
text_widget.initialize_menubar(menubar);
app->set_menubar(menubar);
window->set_menubar(menubar);
if (file_to_edit)
if (!text_widget.open_file(file_to_edit))
@ -101,5 +101,7 @@ int main(int argc, char** argv)
window->show();
window->set_icon(app_icon.bitmap_for_size(16));
window->set_menubar(menubar);
return app->exec();
}

View file

@ -234,11 +234,11 @@ int main(int argc, char** argv)
root_widget.layout()->set_spacing(0);
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("CatDog Demo");
auto& app_menu = menubar->add_menu("File");
app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); }));
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::CommonActions::make_about_action("CatDog Demo", app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
window->show();
root_widget.track_cursor_globally();

View file

@ -264,7 +264,7 @@ int main(int argc, char** argv)
window->set_icon(app_icon.bitmap_for_size(16));
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Cube Demo");
auto& app_menu = menubar->add_menu("File");
auto show_window_frame_action = GUI::Action::create_checkable("Show window frame", [&](auto& action) {
cube.set_show_window_frame(action.is_checked());
});
@ -276,7 +276,7 @@ int main(int argc, char** argv)
app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); }));
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::CommonActions::make_about_action("Cube Demo", app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
cube.on_context_menu_request = [&](auto& event) {
app_menu.popup(event.screen_position());

View file

@ -100,13 +100,13 @@ int main(int argc, char* argv[])
auto& eyes = window->set_main_widget<EyesWidget>(num_eyes, full_rows, extra_columns);
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Eyes Demo");
auto& app_menu = menubar->add_menu("File");
app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); }));
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::CommonActions::make_about_action("Eyes Demo", app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
window->show();
eyes.track_cursor_globally();

View file

@ -199,13 +199,13 @@ int main(int argc, char** argv)
main_widget.set_fill_with_background_color(true);
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Mouse Demo");
auto& app_menu = menubar->add_menu("File");
app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); }));
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::CommonActions::make_about_action("Mouse Demo", app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
window->set_resizable(false);
window->show();
return app->exec();

View file

@ -77,14 +77,13 @@ int main(int argc, char** argv)
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Widget Gallery");
auto& app_menu = menubar->add_menu("File");
app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); }));
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::CommonActions::make_about_action("Widget Gallery", app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
window->show();
return app->exec();

View file

@ -888,7 +888,7 @@ void HackStudioWidget::create_action_tab(GUI::Widget& parent)
void HackStudioWidget::create_app_menubar(GUI::MenuBar& menubar)
{
auto& app_menu = menubar.add_menu("Hack Studio");
auto& app_menu = menubar.add_menu("File");
app_menu.add_action(*m_new_project_action);
app_menu.add_action(*m_open_action);
app_menu.add_action(*m_save_action);

View file

@ -99,7 +99,7 @@ int main(int argc, char** argv)
auto menubar = GUI::MenuBar::construct();
s_hack_studio_widget->initialize_menubar(menubar);
app->set_menubar(menubar);
s_window->set_menubar(menubar);
s_window->show();

View file

@ -129,7 +129,7 @@ int main(int argc, char** argv)
window->set_icon(app_icon.bitmap_for_size(16));
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Inspector");
auto& app_menu = menubar->add_menu("File");
app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); }));
auto& help_menu = menubar->add_menu("Help");
@ -168,7 +168,7 @@ int main(int argc, char** argv)
remote_process.set_inspected_object(remote_object->address);
};
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
window->show();
remote_process.update();

View file

@ -330,7 +330,7 @@ int main(int argc, char** argv)
};
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("GML Playground");
auto& app_menu = menubar->add_menu("File");
app_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) {
Optional<String> open_path = GUI::FilePicker::get_open_filepath(window);
@ -400,7 +400,7 @@ int main(int argc, char** argv)
}));
help_menu.add_action(GUI::CommonActions::make_about_action("GML Playground", app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
window->show();
return app->exec();

View file

@ -141,7 +141,7 @@ int main(int argc, char** argv)
};
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Profiler");
auto& app_menu = menubar->add_menu("File");
app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); }));
auto& view_menu = menubar->add_menu("View");
@ -185,8 +185,7 @@ int main(int argc, char** argv)
}));
help_menu.add_action(GUI::CommonActions::make_about_action("Profiler", app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
window->show();
return app->exec();
}

View file

@ -180,7 +180,7 @@ int main(int argc, char** argv)
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("2048");
auto& app_menu = menubar->add_menu("File");
app_menu.add_action(GUI::Action::create("New game", { Mod_None, Key_F2 }, [&](auto&) {
start_a_new_game();
@ -206,7 +206,7 @@ int main(int argc, char** argv)
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::CommonActions::make_about_action("2048", app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
window->show();

View file

@ -69,23 +69,21 @@ int main(int argc, char** argv)
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Breakout");
auto& app_menu = menubar->add_menu("Game");
app_menu.add_action(GUI::Action::create_checkable("Pause", { {}, Key_P }, [&](auto& action) {
game.set_paused(action.is_checked());
return;
}));
app_menu.add_separator();
app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {
GUI::Application::the()->quit();
return;
}));
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::CommonActions::make_about_action("Breakout", app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
return app->exec();
}

View file

@ -96,7 +96,7 @@ int main(int argc, char** argv)
widget.set_coordinates(config->read_bool_entry("Style", "Coordinates", true));
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Chess");
auto& app_menu = menubar->add_menu("Game");
app_menu.add_action(GUI::Action::create("Resign", { Mod_None, Key_F3 }, [&](auto&) {
widget.resign();
@ -223,7 +223,7 @@ int main(int argc, char** argv)
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::CommonActions::make_about_action("Chess", app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
window->show();
widget.reset();

View file

@ -71,7 +71,7 @@ int main(int argc, char** argv)
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Conway");
auto& app_menu = menubar->add_menu("Game");
app_menu.add_action(GUI::Action::create("Reset", { Mod_None, Key_F2 }, [&](auto&) {
game.reset();
@ -84,7 +84,7 @@ int main(int argc, char** argv)
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::CommonActions::make_about_action("Conway", app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
window->show();

View file

@ -105,7 +105,7 @@ int main(int argc, char** argv)
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Minesweeper");
auto& app_menu = menubar->add_menu("Game");
app_menu.add_action(GUI::Action::create("New game", { Mod_None, Key_F2 }, [&](auto&) {
field.reset();
@ -143,7 +143,7 @@ int main(int argc, char** argv)
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::CommonActions::make_about_action("Minesweeper", app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
window->show();

View file

@ -76,16 +76,15 @@ int main(int argc, char** argv)
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Pong");
auto& app_menu = menubar->add_menu("Game");
app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {
GUI::Application::the()->quit();
return;
}));
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::CommonActions::make_about_action("Pong", app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
return app->exec();
}

View file

@ -80,7 +80,7 @@ int main(int argc, char** argv)
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Snake");
auto& app_menu = menubar->add_menu("Game");
app_menu.add_action(GUI::Action::create("New game", { Mod_None, Key_F2 }, [&](auto&) {
game.reset();
@ -93,7 +93,7 @@ int main(int argc, char** argv)
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::CommonActions::make_about_action("Snake", app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
window->show();

View file

@ -64,7 +64,7 @@ int main(int argc, char** argv)
});
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("Solitaire");
auto& app_menu = menubar->add_menu("Game");
app_menu.add_action(GUI::Action::create("New game", { Mod_None, Key_F2 }, [&](auto&) {
widget->setup();
@ -75,7 +75,7 @@ int main(int argc, char** argv)
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::CommonActions::make_about_action("Solitaire", app_icon, window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
window->set_main_widget(widget);
window->set_icon(app_icon.bitmap_for_size(16));
window->show();

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -125,15 +125,6 @@ void Application::quit(int exit_code)
m_event_loop->quit(exit_code);
}
void Application::set_menubar(RefPtr<MenuBar> menubar)
{
if (m_menubar)
m_menubar->notify_removed_from_application({});
m_menubar = move(menubar);
if (m_menubar)
m_menubar->notify_added_to_application({});
}
void Application::register_global_shortcut_action(Badge<Action>, Action& action)
{
m_global_shortcut_actions.set(action.shortcut(), &action);

View file

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

View file

@ -61,7 +61,7 @@ void MenuBar::unrealize_menubar()
m_menubar_id = -1;
}
void MenuBar::notify_added_to_application(Badge<Application>)
void MenuBar::notify_added_to_window(Badge<Window>)
{
VERIFY(m_menubar_id == -1);
m_menubar_id = realize_menubar();
@ -71,10 +71,9 @@ void MenuBar::notify_added_to_application(Badge<Application>)
VERIFY(menu_id != -1);
WindowServerConnection::the().send_sync<Messages::WindowServer::AddMenuToMenubar>(m_menubar_id, menu_id);
}
WindowServerConnection::the().send_sync<Messages::WindowServer::SetApplicationMenubar>(m_menubar_id);
}
void MenuBar::notify_removed_from_application(Badge<Application>)
void MenuBar::notify_removed_from_window(Badge<Window>)
{
unrealize_menubar();
}

View file

@ -41,8 +41,8 @@ public:
Menu& add_menu(String name);
void notify_added_to_application(Badge<Application>);
void notify_removed_from_application(Badge<Application>);
void notify_added_to_window(Badge<Window>);
void notify_removed_from_window(Badge<Window>);
int menubar_id() const { return m_menubar_id; }

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -110,6 +110,8 @@ Window::Window(Core::Object* parent)
Window::~Window()
{
if (m_menubar)
m_menubar->notify_removed_from_window({});
all_windows->remove(this);
hide();
}
@ -161,6 +163,12 @@ void Window::show()
apply_icon();
if (m_menubar) {
// This little dance makes us create a server-side menubar.
auto menubar = move(m_menubar);
set_menubar(menubar);
}
reified_windows->set(m_window_id, this);
Application::the()->did_create_window({});
update();
@ -1057,9 +1065,13 @@ void Window::set_menubar(RefPtr<MenuBar> menubar)
{
if (m_menubar == menubar)
return;
if (m_menubar)
m_menubar->notify_removed_from_window({});
m_menubar = move(menubar);
if (m_window_id && m_menubar)
if (m_window_id && m_menubar) {
m_menubar->notify_added_to_window({});
WindowServerConnection::the().send_sync<Messages::WindowServer::SetWindowMenubar>(m_window_id, m_menubar->menubar_id());
}
}
}

View file

@ -69,7 +69,7 @@ int main(int argc, char** argv)
auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("HTML");
auto& app_menu = menubar->add_menu("File");
app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) {
app->quit();
}));
@ -77,8 +77,7 @@ int main(int argc, char** argv)
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::CommonActions::make_about_action("HTML", GUI::Icon::default_icon("filetype-html"), window));
app->set_menubar(move(menubar));
window->set_menubar(move(menubar));
window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-html.png"));
return app->exec();