LibVT: Handle non file urls in on hover tooltips

Previously we would simply compute the basename of the hovered url's
path and display it as the resource that will be opened. This patch adds
a fallback for non file urls to simply show the full url, making http
urls show up properly.
This commit is contained in:
networkException 2022-09-04 22:20:16 +02:00 committed by Linus Groh
parent 4abb4317aa
commit b29fbe96dd
Notes: sideshowbarker 2024-07-17 07:31:32 +09:00

View file

@ -831,13 +831,22 @@ void TerminalWidget::mousemove_event(GUI::MouseEvent& event)
auto handlers = Desktop::Launcher::get_handlers_for_url(attribute.href);
if (!handlers.is_empty()) {
auto path = URL(attribute.href).path();
auto name = LexicalPath::basename(path);
if (path == handlers[0]) {
set_tooltip(String::formatted("Execute {}", name));
auto url = URL(attribute.href);
auto path = url.path();
auto app_file = Desktop::AppFile::get_for_app(LexicalPath::basename(handlers[0]));
auto app_name = app_file->is_valid() ? app_file->name() : LexicalPath::basename(handlers[0]);
if (url.scheme() == "file") {
auto file_name = LexicalPath::basename(path);
if (path == handlers[0]) {
set_tooltip(String::formatted("Execute {}", app_name));
} else {
set_tooltip(String::formatted("Open {} with {}", file_name, app_name));
}
} else {
auto af = Desktop::AppFile::get_for_app(LexicalPath::basename(handlers[0]));
set_tooltip(String::formatted("Open {} with {}", name, af->is_valid() ? af->name() : LexicalPath::basename(handlers[0])));
set_tooltip(String::formatted("Open {} with {}", attribute.href, app_name));
}
}
} else {