Browse Source

Merge pull request #6 from cppit/master

Pull cppit/jucipp
merge-requests/365/head
Ole Christian Eidheim 11 years ago
parent
commit
205de3da6d
  1. 1
      juci/config.json
  2. 121
      juci/notebook.cc
  3. 9
      juci/notebook.h
  4. 2
      juci/source.cc
  5. 1
      juci/source.h

1
juci/config.json

@ -2,6 +2,7 @@
"source": { "source": {
"colors": { "colors": {
"text_color": "black", "text_color": "black",
"search": "orange",
"string": "#CC0000", "string": "#CC0000",
"namespace_ref": "#990099", "namespace_ref": "#990099",
"type": "#0066FF", "type": "#0066FF",

121
juci/notebook.cc

@ -1,6 +1,8 @@
#include <fstream> #include <fstream>
#include "notebook.h" #include "notebook.h"
#include "logging.h" #include "logging.h"
#include <gtksourceview/gtksource.h> // c-library
Notebook::View::View() { Notebook::View::View() {
pack2(notebook); pack2(notebook);
@ -55,8 +57,7 @@ void Notebook::Controller::CreateKeybindings(Keybindings::Controller
Gtk::AccelKey(keybindings.config_ Gtk::AccelKey(keybindings.config_
.key_map()["edit_find"]), .key_map()["edit_find"]),
[this]() { [this]() {
OnEditSearch(); entry.show_search("");
// TODO(Oyvang) Zalox, Forgi)Create function OnEditFind();
}); });
keybindings.action_group_menu()-> keybindings.action_group_menu()->
add(Gtk::Action::create("EditCopy", add(Gtk::Action::create("EditCopy",
@ -65,7 +66,9 @@ void Notebook::Controller::CreateKeybindings(Keybindings::Controller
.key_map()["edit_copy"]), .key_map()["edit_copy"]),
[this]() { [this]() {
OnEditCopy(); if (Pages() != 0) {
CurrentTextView().get_buffer()->copy_clipboard(refClipboard_);
}
}); });
keybindings.action_group_menu()-> keybindings.action_group_menu()->
add(Gtk::Action::create("EditCut", add(Gtk::Action::create("EditCut",
@ -73,7 +76,9 @@ void Notebook::Controller::CreateKeybindings(Keybindings::Controller
Gtk::AccelKey(keybindings.config_ Gtk::AccelKey(keybindings.config_
.key_map()["edit_cut"]), .key_map()["edit_cut"]),
[this]() { [this]() {
OnEditCut(); if (Pages() != 0) {
CurrentTextView().get_buffer()->cut_clipboard(refClipboard_);
}
}); });
keybindings.action_group_menu()-> keybindings.action_group_menu()->
add(Gtk::Action::create("EditPaste", add(Gtk::Action::create("EditPaste",
@ -81,7 +86,9 @@ void Notebook::Controller::CreateKeybindings(Keybindings::Controller
Gtk::AccelKey(keybindings.config_ Gtk::AccelKey(keybindings.config_
.key_map()["edit_paste"]), .key_map()["edit_paste"]),
[this]() { [this]() {
OnEditPaste(); if (Pages() != 0) {
CurrentTextView().get_buffer()->paste_clipboard(refClipboard_);
}
}); });
keybindings.action_group_menu()-> keybindings.action_group_menu()->
@ -147,12 +154,12 @@ void Notebook::Controller::CreateKeybindings(Keybindings::Controller
entry.button_next.signal_clicked(). entry.button_next.signal_clicked().
connect( connect(
[this]() { [this]() {
Search(true); search(true);
}); });
entry.button_prev.signal_clicked(). entry.button_prev.signal_clicked().
connect( connect(
[this]() { [this]() {
Search(false); search(false);
}); });
INFO("Notebook signal handlers sucsess"); INFO("Notebook signal handlers sucsess");
} }
@ -171,7 +178,7 @@ void Notebook::Controller::OnOpenFile(std::string path) {
editor_vec_.push_back(new Gtk::HBox()); editor_vec_.push_back(new Gtk::HBox());
scrolledtext_vec_.back()->add(*text_vec_.back()->view); scrolledtext_vec_.back()->add(*text_vec_.back()->view);
editor_vec_.back()->pack_start(*scrolledtext_vec_.back(), true, true); editor_vec_.back()->pack_start(*scrolledtext_vec_.back(), true, true);
size_t pos = path.find_last_of("/\\"); size_t pos = path.find_last_of("/\\"); // TODO #windows
std::string filename=path; std::string filename=path;
if(pos!=std::string::npos) if(pos!=std::string::npos)
filename=path.substr(pos+1); filename=path.substr(pos+1);
@ -211,77 +218,39 @@ void Notebook::Controller::OnCloseCurrentPage() {
void Notebook::Controller::OnFileNewFile() { void Notebook::Controller::OnFileNewFile() {
entry.show_set_filename(); entry.show_set_filename();
} }
void Notebook::Controller::OnEditCopy() {
if (Pages() != 0) {
CurrentTextView().get_buffer()->copy_clipboard(refClipboard_);
}
}
void Notebook::Controller::OnEditPaste() {
if (Pages() != 0) {
CurrentTextView().get_buffer()->paste_clipboard(refClipboard_);
}
}
void Notebook::Controller::OnEditCut() {
if (Pages() != 0) {
CurrentTextView().get_buffer()->cut_clipboard(refClipboard_);
}
}
std::string Notebook::Controller::GetCursorWord() { void Notebook::Controller::search(bool forward) {
INFO("Notebook get cursor word");
std::string word;
Gtk::TextIter start, end;
start = CurrentTextView().get_buffer()->get_insert()->get_iter();
end = CurrentTextView().get_buffer()->get_insert()->get_iter();
if (!end.ends_line()) {
while (!end.ends_word()) {
end.forward_char();
}
}
if (!start.starts_line()) {
while (!start.starts_word()) {
start.backward_char();
}
}
word = CurrentTextView().get_buffer()->get_text(start, end);
// TODO(Oyvang) fix selected text
return word;
}
void Notebook::Controller::OnEditSearch() {
search_match_end_ =
CurrentTextView().get_buffer()->get_iter_at_offset(0);
entry.show_search(GetCursorWord());
}
void Notebook::Controller::Search(bool forward) {
INFO("Notebook search"); INFO("Notebook search");
std::string search_word; auto start = CurrentTextView().search_start;
search_word = entry(); auto end = CurrentTextView().search_end;
Gtk::TextIter test; // fetch buffer and greate settings
auto buffer = CurrentTextView().get_source_buffer();
if ( !forward ) { auto settings = gtk_source_search_settings_new();
if ( search_match_start_ == 0 || // get search text from entry
search_match_start_.get_line_offset() == 0) { gtk_source_search_settings_set_search_text(settings, entry().c_str());
search_match_start_ = CurrentTextView().get_buffer()->end(); // make sure the search continues
} gtk_source_search_settings_set_wrap_around(settings, true);
search_match_start_. auto context = gtk_source_search_context_new(buffer->gobj(), settings);
backward_search(search_word, gtk_source_search_context_set_highlight(context, forward);
Gtk::TextSearchFlags::TEXT_SEARCH_TEXT_ONLY | auto itr = buffer->get_insert()->get_iter();
Gtk::TextSearchFlags::TEXT_SEARCH_VISIBLE_ONLY, buffer->remove_tag_by_name("search", start ? start : itr, end ? end : itr);
search_match_start_, if (forward) {
search_match_end_); DEBUG("Doing forward search");
gtk_source_search_context_forward(context,
end ? end.gobj() : itr.gobj(),
start.gobj(),
end.gobj());
} else { } else {
if ( search_match_end_ == 0 ) { DEBUG("Doing backward search");
search_match_end_ = CurrentTextView().get_buffer()->begin(); gtk_source_search_context_backward(context,
} start ? start.gobj() : itr.gobj(),
search_match_end_. start.gobj(),
forward_search(search_word, end.gobj());
Gtk::TextSearchFlags::TEXT_SEARCH_TEXT_ONLY | }
Gtk::TextSearchFlags::TEXT_SEARCH_VISIBLE_ONLY, buffer->apply_tag_by_name("search", start, end);
search_match_start_, CurrentTextView().scroll_to(end);
search_match_end_); CurrentTextView().search_start = start;
} CurrentTextView().search_end = end;
} }
void Notebook::Controller void Notebook::Controller

9
juci/notebook.h

@ -31,11 +31,6 @@ namespace Notebook {
int CurrentPage(); int CurrentPage();
Gtk::Notebook& Notebook(); Gtk::Notebook& Notebook();
void OnCloseCurrentPage(); void OnCloseCurrentPage();
std::string GetCursorWord();
void OnEditCopy();
void OnEditCut();
void OnEditPaste();
void OnEditSearch();
void OnFileNewFile(); void OnFileNewFile();
bool OnSaveFile(); bool OnSaveFile();
bool OnSaveFile(std::string path); bool OnSaveFile(std::string path);
@ -43,7 +38,7 @@ namespace Notebook {
Gtk::TreeViewColumn* column); Gtk::TreeViewColumn* column);
void OnOpenFile(std::string filename); void OnOpenFile(std::string filename);
int Pages(); int Pages();
void Search(bool forward); void search(bool forward);
View view; View view;
std::string OnSaveFileAs(); std::string OnSaveFileAs();
std::string project_path; std::string project_path;
@ -61,8 +56,6 @@ namespace Notebook {
std::vector<Gtk::ScrolledWindow*> scrolledtext_vec_; std::vector<Gtk::ScrolledWindow*> scrolledtext_vec_;
std::vector<Gtk::HBox*> editor_vec_; std::vector<Gtk::HBox*> editor_vec_;
std::list<Gtk::TargetEntry> listTargets_; std::list<Gtk::TargetEntry> listTargets_;
Gtk::TextIter search_match_end_;
Gtk::TextIter search_match_start_;
Glib::RefPtr<Gtk::Clipboard> refClipboard_; Glib::RefPtr<Gtk::Clipboard> refClipboard_;
}; // class controller }; // class controller
} // namespace Notebook } // namespace Notebook

2
juci/source.cc

@ -27,11 +27,11 @@ config(config), file_path(file_path), project_path(project_path) {
set_smart_home_end(Gsv::SMART_HOME_END_BEFORE); set_smart_home_end(Gsv::SMART_HOME_END_BEFORE);
set_show_line_numbers(config.show_line_numbers); set_show_line_numbers(config.show_line_numbers);
set_highlight_current_line(config.highlight_current_line); set_highlight_current_line(config.highlight_current_line);
sourcefile s(file_path); sourcefile s(file_path);
get_source_buffer()->get_undo_manager()->begin_not_undoable_action(); get_source_buffer()->get_undo_manager()->begin_not_undoable_action();
get_source_buffer()->set_text(s.get_content()); get_source_buffer()->set_text(s.get_content());
get_source_buffer()->get_undo_manager()->end_not_undoable_action(); get_source_buffer()->get_undo_manager()->end_not_undoable_action();
search_start = search_end = this->get_buffer()->end();
} }
string Source::View::get_line(size_t line_number) { string Source::View::get_line(size_t line_number) {

1
juci/source.h

@ -63,6 +63,7 @@ namespace Source {
std::string get_line_before_insert(); std::string get_line_before_insert();
std::string file_path; std::string file_path;
std::string project_path; std::string project_path;
Gtk::TextIter search_start, search_end;
protected: protected:
const Source::Config& config; const Source::Config& config;
bool on_key_press(GdkEventKey* key); bool on_key_press(GdkEventKey* key);

Loading…
Cancel
Save