Browse Source

added legal file-extensions to source

merge-requests/365/head
tedjk 11 years ago
parent
commit
41b745b83d
  1. 4
      juci/api.cc
  2. 17
      juci/config.cc
  3. 7
      juci/config.json
  4. 167
      juci/directories.cc
  5. 3
      juci/notebook.cc
  6. 9
      juci/source.cc
  7. 4
      juci/source.h
  8. 2
      juci/window.cc

4
juci/api.cc

@ -8,9 +8,12 @@ Notebook::Controller* PluginApi::notebook_;
///////////////////////////// /////////////////////////////
PluginApi::PluginApi(Menu::Controller& menu_ctl_, PluginApi::PluginApi(Menu::Controller& menu_ctl_,
Notebook::Controller& notebook_ctl_) { Notebook::Controller& notebook_ctl_) {
DEBUG("Adding pointers for the API");
menu_ = &menu_ctl_; menu_ = &menu_ctl_;
notebook_ = &notebook_ctl_; notebook_ = &notebook_ctl_;
DEBUG("Initiating plugins(from plugins.py)..");
InitPlugins(); InitPlugins();
DEBUG("Plugins initiated..");
} }
PluginApi::~PluginApi() { PluginApi::~PluginApi() {
@ -61,6 +64,7 @@ void PluginApi::InitPlugins() {
} }
void PluginApi::AddMenuElement(std::string plugin_name) { void PluginApi::AddMenuElement(std::string plugin_name) {
DEBUG("Adding menu element for "+plugin_name);
AddMenuXml(plugin_name, "PluginMenu"); AddMenuXml(plugin_name, "PluginMenu");
std::string plugin_action_name = plugin_name+"Menu"; std::string plugin_action_name = plugin_name+"Menu";
menu_->keybindings_.action_group_menu() menu_->keybindings_.action_group_menu()

17
juci/config.cc

@ -11,21 +11,26 @@ MainConfig::MainConfig() :
} }
void MainConfig::GenerateSource() { 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 source_json = cfg_.get_child("source");
boost::property_tree::ptree syntax_json = source_json.get_child("syntax"); 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 colors_json = source_json.get_child("colors");
boost::property_tree::ptree extensions_json = source_json.get_child("extensions");
for (auto &i : colors_json) { for (auto &i : colors_json) {
source_cfg_.InsertTag(i.first, i.second.get_value<std::string>()); source_cfg_.InsertTag(i.first, i.second.get_value<std::string>());
} }
for (auto &i : syntax_json) { for (auto &i : syntax_json) {
source_cfg_.InsertType(i.first, i.second.get_value<std::string>()); source_cfg_.InsertType(i.first, i.second.get_value<std::string>());
} }
INFO("Source cfg generated"); for (auto &i : extensions_json) {
source_cfg_.InsertExtension(i.second.get_value<std::string>());
}
DEBUG("Source cfg fetched");
} }
void MainConfig::GenerateKeybindings() { void MainConfig::GenerateKeybindings() {
INFO("Generating keybindings"); DEBUG("Fetching keybindings");
std::string line; std::string line;
std::ifstream menu_xml("menu.xml"); std::ifstream menu_xml("menu.xml");
if (menu_xml.is_open()) { if (menu_xml.is_open()) {
@ -35,10 +40,11 @@ void MainConfig::GenerateKeybindings() {
boost::property_tree::ptree keys_json = cfg_.get_child("keybindings"); boost::property_tree::ptree keys_json = cfg_.get_child("keybindings");
for (auto &i : keys_json) for (auto &i : keys_json)
keybindings_cfg_.key_map()[i.first] = i.second.get_value<std::string>(); keybindings_cfg_.key_map()[i.first] = i.second.get_value<std::string>();
INFO("Keybindings generated"); DEBUG("Keybindings fetched");
} }
void MainConfig::GenerateDirectoryFilter() { void MainConfig::GenerateDirectoryFilter() {
DEBUG("Fetching directory filter");
boost::property_tree::ptree dir_json = cfg_.get_child("directoryfilter"); 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 ignore_json = dir_json.get_child("ignore");
boost::property_tree::ptree except_json = dir_json.get_child("exceptions"); 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<std::string>()); dir_cfg_.AddException(i.second.get_value<std::string>());
for ( auto &i : ignore_json ) for ( auto &i : ignore_json )
dir_cfg_.AddIgnore(i.second.get_value<std::string>()); dir_cfg_.AddIgnore(i.second.get_value<std::string>());
DEBUG("Directory filter fetched");
} }

7
juci/config.json

@ -16,7 +16,12 @@
"702": "keyword", "702": "keyword",
"703": "own", "703": "own",
"705": "comment" "705": "comment"
} },
"extensions": [
"ext1",
"ext2",
"ext3"
]
}, },
"keybindings": { "keybindings": {
"split_window": "<control><alt>s", "split_window": "<control><alt>s",

167
juci/directories.cc

@ -29,7 +29,6 @@ open_folder(const boost::filesystem::path& dir_path) {
bool Directories::Controller::IsIgnored(std::string path) { bool Directories::Controller::IsIgnored(std::string path) {
DEBUG("Checking if file-/directory is filtered"); DEBUG("Checking if file-/directory is filtered");
std::transform(path.begin(), path.end(), path.begin(), ::tolower); std::transform(path.begin(), path.end(), path.begin(), ::tolower);
// std::cout << "ignored?: " << path << std::endl;
if (config().IsException(path)) { if (config().IsException(path)) {
return false; return false;
} }
@ -48,7 +47,7 @@ list_dirs(const boost::filesystem::path& dir_path,
unsigned file_counter = 0; unsigned file_counter = 0;
Gtk::TreeModel::Row child; Gtk::TreeModel::Row child;
Gtk::TreeModel::Row row; Gtk::TreeModel::Row row;
DEBUG_VAR(dir_path); DEBUG("");
// Fill the treeview // Fill the treeview
for ( boost::filesystem::directory_iterator itr( dir_path ); for ( boost::filesystem::directory_iterator itr( dir_path );
itr != end_itr; itr != end_itr;
@ -80,107 +79,109 @@ list_dirs(const boost::filesystem::path& dir_path,
} }
} }
} }
int Directories::Controller::count(const std::string path) { int Directories::Controller::count(const std::string path) {
int count = 0; int count = 0;
for (int i = 0; i < path.size(); i++) for (int i = 0; i < path.size(); i++)
if (path[i] == '/') count++; if (path[i] == '/')
count++;
return count; return count;
} }
std::string Directories::Controller:: std::string Directories::Controller::
GetCmakeVarValue(const boost::filesystem::path& dir_path, std::string command_name) { GetCmakeVarValue(const boost::filesystem::path& dir_path, std::string command_name) {
INFO("fetches cmake variable value for: "+command_name); INFO("fetches cmake variable value for: "+command_name);
std::string project_name; std::string project_name;
std::string project_name_var; std::string project_name_var;
boost::filesystem::directory_iterator end_itr; boost::filesystem::directory_iterator end_itr;
for (boost::filesystem::directory_iterator itr( dir_path ); for (boost::filesystem::directory_iterator itr( dir_path );
itr != end_itr; itr != end_itr;
++itr ) { ++itr ) {
if (itr->path().filename().string() == "CMakeLists.txt") { if (itr->path().filename().string() == "CMakeLists.txt") {
std::ifstream ifs(itr->path().string()); std::ifstream ifs(itr->path().string());
std::string line; std::string line;
while (std::getline(ifs, line)) { while (std::getline(ifs, line)) {
if (line.find(command_name+"(", 0) != std::string::npos if (line.find(command_name+"(", 0) != std::string::npos
|| 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_start = line.find("{", 0);
size_t variable_end = line.find("}", variable_start); size_t variable_end = line.find("}", variable_start);
project_name_var = line.substr(variable_start+1, project_name_var = line.substr(variable_start+1,
(variable_end)-variable_start-1); (variable_end)-variable_start-1);
boost::algorithm::trim(project_name_var); boost::algorithm::trim(project_name_var);
if (variable_start == std::string::npos) { // not a variabel if (variable_start == std::string::npos) { // not a variabel
variable_start = line.find("(", 0); variable_start = line.find("(", 0);
variable_end = line.find(' ', variable_start); variable_end = line.find(' ', variable_start);
if(variable_end != std::string::npos){ if(variable_end != std::string::npos){
return line.substr(variable_start+1, return line.substr(variable_start+1,
(variable_end)-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){ if(variable_end != std::string::npos){
return line.substr(variable_start+1, return line.substr(variable_start+1,
(variable_end)-variable_start-1); (variable_end)-variable_start-1);
} }
variable_end = line.find(")", variable_start); 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, return line.substr(variable_start+1,
(variable_end)-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; break;
} }
} }
} }
std::ifstream ifs2(itr->path().string()); std::ifstream ifs2(itr->path().string());
while (std::getline(ifs2, line)) { while (std::getline(ifs2, line)) {
if (line.find("set(", 0) != std::string::npos if (line.find("set(", 0) != std::string::npos
|| line.find("set (", 0) != std::string::npos) { || line.find("set (", 0) != std::string::npos) {
if( line.find(project_name_var, 0) != std::string::npos) { if( line.find(project_name_var, 0) != std::string::npos) {
size_t variable_start = line.find(project_name_var, 0) size_t variable_start = line.find(project_name_var, 0)
+project_name_var.length(); +project_name_var.length();
size_t variable_end = line.find(")", variable_start); size_t variable_end = line.find(")", variable_start);
project_name = line.substr(variable_start+1, project_name = line.substr(variable_start+1,
variable_end-variable_start-1); variable_end-variable_start-1);
boost::algorithm::trim(project_name); boost::algorithm::trim(project_name);
INFO("found variable, returning value"); INFO("found variable, returning value");
return project_name; 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::Config(Directories::Config& cfg) : Directories::Config::Config(Directories::Config& cfg) :
ignore_list_(cfg.ignore_list()), exception_list_(cfg.exception_list()) { ignore_list_(cfg.ignore_list()), exception_list_(cfg.exception_list()) {
} }
void Directories::Config::AddIgnore(std::string filter) { void Directories::Config::AddIgnore(std::string filter) {
ignore_list_.push_back(filter); ignore_list_.push_back(filter);
} }
void Directories::Config::AddException(std::string filter) { void Directories::Config::AddException(std::string filter) {
exception_list_.push_back(filter); exception_list_.push_back(filter);
} }
bool Directories::Config::IsIgnored(std::string str) { bool Directories::Config::IsIgnored(std::string str) {
for ( auto &i : ignore_list() ) for ( auto &i : ignore_list() )
if (str.find(i, 0) != std::string::npos) if (str.find(i, 0) != std::string::npos)
return true; return true;
return false; return false;
} }
bool Directories::Config::IsException(std::string str) { bool Directories::Config::IsException(std::string str) {
for ( std::string &i : exception_list() ) for ( std::string &i : exception_list() )
if (i == str) if (i == str)
return true; return true;
return false; return false;
} }

3
juci/notebook.cc

@ -13,7 +13,8 @@ Notebook::View::View() : notebook_() {
view_.set_position(120); 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, Source::Config& source_cfg,
Directories::Config& dir_cfg) : Directories::Config& dir_cfg) :
source_config_(source_cfg), source_config_(source_cfg),

9
juci/source.cc

@ -70,9 +70,18 @@ const std::unordered_map<string, string>& Source::Config::typetable() const {
return typetable_; return typetable_;
} }
std::vector<string>& Source::Config::extensiontable() {
return extensiontable_;
}
void Source::Config::InsertTag(const string &key, const string &value) { void Source::Config::InsertTag(const string &key, const string &value) {
tagtable_[key] = value; tagtable_[key] = value;
} }
void Source::Config::InsertExtension(const string &ext) {
extensiontable_.push_back(ext);
}
// Source::View::Config::SetTagTable() // Source::View::Config::SetTagTable()
// sets the tagtable for the view // sets the tagtable for the view
void Source::Config:: void Source::Config::

4
juci/source.h

@ -20,16 +20,18 @@ namespace Source {
Config(); Config();
const std::unordered_map<std::string, std::string>& tagtable() const; const std::unordered_map<std::string, std::string>& tagtable() const;
const std::unordered_map<std::string, std::string>& typetable() const; const std::unordered_map<std::string, std::string>& typetable() const;
std::vector<std::string>& extensiontable();
void SetTagTable(const std::unordered_map<std::string, std::string> void SetTagTable(const std::unordered_map<std::string, std::string>
&tagtable); &tagtable);
void InsertTag(const std::string &key, const std::string &value); void InsertTag(const std::string &key, const std::string &value);
void SetTypeTable(const std::unordered_map<std::string, std::string> void SetTypeTable(const std::unordered_map<std::string, std::string>
&tagtable); &tagtable);
void InsertType(const std::string &key, const std::string &value); void InsertType(const std::string &key, const std::string &value);
void InsertExtension(const std::string &ext);
private: private:
std::unordered_map<std::string, std::string> tagtable_; std::unordered_map<std::string, std::string> tagtable_;
std::unordered_map<std::string, std::string> typetable_; std::unordered_map<std::string, std::string> typetable_;
std::vector<std::string> extensiontable_;
std::string background_; std::string background_;
}; // class Config }; // class Config

2
juci/window.cc

@ -59,7 +59,7 @@ Window::Window() :
std::thread execute([=]() { std::thread execute([=]() {
std::string path = notebook_.CurrentPagePath(); std::string path = notebook_.CurrentPagePath();
int pos = path.find_last_of("/\\"); int pos = path.find_last_of("/\\");
if(pos != std::string::npos){ if(pos != std::string::npos) {
path.erase(path.begin()+pos,path.end()); path.erase(path.begin()+pos,path.end());
terminal_.SetFolderCommand(path); terminal_.SetFolderCommand(path);
} }

Loading…
Cancel
Save