mirror of
https://github.com/gnustep/apps-projectcenter.git
synced 2025-02-16 08:31:06 +00:00
commit
82c6aa3162
3 changed files with 61 additions and 10 deletions
|
@ -1,3 +1,10 @@
|
|||
2021-02-19 Riccardo Mottola <rm@gnu.org>
|
||||
|
||||
* 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 <rm@gnu.org>
|
||||
|
||||
* Framework/PCFileManager.m
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
#import <Protocols/Preferences.h>
|
||||
#import "Modules/Preferences/EditorFSC/PCEditorFSCPrefs.h"
|
||||
#import <ProjectCenter/PCProjectManager.h>
|
||||
#import <ProjectCenter/PCLogController.h>
|
||||
|
||||
|
||||
@implementation PCEditor (UInterface)
|
||||
|
||||
|
@ -261,6 +263,8 @@
|
|||
|
||||
RELEASE(undoManager);
|
||||
|
||||
RELEASE(_lastSaveDate);
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
@ -283,6 +287,7 @@
|
|||
NSMutableDictionary *attributes = [NSMutableDictionary new];
|
||||
NSFont *font;
|
||||
id <PCPreferences> 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,30 +655,61 @@
|
|||
|
||||
- (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]))
|
||||
{
|
||||
NSInteger choice;
|
||||
|
||||
PCLogInfo(self, @"File modified externally. %@ - %@", _lastSaveDate, fileModDate);
|
||||
choice = NSRunAlertPanel(@"Overwrite File?",
|
||||
@"File %@ was modified externally. Overwrite?",
|
||||
@"Cancel", @"Reload", @"Proceed", [_path lastPathComponent]);
|
||||
if (choice == NSAlertDefaultReturn)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
else if (choice == NSAlertAlternateReturn)
|
||||
{
|
||||
NSLog(@"Self");
|
||||
if ([self revertFileToSaved] == YES)
|
||||
return NO;
|
||||
NSLog(@"reload failed");
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
postNotificationName:PCEditorWillSaveNotification
|
||||
object:self];
|
||||
|
||||
// Send the notification to Gorm...
|
||||
if([[_path pathExtension] isEqual: @"h"])
|
||||
{
|
||||
[[NSDistributedNotificationCenter defaultCenter]
|
||||
postNotificationName: @"GormParseClassNotification"
|
||||
object: _path];
|
||||
}
|
||||
|
||||
saved = [[_storage string] writeToFile:_path atomically:YES];
|
||||
|
||||
if (saved == YES)
|
||||
{
|
||||
[self setIsEdited:NO];
|
||||
|
||||
// re-read date just saved
|
||||
ASSIGN(_lastSaveDate, [[fm fileAttributesAtPath:_path traverseLink:NO] fileModificationDate]);
|
||||
// Send the notification to Gorm...
|
||||
if([[_path pathExtension] isEqual: @"h"])
|
||||
{
|
||||
[[NSDistributedNotificationCenter defaultCenter]
|
||||
postNotificationName: @"GormParseClassNotification"
|
||||
object: _path];
|
||||
}
|
||||
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
postNotificationName:PCEditorDidSaveNotification
|
||||
object:self];
|
||||
|
@ -696,6 +735,7 @@
|
|||
NSAttributedString *as = nil;
|
||||
NSDictionary *at = nil;
|
||||
NSFont *ft = nil;
|
||||
NSFileManager *fm;
|
||||
|
||||
if (_isEdited == NO)
|
||||
{
|
||||
|
@ -729,6 +769,9 @@
|
|||
|
||||
[_intEditorView setNeedsDisplay:YES];
|
||||
[_extEditorView setNeedsDisplay:YES];
|
||||
|
||||
fm = [NSFileManager defaultManager];
|
||||
ASSIGN(_lastSaveDate, [[fm fileAttributesAtPath:_path traverseLink:NO] fileModificationDate]);
|
||||
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
postNotificationName:PCEditorDidRevertNotification
|
||||
|
|
Loading…
Reference in a new issue