Browse Source

Scroll to on search now works

merge-requests/365/head
Jørgen Lien Sellæg 11 years ago
parent
commit
6602bc58dd
  1. 36
      juci/notebook.cc
  2. 1
      juci/notebook.h

36
juci/notebook.cc

@ -29,6 +29,8 @@ Notebook::Controller::Controller(Gtk::Window* window,
ispopup = false; ispopup = false;
view().pack1(directories_.widget(), true, true); view().pack1(directories_.widget(), true, true);
CreateKeybindings(keybindings); CreateKeybindings(keybindings);
end = CurrentTextView().get_source_buffer()->end();
start = CurrentTextView().get_source_buffer()->end();
INFO("Notebook Controller Success"); INFO("Notebook Controller Success");
} // Constructor } // Constructor
@ -415,41 +417,17 @@ void Notebook::Controller::OnEditSearch() {
void Notebook::Controller::Search(bool forward) { void Notebook::Controller::Search(bool forward) {
INFO("Notebook search"); INFO("Notebook search");
/* int page = CurrentPage();
std::string search_word;
search_word = entry_.text();
Gtk::TextIter test;
if ( !forward ) {
if ( search_match_start_ == 0 ||
search_match_start_.get_line_offset() == 0) {
search_match_start_ = Buffer(*text_vec_.at(CurrentPage()))->end();
}
search_match_start_.
backward_search(search_word,
Gtk::TextSearchFlags::TEXT_SEARCH_TEXT_ONLY |
Gtk::TextSearchFlags::TEXT_SEARCH_VISIBLE_ONLY,
search_match_start_,
search_match_end_);
} else {
if ( search_match_end_ == 0 ) {
search_match_end_ = Buffer(*text_vec_.at(CurrentPage()))->begin();
}
search_match_end_.
forward_search(search_word,
Gtk::TextSearchFlags::TEXT_SEARCH_TEXT_ONLY |
Gtk::TextSearchFlags::TEXT_SEARCH_VISIBLE_ONLY,
search_match_start_,
search_match_end_);
}
*/
auto buffer = CurrentTextView().get_source_buffer(); auto buffer = CurrentTextView().get_source_buffer();
auto settings = gtk_source_search_settings_new(); auto settings = gtk_source_search_settings_new();
gtk_source_search_settings_set_search_text(settings, entry_.text().c_str()); gtk_source_search_settings_set_search_text(settings, entry_.text().c_str());
auto context = gtk_source_search_context_new(buffer->gobj(), settings); auto context = gtk_source_search_context_new(buffer->gobj(), settings);
gtk_source_search_context_set_highlight(context, forward); gtk_source_search_context_set_highlight(context, forward);
auto itr = buffer->get_insert()->get_iter().gobj(); auto itr = buffer->get_insert()->get_iter().gobj();
gtk_source_search_context_forward(context, itr, NULL, NULL); gtk_source_search_context_forward(context,
end ? end.gobj() : itr,
start.gobj(),
end.gobj());
CurrentTextView().scroll_to(end);
} }
void Notebook::Controller void Notebook::Controller

1
juci/notebook.h

@ -74,6 +74,7 @@ namespace Notebook {
bool OnKeyRelease(GdkEventKey* key); bool OnKeyRelease(GdkEventKey* key);
std::string OnSaveFileAs(); std::string OnSaveFileAs();
bool LegalExtension(std::string extension); bool LegalExtension(std::string extension);
Gtk::TextIter start, end;
protected: protected:
void TextViewHandlers(Gtk::TextView& textview); void TextViewHandlers(Gtk::TextView& textview);

Loading…
Cancel
Save