From 87bc0ef57b1d21ee1d55fe57e72efcd5c93ca2d2 Mon Sep 17 00:00:00 2001 From: Sergii Stoian Date: Mon, 4 Feb 2008 23:51:28 +0000 Subject: [PATCH] * Framework/PCProjectManager.[mh]: Cleaning up code that manages non-project editors. Use PCEditorManager instead. Remove PCFileManager's dalegate code(FileManagerDelegates category). (-newFile): Call PCFileCreator's method newFileInProject:. * Framework/PCFileManager.[mh]: Move code related to creation of new file in project from here * Framework/PCFileCreator.[mh]: to here. (-createFile): Add additional check before adding file to project (fixes bug #17493). * Framework/English.lproj/NewFile.gorm: Set owner to PCFileCreator. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@26024 72102866-910b-0410-8b05-ffd578937521 --- Documentation/ChangeLog | 13 ++ .../English.lproj/NewFile.gorm/data.classes | 2 +- .../English.lproj/NewFile.gorm/data.info | Bin 210 -> 184 bytes .../English.lproj/NewFile.gorm/objects.gorm | Bin 7578 -> 7352 bytes Framework/PCFileCreator.m | 158 +++++++++++++++++- Framework/PCFileManager.m | 131 --------------- Framework/PCProjectManager.m | 130 +++----------- Headers/ProjectCenter/PCFileCreator.h | 25 ++- Headers/ProjectCenter/PCFileManager.h | 8 - Headers/ProjectCenter/PCProjectManager.h | 26 +-- PCAppController.m | 3 +- 11 files changed, 220 insertions(+), 276 deletions(-) diff --git a/Documentation/ChangeLog b/Documentation/ChangeLog index d88b2eb..a3e39db 100644 --- a/Documentation/ChangeLog +++ b/Documentation/ChangeLog @@ -1,3 +1,16 @@ +2008-02-05 Sergii Stoian + + * Framework/PCProjectManager.[mh]: Cleaning up code that manages + non-project editors. Use PCEditorManager instead. Remove + PCFileManager's dalegate code(FileManagerDelegates category). + (-newFile): Call PCFileCreator's method newFileInProject:. + * Framework/PCFileManager.[mh]: Move code related to creation of + new file in project from here + * Framework/PCFileCreator.[mh]: to here. + (-createFile): Add additional check before adding file to + project (fixes bug #17493). + * Framework/English.lproj/NewFile.gorm: Set owner to PCFileCreator. + 2008-01-22 Sergii Stoian * Framework/PCEditorManager.m: Added. diff --git a/Framework/English.lproj/NewFile.gorm/data.classes b/Framework/English.lproj/NewFile.gorm/data.classes index c3ab968..e82f40c 100644 --- a/Framework/English.lproj/NewFile.gorm/data.classes +++ b/Framework/English.lproj/NewFile.gorm/data.classes @@ -8,7 +8,7 @@ ); Super = NSObject; }; - PCFileManager = { + PCFileCreator = { Actions = ( "closeNewFilePanel:", "createFile:", diff --git a/Framework/English.lproj/NewFile.gorm/data.info b/Framework/English.lproj/NewFile.gorm/data.info index 00306638ad4ccc9a393036917c5cf7fc3da47b57..e17240ec892fff1692774f4c0c974721e046ef11 100644 GIT binary patch delta 98 zcmcb_xPx(m2y=33>O^th5Jn~@113Xe1`faA;F6-uymSTz21W)oAjzi+Bv?g3EGD1C mlGNf7g|O73;>`R!1Llp)AQe1t6+BEKl?ACO3P2-L6LSIN#S|m} delta 124 zcmdnNc!_a>2y33n975$>JUy^=r@5{IxY%wZshtA!n7B{qA=k_llUUXCPA0;|;^)?Upls}+Kr zaxS01APy6g!*MRh&M}+&Hu)oY{wGOQ^-S-~>@EmD-b#^f&SY$>nlD;rMF?R?Lv&?xhi0BL z3srm<0t^`!z0!L%v(riE(o<==D^N3 zmPKN6A}OF<_KJ>d?pV=W!f)>&0wvQ7+yo>W0{>%1j1U=g9O#gJqF;lTs#Nml=`-0+ z3i+=}?;cXQ2Rh{%(q{jBe$MokV#u|kJDVfhRqPUS1=f}tBb`o?dg&yR)P&cjyMt>J zxVElZA1zZs1>JH$&zmtzJdGSAK)km&ebXa{sA~$Bf?vk@+ct+Kljbe{c^YaAY8V{0 zL8NJO97nT8#?&j@OgDyST{5vDoE1pOb)>@)^IUbRXqIMavbravUm~bx*b~kXRC}XP zW&G|aRJ|dn`sA=!6PU&W$dDrxD5*lVXj?vn0{UxRq|^{Co85ZI$eK%IQ^k@wRMZjA1LAU;(+j!b6oi(e)LY{o2Baw3O;r#_^1fi7){CCcfK}0= z>3re&xr)7LDJd{qTkj6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Creator - static PCFileCreator *_creator = nil; -static NSString *_name = @"FileCreator"; static NSDictionary *dict = nil; +@implementation PCFileCreator + + (id)sharedCreator { if (_creator == nil) @@ -107,9 +106,20 @@ static NSDictionary *dict = nil; return _creator; } -- (NSString *)name +- (id)init { - return _name; + self = [super init]; + activeProject = nil; + + return self; +} + +- (void)dealloc +{ + RELEASE(newFilePanel); + RELEASE(dict); + + [super dealloc]; } - (NSDictionary *)creatorDictionary @@ -117,6 +127,13 @@ static NSDictionary *dict = nil; return dict; } +- (void)newFileInProject:(PCProject *)aProject +{ + // Set to nil after panel closing + activeProject = aProject; + [self showNewFilePanel]; +} + - (NSDictionary *)createFileOfType:(NSString *)type path:(NSString *)path project:(PCProject *)aProject @@ -285,3 +302,134 @@ static NSDictionary *dict = nil; @end +@implementation PCFileCreator (UInterface) + +// ============================================================================ +// ==== "New File in Project" Panel +// ============================================================================ +- (void)showNewFilePanel +{ + if (!newFilePanel) + { + if ([NSBundle loadNibNamed:@"NewFile" owner:self] == NO) + { + PCLogError(self, @"error loading NewFile NIB!"); + return; + } + [newFilePanel setFrameAutosaveName:@"NewFile"]; + if (![newFilePanel setFrameUsingName: @"NewFile"]) + { + [newFilePanel center]; + } + [newFilePanel center]; + [nfImage setImage:[NSApp applicationIconImage]]; + [nfTypePB setRefusesFirstResponder:YES]; + [nfTypePB removeAllItems]; + [nfTypePB addItemsWithTitles: + [[dict allKeys] + sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]]; + [nfTypePB selectItemAtIndex:0]; + [nfCancleButton setRefusesFirstResponder:YES]; + [nfCreateButton setRefusesFirstResponder:YES]; + [newFilePanel setDefaultButtonCell:[nfCreateButton cell]]; + } + + [self newFilePopupChanged:nfTypePB]; + + [newFilePanel makeKeyAndOrderFront:self]; + [nfNameField setStringValue:@""]; + [newFilePanel makeFirstResponder:nfNameField]; +} + +- (void)closeNewFilePanel:(id)sender +{ + [newFilePanel orderOut:self]; + activeProject = nil; +} + +- (void)createFile:(id)sender +{ + [self createFile]; + [self closeNewFilePanel:self]; + activeProject = nil; +} + +- (void)newFilePopupChanged:(id)sender +{ + NSString *type = [sender titleOfSelectedItem]; + NSDictionary *creator = [dict objectForKey:type]; + + if (type) + { + [nfDescriptionTV setString:[creator objectForKey:@"TypeDescription"]]; + } +} + +- (void)controlTextDidChange:(NSNotification *)aNotif +{ + if ([aNotif object] != nfNameField) + { + return; + } + + // TODO: Add check for valid file names + if ([[nfNameField stringValue] length] > 0) + { + [nfCreateButton setEnabled:YES]; + } + else + { + [nfCreateButton setEnabled:NO]; + } +} + +- (void)createFile +{ + NSString *path = nil; + NSString *fileName = [nfNameField stringValue]; + NSString *fileType = [nfTypePB titleOfSelectedItem]; + NSDictionary *fileDict = [dict objectForKey:fileType]; + NSString *projectKey = [fileDict objectForKey:@"ProjectKey"]; + +// PCLogInfo(self, @"[createFile] %@", fileName); + + if ([activeProject doesAcceptFile:fileName forKey:projectKey]) + { + path = [[activeProject projectPath] + stringByAppendingPathComponent:fileName]; + } + +// PCLogInfo(self, @"creating file at %@", path); + + // Create file + if (path) + { + NSDictionary *newFiles = nil; + NSEnumerator *enumerator; + NSString *aFile; + + // Do it finally... + newFiles = [self createFileOfType:fileType + path:path + project:activeProject]; + + // Add files to a project + enumerator = [[newFiles allKeys] objectEnumerator]; + while ((aFile = [enumerator nextObject])) + { + fileType = [newFiles objectForKey:aFile]; + fileDict = [dict objectForKey:fileType]; + projectKey = [fileDict objectForKey:@"ProjectKey"]; + + if ([activeProject doesAcceptFile:aFile forKey:projectKey]) + { + [activeProject addFiles:[NSArray arrayWithObject:aFile] + forKey:projectKey + notify:YES]; + } + } + } +} + +@end + diff --git a/Framework/PCFileManager.m b/Framework/PCFileManager.m index f9c3c35..e154ecc 100644 --- a/Framework/PCFileManager.m +++ b/Framework/PCFileManager.m @@ -60,8 +60,6 @@ static PCFileManager *_mgr = nil; if ((self = [super init])) { projectManager = aProjectManager; - creators = [[PCFileCreator sharedCreator] creatorDictionary]; - RETAIN(creators); } return self; } @@ -72,9 +70,6 @@ static PCFileManager *_mgr = nil; NSLog (@"PCFileManager: dealloc"); #endif - RELEASE(creators); - RELEASE(newFilePanel); - if (addFilesPanel) { RELEASE(addFilesPanel); @@ -321,56 +316,6 @@ static PCFileManager *_mgr = nil; return YES; } -- (void)createFile -{ - NSString *path = nil; - NSString *fileName = [nfNameField stringValue]; - NSString *fileType = [nfTypePB titleOfSelectedItem]; - NSDictionary *theCreator = [creators objectForKey:fileType]; - NSString *key = [theCreator objectForKey:@"ProjectKey"]; - -// PCLogInfo(self, @"[createFile] %@", fileName); - - path = [projectManager fileManager:self - willCreateFile:fileName - withKey:key]; - -// PCLogInfo(self, @"creating file at %@", path); - - // Create file - if (path) - { - NSDictionary *newFiles = nil; - PCFileCreator *creator = nil; - PCProject *project = [projectManager activeProject]; - NSEnumerator *enumerator; - NSString *aFile; - - creator = [theCreator objectForKey:@"Creator"]; - if (!creator) - { - NSRunAlertPanel(@"Attention!", - @"Could not create %@. The creator is missing!", - @"OK",nil,nil,fileName); - return; - } - - // Do it finally... - newFiles = [creator createFileOfType:fileType path:path project:project]; - - // Key: name of file - enumerator = [[newFiles allKeys] objectEnumerator]; - while ((aFile = [enumerator nextObject])) - { - fileType = [newFiles objectForKey:aFile]; - theCreator = [creators objectForKey:fileType]; - key = [theCreator objectForKey:@"ProjectKey"]; - - [projectManager fileManager:self didCreateFile:aFile withKey:key]; - } - } -} - @end @implementation PCFileManager (UInterface) @@ -533,82 +478,6 @@ static PCFileManager *_mgr = nil; return nil; } -// ============================================================================ -// ==== "New File in Project" Panel -// ============================================================================ -- (void)showNewFilePanel -{ - if (!newFilePanel) - { - if ([NSBundle loadNibNamed:@"NewFile" owner:self] == NO) - { - PCLogError(self, @"error loading NewFile NIB!"); - return; - } - [newFilePanel setFrameAutosaveName:@"NewFile"]; - if (![newFilePanel setFrameUsingName: @"NewFile"]) - { - [newFilePanel center]; - } - [newFilePanel center]; - [nfImage setImage:[NSApp applicationIconImage]]; - [nfTypePB setRefusesFirstResponder:YES]; - [nfTypePB removeAllItems]; - [nfTypePB addItemsWithTitles: - [[creators allKeys] - sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]]; - [nfTypePB selectItemAtIndex:0]; - [nfCancleButton setRefusesFirstResponder:YES]; - [nfCreateButton setRefusesFirstResponder:YES]; - } - - [self newFilePopupChanged:nfTypePB]; - - [newFilePanel makeKeyAndOrderFront:self]; - [nfNameField setStringValue:@""]; - [newFilePanel makeFirstResponder:nfNameField]; -} - -- (void)closeNewFilePanel:(id)sender -{ - [newFilePanel orderOut:self]; -} - -- (void)createFile:(id)sender -{ - [self createFile]; - [self closeNewFilePanel:self]; -} - -- (void)newFilePopupChanged:(id)sender -{ - NSString *type = [sender titleOfSelectedItem]; - NSDictionary *creator = [creators objectForKey:type]; - - if (type) - { - [nfDescriptionTV setString:[creator objectForKey:@"TypeDescription"]]; - } -} - -- (void)controlTextDidChange:(NSNotification *)aNotif -{ - if ([aNotif object] != nfNameField) - { - return; - } - - // TODO: Add check for valid file names - if ([[nfNameField stringValue] length] > 0) - { - [nfCreateButton setEnabled:YES]; - } - else - { - [nfCreateButton setEnabled:NO]; - } -} - // ============================================================================ // ==== PCAddFilesPanel delegate // ============================================================================ diff --git a/Framework/PCProjectManager.m b/Framework/PCProjectManager.m index f108479..2b0e069 100644 --- a/Framework/PCProjectManager.m +++ b/Framework/PCProjectManager.m @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -67,23 +68,14 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; loadedProjects = [[NSMutableDictionary alloc] init]; - nonProjectEditors = [[NSMutableDictionary alloc] init]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resetSaveTimer:) name:PCSavePeriodDidChangeNotification object:nil]; - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(editorDidClose:) - name:PCEditorDidCloseNotification - object:nil]; - fileManager = [[PCFileManager alloc] initWithProjectManager:self]; - editorManager = [[PCEditorManager alloc] init]; - [editorManager setProjectManager:self]; + } return self; @@ -103,7 +95,6 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; } RELEASE(loadedProjects); - RELEASE(nonProjectEditors); RELEASE(fileManager); RELEASE(bundleManager); @@ -256,6 +247,18 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; return fileManager; } +- (PCEditorManager *)editorManager +{ + if (!editorManager) + { + // For non project editors + editorManager = [[PCEditorManager alloc] init]; + [editorManager setProjectManager:self]; + } + + return editorManager; +} + - (PCProjectInspector *)projectInspector { if (!projectInspector) @@ -1000,6 +1003,16 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; // ==== File actions // ============================================================================ +- (void)openFileAtPath:(NSString *)filePath +{ + if (filePath != nil) + { + [[self editorManager] openEditorForFile:filePath + editable:YES + windowed:YES]; + } +} + - (void)openFile { NSArray *files = nil; @@ -1011,16 +1024,12 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; title:@"Open File" accView:nil]; filePath = [files objectAtIndex:0]; - - if (filePath != nil) - { - [editorManager openEditorForFile:filePath editable:YES windowed:YES]; - } + [self openFileAtPath:filePath]; } - (void)newFile { - [fileManager showNewFilePanel]; + [[PCFileCreator sharedCreator] newFileInProject:activeProject]; } - (BOOL)saveFile @@ -1111,93 +1120,6 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; return [[activeProject projectEditor] closeActiveEditor:self]; } -// Project menu -// ============================================================================ -// ==== Non project editors -// ============================================================================ - -- (void)openFileWithEditor:(NSString *)path -{ -// id editor; -/* NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; - NSString *editor = [ud objectForKey:Editor]; - - if (![editor isEqualToString:@"ProjectCenter"]) - { - NSArray *ea = [editor componentsSeparatedByString:@" "]; - NSString *app = [ea objectAtIndex:0]; - - if ([[app pathExtension] isEqualToString:@"app"]) - { - BOOL ret = [[NSWorkspace sharedWorkspace] openFile:path - withApplication:app]; - - if (ret == NO) - { - PCLogError(self, @"Could not open %@ using %@", path, app); - } - - return nil; - } - - editor = [[editorClass alloc] initExternalEditor:editor - withPath:path - projectEditor:self]; - } - else - { - id editor; - - editor = [[editorClass alloc] initWithPath:path - categoryPath:nil - projectEditor:self]; - [editor setWindowed:YES]; - [editor show]; - - return editor; - } - - [nonProjectEditors setObject:editor forKey:path]; - - [editor release];*/ -} - -- (void)editorDidClose:(NSNotification *)aNotif -{ - id editor = [aNotif object]; - - [nonProjectEditors removeObjectForKey:[editor path]]; -} - -@end - -@implementation PCProjectManager (FileManagerDelegates) - -// willCreateFile -- (NSString *)fileManager:(id)sender - willCreateFile:(NSString *)aFile - withKey:(NSString *)key -{ - NSString *path = nil; - - if ([activeProject doesAcceptFile:aFile forKey:key]) - { - path = [[activeProject projectPath] stringByAppendingPathComponent:aFile]; - } - - return path; -} - -// didCreateFiles -- (void)fileManager:(id)sender - didCreateFile:(NSString *)aFile - withKey:(NSString *)key -{ - [activeProject addFiles:[NSArray arrayWithObject:aFile] - forKey:key - notify:YES]; -} - @end @implementation PCProjectManager (Subprojects) diff --git a/Headers/ProjectCenter/PCFileCreator.h b/Headers/ProjectCenter/PCFileCreator.h index 692cef4..83e781e 100644 --- a/Headers/ProjectCenter/PCFileCreator.h +++ b/Headers/ProjectCenter/PCFileCreator.h @@ -39,14 +39,24 @@ @interface PCFileCreator : NSObject { - NSMutableString *file; + PCProject *activeProject; + NSMutableString *file; + + // New File in Project panel + IBOutlet NSPanel *newFilePanel; + IBOutlet NSImageView *nfImage; + IBOutlet NSPopUpButton *nfTypePB; + IBOutlet NSTextView *nfDescriptionTV; + IBOutlet NSTextField *nfNameField; + IBOutlet NSButton *nfCancleButton; + IBOutlet NSButton *nfCreateButton; } + (id)sharedCreator; -- (NSString *)name; - (NSDictionary *)creatorDictionary; +- (void)newFileInProject:(PCProject *)aProject; // The implementation needs some heavy cleanup! - (NSDictionary *)createFileOfType:(NSString *)type path:(NSString *)path @@ -57,4 +67,15 @@ @end +@interface PCFileCreator (UInterface) + +- (void)showNewFilePanel; +- (void)closeNewFilePanel:(id)sender; +- (void)createFile:(id)sender; +- (void)newFilePopupChanged:(id)sender; +- (void)controlTextDidChange:(NSNotification *)aNotif; +- (void)createFile; + +@end + #endif diff --git a/Headers/ProjectCenter/PCFileManager.h b/Headers/ProjectCenter/PCFileManager.h index e8f8b95..d9ca203 100644 --- a/Headers/ProjectCenter/PCFileManager.h +++ b/Headers/ProjectCenter/PCFileManager.h @@ -45,8 +45,6 @@ enum { PCProjectManager *projectManager; id delegate; // PCProjectManager - NSDictionary *creators; - // New File in Project panel IBOutlet NSPanel *newFilePanel; IBOutlet NSImageView *nfImage; @@ -113,8 +111,6 @@ enum { - (BOOL)moveFile:(NSString *)file intoDirectory:(NSString *)directory; -- (void)createFile; - @end @interface PCFileManager (UInterface) @@ -125,10 +121,6 @@ enum { multiple:(BOOL)yn title:(NSString *)title accView:(NSView *)accessoryView; -- (void)showNewFilePanel; -- (void)closeNewFilePanel:(id)sender; -- (void)createFile:(id)sender; -- (void)newFilePopupChanged:(id)sender; @end diff --git a/Headers/ProjectCenter/PCProjectManager.h b/Headers/ProjectCenter/PCProjectManager.h index c421ce2..c49f4c8 100644 --- a/Headers/ProjectCenter/PCProjectManager.h +++ b/Headers/ProjectCenter/PCProjectManager.h @@ -64,8 +64,6 @@ extern NSString *PCActiveProjectDidChangeNotification; NSTimer *saveTimer; - NSMutableDictionary *nonProjectEditors; - NSBox *projectTypeAccessaryView; id projectTypePopup; @@ -110,6 +108,7 @@ extern NSString *PCActiveProjectDidChangeNotification; // ============================================================================ - (PCBundleManager *)bundleManager; - (PCFileManager *)fileManager; +- (PCEditorManager *)editorManager; - (PCProjectInspector *)projectInspector; - (NSPanel *)inspectorPanel; - (void)showProjectInspector:(id)sender; @@ -169,6 +168,8 @@ extern NSString *PCActiveProjectDidChangeNotification; // ==== File actions // ============================================================================ +// Also called by PCAppController +- (void)openFileAtPath:(NSString *)filePath; - (void)openFile; - (void)newFile; - (BOOL)saveFile; @@ -178,27 +179,6 @@ extern NSString *PCActiveProjectDidChangeNotification; - (BOOL)renameFile; - (void)closeFile; -// ============================================================================ -// ==== Non project editors -// ============================================================================ - -- (void)openFileWithEditor:(NSString *)path; -- (void)editorDidClose:(NSNotification *)aNotif; - -@end - -@interface PCProjectManager (FileManagerDelegates) - -// Returns the full path if the type is valid, nil else. -- (NSString *)fileManager:(id)sender - willCreateFile:(NSString *)aFile - withKey:(NSString *)key; - -// Adds the file to the project and updates the makefile! -- (void)fileManager:(id)sender - didCreateFile:(NSString *)aFile - withKey:(NSString *)key; - @end @interface NSObject (PCProjectManagerDelegates) diff --git a/PCAppController.m b/PCAppController.m index 0ae5b40..5acd6a2 100644 --- a/PCAppController.m +++ b/PCAppController.m @@ -113,7 +113,7 @@ } else { - [projectManager openFileWithEditor:fileName]; + [projectManager openFileAtPath:fileName]; } return YES; @@ -121,7 +121,6 @@ - (void)applicationWillFinishLaunching:(NSNotification *)notification { -// [bundleLoader loadBundles]; } - (void)applicationDidFinishLaunching:(NSNotification *)notification