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 :)
This commit is contained in:
Slimey 2022-11-06 14:16:58 +00:00 committed by Gunnar Beutner
parent 8006bdf6b4
commit bb95374b49
Notes: sideshowbarker 2024-07-17 04:44:21 +09:00
3 changed files with 21 additions and 10 deletions

View File

@ -6,6 +6,7 @@
#include <LibGUI/Action.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/FilePicker.h>
#include <LibGUI/ImageWidget.h>
#include <LibGUI/Label.h>
#include <LibGUI/MessageBox.h>
@ -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<String> 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));
}
}

View File

@ -29,6 +29,8 @@ public:
void update_title();
void initialize_menubar(GUI::Window&);
private:
VideoPlayerWidget(GUI::Window&);

View File

@ -8,11 +8,8 @@
#include "LibVideo/MatroskaDemuxer.h"
#include <LibCore/ArgsParser.h>
#include <LibGUI/Application.h>
#include <LibGUI/FilePicker.h>
#include <LibGUI/Menu.h>
#include <LibGUI/Window.h>
#include <LibMain/Main.h>
#include <LibVideo/PlaybackManager.h>
#include "VideoPlayerWidget.h"
@ -30,17 +27,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto main_widget = TRY(window->try_set_main_widget<VideoPlayer::VideoPlayerWidget>(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<String> 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();
}