aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-10-02 16:44:19 +0200
committerdec05eba <dec05eba@protonmail.com>2020-10-02 16:44:19 +0200
commite9627c23c07d9060f2a6bdccfcd81a0e28adfe9f (patch)
tree55f6bafa8b6e5982932714a86ed33d7ea17e5ac4 /src
parentd9cb6885ab741ba69a966109cb05e26692143ce0 (diff)
Fix file manager crash on filter selection, reset search on selection
Diffstat (limited to 'src')
-rw-r--r--src/Body.cpp14
-rw-r--r--src/QuickMedia.cpp5
-rw-r--r--src/plugins/FileManager.cpp24
3 files changed, 28 insertions, 15 deletions
diff --git a/src/Body.cpp b/src/Body.cpp
index 4aa194b..812840d 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -191,15 +191,7 @@ namespace QuickMedia {
}
void Body::reset_selected() {
- for(size_t i = 0; i < items.size(); ++i) {
- if(items[i]->visible) {
- selected_item = i;
- return;
- }
- }
- selected_item = 0;
- prev_selected_item = selected_item;
- page_scroll = 0.0f;
+ select_first_item();
}
void Body::clear_items() {
@@ -350,6 +342,10 @@ namespace QuickMedia {
}
}
+ if(prev_selected_item < 0 || prev_selected_item >= (int)items.size()) {
+ prev_selected_item = selected_item;
+ }
+
// TODO: Optimize this, especially when scrolling to top/bottom.
// TODO: Test when wrapping is enabled
int selected_item_diff = selected_item - prev_selected_item;
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index fd49556..80faa88 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -2580,6 +2580,7 @@ namespace QuickMedia {
void Program::file_manager_page() {
selected_files.clear();
+ search_bar->clear();
int prev_autosearch_delay = search_bar->text_autosearch_delay;
search_bar->text_autosearch_delay = file_manager->get_search_delay();
Page previous_page = pop_page_stack();
@@ -2588,6 +2589,8 @@ namespace QuickMedia {
// TODO: Make asynchronous.
// TODO: Automatically go to the parent if this fails (recursively).
+ body->select_first_item();
+ body->items.clear();
if(file_manager->get_files_in_directory(body->items) != PluginResult::OK) {
show_notification("QuickMedia", "File manager failed to get files in directory: " + file_manager->get_current_dir().string(), Urgency::CRITICAL);
}
@@ -2612,7 +2615,7 @@ namespace QuickMedia {
if(file_manager->get_files_in_directory(body->items) != PluginResult::OK) {
show_notification("QuickMedia", "File manager failed to get files in directory: " + current_dir_str, Urgency::CRITICAL);
}
- body->reset_selected();
+ body->select_first_item();
return true;
} else {
std::filesystem::path full_path = file_manager->get_current_dir() / selected_item->get_title();
diff --git a/src/plugins/FileManager.cpp b/src/plugins/FileManager.cpp
index d8a0612..ccaf2c1 100644
--- a/src/plugins/FileManager.cpp
+++ b/src/plugins/FileManager.cpp
@@ -41,6 +41,11 @@ namespace QuickMedia {
return file_get_filetime_or(path1, std::filesystem::file_time_type::min()) > file_get_filetime_or(path2, std::filesystem::file_time_type::min());
});
+ if(current_dir != "/") {
+ auto parent_item = BodyItem::create("..");
+ result_items.push_back(std::move(parent_item));
+ }
+
for(auto &p : paths) {
auto body_item = BodyItem::create(p.path().filename().string());
// TODO: Check file magic number instead of extension?
@@ -62,12 +67,21 @@ namespace QuickMedia {
}
bool FileManager::set_child_directory(const std::string &filename) {
- std::filesystem::path new_path = current_dir / filename;
- if(std::filesystem::is_directory(new_path)) {
- current_dir = std::move(new_path);
- return true;
+ if(filename == "..") {
+ std::filesystem::path new_path = current_dir.parent_path();
+ if(std::filesystem::is_directory(new_path)) {
+ current_dir = std::move(new_path);
+ return true;
+ }
+ return false;
+ } else {
+ std::filesystem::path new_path = current_dir / filename;
+ if(std::filesystem::is_directory(new_path)) {
+ current_dir = std::move(new_path);
+ return true;
+ }
+ return false;
}
- return false;
}
const std::filesystem::path& FileManager::get_current_dir() const {