From bb95374b4949fe1e4ad3717ce3001f07ad49a47c Mon Sep 17 00:00:00 2001 From: Slimey <117548228+sl1m3yy@users.noreply.github.com> Date: Sun, 6 Nov 2022 14:16:58 +0000 Subject: [PATCH] VideoPlayer: Add quit action and help menu I also moved the menubar initialization code to VideoPlayerWidget in order to keep all of the bulk out of main.cpp :) --- .../VideoPlayer/VideoPlayerWidget.cpp | 18 ++++++++++++++++++ .../VideoPlayer/VideoPlayerWidget.h | 2 ++ Userland/Applications/VideoPlayer/main.cpp | 11 +---------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp b/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp index 36317349bf..6277892f0c 100644 --- a/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp +++ b/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -200,4 +201,21 @@ void VideoPlayerWidget::update_title() window()->set_title(string_builder.to_string()); } +void VideoPlayerWidget::initialize_menubar(GUI::Window& window) +{ + auto& file_menu = window.add_menu("&File"); + file_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) { + Optional path = GUI::FilePicker::get_open_filepath(&window, "Open video file..."); + if (path.has_value()) + open_file(path.value()); + })); + file_menu.add_separator(); + file_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { + window.close(); + })); + + auto& help_menu = window.add_menu("&Help"); + help_menu.add_action(GUI::CommonActions::make_about_action("Video Player", GUI::Icon::default_icon("window"sv), &window)); +} + } diff --git a/Userland/Applications/VideoPlayer/VideoPlayerWidget.h b/Userland/Applications/VideoPlayer/VideoPlayerWidget.h index c31fe638d8..738ad06025 100644 --- a/Userland/Applications/VideoPlayer/VideoPlayerWidget.h +++ b/Userland/Applications/VideoPlayer/VideoPlayerWidget.h @@ -29,6 +29,8 @@ public: void update_title(); + void initialize_menubar(GUI::Window&); + private: VideoPlayerWidget(GUI::Window&); diff --git a/Userland/Applications/VideoPlayer/main.cpp b/Userland/Applications/VideoPlayer/main.cpp index 673077b96c..de3dc23be2 100644 --- a/Userland/Applications/VideoPlayer/main.cpp +++ b/Userland/Applications/VideoPlayer/main.cpp @@ -8,11 +8,8 @@ #include "LibVideo/MatroskaDemuxer.h" #include #include -#include -#include #include #include -#include #include "VideoPlayerWidget.h" @@ -30,17 +27,11 @@ ErrorOr serenity_main(Main::Arguments arguments) auto main_widget = TRY(window->try_set_main_widget(window)); main_widget->update_title(); + main_widget->initialize_menubar(window); if (!filename.is_empty()) main_widget->open_file(filename); - auto file_menu = TRY(window->try_add_menu("&File")); - TRY(file_menu->try_add_action(GUI::CommonActions::make_open_action([&](auto&) { - Optional path = GUI::FilePicker::get_open_filepath(window, "Open video file..."); - if (path.has_value()) - main_widget->open_file(path.value()); - }))); - window->show(); return app->exec(); }