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
{
if ([[sender selectedCell] isLeaf]) {
if ([[sender selectedCell] isLeaf])
{
NSString *ltitle = [[sender selectedCell] stringValue];
NSString *ctitle = [[sender selectedCellInColumn:0] stringValue];
NSString *ctitlef = [[project projectPath] stringByAppendingPathComponent:ltitle];
@ -124,7 +125,10 @@
[browser setMaxVisibleColumns:3];
[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

View file

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

View file

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

View file

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

View file

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