Browse Source

Fixes #3 Add undo and redo by hotkey

merge-requests/365/head
Jørgen Lien Sellæg 11 years ago
parent
commit
496e962079
  1. 1
      juci/config.json
  2. 1
      juci/menu.xml
  3. 28
      juci/notebook.cc
  4. 2
      juci/notebook.h
  5. 5
      juci/source.cc
  6. 2
      juci/source.h

1
juci/config.json

@ -47,6 +47,7 @@
"edit_cut": "<control>x",
"edit_paste": "<control>v",
"edit_undo": "<control>z",
"edit_redo": "<control>y",
"edit_find": "<control>f",
"compile_and_run": "<control><alt>r",
"compile": "<control>r"

1
juci/menu.xml

@ -20,6 +20,7 @@
<separator/>
<menuitem action='EditFind'/>
<menuitem action='EditUndo'/>
<menuitem action='EditRedo'/>
</menu>
<menu action='ProjectMenu'>
<menuitem action='ProjectCompileAndRun'/>

28
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<Gsv::UndoManager> 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<Gsv::UndoManager> 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();
}

2
juci/notebook.h

@ -36,7 +36,7 @@ namespace Notebook {
Directories::Config& dir_cfg);
~Controller();
Glib::RefPtr<Gtk::TextBuffer> Buffer(Source::Controller *source);
Gtk::TextView& CurrentTextView();
Source::View& CurrentTextView();
int CurrentPage();
Gtk::Box& entry_view();
Gtk::Notebook& Notebook();

5
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);
@ -390,6 +391,6 @@ void Source::Controller::OnOpenFile(const string &filepath) {
});
}
}
Glib::RefPtr<Gtk::TextBuffer> Source::Controller::buffer() {
return view().get_buffer();
Glib::RefPtr<Gsv::Buffer> Source::Controller::buffer() {
return view().get_source_buffer();
}

2
juci/source.h

@ -152,7 +152,7 @@ namespace Source {
int column,
std::vector<AutoCompleteData>
*suggestions);
Glib::RefPtr<Gtk::TextBuffer> buffer();
Glib::RefPtr<Gsv::Buffer> buffer();
bool is_saved() { return is_saved_; }
bool is_changed() { return is_changed_; }
std::string path() { return model().file_path(); }

Loading…
Cancel
Save