From 2202060781efc630a25f196ec0b483e79784531f Mon Sep 17 00:00:00 2001 From: eidheim Date: Tue, 22 Sep 2015 16:47:13 +0200 Subject: [PATCH] Cleanup of source functions, tag_similar_tokens is now a member function. --- src/source.cc | 34 +++++++++++++++++----------------- src/source.h | 2 +- src/window.cc | 5 ----- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/source.cc b/src/source.cc index fe02258..2208466 100644 --- a/src/source.cc +++ b/src/source.cc @@ -1964,23 +1964,6 @@ Source::ClangViewAutocomplete(file_path, project_path, language) { return Token(-1, "", ""); }; - tag_similar_tokens=[this](const Token &token){ - if(source_readable) { - if(token.type>=0 && token.usr.size()>0 && last_similar_tokens_tagged!=token.usr) { - get_buffer()->remove_tag(similar_tokens_tag, get_buffer()->begin(), get_buffer()->end()); - auto offsets=clang_tokens->get_similar_token_offsets(static_cast(token.type), token.spelling, token.usr); - for(auto &offset: offsets) { - get_buffer()->apply_tag(similar_tokens_tag, get_buffer()->get_iter_at_line_index(offset.first.line-1, offset.first.index-1), get_buffer()->get_iter_at_line_index(offset.second.line-1, offset.second.index-1)); - } - last_similar_tokens_tagged=token.usr; - } - } - if(token.type<0 && token.usr.size()==0 && last_similar_tokens_tagged!="") { - get_buffer()->remove_tag(similar_tokens_tag, get_buffer()->begin(), get_buffer()->end()); - last_similar_tokens_tagged=""; - } - }; - rename_similar_tokens=[this](const Token &token, const std::string &text) { size_t number=0; if(source_readable) { @@ -2078,6 +2061,23 @@ Source::ClangViewAutocomplete(file_path, project_path, language) { }; } +void Source::ClangViewRefactor::tag_similar_tokens(const Token &token) { + if(source_readable) { + if(token.type>=0 && token.usr.size()>0 && last_similar_tokens_tagged!=token.usr) { + get_buffer()->remove_tag(similar_tokens_tag, get_buffer()->begin(), get_buffer()->end()); + auto offsets=clang_tokens->get_similar_token_offsets(static_cast(token.type), token.spelling, token.usr); + for(auto &offset: offsets) { + get_buffer()->apply_tag(similar_tokens_tag, get_buffer()->get_iter_at_line_index(offset.first.line-1, offset.first.index-1), get_buffer()->get_iter_at_line_index(offset.second.line-1, offset.second.index-1)); + } + last_similar_tokens_tagged=token.usr; + } + } + if(token.type<0 && token.usr.size()==0 && last_similar_tokens_tagged!="") { + get_buffer()->remove_tag(similar_tokens_tag, get_buffer()->begin(), get_buffer()->end()); + last_similar_tokens_tagged=""; + } +} + Source::ClangViewRefactor::~ClangViewRefactor() { delayed_tag_similar_tokens_connection.disconnect(); } diff --git a/src/source.h b/src/source.h index 3608143..946d3b8 100644 --- a/src/source.h +++ b/src/source.h @@ -81,7 +81,6 @@ namespace Source { std::function()> get_declaration_location; std::function goto_method; std::function get_token; - std::function tag_similar_tokens; std::function rename_similar_tokens; std::function goto_next_diagnostic; @@ -233,6 +232,7 @@ namespace Source { ClangViewRefactor(const boost::filesystem::path &file_path, const boost::filesystem::path& project_path, Glib::RefPtr language); ~ClangViewRefactor(); private: + void tag_similar_tokens(const Token &token); Glib::RefPtr similar_tokens_tag; std::string last_similar_tokens_tagged; sigc::connection delayed_tag_similar_tokens_connection; diff --git a/src/window.cc b/src/window.cc index 82966a5..421fe98 100644 --- a/src/window.cc +++ b/src/window.cc @@ -734,11 +734,6 @@ void Window::rename_token_entry() { if(notebook.get_current_view()->get_token) { auto token=std::make_shared(notebook.get_current_view()->get_token()); if(token->type>=0 && token->usr.size()>0) { - for(int c=0;ctag_similar_tokens) { - notebook.get_view(c)->tag_similar_tokens(*token); - } - } entry_box.labels.emplace_back(); auto label_it=entry_box.labels.begin(); label_it->update=[label_it](int state, const std::string& message){