Enhanced the 'new file window' by adding a description view.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@12548 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Philippe C.D. Robert 2002-02-16 20:46:26 +00:00
parent f5b3597a80
commit b9bcd643d8
5 changed files with 230 additions and 127 deletions

View file

@ -41,7 +41,8 @@
- (void)click:(id)sender - (void)click:(id)sender
{ {
if ([[sender selectedCell] isLeaf]) { if ([[sender selectedCell] isLeaf])
{
NSString *ltitle = [[sender selectedCell] stringValue]; NSString *ltitle = [[sender selectedCell] stringValue];
NSString *ctitle = [[sender selectedCellInColumn:0] stringValue]; NSString *ctitle = [[sender selectedCellInColumn:0] stringValue];
NSString *ctitlef = [[project projectPath] stringByAppendingPathComponent:ltitle]; NSString *ctitlef = [[project projectPath] stringByAppendingPathComponent:ltitle];
@ -124,7 +125,10 @@
[browser setMaxVisibleColumns:3]; [browser setMaxVisibleColumns:3];
[browser setAllowsMultipleSelection:NO]; [browser setAllowsMultipleSelection:NO];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(projectDictDidChange:) name:@"ProjectDictDidChangeNotification" object:project]; [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(projectDictDidChange:)
name:@"ProjectDictDidChangeNotification"
object:project];
} }
- (void)setProject:(PCProject *)aProj - (void)setProject:(PCProject *)aProj

View file

@ -34,21 +34,23 @@
id newFileWindow; id newFileWindow;
id fileTypePopup; id fileTypePopup;
id newFileName; id newFileName;
id descrView;
id delegate; // PCProjectManager id delegate; // PCProjectManager
NSMutableDictionary *creators; NSMutableDictionary *creators;
NSMutableDictionary *typeDescr;
} }
//=========================================================================================== //==============================================================================
// ==== Class methods // ==== Class methods
//=========================================================================================== //==============================================================================
+ (PCFileManager *)fileManager; + (PCFileManager *)fileManager;
//=========================================================================================== //==============================================================================
// ==== Init and free // ==== Init and free
//=========================================================================================== //==============================================================================
- (id)init; - (id)init;
- (void)dealloc; - (void)dealloc;
@ -70,6 +72,7 @@
- (void)showNewFileWindow; - (void)showNewFileWindow;
- (void)buttonsPressed:(id)sender; - (void)buttonsPressed:(id)sender;
- (void)popupChanged:(id)sender;
- (void)createFile; - (void)createFile;

View file

@ -41,109 +41,147 @@
- (void)_initUI - (void)_initUI
{ {
NSView *_c_view; NSView *_c_view;
unsigned int style = NSTitledWindowMask | NSClosableWindowMask | unsigned int style = NSTitledWindowMask
NSMiniaturizableWindowMask | NSResizableWindowMask; | NSClosableWindowMask
NSBox *box; | NSMiniaturizableWindowMask;
NSRect _w_frame; NSBox *box;
NSMatrix* matrix; NSRect _w_frame;
id button; NSMatrix* matrix;
NSButtonCell* buttonCell = [[[NSButtonCell alloc] init] autorelease]; id button;
id textField; NSButtonCell* buttonCell = [[[NSButtonCell alloc] init] autorelease];
id textField;
NSScrollView *scrollView;
/* /*
* the file creation window * the file creation window
* *
*/ */
_w_frame = NSMakeRect(100,100,264,160); _w_frame = NSMakeRect(100,100,320,240);
newFileWindow = [[NSWindow alloc] initWithContentRect:_w_frame newFileWindow = [[NSWindow alloc] initWithContentRect:_w_frame
styleMask:style styleMask:style
backing:NSBackingStoreBuffered backing:NSBackingStoreBuffered
defer:NO]; defer:NO];
[newFileWindow setMinSize:NSMakeSize(264,160)]; [newFileWindow setMinSize:NSMakeSize(320,160)];
[newFileWindow setTitle:@"New File..."]; [newFileWindow setTitle:@"New File..."];
box = [[[NSBox alloc] init] autorelease]; box = [[NSBox alloc] init];
[box setFrame:NSMakeRect(16,96,224,56)]; [box setFrame:NSMakeRect(16,172,288,56)];
fileTypePopup = [[[NSPopUpButton alloc] initWithFrame:NSMakeRect(32,2,160,20) fileTypePopup = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(32,2,216,20)
pullsDown:NO] autorelease]; pullsDown:NO];
//[fileTypePopup addItemWithTitle:@"No type available!"]; [fileTypePopup setAutoresizingMask: (NSViewWidthSizable)];
[fileTypePopup setAutoresizingMask: (NSViewWidthSizable)]; [fileTypePopup setTarget:self];
[box setTitle:@"Type"]; [fileTypePopup setAction:@selector(popupChanged:)];
[box setTitlePosition:NSAtTop]; [box setTitle:@"File Type"];
[box setBorderType:NSGrooveBorder]; [box setTitlePosition:NSAtTop];
[box addSubview:fileTypePopup]; [box setBorderType:NSGrooveBorder];
[box setAutoresizingMask: (NSViewWidthSizable | NSViewMinYMargin)]; [box setAutoresizingMask: (NSViewWidthSizable | NSViewMinYMargin)];
_c_view = [newFileWindow contentView]; [box addSubview:fileTypePopup];
[_c_view addSubview:box]; RELEASE(fileTypePopup);
/* _c_view = [newFileWindow contentView];
* Button matrix
*/
_w_frame = NSMakeRect(136,8,116,24); _w_frame = NSMakeRect (16,96,288,68);
matrix = [[[NSMatrix alloc] initWithFrame: _w_frame scrollView = [[NSScrollView alloc] initWithFrame:_w_frame];
mode: NSHighlightModeMatrix [scrollView setHasHorizontalScroller:NO];
prototype: buttonCell [scrollView setHasVerticalScroller: YES];
numberOfRows: 1 [scrollView setBorderType: NSBezelBorder];
numberOfColumns: 2] autorelease]; [scrollView setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
[matrix setSelectionByRect:YES];
[matrix setAutoresizingMask: (NSViewMinXMargin | NSViewMaxYMargin)]; // This is a placeholder!
[matrix setTarget:self]; _w_frame = [[scrollView contentView] frame];
[matrix setAction:@selector(buttonsPressed:)]; descrView = [[NSTextView alloc] initWithFrame:_w_frame];
[matrix setIntercellSpacing: NSMakeSize(2,2)]; [descrView setMinSize: NSMakeSize (0, 0)];
[_c_view addSubview:matrix]; [descrView setMaxSize:NSMakeSize(1e7, 1e7)];
[descrView setRichText:NO];
[descrView setEditable:NO];
[descrView setSelectable:YES];
[descrView setVerticallyResizable:YES];
[descrView setHorizontallyResizable:NO];
[descrView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
[[descrView textContainer] setWidthTracksTextView:YES];
[scrollView setDocumentView:descrView];
RELEASE(descrView);
button = [matrix cellAtRow:0 column:0]; _w_frame.size = NSMakeSize([scrollView contentSize].width,1e7);
[button setTag:0]; [[descrView textContainer] setContainerSize:_w_frame.size];
[button setStringValue:@"Cancel"];
[button setBordered:YES];
[button setButtonType:NSMomentaryPushButton];
button = [matrix cellAtRow:0 column:1]; [_c_view addSubview:scrollView];
[button setTag:1]; RELEASE(scrollView);
[button setStringValue:@"OK"];
[button setBordered:YES];
[button setButtonType:NSMomentaryPushButton];
/* [_c_view addSubview:box];
* The name of the new file... RELEASE(box);
*/
// Status message /*
textField = [[NSTextField alloc] initWithFrame:NSMakeRect(16,56,48,21)]; * Button matrix
[textField setAlignment: NSLeftTextAlignment]; */
[textField setBordered: NO];
[textField setEditable: NO]; _w_frame = NSMakeRect(188,16,116,24);
[textField setBezeled: NO]; matrix = [[NSMatrix alloc] initWithFrame: _w_frame
[textField setDrawsBackground: NO]; mode: NSHighlightModeMatrix
[textField setStringValue:@"Name:"]; prototype: buttonCell
[textField setAutoresizingMask: (NSViewMaxXMargin | numberOfRows: 1
numberOfColumns: 2];
[matrix setSelectionByRect:YES];
[matrix setAutoresizingMask: (NSViewMinXMargin | NSViewMaxYMargin)];
[matrix setTarget:self];
[matrix setAction:@selector(buttonsPressed:)];
[matrix setIntercellSpacing: NSMakeSize(2,2)];
[_c_view addSubview:matrix];
RELEASE(matrix);
button = [matrix cellAtRow:0 column:0];
[button setTag:0];
[button setStringValue:@"Cancel"];
[button setBordered:YES];
[button setButtonType:NSMomentaryPushButton];
button = [matrix cellAtRow:0 column:1];
[button setTag:1];
[button setStringValue:@"OK"];
[button setBordered:YES];
[button setButtonType:NSMomentaryPushButton];
/*
* The name of the new file...
*/
// Status message
textField = [[NSTextField alloc] initWithFrame:NSMakeRect(16,56,48,21)];
[textField setAlignment: NSLeftTextAlignment];
[textField setBordered: NO];
[textField setEditable: NO];
[textField setBezeled: NO];
[textField setDrawsBackground: NO];
[textField setStringValue:@"Name:"];
[textField setAutoresizingMask: (NSViewMaxXMargin |
NSViewWidthSizable | NSViewWidthSizable |
NSViewMinYMargin)]; NSViewMinYMargin)];
[_c_view addSubview:[textField autorelease]]; [_c_view addSubview:textField];
RELEASE(textField);
// Target // Target
newFileName = [[NSTextField alloc] initWithFrame:NSMakeRect(64,56,176,21)]; newFileName = [[NSTextField alloc] initWithFrame:NSMakeRect(56,56,248,21)];
[newFileName setAlignment: NSLeftTextAlignment]; [newFileName setAlignment: NSLeftTextAlignment];
[newFileName setBordered: YES]; [newFileName setBordered: YES];
[newFileName setBezeled: YES]; [newFileName setBezeled: YES];
[newFileName setEditable: YES]; [newFileName setEditable: YES];
[newFileName setDrawsBackground: YES]; [newFileName setDrawsBackground: YES];
[newFileName setStringValue:@""]; [newFileName setStringValue:@"NewFile"];
[newFileName setAutoresizingMask: (NSViewWidthSizable | NSViewMinYMargin)]; [newFileName setAutoresizingMask: (NSViewWidthSizable | NSViewMinYMargin)];
[_c_view addSubview:[newFileName autorelease]]; [_c_view addSubview:newFileName];
RELEASE(newFileName);
} }
@end @end
@implementation PCFileManager @implementation PCFileManager
//=========================================================================================== //==============================================================================
// ==== Class methods // ==== Class methods
//=========================================================================================== //==============================================================================
static PCFileManager *_mgr = nil; static PCFileManager *_mgr = nil;
@ -155,14 +193,17 @@ static PCFileManager *_mgr = nil;
return _mgr; return _mgr;
} }
//=========================================================================================== //==============================================================================
// ==== Init and free // ==== Init and free
//=========================================================================================== //==============================================================================
- (id)init - (id)init
{ {
if ((self = [super init])) { if ((self = [super init]))
{
creators = [[NSMutableDictionary alloc] init]; creators = [[NSMutableDictionary alloc] init];
typeDescr = [[NSMutableDictionary alloc] init];
[self _initUI]; [self _initUI];
} }
return self; return self;
@ -170,8 +211,9 @@ static PCFileManager *_mgr = nil;
- (void)dealloc - (void)dealloc
{ {
[creators release]; RELEASE(creators);
[newFileWindow release]; RELEASE(newFileWindow);
RELEASE(typeDescr);
[super dealloc]; [super dealloc];
} }
@ -212,6 +254,8 @@ static PCFileManager *_mgr = nil;
NSString *title = nil; NSString *title = nil;
NSArray *types = nil; NSArray *types = nil;
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
if (delegate && if (delegate &&
[delegate respondsToSelector:@selector(fileManagerWillAddFiles:)]) [delegate respondsToSelector:@selector(fileManagerWillAddFiles:)])
{ {
@ -235,14 +279,14 @@ static PCFileManager *_mgr = nil;
[openPanel setCanChooseFiles:YES]; [openPanel setCanChooseFiles:YES];
[openPanel setTitle:title]; [openPanel setTitle:title];
retval = [openPanel runModalForDirectory:[[NSUserDefaults standardUserDefaults] objectForKey:@"LastOpenDirectory"] file:nil types:types]; retval = [openPanel runModalForDirectory:[ud objectForKey:@"LastOpenDirectory"] file:nil types:types];
if (retval == NSOKButton) { if (retval == NSOKButton)
{
NSEnumerator *enumerator; NSEnumerator *enumerator;
NSString *file; NSString *file;
[[NSUserDefaults standardUserDefaults] setObject:[openPanel directory] [ud setObject:[openPanel directory] forKey:@"LastOpenDirectory"];
forKey:@"LastOpenDirectory"];
enumerator = [[openPanel filenames] objectEnumerator]; enumerator = [[openPanel filenames] objectEnumerator];
while (file = [enumerator nextObject]) { while (file = [enumerator nextObject]) {
@ -253,44 +297,60 @@ static PCFileManager *_mgr = nil;
NSString *fileName; NSString *fileName;
NSString *pth; NSString *pth;
if ([delegate fileManager:self shouldAddFile:file forKey:key]) { if ([delegate fileManager:self shouldAddFile:file forKey:key])
{
NSFileManager *fm = [NSFileManager defaultManager];
fileName = [file lastPathComponent]; fileName = [file lastPathComponent];
pth = [[project projectPath] stringByAppendingPathComponent:fileName]; pth = [[project projectPath] stringByAppendingPathComponent:fileName];
if (![key isEqualToString:PCLibraries]) { if (![key isEqualToString:PCLibraries])
if (![[NSFileManager defaultManager] fileExistsAtPath:pth]) { {
[[NSFileManager defaultManager] copyPath:file toPath:pth handler:nil]; if (![fm fileExistsAtPath:pth])
{
[fm copyPath:file toPath:pth handler:nil];
} }
} }
[project addFile:pth forKey:key]; [project addFile:pth forKey:key];
} }
if ([key isEqualToString:PCClasses]) { if ([key isEqualToString:PCClasses])
{
otherKey = PCHeaders; otherKey = PCHeaders;
ext = [NSString stringWithString:@"h"]; ext = [NSString stringWithString:@"h"];
fn = [file stringByDeletingPathExtension]; fn = [file stringByDeletingPathExtension];
fn = [fn stringByAppendingPathExtension:ext]; fn = [fn stringByAppendingPathExtension:ext];
if ([[NSFileManager defaultManager] fileExistsAtPath:fn]) { if ([[NSFileManager defaultManager] fileExistsAtPath:fn])
ret = NSRunAlertPanel(@"Adding Header?",@"Should %@ be added to project %@ as well?",@"Yes",@"No",nil,fn,[project projectName]); {
ret = NSRunAlertPanel(@"Adding Header?",
@"Should %@ be added to project %@ as well?",
@"Yes",@"No",nil,fn,[project projectName]);
} }
} }
else if ([key isEqualToString:PCHeaders]) { else if ([key isEqualToString:PCHeaders])
{
otherKey = PCClasses; otherKey = PCClasses;
ext = [NSString stringWithString:@"m"]; ext = [NSString stringWithString:@"m"];
fn = [file stringByDeletingPathExtension]; fn = [file stringByDeletingPathExtension];
fn = [fn stringByAppendingPathExtension:ext]; fn = [fn stringByAppendingPathExtension:ext];
if ([[NSFileManager defaultManager] fileExistsAtPath:fn]) { if ([[NSFileManager defaultManager] fileExistsAtPath:fn])
ret = NSRunAlertPanel(@"Adding Class?",@"Should %@ be added to project %@ as well?",@"Yes",@"No",nil,fn,[project projectName]); {
ret = NSRunAlertPanel(@"Adding Class?",
@"Should %@ be added to project %@ as well?",
@"Yes",@"No",nil,fn,[project projectName]);
} }
} }
if (ret) { if (ret)
if ([delegate fileManager:self shouldAddFile:fn forKey:otherKey]) { {
if ([delegate fileManager:self shouldAddFile:fn forKey:otherKey])
{
NSString *pp = [project projectPath]; NSString *pp = [project projectPath];
fileName = [fn lastPathComponent]; fileName = [fn lastPathComponent];
pth = [pp stringByAppendingPathComponent:fileName]; pth = [pp stringByAppendingPathComponent:fileName];
@ -305,13 +365,16 @@ static PCFileManager *_mgr = nil;
- (void)showNewFileWindow - (void)showNewFileWindow
{ {
[self popupChanged:fileTypePopup];
[newFileWindow center]; [newFileWindow center];
[newFileWindow makeKeyAndOrderFront:self]; [newFileWindow makeKeyAndOrderFront:self];
} }
- (void)buttonsPressed:(id)sender - (void)buttonsPressed:(id)sender
{ {
switch ([[sender selectedCell] tag]) { switch ([[sender selectedCell] tag])
{
case 0: case 0:
break; break;
case 1: case 1:
@ -322,6 +385,17 @@ static PCFileManager *_mgr = nil;
[newFileName setStringValue:@""]; [newFileName setStringValue:@""];
} }
- (void)popupChanged:(id)sender
{
NSString *k = [sender titleOfSelectedItem];
NSString *t = [typeDescr objectForKey:k];
if( k )
{
[descrView setText:t];
}
}
- (void)createFile - (void)createFile
{ {
NSString *path = nil; NSString *path = nil;
@ -329,7 +403,8 @@ static PCFileManager *_mgr = nil;
NSString *fileType = [fileTypePopup titleOfSelectedItem]; NSString *fileType = [fileTypePopup titleOfSelectedItem];
NSString *key = [[creators objectForKey:fileType] objectForKey:@"ProjectKey"]; NSString *key = [[creators objectForKey:fileType] objectForKey:@"ProjectKey"];
if (delegate) { if (delegate)
{
path = [delegate fileManager:self willCreateFile:fileName withKey:key]; path = [delegate fileManager:self willCreateFile:fileName withKey:key];
} }
@ -338,24 +413,31 @@ static PCFileManager *_mgr = nil;
#endif //DEBUG #endif //DEBUG
// Create file // Create file
if (path) { if (path)
{
NSDictionary *newFiles; NSDictionary *newFiles;
id<FileCreator> creator = [[creators objectForKey:fileType] objectForKey:@"Creator"]; id<FileCreator> creator = [[creators objectForKey:fileType] objectForKey:@"Creator"];
PCProject *p = [delegate activeProject]; PCProject *p = [delegate activeProject];
if (!creator) { if (!creator)
NSRunAlertPanel(@"Attention!",@"Could not create %@. The appropriate creator is missing!",@"OK",nil,nil,fileName); {
NSRunAlertPanel(@"Attention!",
@"Could not create %@. The creator is missing!",
@"OK",nil,nil,fileName);
return; return;
} }
// Do it finally... // Do it finally...
newFiles = [creator createFileOfType:fileType path:path project:p]; newFiles = [creator createFileOfType:fileType path:path project:p];
if (delegate && [delegate respondsToSelector:@selector(fileManager:didCreateFile:withKey:)]) { if (delegate
&& [delegate respondsToSelector:@selector(fileManager:didCreateFile:withKey:)])
{
NSEnumerator *enumerator; NSEnumerator *enumerator;
NSString *aFile; NSString *aFile;
enumerator = [[newFiles allKeys] objectEnumerator]; // Key: name of the file enumerator = [[newFiles allKeys] objectEnumerator]; // Key: name of file
while (aFile = [enumerator nextObject]) { while (aFile = [enumerator nextObject])
{
NSString *theType = [newFiles objectForKey:aFile]; NSString *theType = [newFiles objectForKey:aFile];
NSString *theKey = [[creators objectForKey:theType] objectForKey:@"ProjectKey"]; NSString *theKey = [[creators objectForKey:theType] objectForKey:@"ProjectKey"];
@ -374,22 +456,33 @@ static PCFileManager *_mgr = nil;
NSLog(@"<%@ %x>: Registering creators...",[self class],self); NSLog(@"<%@ %x>: Registering creators...",[self class],self);
#endif //DEBUG #endif //DEBUG
while (type = [enumerator nextObject]) { while (type = [enumerator nextObject])
id creator = [[dict objectForKey:type] objectForKey:@"Creator"]; {
NSDictionary *cd = [dict objectForKey:type];
id creator = [cd objectForKey:@"Creator"];
if (![creator conformsToProtocol:@protocol(FileCreator)]) { if (![creator conformsToProtocol:@protocol(FileCreator)])
[NSException raise:@"FileManagerGenericException" format:@"The target does not conform to the FileCreator protocol!"]; {
[NSException raise:@"FileManagerGenericException"
format:@"The target does not conform to the FileCreator protocol!"];
return; return;
} }
if ([creators objectForKey:type]) { if ([creators objectForKey:type])
[NSException raise:@"FileManagerGenericException" format:@"There is alreay a creator registered for this type!"]; {
[NSException raise:@"FileManagerGenericException"
format:@"There is alreay a creator registered for this type!"];
return; return;
} }
// Register the creator! // Register the creator!
[creators setObject:[dict objectForKey:type] forKey:type]; [creators setObject:[dict objectForKey:type] forKey:type];
[fileTypePopup addItemWithTitle:type]; [fileTypePopup addItemWithTitle:type];
if( [cd objectForKey:@"TypeDescription"] )
{
[typeDescr setObject:[cd objectForKey:@"TypeDescription"] forKey:type];
}
} }
} }

View file

@ -35,7 +35,7 @@
} }
else { else {
NSRunAlertPanel(@"Attention!", NSRunAlertPanel(@"Attention!",
@"This project type is not executable!", @"This project is not executable!",
@"OK",nil,nil); @"OK",nil,nil);
} }
break; break;

View file

@ -67,6 +67,7 @@
[componentView addSubview:scrollView]; [componentView addSubview:scrollView];
RELEASE(scrollView); RELEASE(scrollView);
[componentView sizeToFit]; [componentView sizeToFit];
} }
@ -81,6 +82,7 @@
if((self = [super init])) if((self = [super init]))
{ {
currentProject = aProject; currentProject = aProject;
componentView = nil;
} }
return self; return self;
} }
@ -94,7 +96,7 @@
- (NSView *)componentView - (NSView *)componentView
{ {
if (!componentView) if (componentView == nil)
{ {
[self _createComponentView]; [self _createComponentView];
} }
@ -111,10 +113,11 @@
frame = [[scrollView contentView] frame]; frame = [[scrollView contentView] frame];
[scrollView setDocumentView:editor]; [scrollView setDocumentView:editor];
[editor setNeedsDisplay:YES];
frame.size = NSMakeSize([scrollView contentSize].width,1e7); frame.size = NSMakeSize([scrollView contentSize].width,1e7);
[[editor textContainer] setContainerSize:frame.size]; [[editor textContainer] setContainerSize:frame.size];
[editor setNeedsDisplay:YES];
} }
- (PCEditorView *)editorView - (PCEditorView *)editorView