Browse Source

Merge pull request #113 from eidheim/master

Fixed directory tree focus by comparing boost::filesystem instead of …
merge-requests/365/head
Ole Christian Eidheim 10 years ago
parent
commit
f8f7e73481
  1. 16
      src/directories.cc
  2. 4
      src/directories.h
  3. 13
      src/window.cc

16
src/directories.cc

@ -35,13 +35,13 @@ Directories::Directories() : Gtk::TreeView(), stop_update_thread(false) {
signal_row_activated().connect([this](const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column){ signal_row_activated().connect([this](const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column){
auto iter = tree_store->get_iter(path); auto iter = tree_store->get_iter(path);
if (iter) { if (iter) {
auto path_str=iter->get_value(column_record.path); auto filesystem_path=iter->get_value(column_record.path);
if(path_str!="") { if(filesystem_path!="") {
if (boost::filesystem::is_directory(boost::filesystem::path(path_str))) { if (boost::filesystem::is_directory(boost::filesystem::path(filesystem_path))) {
row_expanded(path) ? collapse_row(path) : expand_row(path, false); row_expanded(path) ? collapse_row(path) : expand_row(path, false);
} else { } else {
if(on_row_activated) if(on_row_activated)
on_row_activated(path_str); on_row_activated(filesystem_path);
} }
} }
} }
@ -57,7 +57,7 @@ Directories::Directories() : Gtk::TreeView(), stop_update_thread(false) {
}); });
signal_row_collapsed().connect([this](const Gtk::TreeModel::iterator& iter, const Gtk::TreeModel::Path& path){ signal_row_collapsed().connect([this](const Gtk::TreeModel::iterator& iter, const Gtk::TreeModel::Path& path){
update_mutex.lock(); update_mutex.lock();
last_write_times.erase(iter->get_value(column_record.path)); last_write_times.erase(iter->get_value(column_record.path).string());
update_mutex.unlock(); update_mutex.unlock();
auto children=iter->children(); auto children=iter->children();
if(children) { if(children) {
@ -170,7 +170,7 @@ void Directories::select(const boost::filesystem::path &path) {
for(auto &a_path: paths) { for(auto &a_path: paths) {
tree_store->foreach_iter([this, &a_path](const Gtk::TreeModel::iterator& iter){ tree_store->foreach_iter([this, &a_path](const Gtk::TreeModel::iterator& iter){
if(iter->get_value(column_record.path)==a_path.string()) { if(iter->get_value(column_record.path)==a_path) {
update_mutex.lock(); update_mutex.lock();
add_path(a_path, *iter); add_path(a_path, *iter);
update_mutex.unlock(); update_mutex.unlock();
@ -181,7 +181,7 @@ void Directories::select(const boost::filesystem::path &path) {
} }
tree_store->foreach_iter([this, &path](const Gtk::TreeModel::iterator& iter){ tree_store->foreach_iter([this, &path](const Gtk::TreeModel::iterator& iter){
if(iter->get_value(column_record.path)==path.string()) { if(iter->get_value(column_record.path)==path) {
auto tree_path=Gtk::TreePath(iter); auto tree_path=Gtk::TreePath(iter);
expand_to_path(tree_path); expand_to_path(tree_path);
set_cursor(tree_path); set_cursor(tree_path);
@ -225,7 +225,7 @@ void Directories::add_path(const boost::filesystem::path& dir_path, const Gtk::T
auto child = tree_store->append(*children); auto child = tree_store->append(*children);
not_deleted.emplace(filename); not_deleted.emplace(filename);
child->set_value(column_record.name, filename); child->set_value(column_record.name, filename);
child->set_value(column_record.path, it->path().string()); child->set_value(column_record.path, it->path());
if (boost::filesystem::is_directory(it->path())) { if (boost::filesystem::is_directory(it->path())) {
child->set_value(column_record.id, "a"+filename); child->set_value(column_record.id, "a"+filename);
auto grandchild=tree_store->append(child->children()); auto grandchild=tree_store->append(child->children());

4
src/directories.h

@ -22,7 +22,7 @@ public:
} }
Gtk::TreeModelColumn<std::string> id; Gtk::TreeModelColumn<std::string> id;
Gtk::TreeModelColumn<std::string> name; Gtk::TreeModelColumn<std::string> name;
Gtk::TreeModelColumn<std::string> path; Gtk::TreeModelColumn<boost::filesystem::path> path;
Gtk::TreeModelColumn<Gdk::RGBA> color; Gtk::TreeModelColumn<Gdk::RGBA> color;
}; };
@ -38,7 +38,7 @@ public:
void update(); void update();
void select(const boost::filesystem::path &path); void select(const boost::filesystem::path &path);
std::function<void(const std::string &file)> on_row_activated; std::function<void(const boost::filesystem::path &path)> on_row_activated;
std::unique_ptr<CMake> cmake; std::unique_ptr<CMake> cmake;
boost::filesystem::path current_path; boost::filesystem::path current_path;

13
src/window.cc

@ -1,3 +1,4 @@
#include "window.h" #include "window.h"
#include "logging.h" #include "logging.h"
#include "config.h" #include "config.h"
@ -55,8 +56,8 @@ Window::Window() : compiling(false) {
show_all_children(); show_all_children();
Directories::get().on_row_activated=[this](const std::string &file) { Directories::get().on_row_activated=[this](const boost::filesystem::path &path) {
notebook.open(file); notebook.open(path);
}; };
//Scroll to end of terminal whenever info is printed //Scroll to end of terminal whenever info is printed
@ -148,7 +149,7 @@ void Window::set_menu_actions() {
about.present(); about.present();
}); });
menu.add_action("preferences", [this]() { menu.add_action("preferences", [this]() {
notebook.open(boost::filesystem::canonical(Config::get().juci_home_path()/"config"/"config.json")); notebook.open(Config::get().juci_home_path()/"config"/"config.json");
}); });
menu.add_action("quit", [this]() { menu.add_action("quit", [this]() {
close(); close();
@ -164,7 +165,7 @@ void Window::set_menu_actions() {
if(filesystem::write(path)) { if(filesystem::write(path)) {
if(Directories::get().current_path!="") if(Directories::get().current_path!="")
Directories::get().update(); Directories::get().update();
notebook.open(boost::filesystem::canonical(path)); notebook.open(path);
Terminal::get().print("New file "+path.string()+" created.\n"); Terminal::get().print("New file "+path.string()+" created.\n");
} }
else else
@ -223,7 +224,7 @@ void Window::set_menu_actions() {
menu.add_action("open_file", [this]() { menu.add_action("open_file", [this]() {
auto path=Dialog::open_file(); auto path=Dialog::open_file();
if(path!="") if(path!="")
notebook.open(boost::filesystem::canonical(path)); notebook.open(path);
}); });
menu.add_action("open_folder", [this]() { menu.add_action("open_folder", [this]() {
auto path = Dialog::open_folder(); auto path = Dialog::open_folder();
@ -256,7 +257,7 @@ void Window::set_menu_actions() {
file.close(); file.close();
if(Directories::get().current_path!="") if(Directories::get().current_path!="")
Directories::get().update(); Directories::get().update();
notebook.open(boost::filesystem::canonical(path)); notebook.open(path);
Terminal::get().print("File saved to: " + notebook.get_current_view()->file_path.string()+"\n"); Terminal::get().print("File saved to: " + notebook.get_current_view()->file_path.string()+"\n");
} }
else else

Loading…
Cancel
Save