Added controbuted patch

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@10306 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2001-07-06 17:10:51 +00:00
parent 39410f2c64
commit e14559b683
8 changed files with 214 additions and 2 deletions

View file

@ -1,3 +1,18 @@
2001-07-04 Pierre-Yves Rivaille <pyrivail@ens-lyon.fr>
Added the ability to create the .m and .h files of a class created
within Gorm (it's a basic implementation but it works)
Added an "application: openFile:" method in the class Gorm and a
GormInfo.plist file, it is now possible to open a Gorm document from
ProjectCenter (and I suppose GWorkspace but I have not checked yet)
a keyEquivalent for the inspector (i was really missing this ...)
no more [menu display] in the initialization of Gorm, I found out that
it prevented a proper docking within WindowMaker's dock, and it does
not seem to have any side effect.
2001-06-24 Mirko Viviani <mirko.viviani@rccr.cremona.it>
* GormWindowEditor.m ([GormWindowEditor -_validateFrame:forViewPtr:

View file

@ -44,6 +44,7 @@ APP_NAME = Gorm
Gorm_PRINCIPAL_CLASS=Gorm
Gorm_APPLICATION_ICON=Gorm.tiff
Gorm_RESOURCE_FILES = \
GormInfo.plist \
ClassInformation.plist \
Defaults.plist \
Palettes/0Menus/0Menus.palette \

32
Gorm.m
View file

@ -346,6 +346,12 @@ NSString *GormLinkPboardType = @"GormLinkPboardType";
return [(id)[self activeDocument] editClass: sender];
}
- (id) createClassFiles: (id)sender
{
return [(id)[self activeDocument] createClassFiles: sender];
}
- (id) endTesting: (id)sender
{
if (isTesting == NO)
@ -536,6 +542,9 @@ NSString *GormLinkPboardType = @"GormLinkPboardType";
[aMenu addItemWithTitle: @"Edit Class..."
action: @selector(editClass:)
keyEquivalent: @""];
[aMenu addItemWithTitle: @"Create Class's Files..."
action: @selector(createClassFiles:)
keyEquivalent: @""];
[aMenu addItemWithTitle: @"Instantiate"
action: @selector(instantiateClass:)
keyEquivalent: @""];
@ -553,7 +562,7 @@ NSString *GormLinkPboardType = @"GormLinkPboardType";
aMenu = [NSMenu new];
[aMenu addItemWithTitle: @"Inspector..."
action: @selector(inspector:)
keyEquivalent: @""];
keyEquivalent: @"i"];
[aMenu addItemWithTitle: @"Palettes..."
action: @selector(palettes:)
keyEquivalent: @""];
@ -607,7 +616,7 @@ NSString *GormLinkPboardType = @"GormLinkPboardType";
[self setMainMenu: mainMenu];
[self setWindowsMenu: windowsMenu];
[mainMenu display];
// [mainMenu display];
[self setDelegate: self];
[super finishLaunching];
}
@ -806,6 +815,25 @@ NSString *GormLinkPboardType = @"GormLinkPboardType";
return doc;
}
- (BOOL)application:(NSApplication *)application openFile:(NSString *)fileName
{
GormDocument *doc = [GormDocument new];
[documents addObject: doc];
RELEASE(doc);
if ([doc loadDocument: fileName] == nil)
{
[documents removeObjectIdenticalTo: doc];
doc = nil;
}
else
{
[[doc window] makeKeyAndOrderFront: self];
}
return (doc != nil);
}
- (GormPalettesManager*) palettesManager
{
if (palettesManager == nil)

View file

@ -25,6 +25,9 @@
- (NSString*) superClassNameForClassNamed: (NSString*)className;
- (BOOL) isSuperclass: (NSString*)superclass
linkedToClass: (NSString*)subclass;
- (BOOL) makeSourceAndHeaderFilesForClass: (NSString*)className
withName:(NSString*)sourcePath
and:(NSString*)headerPath;
- (BOOL) saveToFile: (NSString*)path;
- (BOOL) loadFromFile: (NSString*)path;

View file

@ -677,6 +677,96 @@ NSString *IBClassNameChangedNotification = @"IBClassNameChangedNotification";
return [self isSuperclass: superclass linkedToClass: ssclass];
}
}
/*
* create .m & .h files for a class
*/
- (BOOL) makeSourceAndHeaderFilesForClass: (NSString*)className
withName:(NSString*)sourcePath
and:(NSString*)headerPath
{
NSMutableString *headerFile;
NSMutableString *sourceFile;
NSData *headerData;
NSData *sourceData;
NSArray *outlets, *actions;
int i, n;
headerFile = [NSMutableString stringWithCapacity: 200];
sourceFile = [NSMutableString stringWithCapacity: 200];
outlets = [self allOutletsForClassNamed: className];
actions = [self allActionsForClassNamed: className];
[headerFile appendString: @"/* All Rights reserved */\n\n"];
[sourceFile appendString: @"/* All Rights reserved */\n\n"];
[headerFile appendString: @"#import <AppKit/AppKit.h>\n\n"];
[sourceFile appendString: @"#import <AppKit/AppKit.h>\n"];
if ([[headerPath stringByDeletingLastPathComponent]
isEqualToString:
[sourcePath stringByDeletingLastPathComponent]])
{
[sourceFile appendFormat: @"#import \"%@\"\n\n",
[headerPath lastPathComponent]];
}
else
{
[sourceFile appendFormat: @"#import \"%@\"\n\n",
headerPath];
}
[headerFile appendFormat: @"@interface %@ : %@\n{\n",
className,
[self superClassNameForClassNamed: className]];
[sourceFile appendFormat: @"@implementation %@\n\n",
className];
n = [outlets count];
for( i = 0; i < n; i++)
{
[headerFile appendFormat: @" id %@;\n",
[outlets objectAtIndex: i]];
}
[headerFile appendFormat: @"}\n"];
n = [actions count];
for( i = 0; i < n; i++)
{
[headerFile appendFormat: @"- (void) %@: (id) sender;\n",
[actions objectAtIndex: i]];
[sourceFile
appendFormat: @"\
- (void) %@: (id) sender
{
/* insert your code here */
}
", [actions objectAtIndex: i]];
}
[headerFile appendFormat: @"@end\n"];
[sourceFile appendFormat: @"@end\n"];
headerData = [headerFile dataUsingEncoding:
[NSString defaultCStringEncoding]];
sourceData = [sourceFile dataUsingEncoding:
[NSString defaultCStringEncoding]];
[headerData writeToFile: headerPath atomically: NO];
[sourceData writeToFile: sourcePath atomically: NO];
/* RELEASE(outlets);
RELEASE(actions);
RELEASE(commonPath);
RELEASE(headerFile);
RELEASE(headerData);
RELEASE(headerPath);
RELEASE(sourceFile);
RELEASE(sourceData);
RELEASE(sourcePath);*/
return YES;
}
@end

View file

@ -96,6 +96,7 @@
- (id) createSubclass: (id)sender;
- (id) instantiateClass: (id)sender;
- (id) editClass: (id)sender;
- (id) createClassFiles: (id)sender;
- (void) changeCurrentClass: (id)sender;
@end

View file

@ -521,6 +521,62 @@ static NSImage *classesImage = nil;
return self;
}
- (id) createClassFiles: (id)sender
{
NSSavePanel *sp;
int row = [classesView selectedRow];
id classes = [classManager allClassNames];
int result;
sp = [NSSavePanel savePanel];
[sp setRequiredFileType: @"m"];
[sp setTitle: @"Save source file as..."];
if (documentPath == nil)
result = [sp runModalForDirectory: NSHomeDirectory() file: @""];
else
result = [sp runModalForDirectory:
[documentPath stringByDeletingLastPathComponent]
file: @""];
if (result == NSOKButton)
{
NSString *sourceName = [sp filename];
NSString *headerName;
[sp setRequiredFileType: @"h"];
[sp setTitle: @"Save header file as..."];
result = [sp runModalForDirectory:
[sourceName stringByDeletingLastPathComponent]
file:
[[[sourceName lastPathComponent]
stringByDeletingPathExtension]
stringByAppendingString: @".h"]];
if (result == NSOKButton)
{
headerName = [sp filename];
NSLog(@"createClassFiles");
if (row >= 0 && row < [classes count])
{
NSLog([classes objectAtIndex: row]);
if (![classManager
makeSourceAndHeaderFilesForClass:
[classes objectAtIndex: row]
withName: sourceName
and: headerName])
{
NSRunAlertPanel(@"Alert",
@"Could not create the class's file",
nil, nil, nil);
}
return self;
}
}
}
return nil;
}
- (void) editor: (id<IBEditors>)anEditor didCloseForObject: (id)anObject
{
NSArray *links;

18
GormInfo.plist Normal file
View file

@ -0,0 +1,18 @@
{
NSIcon = "Images/Gorm.tiff";
NSRole = "Editor";
NSTypes = (
{
NSUnixExtensions = ( "gorm" );
NSIcon = "Images/Gorm.tiff";
}
);
ApplicationDescription = "Gorm";
ApplicationIcon = "Images/Gorm.tiff";
ApplicationName = "Gorm";
ApplicationRelease = "0.2";
Authors = ();
Copyright = "Copyright (C) 2000-2001 FSF";
CopyrightDescription = "Released under the GNU GPL";
FullVersionID = "0.2";
}