From 070de20b2abc09cfbba09e7e95a8c1bf732cbe3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Sat, 14 May 2016 02:36:46 +0200 Subject: [PATCH] feature: show warning when files have changed on disk outside of juCi++ --- src/notebook.cc | 1 + src/source.cc | 8 ++++++++ src/source.h | 2 ++ 3 files changed, 11 insertions(+) diff --git a/src/notebook.cc b/src/notebook.cc index 79e7419..c1c5aaa 100644 --- a/src/notebook.cc +++ b/src/notebook.cc @@ -227,6 +227,7 @@ bool Notebook::save(int page) { } if(filesystem::write(view->file_path, view->get_buffer())) { + view->last_read_time=std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); if(auto clang_view=dynamic_cast(view)) { if(clang_view->language->get_id()=="chdr" || clang_view->language->get_id()=="cpphdr") { for(auto a_view: source_views) { diff --git a/src/source.cc b/src/source.cc index cd7b4b1..afd8e93 100644 --- a/src/source.cc +++ b/src/source.cc @@ -2,6 +2,7 @@ #include "config.h" #include "filesystem.h" #include "terminal.h" +#include "info.h" #include #include #include @@ -91,6 +92,7 @@ AspellConfig* Source::View::spellcheck_config=NULL; Source::View::View(const boost::filesystem::path &file_path, Glib::RefPtr language): file_path(file_path), language(language) { get_source_buffer()->begin_not_undoable_action(); + last_read_time=std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); if(language) { if(filesystem::read_non_utf8(file_path, get_buffer())==-1) Terminal::get().print("Warning: "+file_path.string()+" is not a valid UTF-8 file. Saving might corrupt the file.\n"); @@ -1571,6 +1573,12 @@ bool Source::View::on_button_press_event(GdkEventButton *event) { return Gsv::View::on_button_press_event(event); } +bool Source::View::on_focus_in_event(GdkEventFocus* focus_event){ + if(boost::filesystem::last_write_time(file_path)>last_read_time) + Info::get().print(file_path.filename().string() + " was changed outside juCi++, continue with caution."); + return Gtk::Widget::on_focus_in_event(focus_event); +}; + std::pair Source::View::find_tab_char_and_size() { std::unordered_map tab_chars; std::unordered_map tab_sizes; diff --git a/src/source.h b/src/source.h index 7a8ac4a..1aba690 100644 --- a/src/source.h +++ b/src/source.h @@ -125,6 +125,7 @@ namespace Source { bool full_reparse_needed=false; virtual void soft_reparse() {soft_reparse_needed=false;} virtual bool full_reparse() {full_reparse_needed=false; return true;} + std::time_t last_read_time; protected: bool parsed=false; Tooltips diagnostic_tooltips; @@ -161,6 +162,7 @@ namespace Source { bool on_key_press_event_bracket_language(GdkEventKey* key); bool is_bracket_language=false; bool on_button_press_event(GdkEventButton *event) override; + bool on_focus_in_event(GdkEventFocus* focus_event) override; std::pair find_tab_char_and_size(); unsigned tab_size;