Browse Source

Cleanup and improvement of autocompletion.

merge-requests/365/head
eidheim 11 years ago
parent
commit
a1be9e0d92
  1. 4
      juci/selectiondialog.cc
  2. 2
      juci/selectiondialog.h
  3. 57
      juci/source.cc
  4. 2
      juci/source.h

4
juci/selectiondialog.cc

@ -34,7 +34,7 @@ void SelectionDialog::show() {
resize(); resize();
}); });
start_offset=start_mark->get_iter().get_offset(); show_offset=text_view.get_buffer()->get_insert()->get_iter().get_offset();
list_view_text->clear_items(); list_view_text->clear_items();
for (auto &i : rows) { for (auto &i : rows) {
list_view_text->append(i.first); list_view_text->append(i.first);
@ -99,7 +99,7 @@ bool SelectionDialog::on_key_release(GdkEventKey* key) {
if(key->keyval==GDK_KEY_Down || key->keyval==GDK_KEY_Up) if(key->keyval==GDK_KEY_Down || key->keyval==GDK_KEY_Up)
return false; return false;
if(start_offset>text_view.get_buffer()->get_insert()->get_iter().get_offset()) { if(show_offset>text_view.get_buffer()->get_insert()->get_iter().get_offset()) {
hide(); hide();
} }
else { else {

2
juci/selectiondialog.h

@ -24,7 +24,7 @@ private:
void cursor_changed(); void cursor_changed();
Gtk::Entry search_entry; Gtk::Entry search_entry;
int start_offset; int show_offset;
bool row_in_entry; bool row_in_entry;
Gtk::TextView& text_view; Gtk::TextView& text_view;

57
juci/source.cc

@ -584,39 +584,29 @@ bool Source::ClangView::on_key_press_event(GdkEventKey* key) {
Source::ClangViewAutocomplete::ClangViewAutocomplete(const std::string& file_path, const std::string& project_path, Terminal::Controller& terminal): Source::ClangViewAutocomplete::ClangViewAutocomplete(const std::string& file_path, const std::string& project_path, Terminal::Controller& terminal):
Source::ClangView(file_path, project_path, terminal), selection_dialog(*this) { Source::ClangView(file_path, project_path, terminal), selection_dialog(*this) {
get_buffer()->signal_changed().connect([this](){ get_buffer()->signal_changed().connect([this](){
if(last_keyval==GDK_KEY_BackSpace)
return;
std::string line=" "+get_line_before_insert(); std::string line=" "+get_line_before_insert();
if((std::count(line.begin(), line.end(), '\"')%2)!=1 && line.find("//")==std::string::npos) { if((std::count(line.begin(), line.end(), '\"')%2)!=1 && line.find("//")==std::string::npos) {
const std::regex in_specified_namespace("^(.*)(->|\\.|::)([a-zA-Z0-9_]*)$"); const std::regex in_specified_namespace("^(.*[a-zA-Z0-9_])(->|\\.|::)([a-zA-Z0-9_]*)$");
const std::regex within_namespace("^(.*)([^a-zA-Z0-9_]+)([a-zA-Z_][a-zA-Z0-9_]{2,})$"); const std::regex within_namespace("^(.*)([^a-zA-Z0-9_]+)([a-zA-Z0-9_]{3,})$");
std::smatch sm; std::smatch sm;
if(std::regex_match(line, sm, in_specified_namespace)) { if(std::regex_match(line, sm, in_specified_namespace)) {
if(last_keyval=='.' || last_keyval=='>' || last_keyval==':') { prefix=sm[3].str();
if(sm[3]=="" && !autocomplete_starting && !selection_dialog.shown) { if((prefix.size()==0 || prefix[0]<'0' || prefix[0]>'9') && !autocomplete_starting && !selection_dialog.shown) {
prefix=""; autocomplete();
autocomplete();
}
else if(autocomplete_starting)
autocomplete_cancel_starting=true;
} }
else if(last_keyval=='.' && autocomplete_starting)
autocomplete_cancel_starting=true;
} }
else if(std::regex_match(line, sm, within_namespace)) { else if(std::regex_match(line, sm, within_namespace)) {
prefix=sm[3].str(); prefix=sm[3].str();
if((last_keyval>='a' && last_keyval<='z') || (last_keyval>='A' && last_keyval<='Z') || (last_keyval>='0' && last_keyval<='9') || last_keyval=='_') { if((prefix.size()==0 || prefix[0]<'0' || prefix[0]>'9') && !autocomplete_starting && !selection_dialog.shown) {
if(!autocomplete_starting && !selection_dialog.shown) { autocomplete();
autocomplete();
}
}
else if(last_keyval!=0) {
autocomplete_cancel_starting=true;
if(selection_dialog.shown)
selection_dialog.hide();
} }
} }
else if(last_keyval!=0) { else
autocomplete_cancel_starting=true; autocomplete_cancel_starting=true;
if(selection_dialog.shown)
selection_dialog.hide();
}
if(autocomplete_starting || selection_dialog.shown) if(autocomplete_starting || selection_dialog.shown)
delayed_reparse_connection.disconnect(); delayed_reparse_connection.disconnect();
} }
@ -645,38 +635,29 @@ Source::ClangView(file_path, project_path, terminal), selection_dialog(*this) {
} }
bool Source::ClangViewAutocomplete::on_key_press_event(GdkEventKey *key) { bool Source::ClangViewAutocomplete::on_key_press_event(GdkEventKey *key) {
last_keyval=0; last_keyval=key->keyval;
if(selection_dialog.shown) { if(selection_dialog.shown) {
delayed_reparse_connection.disconnect(); delayed_reparse_connection.disconnect();
if(selection_dialog.on_key_press(key)) if(selection_dialog.on_key_press(key))
return true; return true;
} }
last_keyval=key->keyval;
return ClangView::on_key_press_event(key); return ClangView::on_key_press_event(key);
} }
void Source::ClangViewAutocomplete::autocomplete() { void Source::ClangViewAutocomplete::autocomplete() {
if(!autocomplete_starting) { if(!autocomplete_starting) {
autocomplete_starting=true; autocomplete_starting=true;
autocomplete_cancel_starting=false; autocomplete_cancel_starting=false;
if(prefix.size()==0) {
if(selection_dialog.start_mark)
get_buffer()->delete_mark(selection_dialog.start_mark);
auto start_iter=get_buffer()->get_insert()->get_iter();
selection_dialog.start_mark=get_buffer()->create_mark(start_iter);
}
INFO("Source::ClangView::on_key_release getting autocompletions"); INFO("Source::ClangView::on_key_release getting autocompletions");
std::shared_ptr<std::vector<Source::AutoCompleteData> > ac_data=std::make_shared<std::vector<Source::AutoCompleteData> >(); std::shared_ptr<std::vector<Source::AutoCompleteData> > ac_data=std::make_shared<std::vector<Source::AutoCompleteData> >();
autocomplete_done_connection.disconnect(); autocomplete_done_connection.disconnect();
autocomplete_done_connection=autocomplete_done.connect([this, ac_data](){ autocomplete_done_connection=autocomplete_done.connect([this, ac_data](){
if(!autocomplete_cancel_starting) { if(!autocomplete_cancel_starting) {
if(prefix.size()>0) { if(selection_dialog.start_mark)
if(selection_dialog.start_mark) get_buffer()->delete_mark(selection_dialog.start_mark);
get_buffer()->delete_mark(selection_dialog.start_mark); auto start_iter=get_buffer()->get_insert()->get_iter();
auto start_iter=get_buffer()->get_insert()->get_iter(); for(size_t c=0;c<prefix.size();c++)
for(size_t c=0;c<prefix.size();c++) start_iter--;
start_iter--; selection_dialog.start_mark=get_buffer()->create_mark(start_iter);
selection_dialog.start_mark=get_buffer()->create_mark(start_iter);
}
std::map<std::string, std::pair<std::string, std::string> > rows; std::map<std::string, std::pair<std::string, std::string> > rows;
for (auto &data : *ac_data) { for (auto &data : *ac_data) {

2
juci/source.h

@ -136,7 +136,7 @@ namespace Source {
sigc::connection autocomplete_done_connection; sigc::connection autocomplete_done_connection;
bool autocomplete_starting=false; bool autocomplete_starting=false;
bool autocomplete_cancel_starting=false; bool autocomplete_cancel_starting=false;
char last_keyval=0; guint last_keyval=0;
std::string prefix; std::string prefix;
}; };

Loading…
Cancel
Save