Browse Source

Can now undo file reload

merge-requests/382/head
eidheim 8 years ago
parent
commit
97126e24b9
  1. 13
      src/source_base.cc
  2. 2
      src/source_base.h

13
src/source_base.cc

@ -6,7 +6,7 @@
#include <fstream> #include <fstream>
Source::BaseView::BaseView(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::Language> language): Gsv::View(), file_path(file_path), language(language), status_diagnostics(0, 0, 0) { Source::BaseView::BaseView(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::Language> language): Gsv::View(), file_path(file_path), language(language), status_diagnostics(0, 0, 0) {
load(); load(true);
get_buffer()->place_cursor(get_buffer()->get_iter_at_offset(0)); get_buffer()->place_cursor(get_buffer()->get_iter_at_offset(0));
signal_focus_in_event().connect([this](GdkEventFocus *event) { signal_focus_in_event().connect([this](GdkEventFocus *event) {
@ -23,24 +23,27 @@ Source::BaseView::~BaseView() {
delayed_monitor_changed_connection.disconnect(); delayed_monitor_changed_connection.disconnect();
} }
bool Source::BaseView::load() { bool Source::BaseView::load(bool not_undoable_action) {
boost::system::error_code ec; boost::system::error_code ec;
last_write_time=boost::filesystem::last_write_time(file_path, ec); last_write_time=boost::filesystem::last_write_time(file_path, ec);
if(ec) if(ec)
last_write_time=static_cast<std::time_t>(-1); last_write_time=static_cast<std::time_t>(-1);
disable_spellcheck=true; disable_spellcheck=true;
get_source_buffer()->begin_not_undoable_action(); if(not_undoable_action)
get_source_buffer()->begin_not_undoable_action();
class Guard { class Guard {
public: public:
Source::BaseView *view; Source::BaseView *view;
bool not_undoable_action;
~Guard() { ~Guard() {
view->get_source_buffer()->end_not_undoable_action(); if(not_undoable_action)
view->get_source_buffer()->end_not_undoable_action();
view->disable_spellcheck=false; view->disable_spellcheck=false;
} }
}; };
Guard guard{this}; Guard guard{this, not_undoable_action};
if(language) { if(language) {
std::ifstream input(file_path.string(), std::ofstream::binary); std::ifstream input(file_path.string(), std::ofstream::binary);

2
src/source_base.h

@ -14,7 +14,7 @@ namespace Source {
Glib::RefPtr<Gsv::Language> language; Glib::RefPtr<Gsv::Language> language;
bool load(); bool load(bool not_undoable_action=false);
/// Set new text more optimally and without unnecessary scrolling /// Set new text more optimally and without unnecessary scrolling
void replace_text(const std::string &new_text); void replace_text(const std::string &new_text);
virtual void rename(const boost::filesystem::path &path); virtual void rename(const boost::filesystem::path &path);

Loading…
Cancel
Save