Browse Source

Added more functions to Source::View in preparation to rename refactoring.

merge-requests/365/head
eidheim 11 years ago
parent
commit
962a79fe18
  1. 56
      juci/source.cc
  2. 3
      juci/source.h

56
juci/source.cc

@ -897,37 +897,45 @@ Source::ClangViewAutocomplete(file_path, project_path) {
} }
}); });
get_buffer()->signal_mark_set().connect([this](const Gtk::TextBuffer::iterator& iterator, const Glib::RefPtr<Gtk::TextBuffer::Mark>& mark){ get_token=[this](){
if(mark->get_name()=="insert") { std::string usr;
bool found=false; if(clang_readable) {
if(clang_readable) { for(auto &token: *clang_tokens) {
for(auto &token: *clang_tokens) { if(token.get_kind()==clang::Token_Identifier && token.has_type()) {
if(token.get_kind()==clang::Token_Identifier && token.has_type()) { auto insert_offset=(unsigned)get_buffer()->get_insert()->get_iter().get_offset();
auto insert_offset=(unsigned)get_buffer()->get_insert()->get_iter().get_offset(); if(insert_offset>=token.offsets.first && insert_offset<=token.offsets.second) {
if(insert_offset>=token.offsets.first && insert_offset<=token.offsets.second) { auto referenced=token.get_cursor().get_referenced();
found=true; if(referenced)
auto referenced=token.get_cursor().get_referenced(); usr=referenced.get_usr();
if(referenced) {
auto usr_and_spelling=referenced.get_usr()+token.get_spelling();
if(last_similar_tokens_tagged!=usr_and_spelling) {
get_buffer()->remove_tag(similar_tokens_tag, get_buffer()->begin(), get_buffer()->end());
auto offsets=clang_tokens->get_similar_token_offsets(token);
for(auto &offset: offsets) {
get_buffer()->apply_tag(similar_tokens_tag, get_buffer()->get_iter_at_offset(offset.first), get_buffer()->get_iter_at_offset(offset.second));
}
last_similar_tokens_tagged=usr_and_spelling;
break;
}
}
}
} }
} }
} }
if(!found && last_similar_tokens_tagged!="") { }
return usr;
};
tag_similar_tokens=[this](const std::string &usr){
if(clang_readable) {
if(usr.size()>0 && last_similar_tokens_tagged!=usr) {
get_buffer()->remove_tag(similar_tokens_tag, get_buffer()->begin(), get_buffer()->end());
auto offsets=clang_tokens->get_similar_token_offsets(usr);
for(auto &offset: offsets) {
get_buffer()->apply_tag(similar_tokens_tag, get_buffer()->get_iter_at_offset(offset.first), get_buffer()->get_iter_at_offset(offset.second));
}
last_similar_tokens_tagged=usr;
}
if(usr.size()==0 && last_similar_tokens_tagged!="") {
get_buffer()->remove_tag(similar_tokens_tag, get_buffer()->begin(), get_buffer()->end()); get_buffer()->remove_tag(similar_tokens_tag, get_buffer()->begin(), get_buffer()->end());
last_similar_tokens_tagged=""; last_similar_tokens_tagged="";
} }
} }
};
get_buffer()->signal_mark_set().connect([this](const Gtk::TextBuffer::iterator& iterator, const Glib::RefPtr<Gtk::TextBuffer::Mark>& mark){
if(mark->get_name()=="insert") {
auto usr=get_token();
tag_similar_tokens(usr);
}
}); });
get_declaration_location=[this](){ get_declaration_location=[this](){

3
juci/source.h

@ -66,6 +66,9 @@ public:
std::function<std::pair<std::string, unsigned>()> get_declaration_location; std::function<std::pair<std::string, unsigned>()> get_declaration_location;
std::function<void()> goto_method; std::function<void()> goto_method;
std::function<const std::string&()> get_token;
std::function<void(const std::string &token)> tag_similar_tokens;
std::function<void(const std::string &token)> rename_similar_tokens;
protected: protected:
bool on_key_press_event(GdkEventKey* key); bool on_key_press_event(GdkEventKey* key);
private: private:

Loading…
Cancel
Save