From 97126e24b9236ab2bfee33e44b25f184a66e3f54 Mon Sep 17 00:00:00 2001 From: eidheim Date: Tue, 8 May 2018 07:53:04 +0200 Subject: [PATCH] Can now undo file reload --- src/source_base.cc | 13 ++++++++----- src/source_base.h | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/source_base.cc b/src/source_base.cc index 45128c1..8a6813b 100644 --- a/src/source_base.cc +++ b/src/source_base.cc @@ -6,7 +6,7 @@ #include Source::BaseView::BaseView(const boost::filesystem::path &file_path, Glib::RefPtr 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)); signal_focus_in_event().connect([this](GdkEventFocus *event) { @@ -23,24 +23,27 @@ Source::BaseView::~BaseView() { delayed_monitor_changed_connection.disconnect(); } -bool Source::BaseView::load() { +bool Source::BaseView::load(bool not_undoable_action) { boost::system::error_code ec; last_write_time=boost::filesystem::last_write_time(file_path, ec); if(ec) last_write_time=static_cast(-1); disable_spellcheck=true; - get_source_buffer()->begin_not_undoable_action(); + if(not_undoable_action) + get_source_buffer()->begin_not_undoable_action(); class Guard { public: Source::BaseView *view; + bool not_undoable_action; ~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; } }; - Guard guard{this}; + Guard guard{this, not_undoable_action}; if(language) { std::ifstream input(file_path.string(), std::ofstream::binary); diff --git a/src/source_base.h b/src/source_base.h index 73ac1b1..0ded18a 100644 --- a/src/source_base.h +++ b/src/source_base.h @@ -14,7 +14,7 @@ namespace Source { Glib::RefPtr language; - bool load(); + bool load(bool not_undoable_action=false); /// Set new text more optimally and without unnecessary scrolling void replace_text(const std::string &new_text); virtual void rename(const boost::filesystem::path &path);