mirror of
https://github.com/gnustep/apps-gorm.git
synced 2025-04-22 22:20:44 +00:00
Update testInterface: and --test option in gormtool to allow testing the gui from the command line
This commit is contained in:
parent
5c3b84748e
commit
f3aa16ea2f
4 changed files with 75 additions and 43 deletions
|
@ -463,24 +463,27 @@
|
|||
|
||||
archiver = [[NSArchiver alloc] init];
|
||||
[activeDoc deactivateEditors];
|
||||
[archiver encodeClassName: @"GormCustomView"
|
||||
intoClassName: @"GormTestCustomView"];
|
||||
|
||||
// substitute classes from palettes.
|
||||
en = [substituteClasses keyEnumerator];
|
||||
while((subClassName = [en nextObject]) != nil)
|
||||
if ([self isInTool] == NO)
|
||||
{
|
||||
NSString *realClassName = [substituteClasses objectForKey: subClassName];
|
||||
[archiver encodeClassName: @"GormCustomView"
|
||||
intoClassName: @"GormTestCustomView"];
|
||||
|
||||
if([realClassName isEqualToString: @"NSTableView"] ||
|
||||
[realClassName isEqualToString: @"NSOutlineView"] ||
|
||||
[realClassName isEqualToString: @"NSBrowser"])
|
||||
// substitute classes from palettes.
|
||||
en = [substituteClasses keyEnumerator];
|
||||
while((subClassName = [en nextObject]) != nil)
|
||||
{
|
||||
continue;
|
||||
NSString *realClassName = [substituteClasses objectForKey: subClassName];
|
||||
|
||||
if([realClassName isEqualToString: @"NSTableView"] ||
|
||||
[realClassName isEqualToString: @"NSOutlineView"] ||
|
||||
[realClassName isEqualToString: @"NSBrowser"])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
[archiver encodeClassName: subClassName
|
||||
intoClassName: realClassName];
|
||||
}
|
||||
|
||||
[archiver encodeClassName: subClassName
|
||||
intoClassName: realClassName];
|
||||
}
|
||||
|
||||
// do not allow custom classes during testing.
|
||||
|
@ -527,13 +530,23 @@
|
|||
* If the model didn't have a main menu, create one,
|
||||
* otherwise, ensure that 'quit' ends testing mode.
|
||||
*/
|
||||
|
||||
SEL endSelector = NULL;
|
||||
|
||||
endSelector = @selector(deferredEndTesting:);
|
||||
if ([self isInTool])
|
||||
{
|
||||
endSelector = @selector(endTestingNow:);
|
||||
}
|
||||
|
||||
|
||||
if (aMenu == nil)
|
||||
{
|
||||
NSMenu *testMenu;
|
||||
|
||||
testMenu = [[NSMenu alloc] initWithTitle: _(@"Test Menu (Gorm)")];
|
||||
[testMenu addItemWithTitle: _(@"Quit Test")
|
||||
action: @selector(deferredEndTesting:)
|
||||
action: endSelector
|
||||
keyEquivalent: @"q"];
|
||||
[NSApp setMainMenu: testMenu]; // released, when the menu is reset in endTesting.
|
||||
}
|
||||
|
@ -556,7 +569,7 @@
|
|||
found = YES;
|
||||
[item setTitle: _(@"Quit Test")];
|
||||
[item setTarget: self];
|
||||
[item setAction: @selector(deferredEndTesting:)];
|
||||
[item setAction: endSelector];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -569,8 +582,8 @@
|
|||
if(found == NO)
|
||||
{
|
||||
[testMenu addItemWithTitle: _(@"Quit Test")
|
||||
action: @selector(deferredEndTesting:)
|
||||
keyEquivalent: @"q"];
|
||||
action: endSelector
|
||||
keyEquivalent: @"q"];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -666,6 +679,10 @@
|
|||
}
|
||||
|
||||
/** Testing methods... */
|
||||
- (IBAction) endTestingNow: (id)sender
|
||||
{
|
||||
[NSApp terminate: self];
|
||||
}
|
||||
|
||||
- (IBAction) deferredEndTesting: (id) sender
|
||||
{
|
||||
|
|
|
@ -1735,7 +1735,8 @@ static void _real_close(GormDocument *self,
|
|||
}
|
||||
else if ([name isEqual: IBWillBeginTestingInterfaceNotification] && isDocumentOpen)
|
||||
{
|
||||
if ([(id<IB>)[NSApp delegate] activeDocument] == self)
|
||||
id delegate = [NSApp delegate];
|
||||
if ([delegate activeDocument] == self && [delegate isInTool] == NO)
|
||||
{
|
||||
NSEnumerator *enumerator;
|
||||
id obj;
|
||||
|
|
|
@ -33,6 +33,9 @@
|
|||
@class NSSet;
|
||||
|
||||
@interface AppDelegate : GormAbstractDelegate
|
||||
{
|
||||
GormDocument *_doc;
|
||||
}
|
||||
|
||||
- (void) process;
|
||||
|
||||
|
|
|
@ -83,6 +83,12 @@
|
|||
NSLog(@"Breaking any existing connections with instances of class %@", className);
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (id<IBDocuments>) activeDocument
|
||||
{
|
||||
return _doc;
|
||||
}
|
||||
|
||||
// Handle arguments
|
||||
|
||||
- (NSDictionary *) parseArguments
|
||||
|
@ -259,14 +265,15 @@
|
|||
NSProcessInfo *pi = [NSProcessInfo processInfo];
|
||||
|
||||
[NSClassSwapper setIsInInterfaceBuilder: YES];
|
||||
[self setTestingInterface: NO];
|
||||
|
||||
isTesting = NO;
|
||||
|
||||
if ([[pi arguments] count] > 1)
|
||||
{
|
||||
NSString *file = nil;
|
||||
NSString *outputPath = @"./";
|
||||
GormDocumentController *dc = [GormDocumentController sharedDocumentController];
|
||||
GormDocument *doc = nil;
|
||||
// GormDocument *doc = nil;
|
||||
NSDictionary *args = [self parseArguments];
|
||||
ArgPair *opt = nil;
|
||||
NSString *slang = nil;
|
||||
|
@ -286,8 +293,8 @@
|
|||
|
||||
if (file != nil)
|
||||
{
|
||||
doc = [dc openDocumentWithContentsOfFile: file display: NO];
|
||||
if (doc == nil)
|
||||
_doc = [dc openDocumentWithContentsOfFile: file display: NO];
|
||||
if (_doc == nil)
|
||||
{
|
||||
NSLog(@"Unable to load document %@", file);
|
||||
return;
|
||||
|
@ -299,7 +306,7 @@
|
|||
return;
|
||||
}
|
||||
|
||||
NSDebugLog(@"Document = %@", doc);
|
||||
NSDebugLog(@"Document = %@", _doc);
|
||||
|
||||
// Get other options...
|
||||
opt = [args objectForKey: @"--output-path"];
|
||||
|
@ -313,14 +320,14 @@
|
|||
{
|
||||
NSString *stringsFile = [opt value];
|
||||
|
||||
[doc exportStringsToFile: stringsFile];
|
||||
[_doc exportStringsToFile: stringsFile];
|
||||
}
|
||||
|
||||
opt = [args objectForKey: @"--import-strings-file"];
|
||||
if (opt != nil)
|
||||
{
|
||||
NSString *stringsFile = [opt value];
|
||||
[doc importStringsFromFile: stringsFile];
|
||||
[_doc importStringsFromFile: stringsFile];
|
||||
}
|
||||
|
||||
opt = [args objectForKey: @"--export-class"];
|
||||
|
@ -328,7 +335,7 @@
|
|||
{
|
||||
NSString *className = [opt value];
|
||||
BOOL saved = NO;
|
||||
GormClassManager *cm = [doc classManager];
|
||||
GormClassManager *cm = [_doc classManager];
|
||||
NSString *hFile = [className stringByAppendingPathExtension: @"h"];
|
||||
NSString *mFile = [className stringByAppendingPathExtension: @"m"];
|
||||
NSString *hPath = [outputPath stringByAppendingPathComponent: hFile];
|
||||
|
@ -348,7 +355,7 @@
|
|||
if (opt != nil)
|
||||
{
|
||||
NSString *classFile = [opt value];
|
||||
GormClassManager *cm = [doc classManager];
|
||||
GormClassManager *cm = [_doc classManager];
|
||||
|
||||
[cm parseHeader: classFile];
|
||||
}
|
||||
|
@ -356,28 +363,28 @@
|
|||
opt = [args objectForKey: @"--connections"];
|
||||
if (opt != nil)
|
||||
{
|
||||
NSArray *connections = [doc connections];
|
||||
NSArray *connections = [_doc connections];
|
||||
puts([[NSString stringWithFormat: @"%@", connections] cStringUsingEncoding: NSUTF8StringEncoding]);
|
||||
}
|
||||
|
||||
opt = [args objectForKey: @"--classes"];
|
||||
if (opt != nil)
|
||||
{
|
||||
NSDictionary *classes = [[doc classManager] customClassInformation];
|
||||
NSDictionary *classes = [[_doc classManager] customClassInformation];
|
||||
puts([[NSString stringWithFormat: @"%@", classes] cStringUsingEncoding: NSUTF8StringEncoding]);
|
||||
}
|
||||
|
||||
opt = [args objectForKey: @"--objects"];
|
||||
if (opt != nil)
|
||||
{
|
||||
NSSet *objects = [doc topLevelObjects];
|
||||
NSSet *objects = [_doc topLevelObjects];
|
||||
puts([[NSString stringWithFormat: @"%@", objects] cStringUsingEncoding: NSUTF8StringEncoding]);
|
||||
}
|
||||
|
||||
opt = [args objectForKey: @"--errors"];
|
||||
if (opt != nil)
|
||||
{
|
||||
GormFilePrefsManager *mgr = [doc filePrefsManager];
|
||||
GormFilePrefsManager *mgr = [_doc filePrefsManager];
|
||||
NSDictionary *p = [NSDictionary dictionaryWithDictionary: [mgr currentProfile]];
|
||||
puts([[NSString stringWithFormat: @"%@", p] cStringUsingEncoding: NSUTF8StringEncoding]);
|
||||
}
|
||||
|
@ -385,7 +392,7 @@
|
|||
opt = [args objectForKey: @"--warnings"];
|
||||
if (opt != nil)
|
||||
{
|
||||
GormFilePrefsManager *mgr = [doc filePrefsManager];
|
||||
GormFilePrefsManager *mgr = [_doc filePrefsManager];
|
||||
NSDictionary *p = [NSDictionary dictionaryWithDictionary: [mgr currentProfile]];
|
||||
puts([[NSString stringWithFormat: @"%@", p] cStringUsingEncoding: NSUTF8StringEncoding]);
|
||||
}
|
||||
|
@ -393,7 +400,7 @@
|
|||
opt = [args objectForKey: @"--notices"];
|
||||
if (opt != nil)
|
||||
{
|
||||
GormFilePrefsManager *mgr = [doc filePrefsManager];
|
||||
GormFilePrefsManager *mgr = [_doc filePrefsManager];
|
||||
NSDictionary *p = [NSDictionary dictionaryWithDictionary: [mgr currentProfile]];
|
||||
puts([[NSString stringWithFormat: @"%@", p] cStringUsingEncoding: NSUTF8StringEncoding]);
|
||||
}
|
||||
|
@ -415,7 +422,7 @@
|
|||
{
|
||||
NSString *xliffDocumentName = [opt value];
|
||||
BOOL result = NO;
|
||||
GormXLIFFDocument *xd = [GormXLIFFDocument xliffWithGormDocument: doc];
|
||||
GormXLIFFDocument *xd = [GormXLIFFDocument xliffWithGormDocument: _doc];
|
||||
|
||||
if (slang == nil)
|
||||
{
|
||||
|
@ -436,7 +443,7 @@
|
|||
{
|
||||
NSString *xliffDocumentName = [opt value];
|
||||
BOOL result = NO;
|
||||
GormXLIFFDocument *xd = [GormXLIFFDocument xliffWithGormDocument: doc];
|
||||
GormXLIFFDocument *xd = [GormXLIFFDocument xliffWithGormDocument: _doc];
|
||||
|
||||
result = [xd importXLIFFDocumentWithName: xliffDocumentName];
|
||||
if (result == NO)
|
||||
|
@ -457,11 +464,11 @@
|
|||
NSString *type = [dc typeFromFileExtension: [outputFile pathExtension]];
|
||||
NSError *error = nil;
|
||||
|
||||
saved = [doc saveToURL: file
|
||||
ofType: type
|
||||
forSaveOperation: NSSaveOperation
|
||||
error: &error];
|
||||
if (!saved)
|
||||
saved = [_doc saveToURL: file
|
||||
ofType: type
|
||||
forSaveOperation: NSSaveOperation
|
||||
error: &error];
|
||||
if ( !saved )
|
||||
{
|
||||
NSLog(@"Document %@ of type %@ was not saved", file, type);
|
||||
}
|
||||
|
@ -477,6 +484,7 @@
|
|||
if (opt != nil)
|
||||
{
|
||||
NSLog(@"Control-C to end");
|
||||
isTesting = YES;
|
||||
[self testInterface: self];
|
||||
}
|
||||
}
|
||||
|
@ -495,8 +503,11 @@
|
|||
|
||||
NSDebugLog(@"processInfo: %@", [NSProcessInfo processInfo]);
|
||||
[self process];
|
||||
|
||||
[NSApp terminate: nil];
|
||||
|
||||
if (isTesting == NO)
|
||||
{
|
||||
[NSApp terminate: nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) applicationWillTerminate: (NSNotification *)n
|
||||
|
|
Loading…
Reference in a new issue