Browse Source

Merge pull request #1 from cppit/master

Update eidheim/jucipp
merge-requests/365/head
Ole Christian Eidheim 11 years ago
parent
commit
f6d9984d79
  1. 1
      juci/config.json
  2. 1
      juci/menu.xml
  3. 28
      juci/notebook.cc
  4. 2
      juci/notebook.h
  5. 55
      juci/source.cc
  6. 2
      juci/source.h

1
juci/config.json

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

1
juci/menu.xml

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

28
juci/notebook.cc

@ -120,8 +120,31 @@ void Notebook::Controller::CreateKeybindings(Keybindings::Controller
Gtk::AccelKey(keybindings.config_ Gtk::AccelKey(keybindings.config_
.key_map()["edit_undo"]), .key_map()["edit_undo"]),
[this]() { [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(). entry_.view_.entry().signal_activate().
connect( connect(
[this]() { [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(); return text_vec_.at(CurrentPage())->view();
} }

2
juci/notebook.h

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

55
juci/source.cc

@ -28,6 +28,7 @@ Range(const Source::Range &org) :
//// View //// //// View ////
////////////// //////////////
Source::View::View() { Source::View::View() {
Gsv::init();
override_font(Pango::FontDescription("Monospace")); override_font(Pango::FontDescription("Monospace"));
set_show_line_numbers(true); set_show_line_numbers(true);
set_highlight_current_line(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 //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: //sends a signal to the main thread that it is to call the following function:
parsing_done.connect([this](){ parsing_done.connect([this](){
INFO("Updating syntax"); INFO("Updating syntax");
view(). view().
OnUpdateSyntax(model().ExtractTokens(0, buffer()->get_text().size()), OnUpdateSyntax(model().ExtractTokens(0, buffer()->get_text().size()),
model().config()); model().config());
INFO("Syntax updated"); INFO("Syntax updated");
}); });
buffer()->signal_end_user_action().connect([this]() { buffer()->signal_end_user_action().connect([this]() {
std::thread parse([this]() { std::thread parse([this]() {
if (parsing.try_lock()) { if (parsing.try_lock()) {
INFO("Starting parsing"); INFO("Starting parsing");
while (true) { while (true) {
const std::string raw = buffer()->get_text().raw(); const std::string raw = buffer()->get_text().raw();
std::map<std::string, std::string> buffers; std::map<std::string, std::string> buffers;
notebook_->MapBuffers(&buffers); notebook_->MapBuffers(&buffers);
buffers[model().file_path()] = raw; buffers[model().file_path()] = raw;
if (model().ReParse(buffers) == 0 && if (model().ReParse(buffers) == 0 &&
raw == buffer()->get_text().raw()) { raw == buffer()->get_text().raw()) {
break; break;
} }
} }
parsing.unlock(); parsing.unlock();
parsing_done(); parsing_done();
INFO("Parsing completed"); INFO("Parsing completed");
} }
});
parse.detach();
}); });
parse.detach();
});
} }
} }
Glib::RefPtr<Gtk::TextBuffer> Source::Controller::buffer() { Glib::RefPtr<Gsv::Buffer> Source::Controller::buffer() {
return view().get_buffer(); return view().get_source_buffer();
} }

2
juci/source.h

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

Loading…
Cancel
Save