Browse Source

Cleanup of source functions, tag_similar_tokens is now a member function.

merge-requests/365/head
eidheim 10 years ago
parent
commit
2202060781
  1. 34
      src/source.cc
  2. 2
      src/source.h
  3. 5
      src/window.cc

34
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<clang::CursorKind>(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<clang::CursorKind>(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();
}

2
src/source.h

@ -81,7 +81,6 @@ namespace Source {
std::function<std::pair<std::string, clang::Offset>()> get_declaration_location;
std::function<void()> goto_method;
std::function<Token()> get_token;
std::function<void(const Token &token)> tag_similar_tokens;
std::function<size_t(const Token &token, const std::string &text)> rename_similar_tokens;
std::function<void()> goto_next_diagnostic;
@ -233,6 +232,7 @@ namespace Source {
ClangViewRefactor(const boost::filesystem::path &file_path, const boost::filesystem::path& project_path, Glib::RefPtr<Gsv::Language> language);
~ClangViewRefactor();
private:
void tag_similar_tokens(const Token &token);
Glib::RefPtr<Gtk::TextTag> similar_tokens_tag;
std::string last_similar_tokens_tagged;
sigc::connection delayed_tag_similar_tokens_connection;

5
src/window.cc

@ -734,11 +734,6 @@ void Window::rename_token_entry() {
if(notebook.get_current_view()->get_token) {
auto token=std::make_shared<Source::Token>(notebook.get_current_view()->get_token());
if(token->type>=0 && token->usr.size()>0) {
for(int c=0;c<notebook.size();c++) {
if(notebook.get_view(c)->tag_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){

Loading…
Cancel
Save