summaryrefslogtreecommitdiff
path: root/Libraries/LibVT
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-05-12 18:45:03 +0200
committerAndreas Kling <kling@serenityos.org>2020-05-12 18:49:24 +0200
commitf8e3c8326de9c5a3de42542614575ab95357bff2 (patch)
treed6ef035dc873a9393ba9f36407930c8a09c89a35 /Libraries/LibVT
parent512c04c64f849970a5057380478d6de23f5a996a (diff)
downloadserenity-f8e3c8326de9c5a3de42542614575ab95357bff2.zip
Terminal: When offering to open a URL, show name + icon for handler app
Instead of just saying "Open URL" when you right click on a hyperlink in the terminal, we now say something like "Open in Browser". :^)
Diffstat (limited to 'Libraries/LibVT')
-rw-r--r--Libraries/LibVT/TerminalWidget.cpp45
1 files changed, 34 insertions, 11 deletions
diff --git a/Libraries/LibVT/TerminalWidget.cpp b/Libraries/LibVT/TerminalWidget.cpp
index c8db17f80c..e076e0c30d 100644
--- a/Libraries/LibVT/TerminalWidget.cpp
+++ b/Libraries/LibVT/TerminalWidget.cpp
@@ -26,11 +26,13 @@
#include "TerminalWidget.h"
#include "XtermColors.h"
+#include <AK/FileSystemPath.h>
#include <AK/StdLibExtras.h>
#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <AK/Utf8View.h>
#include <Kernel/KeyCode.h>
+#include <LibCore/ConfigFile.h>
#include <LibCore/MimeData.h>
#include <LibDesktop/Launcher.h>
#include <LibGUI/Action.h>
@@ -131,17 +133,6 @@ TerminalWidget::TerminalWidget(int ptm_fd, bool automatic_size_policy, RefPtr<Co
m_context_menu = GUI::Menu::construct();
m_context_menu->add_action(copy_action());
m_context_menu->add_action(paste_action());
-
- m_context_menu_for_hyperlink = GUI::Menu::construct();
- m_context_menu_for_hyperlink->add_action(GUI::Action::create("Open URL", [this](auto&) {
- Desktop::Launcher::open(m_context_menu_href);
- }));
- m_context_menu_for_hyperlink->add_action(GUI::Action::create("Copy URL", [this](auto&) {
- GUI::Clipboard::the().set_data(m_context_menu_href);
- }));
- m_context_menu_for_hyperlink->add_separator();
- m_context_menu_for_hyperlink->add_action(copy_action());
- m_context_menu_for_hyperlink->add_action(paste_action());
}
TerminalWidget::~TerminalWidget()
@@ -849,6 +840,38 @@ void TerminalWidget::context_menu_event(GUI::ContextMenuEvent& event)
m_context_menu->popup(event.screen_position());
} else {
m_context_menu_href = m_hovered_href;
+
+ // Ask LaunchServer for a list of programs that can handle the right-clicked URL.
+ auto handlers = Desktop::Launcher::get_handlers_for_url(m_hovered_href);
+ if (handlers.is_empty()) {
+ m_context_menu->popup(event.screen_position());
+ return;
+ }
+
+ m_context_menu_for_hyperlink = GUI::Menu::construct();
+
+ // Go through the list of handlers and see if we can find a nice display name + icon for them.
+ // Then add them to the context menu.
+ // FIXME: Adapt this code when we actually support calling LaunchServer with a specific handler in mind.
+ for (auto& handler : handlers) {
+ auto af_path = String::format("/res/apps/%s.af", FileSystemPath(handler).basename().characters());
+ auto af = Core::ConfigFile::open(af_path);
+ auto handler_name = af->read_entry("App", "Name", handler);
+ auto handler_icon = af->read_entry("Icons", "16x16", {});
+
+ auto icon = Gfx::Bitmap::load_from_file(handler_icon);
+
+ m_context_menu_for_hyperlink->add_action(GUI::Action::create(String::format("Open in %s", handler_name.characters()), move(icon), [this](auto&) {
+ Desktop::Launcher::open(m_context_menu_href);
+ }));
+ }
+ m_context_menu_for_hyperlink->add_action(GUI::Action::create("Copy URL", [this](auto&) {
+ GUI::Clipboard::the().set_data(m_context_menu_href);
+ }));
+ m_context_menu_for_hyperlink->add_separator();
+ m_context_menu_for_hyperlink->add_action(copy_action());
+ m_context_menu_for_hyperlink->add_action(paste_action());
+
m_context_menu_for_hyperlink->popup(event.screen_position());
}
}