Browse Source

Now adds keywords from lang-files to non-clang-file completion. Also some smaller fixes.

merge-requests/365/head
eidheim 10 years ago
parent
commit
75e1f567fc
  1. 2
      src/config.cc
  2. 1
      src/config.h
  3. 2
      src/notebook.cc
  4. 60
      src/source.cc
  5. 8
      src/source.h

2
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) {
}

1
src/config.h

@ -1,7 +1,6 @@
#ifndef JUCI_CONFIG_H_
#define JUCI_CONFIG_H_
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include "menu.h"
class MainConfig {

2
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;

60
src/source.cc

@ -1139,19 +1139,71 @@ std::vector<std::string> Source::View::spellcheck_get_suggestions(const Gtk::Tex
/////////////////////
Source::GenericView::GenericView(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::Language> 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<Gdk::Pixbuf>());
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<Gdk::Pixbuf>());
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<CompletionBuffer> &completion_buffer, const boost::property_tree::ptree &pt) {
bool case_insensitive=false;
for(auto &node: pt) {
if(node.first=="<xmlcomment>") {
if(static_cast<std::string>(node.second.data())==" case insensitive ")
case_insensitive=true;
}
else if(node.first=="keyword") {
auto data=static_cast<std::string>(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) {
}
}
}
////////////////////////

8
src/source.h

@ -16,6 +16,7 @@
#include <set>
#include <regex>
#include <aspell.h>
#include <boost/property_tree/xml_parser.hpp>
namespace Source {
Glib::RefPtr<Gsv::Language> 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<CompletionBuffer> create() {return Glib::RefPtr<CompletionBuffer>(new CompletionBuffer());}
};
public:
GenericView(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::Language> language);
void add_keywords(Glib::RefPtr<CompletionBuffer> &completion_buffer, const boost::property_tree::ptree &pt);
};
class ClangViewParse : public View {

Loading…
Cancel
Save