diff --git a/src/config.cc b/src/config.cc index 324cd76..56e2115 100644 --- a/src/config.cc +++ b/src/config.cc @@ -79,7 +79,7 @@ bool MainConfig::check_config_file(const boost::property_tree::ptree &default_cf exists=false; } try { - exists&=check_config_file(default_cfg.get_child(node.first), path); + exists&=check_config_file(node.second, path); } catch(const std::exception &e) { } diff --git a/src/config.h b/src/config.h index 7aae271..190de24 100644 --- a/src/config.h +++ b/src/config.h @@ -1,7 +1,6 @@ #ifndef JUCI_CONFIG_H_ #define JUCI_CONFIG_H_ #include -#include #include "menu.h" class MainConfig { diff --git a/src/notebook.cc b/src/notebook.cc index d9e28b9..21e4b37 100644 --- a/src/notebook.cc +++ b/src/notebook.cc @@ -65,7 +65,7 @@ void Notebook::open(const boost::filesystem::path &file_path) { can_read.close(); auto language=Source::guess_language(file_path); - if(language && (language->get_id()=="chdr" || language->get_id()=="c" || language->get_id()=="cpp" || language->get_id()=="objc")) { + if(language && (language->get_id()=="chdr" || language->get_id()=="cpphdr" || language->get_id()=="c" || language->get_id()=="cpp" || language->get_id()=="objc")) { boost::filesystem::path project_path; if(directories.cmake && directories.cmake->project_path!="" && file_path.generic_string().substr(0, directories.cmake->project_path.generic_string().size()+1)==directories.cmake->project_path.generic_string()+'/') { project_path=directories.cmake->project_path; diff --git a/src/source.cc b/src/source.cc index 0c6ae41..cfe6ad9 100644 --- a/src/source.cc +++ b/src/source.cc @@ -1139,19 +1139,71 @@ std::vector Source::View::spellcheck_get_suggestions(const Gtk::Tex ///////////////////// Source::GenericView::GenericView(const boost::filesystem::path &file_path, Glib::RefPtr language) : View(file_path, language) { configure(); + spellcheck_all=true; if(language) { get_source_buffer()->set_language(language); Singleton::terminal()->print("Language for file "+file_path.string()+" set to "+language->get_name()+".\n"); } - spellcheck_all=true; + auto completion=get_completion(); - auto completion_words=Gsv::CompletionWords::create("", Glib::RefPtr()); - completion_words->register_provider(get_buffer()); - completion->add_provider(completion_words); completion->property_show_headers()=false; completion->property_show_icons()=false; completion->property_accelerators()=0; + + auto completion_words=Gsv::CompletionWords::create("", Glib::RefPtr()); + completion_words->register_provider(get_buffer()); + completion->add_provider(completion_words); + + if(language) { + auto language_manager=Gsv::LanguageManager::get_default(); + auto search_paths=language_manager->get_search_path(); + bool found_language_file=false; + boost::filesystem::path language_file; + for(auto &search_path: search_paths) { + boost::filesystem::path p(search_path+'/'+language->get_id()+".lang"); + if(boost::filesystem::exists(p) && boost::filesystem::is_regular_file(p)) { + language_file=p; + found_language_file=true; + break; + } + } + if(found_language_file) { + auto completion_buffer_keywords=CompletionBuffer::create(); + boost::property_tree::ptree pt; + try { + boost::property_tree::xml_parser::read_xml(language_file.string(), pt); + } + catch(const std::exception &e) { + Singleton::terminal()->print("Error: error parsing language file "+language_file.string()+": "+e.what()+'\n'); + } + add_keywords(completion_buffer_keywords, pt); + completion_words->register_provider(completion_buffer_keywords); + } + } +} + +void Source::GenericView::add_keywords(Glib::RefPtr &completion_buffer, const boost::property_tree::ptree &pt) { + bool case_insensitive=false; + for(auto &node: pt) { + if(node.first=="") { + if(static_cast(node.second.data())==" case insensitive ") + case_insensitive=true; + } + else if(node.first=="keyword") { + auto data=static_cast(node.second.data()); + completion_buffer->insert_at_cursor(data+'\n'); + if(case_insensitive) { + std::transform(data.begin(), data.end(), data.begin(), ::tolower); + completion_buffer->insert_at_cursor(data+'\n'); + } + } + try { + add_keywords(completion_buffer, node.second); + } + catch(const std::exception &e) { + } + } } //////////////////////// diff --git a/src/source.h b/src/source.h index 49e63e0..abb84ce 100644 --- a/src/source.h +++ b/src/source.h @@ -16,6 +16,7 @@ #include #include #include +#include namespace Source { Glib::RefPtr guess_language(const boost::filesystem::path &file_path); @@ -158,8 +159,15 @@ namespace Source { }; class GenericView : public View { + private: + class CompletionBuffer : public Gtk::TextBuffer { + public: + static Glib::RefPtr create() {return Glib::RefPtr(new CompletionBuffer());} + }; public: GenericView(const boost::filesystem::path &file_path, Glib::RefPtr language); + + void add_keywords(Glib::RefPtr &completion_buffer, const boost::property_tree::ptree &pt); }; class ClangViewParse : public View {