mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:48:14 +00:00
Help: Add context menu
This commit is contained in:
parent
bd4e88ae3d
commit
e46a4181fa
1 changed files with 24 additions and 0 deletions
|
@ -14,6 +14,7 @@
|
|||
#include <LibGUI/Action.h>
|
||||
#include <LibGUI/Application.h>
|
||||
#include <LibGUI/BoxLayout.h>
|
||||
#include <LibGUI/Clipboard.h>
|
||||
#include <LibGUI/FilteringProxyModel.h>
|
||||
#include <LibGUI/ListView.h>
|
||||
#include <LibGUI/Menu.h>
|
||||
|
@ -277,6 +278,29 @@ int main(int argc, char* argv[])
|
|||
|
||||
window->set_menubar(move(menubar));
|
||||
|
||||
auto context_menu = GUI::Menu::construct();
|
||||
context_menu->add_action(*go_back_action);
|
||||
context_menu->add_action(*go_forward_action);
|
||||
context_menu->add_action(*go_home_action);
|
||||
context_menu->add_separator();
|
||||
|
||||
RefPtr<GUI::Action> copy_action = GUI::CommonActions::make_copy_action([&](auto&) {
|
||||
auto selected_text = page_view.selected_text();
|
||||
if (!selected_text.is_empty())
|
||||
GUI::Clipboard::the().set_plain_text(selected_text);
|
||||
});
|
||||
context_menu->add_action(*copy_action);
|
||||
|
||||
RefPtr<GUI::Action> select_all_function = GUI::CommonActions::make_select_all_action([&](auto&) {
|
||||
page_view.select_all();
|
||||
});
|
||||
context_menu->add_action(*select_all_function);
|
||||
|
||||
page_view.on_context_menu_request = [&](auto& screen_position) {
|
||||
copy_action->set_enabled(!page_view.selected_text().is_empty());
|
||||
context_menu->popup(screen_position);
|
||||
};
|
||||
|
||||
if (start_page) {
|
||||
URL url = URL::create_with_url_or_path(start_page);
|
||||
if (url.is_valid() && url.path().ends_with(".md")) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue