Browse Source

Fixed directory tree focus by comparing boost::filesystem instead of std::string

merge-requests/365/head
U-olece-PC\olece 10 years ago
parent
commit
a77da5e0be
  1. 8
      src/config.cc
  2. 16
      src/directories.cc
  3. 4
      src/directories.h
  4. 13
      src/window.cc

8
src/config.cc

@ -14,10 +14,10 @@ Config::Config() {
for (auto &variable : environment_variables) {
ptr=std::getenv(variable.c_str());
if (ptr!=nullptr && boost::filesystem::exists(ptr)) {
home /= ptr;
home /= ".juci";
break;
}
home /= ptr;
home /= ".juci";
break;
}
}
if(home.empty()) {
std::string searched_envs = "[";

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){
auto iter = tree_store->get_iter(path);
if (iter) {
auto path_str=iter->get_value(column_record.path);
if(path_str!="") {
if (boost::filesystem::is_directory(boost::filesystem::path(path_str))) {
auto filesystem_path=iter->get_value(column_record.path);
if(filesystem_path!="") {
if (boost::filesystem::is_directory(boost::filesystem::path(filesystem_path))) {
row_expanded(path) ? collapse_row(path) : expand_row(path, false);
} else {
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){
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();
auto children=iter->children();
if(children) {
@ -170,7 +170,7 @@ void Directories::select(const boost::filesystem::path &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.string()) {
if(iter->get_value(column_record.path)==a_path) {
update_mutex.lock();
add_path(a_path, *iter);
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){
if(iter->get_value(column_record.path)==path.string()) {
if(iter->get_value(column_record.path)==path) {
auto tree_path=Gtk::TreePath(iter);
expand_to_path(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);
not_deleted.emplace(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())) {
child->set_value(column_record.id, "a"+filename);
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> name;
Gtk::TreeModelColumn<std::string> path;
Gtk::TreeModelColumn<boost::filesystem::path> path;
Gtk::TreeModelColumn<Gdk::RGBA> color;
};
@ -38,7 +38,7 @@ public:
void update();
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;
boost::filesystem::path current_path;

13
src/window.cc

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

Loading…
Cancel
Save