LibWebView+UI: Generate actions to open about: pages
This commit is contained in:
parent
ce331cbcd5
commit
6d30b0f4d4
7 changed files with 45 additions and 55 deletions
|
|
@ -674,6 +674,15 @@ void Application::initialize_actions()
|
|||
view->select_all();
|
||||
});
|
||||
|
||||
m_open_about_page_action = Action::create("About Ladybird"sv, ActionID::OpenAboutPage, [this]() {
|
||||
open_url_in_new_tab(URL::about_version(), Web::HTML::ActivateTab::Yes);
|
||||
});
|
||||
m_open_processes_page_action = Action::create("Open Task Manager"sv, ActionID::OpenProcessesPage, [this]() {
|
||||
open_url_in_new_tab(URL::about_processes(), Web::HTML::ActivateTab::Yes);
|
||||
});
|
||||
m_open_settings_page_action = Action::create("Settings"sv, ActionID::OpenSettingsPage, [this]() {
|
||||
open_url_in_new_tab(URL::about_settings(), Web::HTML::ActivateTab::Yes);
|
||||
});
|
||||
m_view_source_action = Action::create("View Source"sv, ActionID::ViewSource, [this]() {
|
||||
if (auto view = active_web_view(); view.has_value())
|
||||
view->get_source();
|
||||
|
|
|
|||
|
|
@ -79,6 +79,10 @@ public:
|
|||
Action& copy_selection_action() { return *m_copy_selection_action; }
|
||||
Action& paste_action() { return *m_paste_action; }
|
||||
Action& select_all_action() { return *m_select_all_action; }
|
||||
|
||||
Action& open_about_page_action() { return *m_open_about_page_action; }
|
||||
Action& open_processes_page_action() { return *m_open_processes_page_action; }
|
||||
Action& open_settings_page_action() { return *m_open_settings_page_action; }
|
||||
Action& view_source_action() { return *m_view_source_action; }
|
||||
|
||||
Menu& zoom_menu() { return *m_zoom_menu; }
|
||||
|
|
@ -181,6 +185,10 @@ private:
|
|||
RefPtr<Action> m_copy_selection_action;
|
||||
RefPtr<Action> m_paste_action;
|
||||
RefPtr<Action> m_select_all_action;
|
||||
|
||||
RefPtr<Action> m_open_about_page_action;
|
||||
RefPtr<Action> m_open_processes_page_action;
|
||||
RefPtr<Action> m_open_settings_page_action;
|
||||
RefPtr<Action> m_view_source_action;
|
||||
|
||||
RefPtr<Menu> m_zoom_menu;
|
||||
|
|
|
|||
|
|
@ -36,6 +36,9 @@ enum class ActionID {
|
|||
TakeVisibleScreenshot,
|
||||
TakeFullScreenshot,
|
||||
|
||||
OpenAboutPage,
|
||||
OpenProcessesPage,
|
||||
OpenSettingsPage,
|
||||
ViewSource,
|
||||
|
||||
OpenInNewTab,
|
||||
|
|
|
|||
|
|
@ -126,32 +126,6 @@
|
|||
|
||||
#pragma mark - Private methods
|
||||
|
||||
- (void)openAboutVersionPage:(id)sender
|
||||
{
|
||||
auto* current_tab = [NSApp keyWindow];
|
||||
if (![current_tab isKindOfClass:[Tab class]]) {
|
||||
return;
|
||||
}
|
||||
|
||||
[self createNewTab:URL::URL(URL::about_version())
|
||||
fromTab:(Tab*)current_tab
|
||||
activateTab:Web::HTML::ActivateTab::Yes];
|
||||
}
|
||||
|
||||
- (void)openSettings:(id)sender
|
||||
{
|
||||
[self createNewTab:URL::URL::about("settings"_string)
|
||||
fromTab:self.active_tab
|
||||
activateTab:Web::HTML::ActivateTab::Yes];
|
||||
}
|
||||
|
||||
- (void)openTaskManager:(id)sender
|
||||
{
|
||||
[self createNewTab:URL::URL::about("processes"_string)
|
||||
fromTab:self.active_tab
|
||||
activateTab:Web::HTML::ActivateTab::Yes];
|
||||
}
|
||||
|
||||
- (void)openLocation:(id)sender
|
||||
{
|
||||
auto* current_tab = [NSApp keyWindow];
|
||||
|
|
@ -269,14 +243,10 @@
|
|||
auto* process_name = [[NSProcessInfo processInfo] processName];
|
||||
auto* submenu = [[NSMenu alloc] initWithTitle:process_name];
|
||||
|
||||
[submenu addItem:[[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"About %@", process_name]
|
||||
action:@selector(openAboutVersionPage:)
|
||||
keyEquivalent:@""]];
|
||||
[submenu addItem:Ladybird::create_application_menu_item(WebView::Application::the().open_about_page_action())];
|
||||
[submenu addItem:[NSMenuItem separatorItem]];
|
||||
|
||||
[submenu addItem:[[NSMenuItem alloc] initWithTitle:@"Settings"
|
||||
action:@selector(openSettings:)
|
||||
keyEquivalent:@","]];
|
||||
[submenu addItem:Ladybird::create_application_menu_item(WebView::Application::the().open_settings_page_action())];
|
||||
[submenu addItem:[NSMenuItem separatorItem]];
|
||||
|
||||
[submenu addItem:[[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"Hide %@", process_name]
|
||||
|
|
@ -424,9 +394,7 @@
|
|||
keyEquivalent:@"I"];
|
||||
[submenu addItem:self.toggle_devtools_menu_item];
|
||||
|
||||
[submenu addItem:[[NSMenuItem alloc] initWithTitle:@"Open Task Manager"
|
||||
action:@selector(openTaskManager:)
|
||||
keyEquivalent:@"M"]];
|
||||
[submenu addItem:Ladybird::create_application_menu_item(WebView::Application::the().open_processes_page_action())];
|
||||
|
||||
[menu setSubmenu:submenu];
|
||||
return menu;
|
||||
|
|
|
|||
|
|
@ -144,6 +144,17 @@ static void initialize_native_control(WebView::Action& action, id control)
|
|||
set_control_image(control, @"magnifyingglass");
|
||||
break;
|
||||
|
||||
case WebView::ActionID::OpenAboutPage:
|
||||
set_control_image(control, @"info.circle");
|
||||
break;
|
||||
case WebView::ActionID::OpenProcessesPage:
|
||||
set_control_image(control, @"gearshape.2");
|
||||
[control setKeyEquivalent:@"M"];
|
||||
break;
|
||||
case WebView::ActionID::OpenSettingsPage:
|
||||
set_control_image(control, @"gearshape");
|
||||
[control setKeyEquivalent:@","];
|
||||
break;
|
||||
case WebView::ActionID::ViewSource:
|
||||
set_control_image(control, @"text.document");
|
||||
[control setKeyEquivalent:@"u"];
|
||||
|
|
|
|||
|
|
@ -166,14 +166,7 @@ BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, IsPopupWindow
|
|||
QObject::connect(m_find_in_page_action, &QAction::triggered, this, &BrowserWindow::show_find_in_page);
|
||||
|
||||
edit_menu->addSeparator();
|
||||
|
||||
auto* settings_action = new QAction("&Settings", this);
|
||||
settings_action->setIcon(load_icon_from_uri("resource://icons/16x16/settings.png"sv));
|
||||
settings_action->setShortcuts(QKeySequence::keyBindings(QKeySequence::StandardKey::Preferences));
|
||||
edit_menu->addAction(settings_action);
|
||||
QObject::connect(settings_action, &QAction::triggered, this, [this] {
|
||||
new_tab_from_url(URL::URL::about("settings"_string), Web::HTML::ActivateTab::Yes);
|
||||
});
|
||||
edit_menu->addAction(create_application_action(*edit_menu, Application::the().open_settings_page_action()));
|
||||
|
||||
auto* view_menu = m_hamburger_menu->addMenu("&View");
|
||||
menuBar()->addMenu(view_menu);
|
||||
|
|
@ -235,13 +228,7 @@ BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, IsPopupWindow
|
|||
}
|
||||
});
|
||||
|
||||
auto* task_manager_action = new QAction("Open Task &Manager", this);
|
||||
task_manager_action->setIcon(load_icon_from_uri("resource://icons/16x16/app-system-monitor.png"sv));
|
||||
task_manager_action->setShortcuts({ QKeySequence("Ctrl+Shift+M") });
|
||||
inspect_menu->addAction(task_manager_action);
|
||||
QObject::connect(task_manager_action, &QAction::triggered, this, [this]() {
|
||||
new_tab_from_url(URL::URL::about("processes"_string), Web::HTML::ActivateTab::Yes);
|
||||
});
|
||||
inspect_menu->addAction(create_application_action(*inspect_menu, Application::the().open_processes_page_action()));
|
||||
|
||||
auto* debug_menu = create_application_menu(*m_hamburger_menu, Application::the().debug_menu());
|
||||
m_hamburger_menu->addMenu(debug_menu);
|
||||
|
|
@ -250,11 +237,7 @@ BrowserWindow::BrowserWindow(Vector<URL::URL> const& initial_urls, IsPopupWindow
|
|||
auto* help_menu = m_hamburger_menu->addMenu("&Help");
|
||||
menuBar()->addMenu(help_menu);
|
||||
|
||||
auto* about_action = new QAction("&About Ladybird", this);
|
||||
help_menu->addAction(about_action);
|
||||
QObject::connect(about_action, &QAction::triggered, this, [this] {
|
||||
new_tab_from_url(URL::about_version(), Web::HTML::ActivateTab::Yes);
|
||||
});
|
||||
help_menu->addAction(create_application_action(*help_menu, Application::the().open_about_page_action()));
|
||||
|
||||
m_hamburger_menu->addSeparator();
|
||||
file_menu->addSeparator();
|
||||
|
|
|
|||
|
|
@ -106,6 +106,14 @@ static void initialize_native_control(WebView::Action& action, QAction& qaction,
|
|||
qaction.setIcon(load_icon_from_uri("resource://icons/16x16/find.png"sv));
|
||||
break;
|
||||
|
||||
case WebView::ActionID::OpenProcessesPage:
|
||||
qaction.setIcon(load_icon_from_uri("resource://icons/16x16/app-system-monitor.png"sv));
|
||||
qaction.setShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_M));
|
||||
break;
|
||||
case WebView::ActionID::OpenSettingsPage:
|
||||
qaction.setIcon(load_icon_from_uri("resource://icons/16x16/settings.png"sv));
|
||||
qaction.setShortcut(QKeySequence::StandardKey::Preferences);
|
||||
break;
|
||||
case WebView::ActionID::ViewSource:
|
||||
qaction.setIcon(load_icon_from_uri("resource://icons/16x16/filetype-html.png"sv));
|
||||
qaction.setShortcut(QKeySequence(Qt::CTRL | Qt::Key_U));
|
||||
|
|
|
|||
Loading…
Reference in a new issue