diff --git a/juci/config.cc b/juci/config.cc index 388fb88..1c1e454 100644 --- a/juci/config.cc +++ b/juci/config.cc @@ -1,14 +1,14 @@ #include "config.h" - MainConfig::MainConfig() : -keybindings_cfg_(), source_cfg_() { + keybindings_cfg_(), source_cfg_() { boost::property_tree::json_parser::read_json("config.json", cfg_); GenerateSource(); GenerateKeybindings(); - // keybindings_cfg_ = cfg_.get_child("keybindings"); - // notebook_cfg_ = cfg_.get_child("notebook"); - // menu_cfg_ = cfg_.get_child("menu"); + GenerateDirectoryFilter(); + // keybindings_cfg_ = cfg_.get_child("keybindings"); + // notebook_cfg_ = cfg_.get_child("notebook"); + // menu_cfg_ = cfg_.get_child("menu"); } void MainConfig::GenerateSource() { @@ -34,9 +34,15 @@ void MainConfig::GenerateKeybindings() { for (auto &i : keys_json) keybindings_cfg_.key_map()[i.first] = i.second.get_value(); } -Keybindings::Config& MainConfig::keybindings_cfg() { - return keybindings_cfg_; -} -Source::Config& MainConfig::source_cfg() { - return source_cfg_; + +void MainConfig::GenerateDirectoryFilter() { + boost::property_tree::ptree dir_json = cfg_.get_child("directoryfilter"); + boost::property_tree::ptree ignore_json = dir_json.get_child("ignore"); + boost::property_tree::ptree except_json = dir_json.get_child("exceptions"); + for ( auto &i : except_json ) + dir_cfg_.AddException(i.second.get_value()); + for ( auto &i : ignore_json ) + dir_cfg_.AddIgnore(i.second.get_value()); } + + diff --git a/juci/config.h b/juci/config.h index ee49224..edcb5fc 100644 --- a/juci/config.h +++ b/juci/config.h @@ -4,18 +4,22 @@ #include #include "keybindings.h" #include "source.h" +#include "directories.h" class MainConfig { public: MainConfig(); - Source::Config& source_cfg(); - Keybindings::Config& keybindings_cfg(); + Source::Config& source_cfg() { return source_cfg_; } + Keybindings::Config& keybindings_cfg() { return keybindings_cfg_; } + Directories::Config& dir_cfg() { return dir_cfg_; } void PrintMenu(); void GenerateSource(); void GenerateKeybindings(); + void GenerateDirectoryFilter(); private: boost::property_tree::ptree cfg_; boost::property_tree::ptree key_tree_; Source::Config source_cfg_; Keybindings::Config keybindings_cfg_; + Directories::Config dir_cfg_; }; diff --git a/juci/config.json b/juci/config.json index afc983d..e4ff1f5 100644 --- a/juci/config.json +++ b/juci/config.json @@ -25,6 +25,19 @@ "close_tab": "w", "open_folder": "o" }, + "directoryfilter": { + "ignore": [ + "cmake", + "#", + "~", + ".idea", + "in-lowercase.pls" + ], + "exceptions": [ + "cmakelists.txt", + "in-lowercase.pls" + ] + }, "example": { "key": "value", "key2": [ diff --git a/juci/directories.cc b/juci/directories.cc index 0366b35..adbc795 100644 --- a/juci/directories.cc +++ b/juci/directories.cc @@ -1,6 +1,7 @@ #include "directories.h" -Directories::Controller::Controller() { +Directories::Controller::Controller(Directories::Config& cfg) : + config_(cfg) { m_ScrolledWindow.add(m_TreeView); m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); } @@ -18,6 +19,17 @@ open_folder(const boost::filesystem::path& dir_path) { m_refTreeModel->set_sort_column(0, Gtk::SortType::SORT_ASCENDING); } +bool Directories::Controller::IsIgnored(std::string path) { + std::transform(path.begin(), path.end(), path.begin(), ::tolower); + // std::cout << "ignored?: " << path << std::endl; + if (config().IsException(path)) { + return false; + } + if (config().IsIgnored(path)) { + return true; + } + return false; +} void Directories::Controller:: list_dirs(const boost::filesystem::path& dir_path, Gtk::TreeModel::Row &parent, @@ -32,28 +44,30 @@ list_dirs(const boost::filesystem::path& dir_path, for ( boost::filesystem::directory_iterator itr( dir_path ); itr != end_itr; ++itr ) { - if (boost::filesystem::is_directory(itr->status())) { - if (count(itr->path().string()) > count(dir_path.string())) { // is child + if (!IsIgnored(itr->path().filename().string())) { + if (boost::filesystem::is_directory(itr->status())) { + if (count(itr->path().string()) > count(dir_path.string())) { // is child + child = *(m_refTreeModel->append(parent.children())); + std::string col_id("a"+itr->path().filename().string()); + child[view().m_col_id] = col_id; + child[view().m_col_name] = itr->path().filename().string(); + child[view().m_col_path] = itr->path().string(); + list_dirs(itr->path(), child, row_id); + } else { + row = *(m_refTreeModel->append()); + std::string col_id("a"+itr->path().filename().string()); + row[view().m_col_path] = itr->path().string(); + row[view().m_col_id] = col_id; + row[view().m_col_name] = itr->path().filename().string(); + list_dirs(itr->path(), parent, row_id); + } + } else { // is a file child = *(m_refTreeModel->append(parent.children())); - std::string col_id("a"+itr->path().filename().string()); + std::string col_id("b"+itr->path().filename().string()); child[view().m_col_id] = col_id; - child[view().m_col_name] = itr->path().filename().string(); + child[view().m_col_name] = itr->path().filename().string(); child[view().m_col_path] = itr->path().string(); - list_dirs(itr->path(), child, row_id); - } else { - row = *(m_refTreeModel->append()); - std::string col_id("a"+itr->path().filename().string()); - row[view().m_col_path] = itr->path().string(); - row[view().m_col_id] = col_id; - row[view().m_col_name] = itr->path().filename().string(); - list_dirs(itr->path(), parent, row_id); } - } else { // is a file - child = *(m_refTreeModel->append(parent.children())); - std::string col_id("b"+itr->path().filename().string()); - child[view().m_col_id] = col_id; - child[view().m_col_name] = itr->path().filename().string(); - child[view().m_col_path] = itr->path().string(); } } } @@ -101,3 +115,30 @@ get_project_name(const boost::filesystem::path& dir_path) { return "no project name"; } +Directories::Config::Config() { +} +Directories::Config::Config(Directories::Config& cfg) : + ignore_list_(cfg.ignore_list()), exception_list_(cfg.exception_list()) { +} + +void Directories::Config::AddIgnore(std::string filter) { + ignore_list_.push_back(filter); +} + +void Directories::Config::AddException(std::string filter) { + exception_list_.push_back(filter); +} + +bool Directories::Config::IsIgnored(std::string str) { + for ( auto &i : ignore_list() ) + if (str.find(i, 0) != std::string::npos) + return true; + return false; +} + +bool Directories::Config::IsException(std::string str) { + for ( std::string &i : exception_list() ) + if (i == str) + return true; + return false; +} diff --git a/juci/directories.h b/juci/directories.h index c96605a..9a6d3b8 100644 --- a/juci/directories.h +++ b/juci/directories.h @@ -4,10 +4,28 @@ #include #include #include "boost/filesystem.hpp" +#include +#include #include #include + namespace Directories { + + class Config { + public: + Config(Config &original); + Config(); + std::vector ignore_list() { return ignore_list_; } + std::vector exception_list() { return exception_list_; } + void AddIgnore(std::string filter); + void AddException(std::string filter); + bool IsException(std::string path); + bool IsIgnored(std::string path); + private: + std::vector ignore_list_; + std::vector exception_list_; + }; class View : public Gtk::TreeModel::ColumnRecord { public: View() { @@ -22,12 +40,14 @@ namespace Directories { class Model { }; + class Controller { public: Controller(); + Controller(Directories::Config& cfg); View& view() { return view_;} Model& model() { return model_;} - + Directories::Config& config() { return config_;} Gtk::ScrolledWindow& widget() {return m_ScrolledWindow;} bool open_folder (const boost::filesystem::path& dir_path); void list_dirs (const boost::filesystem::path& dir_path, @@ -40,9 +60,11 @@ namespace Directories { Gtk::ScrolledWindow m_ScrolledWindow; Gtk::TreeView m_TreeView; Glib::RefPtr m_refTreeModel; + bool IsIgnored(std::string path); private: View view_; Model model_; + Directories::Config config_; protected: void on_treeview_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column); diff --git a/juci/notebook.cc b/juci/notebook.cc index f2d745c..03230be 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -15,8 +15,10 @@ Notebook::View::View(){ } Notebook::Controller::Controller(Keybindings::Controller& keybindings, - Source::Config& source_cfg) : -source_config_(source_cfg) { + Source::Config& source_cfg, + Directories::Config& dir_cfg) : + source_config_(source_cfg), + directories_(dir_cfg) { OnNewPage("juCi++"); refClipboard_ = Gtk::Clipboard::get(); keybindings.action_group_menu()->add(Gtk::Action::create("FileMenu", diff --git a/juci/notebook.h b/juci/notebook.h index 3b77beb..ce9551a 100644 --- a/juci/notebook.h +++ b/juci/notebook.h @@ -28,7 +28,8 @@ namespace Notebook { public: Controller(Keybindings::Controller& keybindings, - Source::Config& config); + Source::Config& config, + Directories::Config& dir_cfg); ~Controller(); Glib::RefPtr Buffer( Source::Controller *source); Gtk::TextView& CurrentTextView(); diff --git a/juci/window.cc b/juci/window.cc index 99485c2..ec3a174 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -4,7 +4,7 @@ Window::Window() : window_box_(Gtk::ORIENTATION_VERTICAL), main_config_(), keybindings_(main_config_.keybindings_cfg()), - notebook_(keybindings(), main_config_.source_cfg()), + notebook_(keybindings(), main_config_.source_cfg(), main_config_.dir_cfg()), menu_(keybindings()) { set_title("juCi++"); set_default_size(600, 400); diff --git a/juci/window.h b/juci/window.h index 2b79755..a0b810f 100644 --- a/juci/window.h +++ b/juci/window.h @@ -4,7 +4,6 @@ #include "api.h" #include "config.h" #include -#include "directories.h" class Window : public Gtk::Window {