diff options
author | speles <speles@mail.ua> | 2021-03-05 21:43:39 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-03-07 11:00:36 +0100 |
commit | 0071742a5a2fcb89fee6d438dad4e9125e04bc53 (patch) | |
tree | e4b11bb4e129a2d083e6658cba0397ab604912ed /Userland/Applications | |
parent | 63a846a2ac63e9e8583b908c0d78298fc56b12e5 (diff) | |
download | serenity-0071742a5a2fcb89fee6d438dad4e9125e04bc53.zip |
FileManager: Use ArgsParser, handle more options
This adds 2 more flags, that help with the "select on start" invocation.
-s - makes us open the parent directory of the entry, and select it.
-r - makes FileManager to skip real path resolution for cases when we
want to select the symlink in parent directory.
Also, if the file path is passed as argument, not it will open parent
with the file selected.
Diffstat (limited to 'Userland/Applications')
-rw-r--r-- | Userland/Applications/FileManager/main.cpp | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/Userland/Applications/FileManager/main.cpp b/Userland/Applications/FileManager/main.cpp index 6b8128c32a..47d8f93074 100644 --- a/Userland/Applications/FileManager/main.cpp +++ b/Userland/Applications/FileManager/main.cpp @@ -32,6 +32,7 @@ #include <AK/StringBuilder.h> #include <AK/URL.h> #include <Applications/FileManager/FileManagerWindowGML.h> +#include <LibCore/ArgsParser.h> #include <LibCore/ConfigFile.h> #include <LibCore/File.h> #include <LibCore/MimeData.h> @@ -99,6 +100,15 @@ int main(int argc, char** argv) RefPtr<Core::ConfigFile> config = Core::ConfigFile::get_for_app("FileManager"); + Core::ArgsParser args_parser; + bool is_desktop_mode { false }, is_selection_mode { false }, ignore_path_resolution { false }; + String initial_location; + args_parser.add_option(is_desktop_mode, "Run in desktop mode", "desktop", 'd'); + args_parser.add_option(is_selection_mode, "Show entry in parent folder", "select", 's'); + args_parser.add_option(ignore_path_resolution, "Use raw path, do not resolve real path", "raw", 'r'); + args_parser.add_positional_argument(initial_location, "Path to open", "path", Core::ArgsParser::Required::No); + args_parser.parse(argc, argv); + auto app = GUI::Application::construct(argc, argv); if (pledge("stdio thread recvfd sendfd accept cpath rpath wpath fattr proc exec unix", nullptr) < 0) { @@ -106,17 +116,20 @@ int main(int argc, char** argv) return 1; } - if (app->args().contains_slow("--desktop") || app->args().contains_slow("-d")) + if (is_desktop_mode) return run_in_desktop_mode(move(config)); // our initial location is defined as, in order of precedence: - // 1. the first command-line argument (e.g. FileManager /bin) + // 1. the command-line path argument (e.g. FileManager /bin) // 2. the user's home directory // 3. the root directory - String initial_location; - if (argc >= 2) { - initial_location = Core::File::real_path_for(argv[1]); + if (!initial_location.is_empty()) { + if (!ignore_path_resolution) + initial_location = Core::File::real_path_for(initial_location); + + if (!Core::File::is_directory(initial_location)) + is_selection_mode = true; } if (initial_location.is_empty()) @@ -125,10 +138,12 @@ int main(int argc, char** argv) if (initial_location.is_empty()) 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]; + if (is_selection_mode) { + LexicalPath path(initial_location); + initial_location = path.dirname(); + focused_entry = path.basename(); + } return run_in_windowed_mode(move(config), initial_location, focused_entry); } |