From 41b745b83d5c3a8c195ea6504c0b4e13f9cf4697 Mon Sep 17 00:00:00 2001 From: tedjk Date: Fri, 15 May 2015 13:49:50 +0200 Subject: [PATCH] added legal file-extensions to source --- juci/api.cc | 4 ++ juci/config.cc | 17 +++-- juci/config.json | 7 +- juci/directories.cc | 167 ++++++++++++++++++++++---------------------- juci/notebook.cc | 3 +- juci/source.cc | 9 +++ juci/source.h | 4 +- juci/window.cc | 2 +- 8 files changed, 120 insertions(+), 93 deletions(-) diff --git a/juci/api.cc b/juci/api.cc index 6a5f0a4..ee5a634 100644 --- a/juci/api.cc +++ b/juci/api.cc @@ -8,9 +8,12 @@ Notebook::Controller* PluginApi::notebook_; ///////////////////////////// PluginApi::PluginApi(Menu::Controller& menu_ctl_, Notebook::Controller& notebook_ctl_) { + DEBUG("Adding pointers for the API"); menu_ = &menu_ctl_; notebook_ = ¬ebook_ctl_; + DEBUG("Initiating plugins(from plugins.py).."); InitPlugins(); + DEBUG("Plugins initiated.."); } PluginApi::~PluginApi() { @@ -61,6 +64,7 @@ void PluginApi::InitPlugins() { } void PluginApi::AddMenuElement(std::string plugin_name) { + DEBUG("Adding menu element for "+plugin_name); AddMenuXml(plugin_name, "PluginMenu"); std::string plugin_action_name = plugin_name+"Menu"; menu_->keybindings_.action_group_menu() diff --git a/juci/config.cc b/juci/config.cc index 0b9cd6a..b320a6c 100644 --- a/juci/config.cc +++ b/juci/config.cc @@ -11,21 +11,26 @@ MainConfig::MainConfig() : } void MainConfig::GenerateSource() { - INFO("Generating source cfg"); + DEBUG("Fetching source cfg"); boost::property_tree::ptree source_json = cfg_.get_child("source"); boost::property_tree::ptree syntax_json = source_json.get_child("syntax"); boost::property_tree::ptree colors_json = source_json.get_child("colors"); + boost::property_tree::ptree extensions_json = source_json.get_child("extensions"); for (auto &i : colors_json) { source_cfg_.InsertTag(i.first, i.second.get_value()); } for (auto &i : syntax_json) { source_cfg_.InsertType(i.first, i.second.get_value()); } - INFO("Source cfg generated"); + for (auto &i : extensions_json) { + source_cfg_.InsertExtension(i.second.get_value()); + } + + DEBUG("Source cfg fetched"); } void MainConfig::GenerateKeybindings() { - INFO("Generating keybindings"); + DEBUG("Fetching keybindings"); std::string line; std::ifstream menu_xml("menu.xml"); if (menu_xml.is_open()) { @@ -35,10 +40,11 @@ void MainConfig::GenerateKeybindings() { boost::property_tree::ptree keys_json = cfg_.get_child("keybindings"); for (auto &i : keys_json) keybindings_cfg_.key_map()[i.first] = i.second.get_value(); - INFO("Keybindings generated"); + DEBUG("Keybindings fetched"); } void MainConfig::GenerateDirectoryFilter() { + DEBUG("Fetching directory filter"); 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"); @@ -46,6 +52,5 @@ void MainConfig::GenerateDirectoryFilter() { dir_cfg_.AddException(i.second.get_value()); for ( auto &i : ignore_json ) dir_cfg_.AddIgnore(i.second.get_value()); + DEBUG("Directory filter fetched"); } - - diff --git a/juci/config.json b/juci/config.json index 9344fbb..d2621a7 100644 --- a/juci/config.json +++ b/juci/config.json @@ -16,7 +16,12 @@ "702": "keyword", "703": "own", "705": "comment" - } + }, + "extensions": [ + "ext1", + "ext2", + "ext3" + ] }, "keybindings": { "split_window": "s", diff --git a/juci/directories.cc b/juci/directories.cc index b213187..199e4dd 100644 --- a/juci/directories.cc +++ b/juci/directories.cc @@ -29,7 +29,6 @@ open_folder(const boost::filesystem::path& dir_path) { bool Directories::Controller::IsIgnored(std::string path) { DEBUG("Checking if file-/directory is filtered"); std::transform(path.begin(), path.end(), path.begin(), ::tolower); - // std::cout << "ignored?: " << path << std::endl; if (config().IsException(path)) { return false; } @@ -48,7 +47,7 @@ list_dirs(const boost::filesystem::path& dir_path, unsigned file_counter = 0; Gtk::TreeModel::Row child; Gtk::TreeModel::Row row; - DEBUG_VAR(dir_path); + DEBUG(""); // Fill the treeview for ( boost::filesystem::directory_iterator itr( dir_path ); itr != end_itr; @@ -80,107 +79,109 @@ list_dirs(const boost::filesystem::path& dir_path, } } } + int Directories::Controller::count(const std::string path) { int count = 0; for (int i = 0; i < path.size(); i++) - if (path[i] == '/') count++; + if (path[i] == '/') + count++; return count; } - std::string Directories::Controller:: - GetCmakeVarValue(const boost::filesystem::path& dir_path, std::string command_name) { - INFO("fetches cmake variable value for: "+command_name); - std::string project_name; - std::string project_name_var; - boost::filesystem::directory_iterator end_itr; - for (boost::filesystem::directory_iterator itr( dir_path ); - itr != end_itr; - ++itr ) { - if (itr->path().filename().string() == "CMakeLists.txt") { - std::ifstream ifs(itr->path().string()); - std::string line; - while (std::getline(ifs, line)) { - if (line.find(command_name+"(", 0) != std::string::npos - || line.find(command_name+" (", 0) != std::string::npos ) { - size_t variable_start = line.find("{", 0); - size_t variable_end = line.find("}", variable_start); - project_name_var = line.substr(variable_start+1, - (variable_end)-variable_start-1); - boost::algorithm::trim(project_name_var); - if (variable_start == std::string::npos) { // not a variabel - variable_start = line.find("(", 0); +std::string Directories::Controller:: +GetCmakeVarValue(const boost::filesystem::path& dir_path, std::string command_name) { + INFO("fetches cmake variable value for: "+command_name); + std::string project_name; + std::string project_name_var; + boost::filesystem::directory_iterator end_itr; + for (boost::filesystem::directory_iterator itr( dir_path ); + itr != end_itr; + ++itr ) { + if (itr->path().filename().string() == "CMakeLists.txt") { + std::ifstream ifs(itr->path().string()); + std::string line; + while (std::getline(ifs, line)) { + if (line.find(command_name+"(", 0) != std::string::npos + || line.find(command_name+" (", 0) != std::string::npos ) { + size_t variable_start = line.find("{", 0); + size_t variable_end = line.find("}", variable_start); + project_name_var = line.substr(variable_start+1, + (variable_end)-variable_start-1); + boost::algorithm::trim(project_name_var); + if (variable_start == std::string::npos) { // not a variabel + variable_start = line.find("(", 0); - variable_end = line.find(' ', variable_start); - if(variable_end != std::string::npos){ - return line.substr(variable_start+1, - (variable_end)-variable_start-1); - } - variable_end = line.find("#", variable_start); - if(variable_end != std::string::npos){ - return line.substr(variable_start+1, - (variable_end)-variable_start-1); - } - variable_end = line.find(")", variable_start); + variable_end = line.find(' ', variable_start); + if(variable_end != std::string::npos){ + return line.substr(variable_start+1, + (variable_end)-variable_start-1); + } + variable_end = line.find("#", variable_start); + if(variable_end != std::string::npos){ + return line.substr(variable_start+1, + (variable_end)-variable_start-1); + } + variable_end = line.find(")", variable_start); + return line.substr(variable_start+1, + (variable_end)-variable_start-1); + if (variable_start == std::string::npos) { // not a variable + variable_start = line.find("(", 0); + variable_end = line.find(")", variable_start); + INFO("Wasn't a variable, returning value"); return line.substr(variable_start+1, (variable_end)-variable_start-1); - if (variable_start == std::string::npos) { // not a variable - variable_start = line.find("(", 0); - variable_end = line.find(")", variable_start); - INFO("Wasn't a variable, returning value"); - return line.substr(variable_start+1, - (variable_end)-variable_start-1); } break; } } - } - std::ifstream ifs2(itr->path().string()); - while (std::getline(ifs2, line)) { - if (line.find("set(", 0) != std::string::npos - || line.find("set (", 0) != std::string::npos) { - if( line.find(project_name_var, 0) != std::string::npos) { - size_t variable_start = line.find(project_name_var, 0) - +project_name_var.length(); - size_t variable_end = line.find(")", variable_start); - project_name = line.substr(variable_start+1, - variable_end-variable_start-1); - boost::algorithm::trim(project_name); - INFO("found variable, returning value"); - return project_name; - } + } + std::ifstream ifs2(itr->path().string()); + while (std::getline(ifs2, line)) { + if (line.find("set(", 0) != std::string::npos + || line.find("set (", 0) != std::string::npos) { + if( line.find(project_name_var, 0) != std::string::npos) { + size_t variable_start = line.find(project_name_var, 0) + +project_name_var.length(); + size_t variable_end = line.find(")", variable_start); + project_name = line.substr(variable_start+1, + variable_end-variable_start-1); + boost::algorithm::trim(project_name); + INFO("found variable, returning value"); + return project_name; } } - break; } + break; } - INFO("Couldn't find value in CMakeLists.txt"); - return "no project name"; } + INFO("Couldn't find value in CMakeLists.txt"); + return "no project name"; +} - Directories::Config::Config() { - } - Directories::Config::Config(Directories::Config& cfg) : - ignore_list_(cfg.ignore_list()), exception_list_(cfg.exception_list()) { - } +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::AddIgnore(std::string filter) { + ignore_list_.push_back(filter); +} - void Directories::Config::AddException(std::string filter) { - exception_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::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; - } +bool Directories::Config::IsException(std::string str) { + for ( std::string &i : exception_list() ) + if (i == str) + return true; + return false; +} diff --git a/juci/notebook.cc b/juci/notebook.cc index 44470e9..c76409a 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -13,7 +13,8 @@ Notebook::View::View() : notebook_() { view_.set_position(120); } -Notebook::Controller::Controller(Gtk::Window* window, Keybindings::Controller& keybindings, +Notebook::Controller::Controller(Gtk::Window* window, + Keybindings::Controller& keybindings, Source::Config& source_cfg, Directories::Config& dir_cfg) : source_config_(source_cfg), diff --git a/juci/source.cc b/juci/source.cc index d2fed65..7b2dde2 100644 --- a/juci/source.cc +++ b/juci/source.cc @@ -70,9 +70,18 @@ const std::unordered_map& Source::Config::typetable() const { return typetable_; } + std::vector& Source::Config::extensiontable() { + return extensiontable_; +} + void Source::Config::InsertTag(const string &key, const string &value) { tagtable_[key] = value; } + +void Source::Config::InsertExtension(const string &ext) { + extensiontable_.push_back(ext); +} + // Source::View::Config::SetTagTable() // sets the tagtable for the view void Source::Config:: diff --git a/juci/source.h b/juci/source.h index f9b45bd..cbdcfc1 100644 --- a/juci/source.h +++ b/juci/source.h @@ -20,16 +20,18 @@ namespace Source { Config(); const std::unordered_map& tagtable() const; const std::unordered_map& typetable() const; + std::vector& extensiontable(); void SetTagTable(const std::unordered_map &tagtable); void InsertTag(const std::string &key, const std::string &value); void SetTypeTable(const std::unordered_map &tagtable); void InsertType(const std::string &key, const std::string &value); - + void InsertExtension(const std::string &ext); private: std::unordered_map tagtable_; std::unordered_map typetable_; + std::vector extensiontable_; std::string background_; }; // class Config diff --git a/juci/window.cc b/juci/window.cc index ba4c391..d714702 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -59,7 +59,7 @@ Window::Window() : std::thread execute([=]() { std::string path = notebook_.CurrentPagePath(); int pos = path.find_last_of("/\\"); - if(pos != std::string::npos){ + if(pos != std::string::npos) { path.erase(path.begin()+pos,path.end()); terminal_.SetFolderCommand(path); }