mirror of
https://github.com/gnustep/apps-projectcenter.git
synced 2025-03-17 08:01:24 +00:00
* Framework/PCProjectManager.m:
(close): Implemented. Closes not only project but also non project files editors. * Framework/PCProject.m: Clean and alert panels in various situations. * Framework/PCProjectEditor.m: Move closeAllEditors, saveEditedFiles:, saveAllFiles and saveFileAs: methods to PCEditorManager. Use <CodeEditor> close: methods instead of closeFile:save:. (saveFileAs:): Use superclass method. * Framework/PCEditorManager.m: Adopt moved methods. (modifiedFiles): Implemented. Return array of file paths. (hasModifiedFiles): Implemented for future use (e.g. prebuild check in ProjectBuilder). (reviewUnsaved:): Implemented. Go through modified files' editors and close which results in opening of alert "Save?" panels. * PCAppController.m: (applicationShouldTerminate:): Use PCProjectManager close method instead of closeAllProjects. * Modules/Editors/ProjectCenter/PCEditor.m: (_createWindow): Set "edited" flag according to current state. (saveFile): Add alert panel on fail. (closeFile:save:): Rewritten to properly process 'save' flag. * Headers/Protocols/CodeEditor.h: Added close: method. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@27873 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
41f163d735
commit
1699452ef8
11 changed files with 221 additions and 136 deletions
21
ChangeLog
21
ChangeLog
|
@ -1,3 +1,24 @@
|
|||
2009-02-16 Sergii Stoian <stoyan255@gmail.com>
|
||||
|
||||
* Framework/PCProjectManager.m:
|
||||
(close): Implemented. Closes not only project but also non
|
||||
project files editors.
|
||||
* Framework/PCProject.m: Clean and alert panels in various situations.
|
||||
* Framework/PCProjectEditor.m: Move closeAllEditors, saveEditedFiles:,
|
||||
saveAllFiles and saveFileAs: methods to PCEditorManager.
|
||||
(saveFileAs:): Use superclass method.
|
||||
* Framework/PCEditorManager.m: Adopt moved methods.
|
||||
(modifiedFiles): Implemented. Return array of file paths.
|
||||
(hasModifiedFiles): Implemented for future use (e.g. prebuild check
|
||||
in ProjectBuilder).
|
||||
(reviewUnsaved:): Implemented. Go through modified files' editors
|
||||
and close which results in opening of alert "Save?" panels.
|
||||
* PCAppController.m:
|
||||
(applicationShouldTerminate:): Use PCProjectManager close method
|
||||
instead of closeAllProjects.
|
||||
* Modules/Editors/ProjectCenter/PCEditor.m:
|
||||
(_createWindow): Set "edited" flag according to current state.
|
||||
|
||||
2009-02-15 14:14-EST Gregory John Casamento <greg_casamento@yahoo.com>
|
||||
|
||||
* Modules/Debuggers/ProjectCenter/PCDebuggerView.m: Detect when the
|
||||
|
|
|
@ -128,7 +128,7 @@ NSString *PCEditorDidResignActiveNotification =
|
|||
}
|
||||
|
||||
// ===========================================================================
|
||||
// ==== Project and Editor handling
|
||||
// ==== Editor handling
|
||||
// ===========================================================================
|
||||
|
||||
- (id<CodeEditor>)editorForFile:(NSString *)filePath
|
||||
|
@ -236,7 +236,7 @@ NSString *PCEditorDidResignActiveNotification =
|
|||
return;
|
||||
}
|
||||
|
||||
[_activeEditor closeFile:self save:YES];
|
||||
[_activeEditor close:sender];
|
||||
}
|
||||
|
||||
- (void)closeEditorForFile:(NSString *)file
|
||||
|
@ -245,15 +245,126 @@ NSString *PCEditorDidResignActiveNotification =
|
|||
|
||||
if ([_editorsDict count] > 0 && (editor = [_editorsDict objectForKey:file]))
|
||||
{
|
||||
[editor closeFile:self save:YES];
|
||||
[_editorsDict removeObjectForKey:file];
|
||||
[editor close:self];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSArray *)modifiedFiles
|
||||
{
|
||||
NSEnumerator *enumerator = [_editorsDict keyEnumerator];
|
||||
NSString *key = nil;
|
||||
id<CodeEditor> editor;
|
||||
NSMutableArray *modifiedFiles = [[NSMutableArray alloc] init];
|
||||
|
||||
while ((key = [enumerator nextObject]))
|
||||
{
|
||||
editor = [_editorsDict objectForKey:key];
|
||||
if ([editor isEdited])
|
||||
{
|
||||
[modifiedFiles addObject:key];
|
||||
}
|
||||
}
|
||||
|
||||
return AUTORELEASE((NSArray *)modifiedFiles);
|
||||
}
|
||||
|
||||
- (BOOL)hasModifiedFiles
|
||||
{
|
||||
if ([[self modifiedFiles] count])
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)reviewUnsaved:(NSArray *)modifiedFiles
|
||||
{
|
||||
NSEnumerator *enumerator = [modifiedFiles objectEnumerator];
|
||||
NSString *filePath;
|
||||
id<CodeEditor> editor;
|
||||
|
||||
while ((filePath = [enumerator nextObject]))
|
||||
{
|
||||
editor = [_editorsDict objectForKey:filePath];
|
||||
|
||||
[self orderFrontEditorForFile:filePath];
|
||||
|
||||
if ([editor close:self] == NO)
|
||||
{ // Operation should be aborted
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)closeAllEditors
|
||||
{
|
||||
NSArray *modifiedFiles = [self modifiedFiles];
|
||||
int ret;
|
||||
|
||||
if ([modifiedFiles count])
|
||||
{
|
||||
ret = NSRunAlertPanel(@"Close",
|
||||
@"Project has unsaved files.",
|
||||
@"Review Unsaved",
|
||||
@"Close Anyway",
|
||||
@"Save and Close");
|
||||
switch (ret)
|
||||
{
|
||||
case NSAlertDefaultReturn: // Review Unsaved
|
||||
if ([self reviewUnsaved:modifiedFiles] == NO)
|
||||
{ // Operation was canceled
|
||||
return NO;
|
||||
}
|
||||
break;
|
||||
|
||||
case NSAlertAlternateReturn: // Close Anyway
|
||||
break;
|
||||
|
||||
case NSAlertOtherReturn: // Save and Close
|
||||
if ([self saveAllFiles] == NO)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
[_editorsDict removeAllObjects];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
// ==== Active editor file handling
|
||||
// ==== File handling
|
||||
// ===========================================================================
|
||||
|
||||
- (BOOL)saveAllFiles
|
||||
{
|
||||
NSEnumerator *enumerator = [_editorsDict keyEnumerator];
|
||||
id<CodeEditor> editor;
|
||||
NSString *key;
|
||||
BOOL ret = YES;
|
||||
|
||||
while ((key = [enumerator nextObject]))
|
||||
{
|
||||
editor = [_editorsDict objectForKey:key];
|
||||
|
||||
if ([editor saveFileIfNeeded] == NO)
|
||||
{
|
||||
ret = NSRunAlertPanel(@"Save Files",
|
||||
@"Couldn't save file '%@'.\n"
|
||||
"Operation stopped.",
|
||||
@"Ok",nil,nil);
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
- (BOOL)saveFile
|
||||
{
|
||||
id<CodeEditor> editor = [self activeEditor];
|
||||
|
|
|
@ -432,8 +432,8 @@ NSString
|
|||
// Remove backup file if exists
|
||||
if ([fm fileExistsAtPath:backup] && ![fm removeFileAtPath:backup handler:nil])
|
||||
{
|
||||
NSRunAlertPanel(@"Save project",
|
||||
@"Error removing the old project backup!",
|
||||
NSRunAlertPanel(@"Save Project",
|
||||
@"Couldn't remove the old project backup file",
|
||||
@"OK",nil,nil);
|
||||
return NO;
|
||||
}
|
||||
|
@ -443,8 +443,8 @@ NSString
|
|||
{
|
||||
if ([fm copyPath:file toPath:backup handler:nil] == NO)
|
||||
{
|
||||
NSRunAlertPanel(@"Save project",
|
||||
@"Error when saving project backup file!",
|
||||
NSRunAlertPanel(@"Save Project",
|
||||
@"Couldn't save project backup file",
|
||||
@"OK",nil,nil);
|
||||
return NO;
|
||||
}
|
||||
|
@ -455,6 +455,9 @@ NSString
|
|||
forKey:PCLastEditing];
|
||||
if ([projectDict writeToFile:file atomically:YES] == NO)
|
||||
{
|
||||
NSRunAlertPanel(@"Save Project",
|
||||
@"Couldn't save project file",
|
||||
@"OK",nil,nil,projectName);
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
@ -465,9 +468,9 @@ NSString
|
|||
// Save GNUmakefile
|
||||
if ([self writeMakefile] == NO)
|
||||
{
|
||||
NSRunAlertPanel(@"Save project",
|
||||
@"Error when writing makefile for project %@",
|
||||
@"OK",nil,nil,projectName);
|
||||
NSRunAlertPanel(@"Save Project",
|
||||
@"Couldn't write GNUmakefile",
|
||||
@"OK",nil,nil);
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
@ -493,7 +496,7 @@ NSString
|
|||
|
||||
ret = NSRunAlertPanel(@"Close Project",
|
||||
@"Project or subprojects are modified",
|
||||
@"Save and Close",@"Don't save",@"Cancel");
|
||||
@"Save and Close",@"Don't save",@"Stop");
|
||||
switch (ret)
|
||||
{
|
||||
case NSAlertDefaultReturn:
|
||||
|
|
|
@ -279,112 +279,20 @@
|
|||
}
|
||||
}
|
||||
|
||||
// Called by PCProject. After that retainCount goes down and [self dealloc]
|
||||
// called by autorelease mechanism
|
||||
- (BOOL)closeAllEditors
|
||||
{
|
||||
NSEnumerator *enumerator = [_editorsDict keyEnumerator];
|
||||
id<CodeEditor> editor;
|
||||
NSString *key = nil;
|
||||
NSMutableArray *editedFiles = [[NSMutableArray alloc] init];
|
||||
|
||||
while ((key = [enumerator nextObject]))
|
||||
{
|
||||
editor = [_editorsDict objectForKey:key];
|
||||
if ([editor isEdited])
|
||||
{
|
||||
[editedFiles addObject:[key lastPathComponent]];
|
||||
}
|
||||
else
|
||||
{
|
||||
[editor closeFile:self save:YES];
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Order panel with list of changed files
|
||||
if ([editedFiles count])
|
||||
{
|
||||
if ([self saveEditedFiles:(NSArray *)editedFiles] == NO)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
[_editorsDict removeAllObjects];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
// ==== File handling
|
||||
// ===========================================================================
|
||||
|
||||
- (BOOL)saveEditedFiles:(NSArray *)files
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = NSRunAlertPanel(@"Alert",
|
||||
@"Project has modified files\n%@",
|
||||
@"Save and Close",@"Close",@"Don't close",
|
||||
files);
|
||||
switch (ret)
|
||||
{
|
||||
case NSAlertDefaultReturn:
|
||||
if ([self saveAllFiles] == NO)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
break;
|
||||
|
||||
case NSAlertAlternateReturn:
|
||||
// Close files without saving
|
||||
break;
|
||||
|
||||
case NSAlertOtherReturn:
|
||||
return NO;
|
||||
break;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
// TODO: move to PCEditorManager
|
||||
- (BOOL)saveAllFiles
|
||||
{
|
||||
NSEnumerator *enumerator = [_editorsDict keyEnumerator];
|
||||
id<CodeEditor> editor;
|
||||
NSString *key;
|
||||
BOOL ret = YES;
|
||||
|
||||
while ((key = [enumerator nextObject]))
|
||||
{
|
||||
editor = [_editorsDict objectForKey:key];
|
||||
|
||||
if ([editor saveFileIfNeeded] == NO)
|
||||
{
|
||||
ret = NO;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
- (BOOL)saveFileAs:(NSString *)file
|
||||
{
|
||||
id<CodeEditor> editor = [self activeEditor];
|
||||
NSString *categoryPath = nil;
|
||||
BOOL res;
|
||||
|
||||
if (editor != nil)
|
||||
{
|
||||
BOOL res;
|
||||
BOOL iw = [editor isWindowed];
|
||||
NSString *categoryPath = [editor categoryPath];
|
||||
|
||||
res = [editor saveFileTo:file];
|
||||
[editor closeFile:self save:NO];
|
||||
|
||||
editor = [self openEditorForFile:file
|
||||
editable:YES // fixme
|
||||
windowed:iw];
|
||||
categoryPath = [editor categoryPath];
|
||||
res = [super saveFileAs:file];
|
||||
[editor setCategoryPath:categoryPath];
|
||||
|
||||
return res;
|
||||
|
|
|
@ -79,6 +79,21 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange";
|
|||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)close
|
||||
{
|
||||
if ([self closeAllProjects] == NO)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
if ((editorManager != nil) && ([editorManager closeAllEditors] == NO))
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
#ifdef DEVELOPMENT
|
||||
|
|
|
@ -67,10 +67,16 @@
|
|||
- (void)closeActiveEditor:(id)sender;
|
||||
- (void)closeEditorForFile:(NSString *)file;
|
||||
|
||||
- (NSArray *)modifiedFiles;
|
||||
- (BOOL)hasModifiedFiles;
|
||||
- (BOOL)reviewUnsaved:(NSArray *)modifiedFiles;
|
||||
- (BOOL)closeAllEditors;
|
||||
|
||||
// ===========================================================================
|
||||
// ==== File handling
|
||||
// ===========================================================================
|
||||
|
||||
- (BOOL)saveAllFiles;
|
||||
- (BOOL)saveFile;
|
||||
- (BOOL)saveFileAs:(NSString *)file;
|
||||
- (BOOL)saveFileTo:(NSString *)file;
|
||||
|
|
|
@ -71,14 +71,11 @@
|
|||
windowed:(BOOL)windowed;
|
||||
|
||||
- (void)orderFrontEditorForFile:(NSString *)path;
|
||||
- (BOOL)closeAllEditors;
|
||||
|
||||
// ===========================================================================
|
||||
// ==== File handling
|
||||
// ===========================================================================
|
||||
|
||||
- (BOOL)saveEditedFiles:(NSArray *)files;
|
||||
- (BOOL)saveAllFiles;
|
||||
- (BOOL)saveFileAs:(NSString *)file;
|
||||
|
||||
// ===========================================================================
|
||||
|
|
|
@ -89,6 +89,7 @@ extern NSString *PCActiveProjectDidChangeNotification;
|
|||
// ==== Intialization & deallocation
|
||||
// ============================================================================
|
||||
- (id)init;
|
||||
- (BOOL)close;
|
||||
- (void)dealloc;
|
||||
- (void)setDelegate:(id)aDelegate;
|
||||
- (id)delegate;
|
||||
|
|
|
@ -75,6 +75,7 @@
|
|||
- (BOOL)saveFileTo:(NSString *)path;
|
||||
- (BOOL)revertFileToSaved;
|
||||
- (BOOL)closeFile:(id)sender save:(BOOL)save;
|
||||
- (BOOL)close:(id)sender;
|
||||
|
||||
// ===========================================================================
|
||||
// ==== Parser and scrolling
|
||||
|
|
|
@ -77,6 +77,9 @@
|
|||
[_window setContentView:_extScrollView];
|
||||
[_window makeFirstResponder:_extEditorView];
|
||||
RELEASE(_extScrollView);
|
||||
|
||||
// Honor "edited" state
|
||||
[_window setDocumentEdited:_isEdited];
|
||||
}
|
||||
|
||||
- (void)_createInternalView
|
||||
|
@ -613,6 +616,12 @@
|
|||
postNotificationName:PCEditorDidSaveNotification
|
||||
object:self];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSRunAlertPanel(@"Save File",
|
||||
@"Couldn't save file '%@'!",
|
||||
@"OK", nil, nil, [_path lastPathComponent]);
|
||||
}
|
||||
|
||||
return saved;
|
||||
}
|
||||
|
@ -659,9 +668,31 @@
|
|||
return YES;
|
||||
}
|
||||
|
||||
// FIXME: Do we really need this method?
|
||||
- (BOOL)closeFile:(id)sender save:(BOOL)save
|
||||
{
|
||||
if ((save == NO) || [self editorShouldClose])
|
||||
if (save == YES)
|
||||
{
|
||||
[self saveFileIfNeeded];
|
||||
}
|
||||
|
||||
// Close window first if visible
|
||||
if (_isWindowed && [_window isVisible] && (sender != _window))
|
||||
{
|
||||
[_window close];
|
||||
}
|
||||
|
||||
// Inform about closing
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
postNotificationName:PCEditorDidCloseNotification
|
||||
object:self];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)close:(id)sender
|
||||
{
|
||||
if ([self editorShouldClose] == YES)
|
||||
{
|
||||
// Close window first if visible
|
||||
if (_isWindowed && [_window isVisible] && (sender != _window))
|
||||
|
@ -684,7 +715,7 @@
|
|||
{
|
||||
if (_isEdited)
|
||||
{
|
||||
BOOL ret;
|
||||
int ret;
|
||||
|
||||
if (_isWindowed && [_window isVisible])
|
||||
{
|
||||
|
@ -692,31 +723,24 @@
|
|||
}
|
||||
|
||||
ret = NSRunAlertPanel(@"Close File",
|
||||
@"File %@ has been modified",
|
||||
@"File has been modified. Save?",
|
||||
@"Save and Close", @"Don't save", @"Cancel",
|
||||
[_path lastPathComponent]);
|
||||
|
||||
if (ret == YES) // Save and Close
|
||||
switch (ret)
|
||||
{
|
||||
case NSAlertDefaultReturn: // Save And Close
|
||||
if ([self saveFile] == NO)
|
||||
{
|
||||
NSRunAlertPanel(@"Close file",
|
||||
@"Error when saving file '%@'!",
|
||||
@"OK", nil, nil, [_path lastPathComponent]);
|
||||
return NO;
|
||||
}
|
||||
else
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
else if (ret == NO) // Close but don't save
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
else // Cancel closing
|
||||
{
|
||||
break;
|
||||
|
||||
case NSAlertAlternateReturn: // Don't save
|
||||
break;
|
||||
|
||||
case NSAlertOtherReturn: // Cancel
|
||||
return NO;
|
||||
break;
|
||||
}
|
||||
|
||||
[self setIsEdited:NO];
|
||||
|
@ -741,7 +765,7 @@
|
|||
}
|
||||
else
|
||||
{
|
||||
return [self closeFile:sender save:YES];
|
||||
return [self close:sender];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -165,10 +165,8 @@
|
|||
quit = [projectManager saveAllProjects];
|
||||
}
|
||||
|
||||
// Close all loaded projects
|
||||
quit = [projectManager closeAllProjects];
|
||||
|
||||
if (quit == NO)
|
||||
// Close ProjectManager (projects, editors, etc.)
|
||||
if ([projectManager close] == NO)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue