* 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
This commit is contained in:
Sergii Stoian 2008-02-04 23:51:28 +00:00
parent 4e24cf3451
commit 87bc0ef57b
11 changed files with 220 additions and 276 deletions

View file

@ -1,3 +1,16 @@
2008-02-05 Sergii Stoian <stoyan255@gmail.com>
* 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 <stoyan255@gmail.com>
* Framework/PCEditorManager.m: Added.

View file

@ -8,7 +8,7 @@
);
Super = NSObject;
};
PCFileManager = {
PCFileCreator = {
Actions = (
"closeNewFilePanel:",
"createFile:",

View file

@ -30,12 +30,11 @@
#include <ProjectCenter/PCLogController.h>
@implementation PCFileCreator
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

View file

@ -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
// ============================================================================

View file

@ -29,6 +29,7 @@
#include <ProjectCenter/PCBundleManager.h>
#include <ProjectCenter/PCFileManager.h>
#include <ProjectCenter/PCFileCreator.h>
#include <ProjectCenter/PCEditorManager.h>
#include <ProjectCenter/PCProjectManager.h>
@ -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<CodeEditor> 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<CodeEditor> 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<CodeEditor> 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)

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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