From 1026360c595818eabe75813bcd02258c4d0dddc7 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 24 May 2021 07:53:33 +0200 Subject: 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 --- src/plugins/FileManager.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src/plugins') 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 -- cgit v1.2.3