summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorspeles <speles@mail.ua>2021-02-28 20:54:03 +0200
committerAndreas Kling <kling@serenityos.org>2021-03-01 11:16:18 +0100
commite964d238b89bf6d804d7b3ef7c0316fc8a1c285f (patch)
treee558676faecfaa6642f620cff35c0bde04a25486
parentaa9c5d4418d2ffbb1efba6293c9ea961a3ab0592 (diff)
downloadserenity-e964d238b89bf6d804d7b3ef7c0316fc8a1c285f.zip
FileManager+LaunchServer: Add launching FileManager with focus on file
-rw-r--r--Userland/Applications/FileManager/main.cpp17
-rw-r--r--Userland/Services/LaunchServer/Launcher.cpp8
2 files changed, 20 insertions, 5 deletions
diff --git a/Userland/Applications/FileManager/main.cpp b/Userland/Applications/FileManager/main.cpp
index dc61d088ac..d93059bf18 100644
--- a/Userland/Applications/FileManager/main.cpp
+++ b/Userland/Applications/FileManager/main.cpp
@@ -73,7 +73,7 @@
using namespace FileManager;
static int run_in_desktop_mode(RefPtr<Core::ConfigFile>);
-static int run_in_windowed_mode(RefPtr<Core::ConfigFile>, String initial_location);
+static int run_in_windowed_mode(RefPtr<Core::ConfigFile>, String initial_location, String entry_focused_on_init);
static void do_copy(const Vector<String>& selected_file_paths, FileUtils::FileOperation file_operation);
static void do_paste(const String& target_directory, GUI::Window* window);
static void do_create_link(const Vector<String>& selected_file_paths, GUI::Window* window);
@@ -124,7 +124,12 @@ int main(int argc, char** argv)
if (initial_location.is_empty())
initial_location = "/";
- return run_in_windowed_mode(move(config), initial_location);
+ // the second command-line argument is the name of the entry we wan't the focus to be on
+ String focused_entry;
+ if (argc >= 3)
+ focused_entry = argv[2];
+
+ return run_in_windowed_mode(move(config), initial_location, focused_entry);
}
void do_copy(const Vector<String>& selected_file_paths, FileUtils::FileOperation file_operation)
@@ -316,7 +321,7 @@ int run_in_desktop_mode([[maybe_unused]] RefPtr<Core::ConfigFile> config)
return GUI::Application::the()->exec();
}
-int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_location)
+int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_location, String entry_focused_on_init)
{
auto window = GUI::Window::construct();
window->set_title("File Manager");
@@ -1041,6 +1046,12 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
view_as_icons_action->set_checked(true);
}
+ if (!entry_focused_on_init.is_empty()) {
+ auto matches = directory_view.current_view().model()->matches(entry_focused_on_init, GUI::Model::MatchesFlag::MatchFull | GUI::Model::MatchesFlag::FirstMatchOnly);
+ if (!matches.is_empty())
+ directory_view.current_view().set_cursor(matches.first(), GUI::AbstractView::SelectionUpdate::Set);
+ }
+
// Write window position to config file on close request.
window->on_close_request = [&] {
config->write_num_entry("Window", "Left", window->x());
diff --git a/Userland/Services/LaunchServer/Launcher.cpp b/Userland/Services/LaunchServer/Launcher.cpp
index bab8d9d623..c763f9bdf7 100644
--- a/Userland/Services/LaunchServer/Launcher.cpp
+++ b/Userland/Services/LaunchServer/Launcher.cpp
@@ -298,8 +298,12 @@ bool Launcher::open_file_url(const URL& url)
}
// TODO: Make directory opening configurable
- if (S_ISDIR(st.st_mode))
- return spawn("/bin/FileManager", { url.path() });
+ if (S_ISDIR(st.st_mode)) {
+ Vector<String> fm_arguments { url.path() };
+ if (!url.fragment().is_empty())
+ fm_arguments.append(url.fragment());
+ return spawn("/bin/FileManager", fm_arguments);
+ }
if ((st.st_mode & S_IFMT) == S_IFREG && st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))
return spawn(url.path(), {});