Browse Source

Now properly removes spellcheck errors when the word is no longer in a string or comment. Also reverted the info/status field position.

merge-requests/365/head
eidheim 10 years ago
parent
commit
3cf7429ccd
  1. 4
      src/notebook.cc
  2. 44
      src/source.cc
  3. 1
      src/source.h
  4. 14
      src/window.cc
  5. 2
      src/window.h

4
src/notebook.cc

@ -86,11 +86,11 @@ void Notebook::open(const boost::filesystem::path &file_path) {
source_views.back()->on_update_status=[this](Source::View* view, const std::string &status) { source_views.back()->on_update_status=[this](Source::View* view, const std::string &status) {
if(get_current_page()!=-1 && get_current_view()==view) if(get_current_page()!=-1 && get_current_view()==view)
Singleton::status()->set_text(status); Singleton::status()->set_text(status+" ");
}; };
source_views.back()->on_update_info=[this](Source::View* view, const std::string &info) { source_views.back()->on_update_info=[this](Source::View* view, const std::string &info) {
if(get_current_page()!=-1 && get_current_view()==view) if(get_current_page()!=-1 && get_current_view()==view)
Singleton::info()->set_text(info); Singleton::info()->set_text(" "+info);
}; };
scrolled_windows.emplace_back(new Gtk::ScrolledWindow()); scrolled_windows.emplace_back(new Gtk::ScrolledWindow());

44
src/source.cc

@ -220,22 +220,32 @@ Source::View::View(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::L
spellcheck_word(word.first, word.second); spellcheck_word(word.first, word.second);
} }
} }
else {
auto tags=iter.get_tags();
bool has_spellcheck_error=false;
for(auto &tag: tags) {
if(tag->property_name()=="spellcheck_error") {
has_spellcheck_error=true;
break;
}
}
if(has_spellcheck_error) {
auto word=spellcheck_get_word(iter);
get_buffer()->remove_tag_by_name("spellcheck_error", word.first, word.second);
}
}
} }
} }
delayed_spellcheck_error_clear.disconnect();
delayed_spellcheck_error_clear=Glib::signal_timeout().connect([this]() {
auto iter=get_buffer()->begin();
bool spell_check=get_source_buffer()->iter_has_context_class(iter, "string") || get_source_buffer()->iter_has_context_class(iter, "comment");
Gtk::TextIter begin_no_spellcheck_iter;
if(!spell_check)
begin_no_spellcheck_iter=iter;
while(iter!=get_buffer()->end()) {
auto iter1=iter;
auto iter2=iter;
get_source_buffer()->iter_forward_to_context_class_toggle(iter1, "string");
get_source_buffer()->iter_forward_to_context_class_toggle(iter2, "comment");
if(iter2<iter1)
iter=iter2;
else
iter=iter1;
spell_check=!spell_check;
if(!spell_check)
begin_no_spellcheck_iter=iter;
else
get_buffer()->remove_tag_by_name("spellcheck_error", begin_no_spellcheck_iter, iter);
}
return false;
}, 1000);
}); });
get_buffer()->signal_mark_set().connect([this](const Gtk::TextBuffer::iterator& iter, const Glib::RefPtr<Gtk::TextBuffer::Mark>& mark) { get_buffer()->signal_mark_set().connect([this](const Gtk::TextBuffer::iterator& iter, const Glib::RefPtr<Gtk::TextBuffer::Mark>& mark) {
@ -253,12 +263,6 @@ Source::View::View(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::L
} }
} }
if(need_suggestions) { if(need_suggestions) {
auto iter=get_buffer()->get_insert()->get_iter();
if(!((spellcheck_all && !get_source_buffer()->iter_has_context_class(iter, "no-spell-check")) || get_source_buffer()->iter_has_context_class(iter, "comment") || get_source_buffer()->iter_has_context_class(iter, "string"))) {
auto word=spellcheck_get_word(iter);
get_buffer()->remove_tag_by_name("spellcheck_error", word.first, word.second);
return false;
}
spellcheck_suggestions_dialog=std::unique_ptr<SelectionDialog>(new SelectionDialog(*this, get_buffer()->create_mark(get_buffer()->get_insert()->get_iter()), false)); 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->on_hide=[this](){
spellcheck_suggestions_dialog_shown=false; spellcheck_suggestions_dialog_shown=false;

1
src/source.h

@ -126,6 +126,7 @@ namespace Source {
void spellcheck_word(const Gtk::TextIter& start, const Gtk::TextIter& end); void spellcheck_word(const Gtk::TextIter& start, const Gtk::TextIter& end);
std::vector<std::string> spellcheck_get_suggestions(const Gtk::TextIter& start, const Gtk::TextIter& end); std::vector<std::string> spellcheck_get_suggestions(const Gtk::TextIter& start, const Gtk::TextIter& end);
sigc::connection delayed_spellcheck_suggestions_connection; sigc::connection delayed_spellcheck_suggestions_connection;
sigc::connection delayed_spellcheck_error_clear;
bool last_keyval_is_backspace=false; bool last_keyval_is_backspace=false;
}; };

14
src/window.cc

@ -44,20 +44,18 @@ Window::Window() : box(Gtk::ORIENTATION_VERTICAL), notebook(directories), compil
directory_and_notebook_panes.pack1(directories, Gtk::SHRINK); directory_and_notebook_panes.pack1(directories, Gtk::SHRINK);
notebook_vbox.pack_start(notebook); notebook_vbox.pack_start(notebook);
notebook_vbox.pack_end(entry_box, Gtk::PACK_SHRINK);
entry_and_info_status_vbox.pack_start(entry_box, Gtk::PACK_SHRINK);
info_and_status_hbox.pack_start(*Singleton::info(), Gtk::PACK_SHRINK);
info_and_status_hbox.pack_end(*Singleton::status(), Gtk::PACK_SHRINK);
entry_and_info_status_vbox.pack_end(info_and_status_hbox, Gtk::PACK_SHRINK);
notebook_vbox.pack_end(entry_and_info_status_vbox, Gtk::PACK_SHRINK);
directory_and_notebook_panes.pack2(notebook_vbox, Gtk::SHRINK); directory_and_notebook_panes.pack2(notebook_vbox, Gtk::SHRINK);
directory_and_notebook_panes.set_position(120); directory_and_notebook_panes.set_position(120);
vpaned.set_position(300); vpaned.set_position(300);
vpaned.pack1(directory_and_notebook_panes, true, false); vpaned.pack1(directory_and_notebook_panes, true, false);
terminal_scrolled_window.add(*Singleton::terminal()); terminal_scrolled_window.add(*Singleton::terminal());
vpaned.pack2(terminal_scrolled_window, true, true); terminal_vbox.pack_start(terminal_scrolled_window);
info_and_status_hbox.pack_start(*Singleton::info(), Gtk::PACK_SHRINK);
info_and_status_hbox.pack_end(*Singleton::status(), Gtk::PACK_SHRINK);
terminal_vbox.pack_end(info_and_status_hbox, Gtk::PACK_SHRINK);
vpaned.pack2(terminal_vbox, true, true);
box.pack_end(vpaned); box.pack_end(vpaned);
show_all_children(); show_all_children();

2
src/window.h

@ -31,7 +31,7 @@ private:
Gtk::VPaned vpaned; Gtk::VPaned vpaned;
Gtk::Paned directory_and_notebook_panes; Gtk::Paned directory_and_notebook_panes;
Gtk::VBox notebook_vbox; Gtk::VBox notebook_vbox;
Gtk::VBox entry_and_info_status_vbox; Gtk::VBox terminal_vbox;
Gtk::ScrolledWindow terminal_scrolled_window; Gtk::ScrolledWindow terminal_scrolled_window;
Gtk::HBox info_and_status_hbox; Gtk::HBox info_and_status_hbox;
Gtk::AboutDialog about; Gtk::AboutDialog about;

Loading…
Cancel
Save