Skip to content

Commit

Permalink
FileManager+LaunchServer: Add launching FileManager with focus on file
Browse files Browse the repository at this point in the history
  • Loading branch information
speles authored and awesomekling committed Mar 1, 2021
1 parent aa9c5d4 commit e964d23
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
17 changes: 14 additions & 3 deletions Userland/Applications/FileManager/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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());
Expand Down
8 changes: 6 additions & 2 deletions Userland/Services/LaunchServer/Launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(), {});
Expand Down

0 comments on commit e964d23

Please sign in to comment.