Browse Source

Minor similar tokens fix.

merge-requests/365/head
eidheim 10 years ago
parent
commit
1eff103d9a
  1. 14
      src/source.cc
  2. 9
      src/source.h
  3. 2
      src/window.cc

14
src/source.cc

@ -1905,9 +1905,9 @@ Source::ClangViewAutocomplete(file_path, project_path, language) {
similar_tokens_tag->property_weight()=Pango::WEIGHT_BOLD; similar_tokens_tag->property_weight()=Pango::WEIGHT_BOLD;
get_buffer()->signal_changed().connect([this]() { get_buffer()->signal_changed().connect([this]() {
if(!renaming && last_similar_tokens_tagged!="") { if(!renaming && last_tagged_token) {
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_tagged_token=Token();
} }
}); });
@ -1929,7 +1929,7 @@ Source::ClangViewAutocomplete(file_path, project_path, language) {
} }
} }
} }
return Token(-1, "", ""); return Token();
}; };
rename_similar_tokens=[this](const Token &token, const std::string &text) { rename_similar_tokens=[this](const Token &token, const std::string &text) {
@ -2031,18 +2031,18 @@ Source::ClangViewAutocomplete(file_path, project_path, language) {
void Source::ClangViewRefactor::tag_similar_tokens(const Token &token) { void Source::ClangViewRefactor::tag_similar_tokens(const Token &token) {
if(source_readable) { if(source_readable) {
if(token.type>=0 && token.usr.size()>0 && last_similar_tokens_tagged!=token.usr) { if(token && last_tagged_token!=token) {
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());
auto offsets=clang_tokens->get_similar_token_offsets(static_cast<clang::CursorKind>(token.type), token.spelling, token.usr); auto offsets=clang_tokens->get_similar_token_offsets(static_cast<clang::CursorKind>(token.type), token.spelling, token.usr);
for(auto &offset: offsets) { 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)); 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; last_tagged_token=token;
} }
} }
if(token.type<0 && token.usr.size()==0 && last_similar_tokens_tagged!="") { if(!token && last_tagged_token) {
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_tagged_token=Token();
} }
} }

9
src/source.h

@ -52,8 +52,15 @@ namespace Source {
class Token { class Token {
public: public:
Token(): type(-1) {}
Token(int type, const std::string &spelling, const std::string &usr): Token(int type, const std::string &spelling, const std::string &usr):
type(type), spelling(spelling), usr(usr) {} type(type), spelling(spelling), usr(usr) {}
operator bool() const {return (type>=0 && spelling.size()>0 && usr.size()>0);}
bool operator==(const Token &o) const {return (type==o.type &&
spelling==o.spelling &&
usr==o.usr);}
bool operator!=(const Token &o) const {return !(*this==o);}
int type; int type;
std::string spelling; std::string spelling;
std::string usr; std::string usr;
@ -234,7 +241,7 @@ namespace Source {
private: private:
void tag_similar_tokens(const Token &token); void tag_similar_tokens(const Token &token);
Glib::RefPtr<Gtk::TextTag> similar_tokens_tag; Glib::RefPtr<Gtk::TextTag> similar_tokens_tag;
std::string last_similar_tokens_tagged; Token last_tagged_token;
sigc::connection delayed_tag_similar_tokens_connection; sigc::connection delayed_tag_similar_tokens_connection;
std::unique_ptr<SelectionDialog> selection_dialog; std::unique_ptr<SelectionDialog> selection_dialog;
bool renaming=false; bool renaming=false;

2
src/window.cc

@ -733,7 +733,7 @@ void Window::rename_token_entry() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
if(notebook.get_current_view()->get_token) { if(notebook.get_current_view()->get_token) {
auto token=std::make_shared<Source::Token>(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) { if(token) {
entry_box.labels.emplace_back(); entry_box.labels.emplace_back();
auto label_it=entry_box.labels.begin(); auto label_it=entry_box.labels.begin();
label_it->update=[label_it](int state, const std::string& message){ label_it->update=[label_it](int state, const std::string& message){

Loading…
Cancel
Save