Browse Source

feature: show warning when files have changed on disk outside of juCi++

merge-requests/365/head
Jørgen Lien Sellæg 10 years ago
parent
commit
070de20b2a
  1. 1
      src/notebook.cc
  2. 8
      src/source.cc
  3. 2
      src/source.h

1
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<Source::ClangView*>(view)) {
if(clang_view->language->get_id()=="chdr" || clang_view->language->get_id()=="cpphdr") {
for(auto a_view: source_views) {

8
src/source.cc

@ -2,6 +2,7 @@
#include "config.h"
#include "filesystem.h"
#include "terminal.h"
#include "info.h"
#include <gtksourceview/gtksource.h>
#include <boost/property_tree/json_parser.hpp>
#include <boost/spirit/home/qi/char.hpp>
@ -91,6 +92,7 @@ AspellConfig* Source::View::spellcheck_config=NULL;
Source::View::View(const boost::filesystem::path &file_path, Glib::RefPtr<Gsv::Language> 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<char, unsigned> Source::View::find_tab_char_and_size() {
std::unordered_map<char, size_t> tab_chars;
std::unordered_map<unsigned, size_t> tab_sizes;

2
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<char, unsigned> find_tab_char_and_size();
unsigned tab_size;

Loading…
Cancel
Save