From 1e018e675cb7fbcae3e01c2deb12a953f090d0d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Fri, 27 Mar 2015 22:28:11 +0100 Subject: [PATCH 1/7] proof of concept syntax highlighting --- juci/config.cc | 11 ++- juci/notebook.cc | 3 +- juci/source.cc | 252 ++++++++++++++++++++++++++++++++++------------- juci/source.h | 84 +++++++++++----- 4 files changed, 251 insertions(+), 99 deletions(-) diff --git a/juci/config.cc b/juci/config.cc index 388fb88..ff6440a 100644 --- a/juci/config.cc +++ b/juci/config.cc @@ -15,11 +15,14 @@ void MainConfig::GenerateSource() { 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"); - for ( auto &i : syntax_json ) + for ( auto &i : colors_json ) { source_cfg_.InsertTag(i.first, i.second.get_value()); - - for ( auto &i : colors_json ) - source_cfg_.InsertType(i.first, i.second.get_value()); + std::cout << "inserting tag, key: " << i.first << " value: " << i.second.get_value() << std::endl; + } + for ( auto &i : syntax_json ) { + source_cfg_.InsertType(i.first, i.second.get_value()); + std::cout << "inserting type, key: " << i.first << " value: " << i.second.get_value() << std::endl; + } } void MainConfig::GenerateKeybindings() { diff --git a/juci/notebook.cc b/juci/notebook.cc index 5b44bd2..e1485d2 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -33,7 +33,8 @@ source_config_(source_cfg) { .key_map()["new_cc_file"]), [this]() { is_new_file_ = true; - OnFileNewCCFile(); + // OnFileNewCCFile(); + OnOpenFile("/home/zalox/bachelor/juci/juci/source.cc"); }); keybindings.action_group_menu()->add(Gtk::Action::create("FileNewH", "New h file"), diff --git a/juci/source.cc b/juci/source.cc index 95307e2..176890f 100644 --- a/juci/source.cc +++ b/juci/source.cc @@ -5,19 +5,40 @@ #include #include +#define DBGVAR( os, var ) \ + (os) << "DBG: " << __FILE__ << "(" << __LINE__ << ") " \ + << #var << " = [" << (var) << "]" << std::endl + +Source::Location:: +Location(int line_number, int column_offset) : + line_number_(line_number), column_offset_(column_offset) { } + +Source::Location:: +Location(const Source::Location &org) : + line_number_(org.line_number_), column_offset_(org.column_offset_) { } + +Source::Range:: +Range(const Location &start, const Location &end, int kind) : + start_(start), end_(end), kind_(kind) { } + +Source::Range:: +Range(const Source::Range &org) : + start_(org.start_), end_(org.end_), kind_(org.kind_) { } + + ////////////// //// View //// ////////////// Source::View::View() { - // std::cout << "View constructor run" << std::endl; override_font(Pango::FontDescription("Monospace")); + DBGVAR(std::cout, "View Constructor"); } // Source::View::UpdateLine // returns the new line string Source::View::UpdateLine() { Gtk::TextIter line(get_buffer()->get_insert()->get_iter()); - // std::cout << line.get_line() << std::endl; - // for each word --> check what it is --> apply appropriate tag + DBGVAR(std::cout, line.get_line()); + DBGVAR(std::cout, line.get_line_offset()); return ""; } @@ -31,58 +52,62 @@ string Source::View::GetLine(const Gtk::TextIter &begin) { // Source::View::ApplyTheme() // Applies theme in textview void Source::View::ApplyConfig(const Source::Config &config) { - for (auto &item : config.tagtable()) { - // std::cout << "Apply: f: " << item.first << ", s: " << - // item.second << std::endl; + // DBGVAR(std::cout, "Start of apply config"); + for (auto &item : config.tagtable()) get_buffer()->create_tag(item.first)->property_foreground() = item.second; - } + std::cout << "End of apply config" << std::endl; } -void Source::View::OnOpenFile(std::vector &locations, +void Source::View::OnOpenFile(const std::vector &ranges, const Source::Config &config) { - /* ApplyConfig(config); + ApplyConfig(config); Glib::RefPtr buffer = get_buffer(); - for (auto &loc : locations) { - string type = std::to_string(loc.kind()); + for (auto &range : ranges) { + string type = std::to_string(range.kind()); try { config.typetable().at(type); } catch (std::exception) { continue; } - int linum_start = loc.line_number_begin(); - int linum_end = loc.line_number_end(); - int begin = loc.begin(); - int end = loc.end(); + int linum_start = range.start().line_number()-1; + int linum_end = range.end().line_number()-1; + + int begin = range.start().column_offset()-1; + int end = range.end().column_offset()-1; + if (end < 0) end = 0; if (begin < 0) begin = 0; - // std::cout << "Libc: "; - // std::cout << "type: " << type; - // std::cout << " linum_s: " << linum_start+1 << " linum_e: " << linum_end+1; - // std::cout << ", begin: " << begin << ", end: " << end << std::endl; + std::cout << "Libc: "; + std::cout << "type: " << type; + std::cout << " linum_s: " << linum_start; + std::cout << " linum_e: " << linum_end; + std::cout << ", begin: " << begin << ", end: " << end << std::endl; Gtk::TextIter begin_iter = buffer->get_iter_at_line_offset(linum_start, begin); Gtk::TextIter end_iter = buffer->get_iter_at_line_offset(linum_end, end); - // std::cout << get_buffer()->get_text(begin_iter, end_iter) << std::endl; + std::cout << get_buffer()->get_text(begin_iter, end_iter) << std::endl; if (begin_iter.get_line() == end_iter.get_line()) { buffer->apply_tag_by_name(config.typetable().at(type), begin_iter, end_iter); } } - */ + // DBGVAR(std::cout, "End of OnOpenFile"); } // Source::View::Config::Config(Config &config) // copy-constructor Source::Config::Config(const Source::Config &original) { + // DBGVAR(std::cout, "Start of Config constructor"); SetTagTable(original.tagtable()); SetTypeTable(original.typetable()); + // DBGVAR(std::cout, "End of Config constructor"); } -Source::Config::Config(){} +Source::Config::Config() {} // Source::View::Config::tagtable() // returns a const refrence to the tagtable @@ -96,14 +121,13 @@ const std::unordered_map& Source::Config::typetable() const { return typetable_; } - void Source::Config::InsertTag(const string &key, const string &value) { tagtable_[key] = value; } // Source::View::Config::SetTagTable() // sets the tagtable for the view -void Source::Config::SetTypeTable( - const std::unordered_map &typetable) { +void Source::Config:: +SetTypeTable(const std::unordered_map &typetable) { typetable_ = typetable; } @@ -112,8 +136,8 @@ void Source::Config::InsertType(const string &key, const string &value) { } // Source::View::Config::SetTagTable() // sets the tagtable for the view -void Source::Config::SetTagTable( - const std::unordered_map &tagtable) { +void Source::Config:: +SetTagTable(const std::unordered_map &tagtable) { tagtable_ = tagtable; } @@ -124,22 +148,137 @@ Source::Model::Model(const Source::Config &config) : config_(config) { } -Source::Config& Source::Model::config() { - return config_; +void Source::Model:: +initSyntaxHighlighting(const std::string &filepath, + const std::string &project_path, + int start_offset, + int end_offset) { + // DBGVAR(std::cout, "Start of initsntax"); + set_file_path(filepath); + set_project_path(project_path); + std::vector arguments = get_compilation_commands(); + clang::TranslationUnit tu(true, filepath, arguments); + // DBGVAR(std::cout, &tu); + // DBGVAR(std::cout, "Start of extract tokens"); + // DBGVAR(std::cout, file_path()); + // DBGVAR(std::cout, &tu); + clang::SourceLocation start(&tu, file_path(), start_offset); + // DBGVAR(std::cout, "After start"); + clang::SourceLocation end(&tu, file_path(), end_offset); + // DBGVAR(std::cout, "After end"); + clang::SourceRange range(&start, &end); + // DBGVAR(std::cout, "After range"); + clang::Tokens tokens(&tu, &range); + + + + // DBGVAR(std::cout, "After tokens"); + std::vector tks = tokens.tokens(); + // DBGVAR(std::cout, "After tokens tokens"); + // DBGVAR(std::cout, "before for loop"); + for (auto &token : tks) { + // std::cout << token.kind() << std::endl; + switch (token.kind()) { + // case 0: PunctuationToken(&token); break; // A tkn with punctation + // case 1: KeywordToken(&token); break; // A language keyword. + // case 2: IdentifierToken(&token); break; // An identifier, not a keyword + // case 3: LiteralToken(&token); break; // A num, string, or char literal + case 4: + // std::cout << "Comment token" << std::endl; + clang::SourceRange range = token.get_source_range(&tu); + // DBGVAR(std::cout, "etter range"); + unsigned begin_line_num, begin_offset, end_line_num, end_offset; + clang::SourceLocation begin(&range, true); + clang::SourceLocation end(&range, false); + // DBGVAR(std::cout, "Herre krasje etter begin"); + begin.get_location_info(NULL, &begin_line_num, &begin_offset, NULL); + // DBGVAR(std::cout, "etter utpressing av begin"); + end.get_location_info(NULL, &end_line_num, &end_offset, NULL); + // DBGVAR(std::cout, "etter utpressing av end"); + source_ranges_.emplace_back(Source::Location(begin_line_num, begin_offset), + Source::Location(end_line_num, end_offset), 705); + std::string k = token.get_token_spelling(&tu); + break; // A comment. + } + } + // DBGVAR(std::cout, "End of extract tokens"); + extractTokens(start_offset, end_offset); + // DBGVAR(std::cout, "End of of initsntax"); } -const string Source::Model::filepath() { - return filepath_; +// sets the filepath for this mvc +void Source::Model:: +set_file_path(const std::string &file_path) { + file_path_ = file_path; +} +// sets the project path for this mvc +void Source::Model:: +set_project_path(const std::string &project_path) { + project_path_ = project_path; +} +// sets the ranges for keywords in this mvc +void Source::Model:: +set_ranges(const std::vector &source_ranges) { + source_ranges_ = source_ranges; +} +// gets the file_path member +const std::string& Source::Model::file_path() const { + return file_path_; +} +// gets the project_path member +const std::string& Source::Model::project_path() const { + return project_path_; +} +// gets the ranges member +const std::vector& Source::Model::source_ranges() const { + return source_ranges_; +} +// gets the config member +const Source::Config& Source::Model::config() const { + return config_; } -void Source::Model::SetFilePath(const string &filepath) { - filepath_ = filepath; +std::vector Source::Model:: +get_compilation_commands() { + // DBGVAR(std::cout, "Start of get compilation commands"); + clang::CompilationDatabase db(project_path()+"/"); + clang::CompileCommands commands(file_path(), &db); + std::vector cmds = commands.get_commands(); + std::vector arguments; + for (auto &i : cmds) { + std::vector lol = i.get_command_as_args(); + for (int a = 1; a < lol.size()-4; a++) { + arguments.emplace_back(lol[a].c_str()); + } + } + // DBGVAR(std::cout, "End of get compilation commands"); + return arguments; } void Source::Model:: -SetSourceLocations(const std::vector &locations) { - locations_ = locations; +extractTokens(int start_offset, int end_offset) { + +} + +void Source::Model::LiteralToken(clang::Token *token) { + std::cout << "Literal token" << std::endl; +} + +void Source::Model::CommentToken(clang::Token *token) { +} + +void Source::Model::IdentifierToken(clang::Token *token) { + std::cout << "Identifyer token" << std::endl; } + +void Source::Model::KeywordToken(clang::Token *token) { + std::cout << "Keyword token" << std::endl; +} + +void Source::Model::PunctuationToken(clang::Token *token) { + std::cout << "Punctuation token" << std::endl; +} + //////////////////// //// Controller //// //////////////////// @@ -172,46 +311,25 @@ void Source::Controller::OnLineEdit() { void Source::Controller::OnNewEmptyFile() { string filename("/tmp/juci_t"); sourcefile s(filename); - model().SetFilePath(filename); + model().set_file_path(filename); + model().set_project_path(filename); s.save(""); } +string extract_file_path(const std::string &file_path) { + return file_path.substr(0, file_path.find_last_of('/')); +} + void Source::Controller::OnOpenFile(const string &filepath) { sourcefile s(filepath); buffer()->set_text(s.get_content()); int start_offset = buffer()->begin().get_offset(); int end_offset = buffer()->end().get_offset(); - - std::string project_path = - filepath.substr(0, filepath.find_last_of('/')); - - clang::CompilationDatabase db(project_path); - clang::CompileCommands commands(filepath, &db); - std::vector cmds = commands.get_commands(); - std::vector arguments; - for (auto &i : cmds) { - std::vector lol = i.get_command_as_args(); - for (int a = 1; a < lol.size()-4; a++) { - arguments.emplace_back(lol[a].c_str()); - } - } - clang::TranslationUnit tu(true, filepath, arguments); - clang::SourceLocation start(&tu, filepath, start_offset); - clang::SourceLocation end(&tu, filepath, end_offset); - clang::SourceRange range(&start, &end); - clang::Tokens tokens(&tu, &range); - std::vector tks = tokens.tokens(); - - for (auto &t : tks) { - clang::SourceLocation loc = t.get_source_location(&tu); - unsigned line; - unsigned column; - loc.get_location_info(NULL, &line, &column, NULL); - } - - // std::cout << t.elapsed().user << std::endl; - // model().SetSourceLocations(tu.getSourceLocations()); - // view().OnOpenFile(model().getSourceLocations(), model().theme()); + model().initSyntaxHighlighting(filepath, + extract_file_path(filepath), + start_offset, + end_offset); + view().OnOpenFile(model().source_ranges(), model().config()); } Glib::RefPtr Source::Controller::buffer() { diff --git a/juci/source.h b/juci/source.h index 9b5406d..516a57b 100644 --- a/juci/source.h +++ b/juci/source.h @@ -1,6 +1,6 @@ #ifndef JUCI_SOURCE_H_ #define JUCI_SOURCE_H_ - +#include #include #include #include @@ -27,32 +27,37 @@ namespace Source { std::unordered_map typetable_; string background_; }; // class Config - /* - class BufferLocation { - BufferLocation(const BufferLocation &location); - BufferLocation(int, int); - int line_number() { return line_number_; } - int column_number() { return column_offset_; } + + class Location { + public: + Location(const Location &location); + Location(int line_number, int column_offset); + int line_number() const { return line_number_; } + int column_offset() const { return column_offset_; } private: int line_number_; int column_offset_; }; - class BufferRange { - BufferRange(const BufferLocation &start, const BufferLocation &end) : - start_(start), end_(end) { } + class Range { + public: + Range(const Location &start, const Location &end, int kind); + Range(const Range &org); + const Location& start() const { return start_; } + const Location& end() const { return end_; } + int kind() const { return kind_; } private: - BufferLocation start_; - BufferLocation end_; - };*/ - + Location start_; + Location end_; + int kind_; + }; class View : public Gtk::TextView { public: View(); string UpdateLine(); void ApplyConfig(const Config &config); - void OnOpenFile(std::vector &locations, + void OnOpenFile(const std::vector &locations, const Config &config); private: string GetLine(const Gtk::TextIter &begin); @@ -60,25 +65,49 @@ namespace Source { class Model{ public: - Model(const Source::Config &config); - //Model(); - Config& config(); - const string filepath(); - void SetFilePath(const string &filepath); - void SetSourceLocations( const std::vector &locations); - std::vector& getSourceLocations() { - return locations_; - } + // constructor for Source::Model + explicit Model(const Source::Config &config); + // inits the syntax highligthing on file open + void initSyntaxHighlighting(const std::string &filepath, + const std::string &project_path, + int start_offset, + int end_offset); + // sets the filepath for this mvc + void set_file_path(const string &file_path); + // sets the project path for this mvc + void set_project_path(const string &project_path); + // sets the ranges for keywords in this mvc + void set_ranges(const std::vector &ranges); + // gets the file_path member + const string& file_path() const; + // gets the project_path member + const string& project_path() const; + // gets the ranges member + const std::vector& source_ranges() const; + // gets the config member + const Config& config() const; + ~Model() { + std::cout << "SNOUTHN" << std::endl; + } private: Source::Config config_; - string filepath_; - std::vector locations_; + string file_path_; + string project_path_; + std::vector source_ranges_; + clang::TranslationUnit tu_; + void extractTokens(int, int); + void LiteralToken(clang::Token *token); + void CommentToken(clang::Token *token); + void IdentifierToken(clang::Token *token); + void KeywordToken(clang::Token *token); + void PunctuationToken(clang::Token *token); + std::vector get_compilation_commands(); }; class Controller { public: - Controller(const Source::Config &config); + explicit Controller(const Source::Config &config); Controller(); View& view(); Model& model(); @@ -89,6 +118,7 @@ namespace Source { private: void OnLineEdit(); void OnSaveFile(); + protected: View view_; Model model_; From 2e0a497bae172c3367c9856e1c4cebac3d536bb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Wed, 8 Apr 2015 11:10:56 +0200 Subject: [PATCH 2/7] working proof of concept syntax --- juci/CMakeLists.txt | 2 +- juci/source.cc | 187 +++++++++++++++++++++++--------------------- juci/source.h | 16 ++-- 3 files changed, 107 insertions(+), 98 deletions(-) diff --git a/juci/CMakeLists.txt b/juci/CMakeLists.txt index d4f326d..abe2d87 100644 --- a/juci/CMakeLists.txt +++ b/juci/CMakeLists.txt @@ -3,7 +3,7 @@ set(project_name juci) set(module juci_to_python_api) project (${project_name}) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/") INCLUDE(FindPkgConfig) diff --git a/juci/source.cc b/juci/source.cc index 176890f..cd8ff80 100644 --- a/juci/source.cc +++ b/juci/source.cc @@ -4,6 +4,7 @@ #include #include #include +#include #define DBGVAR( os, var ) \ (os) << "DBG: " << __FILE__ << "(" << __LINE__ << ") " \ @@ -31,15 +32,6 @@ Range(const Source::Range &org) : ////////////// Source::View::View() { override_font(Pango::FontDescription("Monospace")); - DBGVAR(std::cout, "View Constructor"); -} -// Source::View::UpdateLine -// returns the new line -string Source::View::UpdateLine() { - Gtk::TextIter line(get_buffer()->get_insert()->get_iter()); - DBGVAR(std::cout, line.get_line()); - DBGVAR(std::cout, line.get_line_offset()); - return ""; } string Source::View::GetLine(const Gtk::TextIter &begin) { @@ -52,15 +44,18 @@ string Source::View::GetLine(const Gtk::TextIter &begin) { // Source::View::ApplyTheme() // Applies theme in textview void Source::View::ApplyConfig(const Source::Config &config) { - // DBGVAR(std::cout, "Start of apply config"); - for (auto &item : config.tagtable()) - get_buffer()->create_tag(item.first)->property_foreground() = item.second; - std::cout << "End of apply config" << std::endl; + for (auto &item : config.tagtable()) { + if (get_buffer()->get_tag_table()->lookup(item.first) == 0) + get_buffer()->create_tag(item.first)->property_foreground() = item.second; + } } -void Source::View::OnOpenFile(const std::vector &ranges, +void Source::View::OnUpdateSyntax(const std::vector &ranges, const Source::Config &config) { + get_buffer()->remove_all_tags(get_buffer()->begin(), + get_buffer()->end()); ApplyConfig(config); + Glib::RefPtr buffer = get_buffer(); for (auto &range : ranges) { string type = std::to_string(range.kind()); @@ -79,32 +74,22 @@ void Source::View::OnOpenFile(const std::vector &ranges, if (end < 0) end = 0; if (begin < 0) begin = 0; - std::cout << "Libc: "; - std::cout << "type: " << type; - std::cout << " linum_s: " << linum_start; - std::cout << " linum_e: " << linum_end; - std::cout << ", begin: " << begin << ", end: " << end << std::endl; - Gtk::TextIter begin_iter = buffer->get_iter_at_line_offset(linum_start, begin); Gtk::TextIter end_iter = buffer->get_iter_at_line_offset(linum_end, end); - std::cout << get_buffer()->get_text(begin_iter, end_iter) << std::endl; if (begin_iter.get_line() == end_iter.get_line()) { buffer->apply_tag_by_name(config.typetable().at(type), begin_iter, end_iter); } } - // DBGVAR(std::cout, "End of OnOpenFile"); } // Source::View::Config::Config(Config &config) // copy-constructor Source::Config::Config(const Source::Config &original) { - // DBGVAR(std::cout, "Start of Config constructor"); SetTagTable(original.tagtable()); SetTypeTable(original.typetable()); - // DBGVAR(std::cout, "End of Config constructor"); } Source::Config::Config() {} @@ -151,59 +136,39 @@ Source::Model::Model(const Source::Config &config) : void Source::Model:: initSyntaxHighlighting(const std::string &filepath, const std::string &project_path, + const std::string &text, int start_offset, int end_offset) { - // DBGVAR(std::cout, "Start of initsntax"); set_file_path(filepath); set_project_path(project_path); std::vector arguments = get_compilation_commands(); - clang::TranslationUnit tu(true, filepath, arguments); - // DBGVAR(std::cout, &tu); - // DBGVAR(std::cout, "Start of extract tokens"); - // DBGVAR(std::cout, file_path()); - // DBGVAR(std::cout, &tu); - clang::SourceLocation start(&tu, file_path(), start_offset); - // DBGVAR(std::cout, "After start"); - clang::SourceLocation end(&tu, file_path(), end_offset); - // DBGVAR(std::cout, "After end"); - clang::SourceRange range(&start, &end); - // DBGVAR(std::cout, "After range"); - clang::Tokens tokens(&tu, &range); - - - - // DBGVAR(std::cout, "After tokens"); - std::vector tks = tokens.tokens(); - // DBGVAR(std::cout, "After tokens tokens"); - // DBGVAR(std::cout, "before for loop"); - for (auto &token : tks) { - // std::cout << token.kind() << std::endl; - switch (token.kind()) { - // case 0: PunctuationToken(&token); break; // A tkn with punctation - // case 1: KeywordToken(&token); break; // A language keyword. - // case 2: IdentifierToken(&token); break; // An identifier, not a keyword - // case 3: LiteralToken(&token); break; // A num, string, or char literal - case 4: - // std::cout << "Comment token" << std::endl; - clang::SourceRange range = token.get_source_range(&tu); - // DBGVAR(std::cout, "etter range"); - unsigned begin_line_num, begin_offset, end_line_num, end_offset; - clang::SourceLocation begin(&range, true); - clang::SourceLocation end(&range, false); - // DBGVAR(std::cout, "Herre krasje etter begin"); - begin.get_location_info(NULL, &begin_line_num, &begin_offset, NULL); - // DBGVAR(std::cout, "etter utpressing av begin"); - end.get_location_info(NULL, &end_line_num, &end_offset, NULL); - // DBGVAR(std::cout, "etter utpressing av end"); - source_ranges_.emplace_back(Source::Location(begin_line_num, begin_offset), - Source::Location(end_line_num, end_offset), 705); - std::string k = token.get_token_spelling(&tu); - break; // A comment. - } - } - // DBGVAR(std::cout, "End of extract tokens"); + tu_ = clang::TranslationUnit(true, + filepath, + arguments, + text); extractTokens(start_offset, end_offset); - // DBGVAR(std::cout, "End of of initsntax"); +} + +// Source::View::UpdateLine +void Source::View::OnLineEdit(const std::vector &locations, + const Source::Config &config) { + OnUpdateSyntax(locations, config); +} + +// Source::Model::UpdateLine +void Source::Model::OnLineEdit(const std::string &buffer) { + int i = tu_.ReparseTranslationUnit(file_path(), buffer); + set_ranges(std::vector()); + extractTokens(0, buffer.size()); +} + + +// Source::Controller::OnLineEdit() +// fired when a line in the buffer is edited +void Source::Controller::OnLineEdit() { + model().OnLineEdit(buffer()->get_text()); + view().OnLineEdit(model().source_ranges(), + model().config()); } // sets the filepath for this mvc @@ -240,7 +205,6 @@ const Source::Config& Source::Model::config() const { std::vector Source::Model:: get_compilation_commands() { - // DBGVAR(std::cout, "Start of get compilation commands"); clang::CompilationDatabase db(project_path()+"/"); clang::CompileCommands commands(file_path(), &db); std::vector cmds = commands.get_commands(); @@ -251,32 +215,58 @@ get_compilation_commands() { arguments.emplace_back(lol[a].c_str()); } } - // DBGVAR(std::cout, "End of get compilation commands"); return arguments; } void Source::Model:: extractTokens(int start_offset, int end_offset) { - + clang::SourceLocation start(&tu_, file_path(), start_offset); + clang::SourceLocation end(&tu_, file_path(), end_offset); + clang::SourceRange range(&start, &end); + clang::Tokens tokens(&tu_, &range); + std::vector tks = tokens.tokens(); + for (auto &token : tks) { + switch (token.kind()) { + case 0: PunctuationToken(&token); break; // A tkn with punctation + case 1: KeywordToken(&token); break; // A language keyword. + case 2: IdentifierToken(&token); break; // An identifier, not a keyword + case 3: LiteralToken(&token); break; // A num, string, or char literal + case 4: CommentToken(&token); break; // A comment token + } + } } void Source::Model::LiteralToken(clang::Token *token) { - std::cout << "Literal token" << std::endl; + HighlightToken(token, 109);; } void Source::Model::CommentToken(clang::Token *token) { + HighlightToken(token, 705); } void Source::Model::IdentifierToken(clang::Token *token) { - std::cout << "Identifyer token" << std::endl; + } void Source::Model::KeywordToken(clang::Token *token) { - std::cout << "Keyword token" << std::endl; + HighlightToken(token, 702);; } void Source::Model::PunctuationToken(clang::Token *token) { - std::cout << "Punctuation token" << std::endl; +} + + +void Source::Model::HighlightToken(clang::Token *token, int token_kind) { + clang::SourceRange range = token->get_source_range(&tu_); + unsigned begin_line_num, begin_offset, end_line_num, end_offset; + clang::SourceLocation begin(&range, true); + clang::SourceLocation end(&range, false); + begin.get_location_info(NULL, &begin_line_num, &begin_offset, NULL); + end.get_location_info(NULL, &end_line_num, &end_offset, NULL); + source_ranges_.emplace_back(Source::Location(begin_line_num, + begin_offset), + Source::Location(end_line_num, + end_offset), token_kind); } //////////////////// @@ -287,11 +277,9 @@ void Source::Model::PunctuationToken(clang::Token *token) { // Constructor for Controller Source::Controller::Controller(const Source::Config &config) : model_(config) { - view().get_buffer()->signal_changed().connect([this](){ - this->OnLineEdit(); - }); } + // Source::Controller::view() // return shared_ptr to the view Source::View& Source::Controller::view() { @@ -302,11 +290,6 @@ Source::View& Source::Controller::view() { Source::Model& Source::Controller::model() { return model_; } -// Source::Controller::OnLineEdit() -// fired when a line in the buffer is edited -void Source::Controller::OnLineEdit() { - view().UpdateLine(); -} void Source::Controller::OnNewEmptyFile() { string filename("/tmp/juci_t"); @@ -320,16 +303,38 @@ string extract_file_path(const std::string &file_path) { return file_path.substr(0, file_path.find_last_of('/')); } +std::vector extentions() { + return {".h", ".cc", ".cpp", ".hpp"}; +} + +bool check_extention(const std::string &file_path) { + std::string extention = file_path.substr(file_path.find_last_of('.'), + file_path.size()); + for (auto &ex : extentions()) { + if (extention == ex) { + return true; + } + } + return false; +} + void Source::Controller::OnOpenFile(const string &filepath) { sourcefile s(filepath); buffer()->set_text(s.get_content()); int start_offset = buffer()->begin().get_offset(); int end_offset = buffer()->end().get_offset(); - model().initSyntaxHighlighting(filepath, - extract_file_path(filepath), - start_offset, - end_offset); - view().OnOpenFile(model().source_ranges(), model().config()); + + if (check_extention(filepath)) { + model().initSyntaxHighlighting(filepath, + extract_file_path(filepath), + buffer()->get_text(), + start_offset, + end_offset); + view().OnUpdateSyntax(model().source_ranges(), model().config()); + } + view().get_buffer()->signal_changed().connect([this]() { + OnLineEdit(); + }); } Glib::RefPtr Source::Controller::buffer() { diff --git a/juci/source.h b/juci/source.h index 516a57b..3e593c6 100644 --- a/juci/source.h +++ b/juci/source.h @@ -55,9 +55,11 @@ namespace Source { class View : public Gtk::TextView { public: View(); - string UpdateLine(); + void ApplyConfig(const Config &config); - void OnOpenFile(const std::vector &locations, + void OnLineEdit(const std::vector &locations, + const Config &config); + void OnUpdateSyntax(const std::vector &locations, const Config &config); private: string GetLine(const Gtk::TextIter &begin); @@ -70,6 +72,7 @@ namespace Source { // inits the syntax highligthing on file open void initSyntaxHighlighting(const std::string &filepath, const std::string &project_path, + const std::string &text, int start_offset, int end_offset); // sets the filepath for this mvc @@ -87,11 +90,11 @@ namespace Source { const std::vector& source_ranges() const; // gets the config member const Config& config() const; - ~Model() { - std::cout << "SNOUTHN" << std::endl; - } + ~Model() { } + void OnLineEdit(const std::string &buffer); + private: - Source::Config config_; + Config config_; string file_path_; string project_path_; std::vector source_ranges_; @@ -102,6 +105,7 @@ namespace Source { void IdentifierToken(clang::Token *token); void KeywordToken(clang::Token *token); void PunctuationToken(clang::Token *token); + void HighlightToken(clang::Token *token, int token_kind); std::vector get_compilation_commands(); }; From 7eeb0470acdef66fc77bb9fbfc8a1cb2c0ba91bd Mon Sep 17 00:00:00 2001 From: tedjk Date: Mon, 13 Apr 2015 16:04:01 +0200 Subject: [PATCH 3/7] made project name from cmakelists.txt more flexible --- juci/directories.cc | 17 ++++++++++++++--- juci/directories.h | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/juci/directories.cc b/juci/directories.cc index adbc795..04aa9f8 100644 --- a/juci/directories.cc +++ b/juci/directories.cc @@ -95,18 +95,29 @@ get_project_name(const boost::filesystem::path& dir_path) { size_t variabel_end = line.find("}", variabel_start); project_name_var = line.substr(variabel_start+1, (variabel_end)-variabel_start-1); + boost::algorithm::trim(project_name_var); + if (variabel_start == std::string::npos) { // not a variabel + variabel_start = line.find("(", 0); + variabel_end = line.find(")", variabel_start); + return line.substr(variabel_start+1, + (variabel_end)-variabel_start-1); + } break; } } std::ifstream ifs2(itr->path().string()); while (std::getline(ifs2, line)) { - if (line.find("set("+project_name_var, 0) != std::string::npos) { + 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 variabel_start = line.find(project_name_var, 0) +project_name_var.length(); size_t variabel_end = line.find(")", variabel_start); - project_name = line.substr(variabel_start, - variabel_end-variabel_start); + project_name = line.substr(variabel_start+1, + variabel_end-variabel_start-1); + boost::algorithm::trim(project_name); return project_name; + } } } break; diff --git a/juci/directories.h b/juci/directories.h index 9a6d3b8..c5b3579 100644 --- a/juci/directories.h +++ b/juci/directories.h @@ -4,6 +4,7 @@ #include #include #include "boost/filesystem.hpp" +#include "boost/algorithm/string.hpp" #include #include #include From f0c622fb89a58aa1dd82b15cb4f3ac32f80ae6b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Mon, 13 Apr 2015 19:40:24 +0200 Subject: [PATCH 4/7] betaalpha syntax highlighting --- juci/source.cc | 215 ++++++++++++++++++++++++++++--------------------- juci/source.h | 39 +++++---- 2 files changed, 146 insertions(+), 108 deletions(-) diff --git a/juci/source.cc b/juci/source.cc index cd8ff80..30a0e93 100644 --- a/juci/source.cc +++ b/juci/source.cc @@ -4,11 +4,10 @@ #include #include #include -#include -#define DBGVAR( os, var ) \ - (os) << "DBG: " << __FILE__ << "(" << __LINE__ << ") " \ - << #var << " = [" << (var) << "]" << std::endl + +#define log( var ) \ + std::cout << "source.cc (" << __LINE__ << ") " << #var << std::endl Source::Location:: Location(int line_number, int column_offset) : @@ -45,44 +44,11 @@ string Source::View::GetLine(const Gtk::TextIter &begin) { // Applies theme in textview void Source::View::ApplyConfig(const Source::Config &config) { for (auto &item : config.tagtable()) { - if (get_buffer()->get_tag_table()->lookup(item.first) == 0) - get_buffer()->create_tag(item.first)->property_foreground() = item.second; + get_buffer()->create_tag(item.first)->property_foreground() = item.second; } } -void Source::View::OnUpdateSyntax(const std::vector &ranges, - const Source::Config &config) { - get_buffer()->remove_all_tags(get_buffer()->begin(), - get_buffer()->end()); - ApplyConfig(config); - Glib::RefPtr buffer = get_buffer(); - for (auto &range : ranges) { - string type = std::to_string(range.kind()); - try { - config.typetable().at(type); - } catch (std::exception) { - continue; - } - - int linum_start = range.start().line_number()-1; - int linum_end = range.end().line_number()-1; - - int begin = range.start().column_offset()-1; - int end = range.end().column_offset()-1; - - if (end < 0) end = 0; - if (begin < 0) begin = 0; - - Gtk::TextIter begin_iter = buffer->get_iter_at_line_offset(linum_start, - begin); - Gtk::TextIter end_iter = buffer->get_iter_at_line_offset(linum_end, end); - if (begin_iter.get_line() == end_iter.get_line()) { - buffer->apply_tag_by_name(config.typetable().at(type), - begin_iter, end_iter); - } - } -} // Source::View::Config::Config(Config &config) @@ -134,7 +100,7 @@ Source::Model::Model(const Source::Config &config) : } void Source::Model:: -initSyntaxHighlighting(const std::string &filepath, +InitSyntaxHighlighting(const std::string &filepath, const std::string &project_path, const std::string &text, int start_offset, @@ -146,29 +112,28 @@ initSyntaxHighlighting(const std::string &filepath, filepath, arguments, text); - extractTokens(start_offset, end_offset); } // Source::View::UpdateLine -void Source::View::OnLineEdit(const std::vector &locations, - const Source::Config &config) { +void Source::View:: +OnLineEdit(const std::vector &locations, + const Source::Config &config) { + log("before onupdatesyntax"); OnUpdateSyntax(locations, config); + log("after onupdatesyntax"); } // Source::Model::UpdateLine -void Source::Model::OnLineEdit(const std::string &buffer) { - int i = tu_.ReparseTranslationUnit(file_path(), buffer); - set_ranges(std::vector()); - extractTokens(0, buffer.size()); +int Source::Model:: +ReParse(const std::string &buffer) { + return tu_.ReparseTranslationUnit(file_path(), buffer); } // Source::Controller::OnLineEdit() // fired when a line in the buffer is edited void Source::Controller::OnLineEdit() { - model().OnLineEdit(buffer()->get_text()); - view().OnLineEdit(model().source_ranges(), - model().config()); + } // sets the filepath for this mvc @@ -181,11 +146,6 @@ void Source::Model:: set_project_path(const std::string &project_path) { project_path_ = project_path; } -// sets the ranges for keywords in this mvc -void Source::Model:: -set_ranges(const std::vector &source_ranges) { - source_ranges_ = source_ranges; -} // gets the file_path member const std::string& Source::Model::file_path() const { return file_path_; @@ -194,10 +154,6 @@ const std::string& Source::Model::file_path() const { const std::string& Source::Model::project_path() const { return project_path_; } -// gets the ranges member -const std::vector& Source::Model::source_ranges() const { - return source_ranges_; -} // gets the config member const Source::Config& Source::Model::config() const { return config_; @@ -218,8 +174,9 @@ get_compilation_commands() { return arguments; } -void Source::Model:: -extractTokens(int start_offset, int end_offset) { +std::vector Source::Model:: +ExtractTokens(int start_offset, int end_offset) { + std::vector ranges; clang::SourceLocation start(&tu_, file_path(), start_offset); clang::SourceLocation end(&tu_, file_path(), end_offset); clang::SourceRange range(&start, &end); @@ -227,43 +184,44 @@ extractTokens(int start_offset, int end_offset) { std::vector tks = tokens.tokens(); for (auto &token : tks) { switch (token.kind()) { - case 0: PunctuationToken(&token); break; // A tkn with punctation - case 1: KeywordToken(&token); break; // A language keyword. - case 2: IdentifierToken(&token); break; // An identifier, not a keyword - case 3: LiteralToken(&token); break; // A num, string, or char literal - case 4: CommentToken(&token); break; // A comment token + case 0: HighlightCursor(&token, &ranges); break; // PunctuationToken + case 1: HighlightToken(&token, &ranges, 702); break; // KeywordToken + case 2: HighlightCursor(&token, &ranges); break; // IdentifierToken + case 3: HighlightToken(&token, &ranges, 109); break; // LiteralToken + case 4: HighlightToken(&token, &ranges, 705); break; // CommentToken } } + log("returns ranges"); + return ranges; } -void Source::Model::LiteralToken(clang::Token *token) { - HighlightToken(token, 109);; -} - -void Source::Model::CommentToken(clang::Token *token) { - HighlightToken(token, 705); -} - -void Source::Model::IdentifierToken(clang::Token *token) { - -} - -void Source::Model::KeywordToken(clang::Token *token) { - HighlightToken(token, 702);; -} - -void Source::Model::PunctuationToken(clang::Token *token) { +void Source::Model:: +HighlightCursor(clang::Token *token, + std::vector *source_ranges) { + clang::SourceLocation location = token->get_source_location(&tu_); + clang::Cursor cursor(&tu_, &location); + clang::SourceRange range(&cursor); + clang::SourceLocation begin(&range, true); + clang::SourceLocation end(&range, false); + unsigned begin_line_num, begin_offset, end_line_num, end_offset; + begin.get_location_info(NULL, &begin_line_num, &begin_offset, NULL); + end.get_location_info(NULL, &end_line_num, &end_offset, NULL); + source_ranges->emplace_back(Source::Location(begin_line_num, + begin_offset), + Source::Location(end_line_num, + end_offset), (int) cursor.kind()); } - - -void Source::Model::HighlightToken(clang::Token *token, int token_kind) { +void Source::Model:: +HighlightToken(clang::Token *token, + std::vector *source_ranges, + int token_kind) { clang::SourceRange range = token->get_source_range(&tu_); unsigned begin_line_num, begin_offset, end_line_num, end_offset; clang::SourceLocation begin(&range, true); clang::SourceLocation end(&range, false); begin.get_location_info(NULL, &begin_line_num, &begin_offset, NULL); end.get_location_info(NULL, &end_line_num, &end_offset, NULL); - source_ranges_.emplace_back(Source::Location(begin_line_num, + source_ranges->emplace_back(Source::Location(begin_line_num, begin_offset), Source::Location(end_line_num, end_offset), token_kind); @@ -318,6 +276,47 @@ bool check_extention(const std::string &file_path) { return false; } +void Source::View::OnUpdateSyntax(const std::vector &ranges, + const Source::Config &config) { + if (ranges.empty() || ranges.size() == 0) { + log("ranges empty"); + return; + } + Glib::RefPtr buffer = get_buffer(); + log("after getting buffer"); + int i = 0; + log("after i int"); + std::cout << "rangeslengde: " << ranges.size() << std::endl; + for (auto &range : ranges) { + string type = std::to_string(range.kind()); + try { + config.typetable().at(type); + } catch (std::exception) { + continue; + } + + int linum_start = range.start().line_number()-1; + int linum_end = range.end().line_number()-1; + + int begin = range.start().column_offset()-1; + int end = range.end().column_offset()-1; + + if (end < 0) end = 0; + if (begin < 0) begin = 0; + Gtk::TextIter begin_iter = + buffer->get_iter_at_line_offset(linum_start, begin); + Gtk::TextIter end_iter = + buffer->get_iter_at_line_offset(linum_end, end); + buffer->remove_all_tags(begin_iter, end_iter); + if (begin_iter.get_line() == end_iter.get_line()) { + buffer->apply_tag_by_name(config.typetable().at(type), + begin_iter, end_iter); + } + i++; + } + log("End of onupdatesyntax"); +} + void Source::Controller::OnOpenFile(const string &filepath) { sourcefile s(filepath); buffer()->set_text(s.get_content()); @@ -325,18 +324,50 @@ void Source::Controller::OnOpenFile(const string &filepath) { int end_offset = buffer()->end().get_offset(); if (check_extention(filepath)) { - model().initSyntaxHighlighting(filepath, + view().ApplyConfig(model().config()); + model().InitSyntaxHighlighting(filepath, extract_file_path(filepath), - buffer()->get_text(), + buffer()->get_text().raw(), start_offset, end_offset); - view().OnUpdateSyntax(model().source_ranges(), model().config()); + view().OnUpdateSyntax(model().ExtractTokens(start_offset, end_offset), + model().config()); } - view().get_buffer()->signal_changed().connect([this]() { - OnLineEdit(); + + buffer()->signal_end_user_action().connect([this]() { + if (!go) { + std::thread parse([this]() { + if(parsing.try_lock()) { + const std::string raw = buffer()->get_text().raw(); + int b = model().ReParse(raw); + if (b == 0) { + if (raw == buffer()->get_text().raw()) { + log("alike!"); + syntax.lock(); + go = true; + syntax.unlock(); + } else { + log("buffer changed"); + } + } + parsing.unlock(); + } + }); + parse.detach(); + } }); -} + buffer()->signal_begin_user_action().connect([this]() { + if (go) { + syntax.lock(); + view(). + OnUpdateSyntax(model().ExtractTokens(0, buffer()->get_text().size()), + model().config()); + go = false; + syntax.unlock(); + } + }); +} Glib::RefPtr Source::Controller::buffer() { return view().get_buffer(); } diff --git a/juci/source.h b/juci/source.h index 3e593c6..67b3d9a 100644 --- a/juci/source.h +++ b/juci/source.h @@ -6,6 +6,8 @@ #include #include "gtkmm.h" #include "clangmm.h" +#include +#include using std::string; @@ -46,6 +48,13 @@ namespace Source { const Location& start() const { return start_; } const Location& end() const { return end_; } int kind() const { return kind_; } + void to_stream() const { + std::cout << "range: [" << start_.line_number()-1; + std::cout << ", " << end_.line_number()-1 << "] "; + std::cout << "<" << start_.column_offset()-1; + std::cout << ", " << end_.column_offset()-1 << ">"; + std::cout << std::endl; + } private: Location start_; Location end_; @@ -55,12 +64,12 @@ namespace Source { class View : public Gtk::TextView { public: View(); - void ApplyConfig(const Config &config); void OnLineEdit(const std::vector &locations, const Config &config); void OnUpdateSyntax(const std::vector &locations, - const Config &config); + const Config &config); + private: string GetLine(const Gtk::TextIter &begin); }; // class View @@ -70,7 +79,7 @@ namespace Source { // constructor for Source::Model explicit Model(const Source::Config &config); // inits the syntax highligthing on file open - void initSyntaxHighlighting(const std::string &filepath, + void InitSyntaxHighlighting(const std::string &filepath, const std::string &project_path, const std::string &text, int start_offset, @@ -79,33 +88,28 @@ namespace Source { void set_file_path(const string &file_path); // sets the project path for this mvc void set_project_path(const string &project_path); - // sets the ranges for keywords in this mvc - void set_ranges(const std::vector &ranges); // gets the file_path member const string& file_path() const; // gets the project_path member const string& project_path() const; - // gets the ranges member - const std::vector& source_ranges() const; // gets the config member const Config& config() const; ~Model() { } - void OnLineEdit(const std::string &buffer); + int ReParse(const std::string &buffer); + std::vector ExtractTokens(int, int); private: Config config_; string file_path_; string project_path_; - std::vector source_ranges_; clang::TranslationUnit tu_; - void extractTokens(int, int); - void LiteralToken(clang::Token *token); - void CommentToken(clang::Token *token); - void IdentifierToken(clang::Token *token); - void KeywordToken(clang::Token *token); - void PunctuationToken(clang::Token *token); - void HighlightToken(clang::Token *token, int token_kind); + void HighlightToken(clang::Token *token, + std::vector *source_ranges, + int token_kind); + void HighlightCursor(clang::Token *token, + std::vector *source_ranges); + std::vector get_compilation_commands(); }; @@ -122,6 +126,9 @@ namespace Source { private: void OnLineEdit(); void OnSaveFile(); + std::mutex syntax; + std::mutex parsing; + bool go = false; protected: View view_; From efc8eccadf2d3fc5aae6fa57b43eec326bb8df83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Tue, 14 Apr 2015 09:16:15 +0200 Subject: [PATCH 5/7] fix syntax --- juci/source.cc | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/juci/source.cc b/juci/source.cc index 30a0e93..fa2fb70 100644 --- a/juci/source.cc +++ b/juci/source.cc @@ -118,9 +118,7 @@ InitSyntaxHighlighting(const std::string &filepath, void Source::View:: OnLineEdit(const std::vector &locations, const Source::Config &config) { - log("before onupdatesyntax"); OnUpdateSyntax(locations, config); - log("after onupdatesyntax"); } // Source::Model::UpdateLine @@ -132,9 +130,7 @@ ReParse(const std::string &buffer) { // Source::Controller::OnLineEdit() // fired when a line in the buffer is edited -void Source::Controller::OnLineEdit() { - -} +void Source::Controller::OnLineEdit() { } // sets the filepath for this mvc void Source::Model:: @@ -191,7 +187,6 @@ ExtractTokens(int start_offset, int end_offset) { case 4: HighlightToken(&token, &ranges, 705); break; // CommentToken } } - log("returns ranges"); return ranges; } @@ -237,7 +232,6 @@ Source::Controller::Controller(const Source::Config &config) : model_(config) { } - // Source::Controller::view() // return shared_ptr to the view Source::View& Source::Controller::view() { @@ -279,14 +273,11 @@ bool check_extention(const std::string &file_path) { void Source::View::OnUpdateSyntax(const std::vector &ranges, const Source::Config &config) { if (ranges.empty() || ranges.size() == 0) { - log("ranges empty"); return; } Glib::RefPtr buffer = get_buffer(); - log("after getting buffer"); + buffer->remove_all_tags(buffer->begin(), buffer->end()); int i = 0; - log("after i int"); - std::cout << "rangeslengde: " << ranges.size() << std::endl; for (auto &range : ranges) { string type = std::to_string(range.kind()); try { @@ -307,14 +298,12 @@ void Source::View::OnUpdateSyntax(const std::vector &ranges, buffer->get_iter_at_line_offset(linum_start, begin); Gtk::TextIter end_iter = buffer->get_iter_at_line_offset(linum_end, end); - buffer->remove_all_tags(begin_iter, end_iter); if (begin_iter.get_line() == end_iter.get_line()) { buffer->apply_tag_by_name(config.typetable().at(type), begin_iter, end_iter); } i++; } - log("End of onupdatesyntax"); } void Source::Controller::OnOpenFile(const string &filepath) { @@ -337,17 +326,15 @@ void Source::Controller::OnOpenFile(const string &filepath) { buffer()->signal_end_user_action().connect([this]() { if (!go) { std::thread parse([this]() { - if(parsing.try_lock()) { - const std::string raw = buffer()->get_text().raw(); - int b = model().ReParse(raw); - if (b == 0) { - if (raw == buffer()->get_text().raw()) { - log("alike!"); + if (parsing.try_lock()) { + while (true) { + const std::string raw = buffer()->get_text().raw(); + if (model().ReParse(raw) == 0 && + raw == buffer()->get_text().raw()) { syntax.lock(); go = true; syntax.unlock(); - } else { - log("buffer changed"); + break; } } parsing.unlock(); @@ -357,6 +344,7 @@ void Source::Controller::OnOpenFile(const string &filepath) { } }); + buffer()->signal_begin_user_action().connect([this]() { if (go) { syntax.lock(); From a411cb3f76e236c9384fb27bc224418de0f9a2b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Tue, 14 Apr 2015 09:42:44 +0200 Subject: [PATCH 6/7] Add multiline syntax --- juci/source.cc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/juci/source.cc b/juci/source.cc index fa2fb70..2117b79 100644 --- a/juci/source.cc +++ b/juci/source.cc @@ -277,7 +277,6 @@ void Source::View::OnUpdateSyntax(const std::vector &ranges, } Glib::RefPtr buffer = get_buffer(); buffer->remove_all_tags(buffer->begin(), buffer->end()); - int i = 0; for (auto &range : ranges) { string type = std::to_string(range.kind()); try { @@ -285,10 +284,8 @@ void Source::View::OnUpdateSyntax(const std::vector &ranges, } catch (std::exception) { continue; } - int linum_start = range.start().line_number()-1; int linum_end = range.end().line_number()-1; - int begin = range.start().column_offset()-1; int end = range.end().column_offset()-1; @@ -298,11 +295,8 @@ void Source::View::OnUpdateSyntax(const std::vector &ranges, buffer->get_iter_at_line_offset(linum_start, begin); Gtk::TextIter end_iter = buffer->get_iter_at_line_offset(linum_end, end); - if (begin_iter.get_line() == end_iter.get_line()) { buffer->apply_tag_by_name(config.typetable().at(type), begin_iter, end_iter); - } - i++; } } From 20e009500baeed01f93162f62e934058030b6f2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Tue, 14 Apr 2015 09:53:26 +0200 Subject: [PATCH 7/7] fix crash on open folder --- juci/directories.cc | 2 +- juci/directories.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/juci/directories.cc b/juci/directories.cc index 04aa9f8..0a03e53 100644 --- a/juci/directories.cc +++ b/juci/directories.cc @@ -6,7 +6,7 @@ Directories::Controller::Controller(Directories::Config& cfg) : m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); } -bool Directories::Controller:: +void Directories::Controller:: open_folder(const boost::filesystem::path& dir_path) { m_refTreeModel = Gtk::TreeStore::create(view()); m_TreeView.set_model(m_refTreeModel); diff --git a/juci/directories.h b/juci/directories.h index 47b56e2..4105e7b 100644 --- a/juci/directories.h +++ b/juci/directories.h @@ -48,7 +48,7 @@ namespace Directories { 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 open_folder(const boost::filesystem::path& dir_path); void list_dirs(const boost::filesystem::path& dir_path, Gtk::TreeModel::Row &row, unsigned depth); std::string get_project_name(const boost::filesystem::path& dir_path);