diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-05-24 07:53:33 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-05-24 07:54:32 +0200 |
commit | 1026360c595818eabe75813bcd02258c4d0dddc7 (patch) | |
tree | 2d1c9877c695c53942247aafed99a086be2387a4 /src/plugins | |
parent | 318d230c19954c8dade052b05a9e23d5d2c53e7e (diff) |
Save the last accessed file manager directory and use that the next time. Add ctrl+s for 4chan without viewing the image/video in fullscreen mode
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/FileManager.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/plugins/FileManager.cpp b/src/plugins/FileManager.cpp index 5ca7dc7..2207c65 100644 --- a/src/plugins/FileManager.cpp +++ b/src/plugins/FileManager.cpp @@ -4,6 +4,16 @@ #include "../../include/QuickMedia.hpp" namespace QuickMedia { + static bool last_accessed_dir_loaded = false; + static std::filesystem::path last_accessed_dir; + static Path last_accessed_dir_path; + static void set_last_accessed_dir(const std::filesystem::path &path) { + if(last_accessed_dir_path.data.empty()) + last_accessed_dir_path = get_storage_dir().join("file-manager").join("last_accessed_dir"); + file_overwrite_atomic(last_accessed_dir_path, path.string()); + last_accessed_dir = path; + } + // Returns empty string if no extension static const char* get_ext(const std::filesystem::path &path) { const char *path_c = path.c_str(); @@ -50,6 +60,7 @@ namespace QuickMedia { if(result != PluginResult::OK) return result; + set_last_accessed_dir(current_dir); auto body = create_body(); body->items = std::move(result_items); result_tabs.push_back(Tab{std::move(body), nullptr, nullptr}); @@ -57,9 +68,8 @@ namespace QuickMedia { } bool FileManagerPage::set_current_directory(const std::string &path) { - if(!std::filesystem::is_directory(path)) - return false; current_dir = path; + set_last_accessed_dir(current_dir); return true; } @@ -144,4 +154,19 @@ namespace QuickMedia { return PluginResult::OK; } + + // static + std::filesystem::path& FileManagerPage::get_last_accessed_directory(std::filesystem::path &fallback) { + if(!last_accessed_dir_loaded) { + last_accessed_dir_loaded = true; + std::string last_accessed_dir_str; + file_get_content(get_storage_dir().join("file-manager").join("last_accessed_dir"), last_accessed_dir_str); + last_accessed_dir = std::move(last_accessed_dir_str); + } + + if(last_accessed_dir.empty()) + return fallback; + else + return last_accessed_dir; + } }
\ No newline at end of file |