From 76f1965dbbe8a84a3312173fca3a2d0630daac35 Mon Sep 17 00:00:00 2001 From: eidheim Date: Sun, 24 Apr 2016 21:05:34 +0200 Subject: [PATCH] Optimized Directories::select, making the function more responsive with large directories --- src/directories.cc | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/directories.cc b/src/directories.cc index 0200414..09dd08a 100644 --- a/src/directories.cc +++ b/src/directories.cc @@ -467,22 +467,51 @@ void Directories::select(const boost::filesystem::path &select_path) { JDEBUG("start"); if(path=="") return; - - if(select_path.generic_string().substr(0, path.generic_string().size()+1)!=path.generic_string()+'/') + + if(!filesystem::file_in_path(select_path, path)) return; + //return if the select_path is already selected + auto iter=get_selection()->get_selected(); + if(iter) { + if(iter->get_value(column_record.path)==select_path) + return; + } + std::list paths; boost::filesystem::path parent_path; if(boost::filesystem::is_directory(select_path)) parent_path=select_path; else parent_path=select_path.parent_path(); + + //check if select_path is already expanded + size_t expanded; + { + std::unique_lock lock(update_mutex); + expanded=last_write_times.find(parent_path.string())!=last_write_times.end(); + } + if(expanded) { + //set cursor at select_path and return + tree_store->foreach_iter([this, &select_path](const Gtk::TreeModel::iterator &iter){ + if(iter->get_value(column_record.path)==select_path) { + auto tree_path=Gtk::TreePath(iter); + expand_to_path(tree_path); + set_cursor(tree_path); + return true; + } + return false; + }); + return; + } + paths.emplace_front(parent_path); while(parent_path!=path) { parent_path=parent_path.parent_path(); paths.emplace_front(parent_path); } + //expand to select_path for(auto &a_path: paths) { tree_store->foreach_iter([this, &a_path](const Gtk::TreeModel::iterator &iter){ if(iter->get_value(column_record.path)==a_path) { @@ -494,6 +523,7 @@ void Directories::select(const boost::filesystem::path &select_path) { }); } + //set cursor at select_path tree_store->foreach_iter([this, &select_path](const Gtk::TreeModel::iterator &iter){ if(iter->get_value(column_record.path)==select_path) { auto tree_path=Gtk::TreePath(iter);