From e964d238b89bf6d804d7b3ef7c0316fc8a1c285f Mon Sep 17 00:00:00 2001 From: speles Date: Sun, 28 Feb 2021 20:54:03 +0200 Subject: FileManager+LaunchServer: Add launching FileManager with focus on file --- Userland/Applications/FileManager/main.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'Userland/Applications/FileManager') 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); -static int run_in_windowed_mode(RefPtr, String initial_location); +static int run_in_windowed_mode(RefPtr, String initial_location, String entry_focused_on_init); static void do_copy(const Vector& 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& 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& selected_file_paths, FileUtils::FileOperation file_operation) @@ -316,7 +321,7 @@ int run_in_desktop_mode([[maybe_unused]] RefPtr config) return GUI::Application::the()->exec(); } -int run_in_windowed_mode(RefPtr config, String initial_location) +int run_in_windowed_mode(RefPtr 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 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()); -- cgit v1.2.3