From c2da91c9787d8ff8e7f52ed6b27ec2e116973c71 Mon Sep 17 00:00:00 2001 From: es Date: Mon, 15 Jun 2015 14:08:06 +0200 Subject: [PATCH 1/5] Proof of concept --- juci/notebook.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/juci/notebook.cc b/juci/notebook.cc index 2d671d2..c9c6ad1 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -1,6 +1,8 @@ #include #include "notebook.h" #include "logging.h" +#include // c-library + Notebook::Model::Model() { cc_extension_ = ".cpp"; @@ -412,8 +414,8 @@ void Notebook::Controller::OnEditSearch() { } void Notebook::Controller::Search(bool forward) { - INFO("Notebook search"); - int page = CurrentPage(); + INFO("Notebook search"); + /* int page = CurrentPage(); std::string search_word; search_word = entry_.text(); Gtk::TextIter test; @@ -440,6 +442,14 @@ void Notebook::Controller::Search(bool forward) { search_match_start_, search_match_end_); } +*/ + auto buffer = CurrentTextView().get_source_buffer(); + auto settings = gtk_source_search_settings_new(); + gtk_source_search_settings_set_search_text(settings, entry_.text().c_str()); + auto context = gtk_source_search_context_new(buffer->gobj(), settings); + gtk_source_search_context_set_highlight(context, forward); + auto itr = buffer->get_insert()->get_iter().gobj(); + gtk_source_search_context_forward(context, itr, NULL, NULL); } void Notebook::Controller From 6602bc58dd49d89698dda395857f8901c7be3c9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Tue, 16 Jun 2015 00:05:32 +0200 Subject: [PATCH 2/5] Scroll to on search now works --- juci/notebook.cc | 36 +++++++----------------------------- juci/notebook.h | 1 + 2 files changed, 8 insertions(+), 29 deletions(-) diff --git a/juci/notebook.cc b/juci/notebook.cc index c9c6ad1..9b7b060 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -29,6 +29,8 @@ Notebook::Controller::Controller(Gtk::Window* window, ispopup = false; view().pack1(directories_.widget(), true, true); CreateKeybindings(keybindings); + end = CurrentTextView().get_source_buffer()->end(); + start = CurrentTextView().get_source_buffer()->end(); INFO("Notebook Controller Success"); } // Constructor @@ -415,41 +417,17 @@ void Notebook::Controller::OnEditSearch() { void Notebook::Controller::Search(bool forward) { 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 settings = gtk_source_search_settings_new(); gtk_source_search_settings_set_search_text(settings, entry_.text().c_str()); auto context = gtk_source_search_context_new(buffer->gobj(), settings); gtk_source_search_context_set_highlight(context, forward); 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 diff --git a/juci/notebook.h b/juci/notebook.h index fa3fc80..c8f0d9f 100644 --- a/juci/notebook.h +++ b/juci/notebook.h @@ -74,6 +74,7 @@ namespace Notebook { bool OnKeyRelease(GdkEventKey* key); std::string OnSaveFileAs(); bool LegalExtension(std::string extension); + Gtk::TextIter start, end; protected: void TextViewHandlers(Gtk::TextView& textview); From 07d7741928b2c958137971f0a3548ada14abe4fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Tue, 16 Jun 2015 00:16:27 +0200 Subject: [PATCH 3/5] Add wrapping search --- juci/notebook.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/juci/notebook.cc b/juci/notebook.cc index 9b7b060..f4862da 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -420,8 +420,12 @@ void Notebook::Controller::Search(bool forward) { auto buffer = CurrentTextView().get_source_buffer(); auto settings = gtk_source_search_settings_new(); gtk_source_search_settings_set_search_text(settings, entry_.text().c_str()); +gtk_source_search_settings_set_wrap_around(settings, TRUE); auto context = gtk_source_search_context_new(buffer->gobj(), settings); gtk_source_search_context_set_highlight(context, forward); + + + auto itr = buffer->get_insert()->get_iter().gobj(); gtk_source_search_context_forward(context, end ? end.gobj() : itr, From bca64014af20d42cbbd3d7f1bb35b86d581b93f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Wed, 17 Jun 2015 16:02:45 +0200 Subject: [PATCH 4/5] Add mark of current search result, needs more work --- juci/config.json | 1 + juci/notebook.cc | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/juci/config.json b/juci/config.json index 7c0b9d1..1a73d5c 100644 --- a/juci/config.json +++ b/juci/config.json @@ -2,6 +2,7 @@ "source": { "colors": { "text_color": "black", + "search": "orange", "string": "#CC0000", "namespace_ref": "#990099", "type": "#0066FF", diff --git a/juci/notebook.cc b/juci/notebook.cc index c8fae34..39cbaab 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -416,20 +416,25 @@ void Notebook::Controller::OnEditSearch() { void Notebook::Controller::Search(bool forward) { INFO("Notebook search"); + + // fetch buffer and greate settings auto buffer = CurrentTextView().get_source_buffer(); auto settings = gtk_source_search_settings_new(); + + // get search text from entry gtk_source_search_settings_set_search_text(settings, entry_.text().c_str()); -gtk_source_search_settings_set_wrap_around(settings, TRUE); + + // make sure the search continues + gtk_source_search_settings_set_wrap_around(settings, true); auto context = gtk_source_search_context_new(buffer->gobj(), settings); gtk_source_search_context_set_highlight(context, forward); - - - auto itr = buffer->get_insert()->get_iter().gobj(); gtk_source_search_context_forward(context, end ? end.gobj() : itr, start.gobj(), end.gobj()); + + buffer->apply_tag_by_name("search", start, end); CurrentTextView().scroll_to(end); } From d79349cc9ad301ee79e7996b9dcc33280c6f122a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Sat, 20 Jun 2015 14:41:04 +0200 Subject: [PATCH 5/5] jumping search now works --- juci/notebook.cc | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/juci/notebook.cc b/juci/notebook.cc index bffd6e5..ce4fea2 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -426,16 +426,31 @@ void Notebook::Controller::Search(bool forward) { // get search text from entry gtk_source_search_settings_set_search_text(settings, entry_.text().c_str()); - // make sure the search continues + // make sure the search continues at top again gtk_source_search_settings_set_wrap_around(settings, true); + auto context = gtk_source_search_context_new(buffer->gobj(), settings); - gtk_source_search_context_set_highlight(context, forward); - auto itr = buffer->get_insert()->get_iter().gobj(); - gtk_source_search_context_forward(context, - end ? end.gobj() : itr, + + // makes the search mark all results + gtk_source_search_context_set_highlight(context, true); + + // gets iter at user input + auto itr = buffer->get_insert()->get_iter(); + DEBUG("Removing search tag") + buffer->remove_tag_by_name("search", start ? start : itr, end ? end : itr); + DEBUG("Before search"); + if (forward) { + gtk_source_search_context_forward(context, + end ? end.gobj() : itr.gobj(), start.gobj(), end.gobj()); - + } else { + gtk_source_search_context_backward(context, + start ? end.gobj() : itr.gobj(), + start.gobj(), + end.gobj()); + } + DEBUG("Before mark of search"); buffer->apply_tag_by_name("search", start, end); CurrentTextView().scroll_to(end); }