Browse Source

Fixes #130, but need some testing before merge

merge-requests/365/head
eidheim 10 years ago
parent
commit
da62ee9bd6
  1. 4
      src/selectiondialog.h
  2. 29
      src/source.cc
  3. 4
      src/source.h
  4. 31
      src/source_clang.cc
  5. 3
      src/source_clang.h

4
src/selectiondialog.h

@ -37,6 +37,8 @@ public:
std::function<void()> on_hide;
std::function<void(const std::string& selected, bool hide_window)> on_select;
Glib::RefPtr<Gtk::TextBuffer::Mark> start_mark;
bool shown=false;
protected:
virtual void resize();
virtual void update_tooltips();
@ -50,8 +52,6 @@ protected:
std::unique_ptr<Tooltips> tooltips;
std::unordered_map<std::string, std::string> tooltip_texts;
std::string last_row;
private:
bool shown=false;
};
class SelectionDialog : public SelectionDialogBase {

29
src/source.cc

@ -8,8 +8,6 @@
#include "filesystem.h"
#include "terminal.h"
using namespace std; //TODO: remove
namespace sigc {
#ifndef SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE
template <typename Functor>
@ -219,7 +217,7 @@ Source::View::View(const boost::filesystem::path &file_path, const boost::filesy
return;
if(mark->get_name()=="insert") {
if(spellcheck_suggestions_dialog_shown)
if(spellcheck_suggestions_dialog && spellcheck_suggestions_dialog->shown)
spellcheck_suggestions_dialog->hide();
delayed_spellcheck_suggestions_connection.disconnect();
delayed_spellcheck_suggestions_connection=Glib::signal_timeout().connect([this]() {
@ -233,9 +231,6 @@ Source::View::View(const boost::filesystem::path &file_path, const boost::filesy
}
if(need_suggestions) {
spellcheck_suggestions_dialog=std::unique_ptr<SelectionDialog>(new SelectionDialog(*this, get_buffer()->create_mark(get_buffer()->get_insert()->get_iter()), false));
spellcheck_suggestions_dialog->on_hide=[this](){
spellcheck_suggestions_dialog_shown=false;
};
auto word=spellcheck_get_word(get_buffer()->get_insert()->get_iter());
auto suggestions=spellcheck_get_suggestions(word.first, word.second);
if(suggestions.size()==0)
@ -250,7 +245,6 @@ Source::View::View(const boost::filesystem::path &file_path, const boost::filesy
delayed_tooltips_connection.disconnect();
};
spellcheck_suggestions_dialog->show();
spellcheck_suggestions_dialog_shown=true;
}
return false;
}, 500);
@ -261,7 +255,7 @@ Source::View::View(const boost::filesystem::path &file_path, const boost::filesy
set_info(info);
});
set_tooltip_events();
set_tooltip_and_dialog_events();
tab_char=Config::get().source.default_tab_char;
tab_size=Config::get().source.default_tab_size;
@ -386,7 +380,7 @@ void Source::View::configure() {
get_buffer()->remove_tag_by_name("spellcheck_error", get_buffer()->begin(), get_buffer()->end());
}
void Source::View::set_tooltip_events() {
void Source::View::set_tooltip_and_dialog_events() {
signal_motion_notify_event().connect([this](GdkEventMotion* event) {
if(on_motion_last_x!=event->x || on_motion_last_y!=event->y) {
delayed_tooltips_connection.disconnect();
@ -442,6 +436,13 @@ void Source::View::set_tooltip_events() {
delayed_tooltips_connection.disconnect();
type_tooltips.hide();
diagnostic_tooltips.hide();
delayed_spellcheck_suggestions_connection.disconnect();
if(spellcheck_suggestions_dialog)
spellcheck_suggestions_dialog->hide();
if(autocomplete_dialog)
autocomplete_dialog->hide();
if(selection_dialog)
selection_dialog->hide();
return false;
});
@ -449,6 +450,7 @@ void Source::View::set_tooltip_events() {
delayed_tooltips_connection.disconnect();
type_tooltips.hide();
diagnostic_tooltips.hide();
delayed_spellcheck_suggestions_connection.disconnect();
return false;
});
@ -456,6 +458,7 @@ void Source::View::set_tooltip_events() {
delayed_tooltips_connection.disconnect();
type_tooltips.hide();
diagnostic_tooltips.hide();
delayed_spellcheck_suggestions_connection.disconnect();
return false;
});
}
@ -931,7 +934,7 @@ bool Source::View::find_left_bracket_backward(Gtk::TextIter iter, Gtk::TextIter
//Basic indentation
bool Source::View::on_key_press_event(GdkEventKey* key) {
if(spellcheck_suggestions_dialog_shown) {
if(spellcheck_suggestions_dialog && spellcheck_suggestions_dialog->shown) {
if(spellcheck_suggestions_dialog->on_key_press(key))
return true;
}
@ -1235,8 +1238,8 @@ std::pair<char, unsigned> Source::View::find_tab_char_and_size() {
}
else if(!iter.ends_line()) {
if(tab_count!=last_tab_count)
tab_sizes[abs(tab_count-last_tab_count)]++;
last_tab_diff=abs(tab_count-last_tab_count);
tab_sizes[std::abs(tab_count-last_tab_count)]++;
last_tab_diff=std::abs(tab_count-last_tab_count);
last_tab_count=tab_count;
last_char=0;
}
@ -1290,7 +1293,7 @@ std::pair<char, unsigned> Source::View::find_tab_char_and_size() {
}
else if(!iter.ends_line()) {
if(tab_count!=last_tab_count)
tab_sizes[abs(tab_count-last_tab_count)]++;
tab_sizes[std::abs(tab_count-last_tab_count)]++;
last_tab_count=tab_count;
}
}

4
src/source.h

@ -85,6 +85,7 @@ namespace Source {
std::function<void()> goto_next_diagnostic;
std::function<void()> apply_fix_its;
std::unique_ptr<CompletionDialog> autocomplete_dialog;
std::unique_ptr<SelectionDialog> selection_dialog;
sigc::connection delayed_tooltips_connection;
@ -114,7 +115,7 @@ namespace Source {
virtual void show_type_tooltips(const Gdk::Rectangle &rectangle) {}
gdouble on_motion_last_x;
gdouble on_motion_last_y;
void set_tooltip_events();
void set_tooltip_and_dialog_events();
std::string get_line(const Gtk::TextIter &iter);
std::string get_line(Glib::RefPtr<Gtk::TextBuffer::Mark> mark);
@ -143,7 +144,6 @@ namespace Source {
bool spellcheck_all=false;
std::unique_ptr<SelectionDialog> spellcheck_suggestions_dialog;
bool spellcheck_suggestions_dialog_shown=false;
bool last_keyval_is_backspace=false;
bool last_keyval_is_return=false;
private:

31
src/source_clang.cc

@ -422,7 +422,7 @@ void Source::ClangViewParse::show_type_tooltips(const Gdk::Rectangle &rectangle)
//Clang indentation.
bool Source::ClangViewParse::on_key_press_event(GdkEventKey* key) {
if(spellcheck_suggestions_dialog_shown) {
if(spellcheck_suggestions_dialog && spellcheck_suggestions_dialog->shown) {
if(spellcheck_suggestions_dialog->on_key_press(key))
return true;
}
@ -622,7 +622,7 @@ Source::ClangViewParse(file_path, project_path, language), autocomplete_state(Au
}
else {
if(autocomplete_state==AutocompleteState::STARTING)
autocomplete_state=AutocompleteState::CANCELED;
autocomplete_state=AutocompleteState::RESTARTING;
else {
auto iter=get_buffer()->get_insert()->get_iter();
if(last_keyval=='.' || last_keyval==':' || (last_keyval=='>' && iter.backward_char() && iter.backward_char() && *iter=='-'))
@ -633,17 +633,10 @@ Source::ClangViewParse(file_path, project_path, language), autocomplete_state(Au
});
get_buffer()->signal_mark_set().connect([this](const Gtk::TextBuffer::iterator& iterator, const Glib::RefPtr<Gtk::TextBuffer::Mark>& mark){
if(mark->get_name()=="insert") {
if(autocomplete_state==AutocompleteState::SHOWN)
autocomplete_dialog->hide();
if(autocomplete_state==AutocompleteState::STARTING)
autocomplete_state=AutocompleteState::CANCELED;
}
});
signal_scroll_event().connect([this](GdkEventScroll* event){
if(autocomplete_state==AutocompleteState::SHOWN)
autocomplete_dialog->hide();
return false;
}, false);
signal_key_release_event().connect([this](GdkEventKey* key){
if(autocomplete_state==AutocompleteState::SHOWN) {
if(autocomplete_dialog->on_key_release(key))
@ -654,8 +647,6 @@ Source::ClangViewParse(file_path, project_path, language), autocomplete_state(Au
}, false);
signal_focus_out_event().connect([this](GdkEventFocus* event) {
if(autocomplete_state==AutocompleteState::SHOWN)
autocomplete_dialog->hide();
if(autocomplete_state==AutocompleteState::STARTING)
autocomplete_state=AutocompleteState::CANCELED;
return false;
@ -666,6 +657,11 @@ Source::ClangViewParse(file_path, project_path, language), autocomplete_state(Au
set_status("");
soft_reparse();
autocomplete_state=AutocompleteState::IDLE;
}
else if(autocomplete_state==AutocompleteState::RESTARTING) {
set_status("");
soft_reparse();
autocomplete_state=AutocompleteState::IDLE;
autocomplete_restart();
}
else {
@ -815,14 +811,14 @@ void Source::ClangViewAutocomplete::autocomplete_check() {
prefix_mutex.lock();
prefix=sm[3].str();
prefix_mutex.unlock();
if(autocomplete_state==AutocompleteState::IDLE && (prefix.size()==0 || prefix[0]<'0' || prefix[0]>'9'))
if(prefix.size()==0 || prefix[0]<'0' || prefix[0]>'9')
autocomplete();
}
else if(boost::regex_match(line, sm, within_namespace)) {
prefix_mutex.lock();
prefix=sm[3].str();
prefix_mutex.unlock();
if(autocomplete_state==AutocompleteState::IDLE && (prefix.size()==0 || prefix[0]<'0' || prefix[0]>'9'))
if(prefix.size()==0 || prefix[0]<'0' || prefix[0]>'9')
autocomplete();
}
if(autocomplete_state!=AutocompleteState::IDLE)
@ -832,12 +828,13 @@ void Source::ClangViewAutocomplete::autocomplete_check() {
void Source::ClangViewAutocomplete::autocomplete() {
if(parse_state!=ParseState::PROCESSING)
return;
if(autocomplete_state==AutocompleteState::STARTING) {
autocomplete_state=AutocompleteState::CANCELED;
return;
}
if(autocomplete_state==AutocompleteState::CANCELED)
autocomplete_state=AutocompleteState::RESTARTING;
if(autocomplete_state!=AutocompleteState::IDLE)
return;
autocomplete_state=AutocompleteState::STARTING;
autocomplete_data.clear();

3
src/source_clang.h

@ -72,7 +72,7 @@ namespace Source {
class ClangViewAutocomplete : public ClangViewParse {
protected:
enum class AutocompleteState {IDLE, STARTING, CANCELED, SHOWN};
enum class AutocompleteState {IDLE, STARTING, RESTARTING, CANCELED, SHOWN};
public:
class AutoCompleteData {
public:
@ -101,7 +101,6 @@ namespace Source {
void autocomplete_check();
void autocomplete();
std::vector<AutoCompleteData> autocomplete_data;
std::unique_ptr<CompletionDialog> autocomplete_dialog;
std::unordered_map<std::string, std::string> autocomplete_dialog_rows;
std::vector<AutoCompleteData> autocomplete_get_suggestions(const std::string &buffer, int line_number, int column);
Glib::Dispatcher autocomplete_done;

Loading…
Cancel
Save