mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:17:35 +00:00
Userland: Add GUI::Window::add_menu() and use it everywhere
Applications previously had to create a GUI::Menubar object, add menus to it, and then call GUI::Window::set_menubar(). This patch introduces GUI::Window::add_menu() which creates the menubar automatically and adds items to it. Application code becomes slightly simpler as a result. :^)
This commit is contained in:
parent
a4fdb7f029
commit
687a12d7fb
58 changed files with 187 additions and 311 deletions
|
@ -35,11 +35,11 @@ PDFViewerWidget::PDFViewerWidget()
|
|||
};
|
||||
}
|
||||
|
||||
void PDFViewerWidget::initialize_menubar(GUI::Menubar& menubar)
|
||||
void PDFViewerWidget::initialize_menubar(GUI::Window& window)
|
||||
{
|
||||
auto& file_menu = menubar.add_menu("&File");
|
||||
auto& file_menu = window.add_menu("&File");
|
||||
file_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) {
|
||||
Optional<String> open_path = GUI::FilePicker::get_open_filepath(window());
|
||||
Optional<String> open_path = GUI::FilePicker::get_open_filepath(&window);
|
||||
if (open_path.has_value())
|
||||
open_file(open_path.value());
|
||||
}));
|
||||
|
@ -48,8 +48,8 @@ void PDFViewerWidget::initialize_menubar(GUI::Menubar& menubar)
|
|||
GUI::Application::the()->quit();
|
||||
}));
|
||||
|
||||
auto& help_menu = menubar.add_menu("&Help");
|
||||
help_menu.add_action(GUI::CommonActions::make_about_action("PDF Viewer", GUI::Icon::default_icon("app-pdf-viewer"), window()));
|
||||
auto& help_menu = window.add_menu("&Help");
|
||||
help_menu.add_action(GUI::CommonActions::make_about_action("PDF Viewer", GUI::Icon::default_icon("app-pdf-viewer"), &window));
|
||||
}
|
||||
|
||||
void PDFViewerWidget::create_toolbar()
|
||||
|
|
|
@ -21,7 +21,7 @@ class PDFViewerWidget final : public GUI::Widget {
|
|||
public:
|
||||
~PDFViewerWidget() override = default;
|
||||
|
||||
void initialize_menubar(GUI::Menubar&);
|
||||
void initialize_menubar(GUI::Window&);
|
||||
void create_toolbar();
|
||||
void open_file(const String& path);
|
||||
|
||||
|
|
|
@ -21,9 +21,8 @@ int main(int argc, char** argv)
|
|||
|
||||
auto& pdf_viewer_widget = window->set_main_widget<PDFViewerWidget>();
|
||||
|
||||
auto menubar = GUI::Menubar::construct();
|
||||
pdf_viewer_widget.initialize_menubar(menubar);
|
||||
window->set_menubar(menubar);
|
||||
pdf_viewer_widget.initialize_menubar(*window);
|
||||
|
||||
window->show();
|
||||
window->set_icon(app_icon.bitmap_for_size(16));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue