diff --git a/ChangeLog b/ChangeLog index e1556fe..b66ce27 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2021-02-19 Riccardo Mottola + + * Modules/Editors/ProjectCenter/PCEditor.h + * Modules/Editors/ProjectCenter/PCEditor.m + Keep track of the file modification date on each open/save, + compare it to the current file to detect external modifications. + 2021-02-12 Riccardo Mottola * Framework/PCFileManager.m diff --git a/Modules/Editors/ProjectCenter/PCEditor.h b/Modules/Editors/ProjectCenter/PCEditor.h index 64679b4..96f97f4 100644 --- a/Modules/Editors/ProjectCenter/PCEditor.h +++ b/Modules/Editors/ProjectCenter/PCEditor.h @@ -1,7 +1,7 @@ /* GNUstep ProjectCenter - http://www.gnustep.org/experience/ProjectCenter.html - Copyright (C) 2002-2014 Free Software Foundation + Copyright (C) 2002-2021 Free Software Foundation Authors: Philippe C.D. Robert Serg Stoyan @@ -50,6 +50,7 @@ BOOL _isEditable; BOOL _isWindowed; BOOL _isExternal; + NSDate *_lastSaveDate; // Search NSView *goToLineView; diff --git a/Modules/Editors/ProjectCenter/PCEditor.m b/Modules/Editors/ProjectCenter/PCEditor.m index b6da8ef..bb97314 100644 --- a/Modules/Editors/ProjectCenter/PCEditor.m +++ b/Modules/Editors/ProjectCenter/PCEditor.m @@ -30,6 +30,8 @@ #import #import "Modules/Preferences/EditorFSC/PCEditorFSCPrefs.h" #import +#import + @implementation PCEditor (UInterface) @@ -261,6 +263,8 @@ RELEASE(undoManager); + RELEASE(_lastSaveDate); + [super dealloc]; } @@ -283,6 +287,7 @@ NSMutableDictionary *attributes = [NSMutableDictionary new]; NSFont *font; id prefs; + NSFileManager *fm; // Inform about future file opening [[NSNotificationCenter defaultCenter] @@ -320,6 +325,9 @@ [_storage setAttributedString:attributedString]; RELEASE(attributedString); + fm = [NSFileManager defaultManager]; + ASSIGN(_lastSaveDate, [[fm fileAttributesAtPath:_path traverseLink:NO] fileModificationDate]); + // [self _createInternalView]; /* if (categoryPath) // category == nil if we're non project editor { @@ -647,12 +655,23 @@ - (BOOL)saveFile { - BOOL saved = NO; + BOOL saved = NO; + NSFileManager *fm; + NSDate *fileModDate; if (_isEdited == NO) { return YES; } + + fm = [NSFileManager defaultManager]; + + fileModDate = [[fm fileAttributesAtPath:_path traverseLink:NO] fileModificationDate]; + // Check if the file was ever written and its time is the same as the current file modification date + if (!(_lastSaveDate && [fileModDate isEqualToDate:_lastSaveDate])) + { + PCLogInfo(self, @"File modified externally?"); + } [[NSNotificationCenter defaultCenter] postNotificationName:PCEditorWillSaveNotification @@ -687,7 +706,15 @@ - (BOOL)saveFileTo:(NSString *)path { - return [[_storage string] writeToFile:path atomically:YES]; + NSFileManager *fm = [NSFileManager defaultManager]; + + if ([[_storage string] writeToFile:path atomically:YES]) + { + ASSIGN(_lastSaveDate, [[fm fileAttributesAtPath:_path traverseLink:NO] fileModificationDate]); + return YES; + } + + return NO; } - (BOOL)revertFileToSaved @@ -696,6 +723,7 @@ NSAttributedString *as = nil; NSDictionary *at = nil; NSFont *ft = nil; + NSFileManager *fm; if (_isEdited == NO) { @@ -729,6 +757,9 @@ [_intEditorView setNeedsDisplay:YES]; [_extEditorView setNeedsDisplay:YES]; + + fm = [NSFileManager defaultManager]; + ASSIGN(_lastSaveDate, [[fm fileAttributesAtPath:_path traverseLink:NO] fileModificationDate]); [[NSNotificationCenter defaultCenter] postNotificationName:PCEditorDidRevertNotification