diff --git a/juci/config.json b/juci/config.json index 8b164ef..ecedfe6 100644 --- a/juci/config.json +++ b/juci/config.json @@ -47,6 +47,7 @@ "edit_cut": "x", "edit_paste": "v", "edit_undo": "z", + "edit_redo": "y", "edit_find": "f", "compile_and_run": "r", "compile": "r" diff --git a/juci/menu.xml b/juci/menu.xml index dbe4b12..2eab08a 100644 --- a/juci/menu.xml +++ b/juci/menu.xml @@ -20,6 +20,7 @@ + diff --git a/juci/notebook.cc b/juci/notebook.cc index b634762..732aa54 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -120,8 +120,31 @@ void Notebook::Controller::CreateKeybindings(Keybindings::Controller Gtk::AccelKey(keybindings.config_ .key_map()["edit_undo"]), [this]() { - //OnUndo(); - }); + INFO("On undo"); + Glib::RefPtr undo_manager = + CurrentTextView().get_source_buffer()->get_undo_manager(); + if (Pages() != 0 && undo_manager->can_undo()) { + undo_manager->undo(); + } + INFO("Done undo"); + } + ); + + keybindings.action_group_menu()-> + add(Gtk::Action::create("EditRedo", + "Redo"), + Gtk::AccelKey(keybindings.config_ + .key_map()["edit_redo"]), + [this]() { + INFO("On Redo"); + Glib::RefPtr undo_manager = + CurrentTextView().get_source_buffer()->get_undo_manager(); + if (Pages() != 0 && undo_manager->can_redo()) { + undo_manager->redo(); + } + INFO("Done Redo"); + }); + entry_.view_.entry().signal_activate(). connect( [this]() { @@ -515,7 +538,8 @@ void Notebook::Controller } } -Gtk::TextView& Notebook::Controller::CurrentTextView() { +Source::View& Notebook::Controller::CurrentTextView() { + INFO("Getting sourceview"); return text_vec_.at(CurrentPage())->view(); } diff --git a/juci/notebook.h b/juci/notebook.h index e7681ca..5dae038 100644 --- a/juci/notebook.h +++ b/juci/notebook.h @@ -36,7 +36,7 @@ namespace Notebook { Directories::Config& dir_cfg); ~Controller(); Glib::RefPtr Buffer(Source::Controller *source); - Gtk::TextView& CurrentTextView(); + Source::View& CurrentTextView(); int CurrentPage(); Gtk::Box& entry_view(); Gtk::Notebook& Notebook(); diff --git a/juci/source.cc b/juci/source.cc index 9e54688..aaf2dc2 100644 --- a/juci/source.cc +++ b/juci/source.cc @@ -28,6 +28,7 @@ Range(const Source::Range &org) : //// View //// ////////////// Source::View::View() { + Gsv::init(); override_font(Pango::FontDescription("Monospace")); set_show_line_numbers(true); set_highlight_current_line(true); @@ -360,36 +361,36 @@ void Source::Controller::OnOpenFile(const string &filepath) { //OnUpdateSyntax must happen in main thread, so the parse-thread //sends a signal to the main thread that it is to call the following function: parsing_done.connect([this](){ - INFO("Updating syntax"); - view(). - OnUpdateSyntax(model().ExtractTokens(0, buffer()->get_text().size()), - model().config()); - INFO("Syntax updated"); - }); + INFO("Updating syntax"); + view(). + OnUpdateSyntax(model().ExtractTokens(0, buffer()->get_text().size()), + model().config()); + INFO("Syntax updated"); + }); buffer()->signal_end_user_action().connect([this]() { - std::thread parse([this]() { - if (parsing.try_lock()) { - INFO("Starting parsing"); - while (true) { - const std::string raw = buffer()->get_text().raw(); - std::map buffers; - notebook_->MapBuffers(&buffers); - buffers[model().file_path()] = raw; - if (model().ReParse(buffers) == 0 && - raw == buffer()->get_text().raw()) { - break; - } - } - parsing.unlock(); - parsing_done(); - INFO("Parsing completed"); - } + std::thread parse([this]() { + if (parsing.try_lock()) { + INFO("Starting parsing"); + while (true) { + const std::string raw = buffer()->get_text().raw(); + std::map buffers; + notebook_->MapBuffers(&buffers); + buffers[model().file_path()] = raw; + if (model().ReParse(buffers) == 0 && + raw == buffer()->get_text().raw()) { + break; + } + } + parsing.unlock(); + parsing_done(); + INFO("Parsing completed"); + } + }); + parse.detach(); }); - parse.detach(); - }); } } -Glib::RefPtr Source::Controller::buffer() { - return view().get_buffer(); +Glib::RefPtr Source::Controller::buffer() { + return view().get_source_buffer(); } diff --git a/juci/source.h b/juci/source.h index 89aa1f2..a864b96 100644 --- a/juci/source.h +++ b/juci/source.h @@ -152,7 +152,7 @@ namespace Source { int column, std::vector *suggestions); - Glib::RefPtr buffer(); + Glib::RefPtr buffer(); bool is_saved() { return is_saved_; } bool is_changed() { return is_changed_; } std::string path() { return model().file_path(); }