mirror of
https://github.com/gnustep/apps-gorm.git
synced 2025-02-24 12:01:16 +00:00
Merge pull request #26 from gnustep/alert_refactor
This commit is contained in:
commit
6b1f66ed00
5 changed files with 169 additions and 103 deletions
|
@ -149,7 +149,8 @@
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gorm specific methods...
|
// Handle all alerts here...
|
||||||
|
|
||||||
- (BOOL) shouldUpgradeOlderArchive
|
- (BOOL) shouldUpgradeOlderArchive
|
||||||
{
|
{
|
||||||
NSInteger retval = NSRunAlertPanel(_(@"Compatibility Warning"),
|
NSInteger retval = NSRunAlertPanel(_(@"Compatibility Warning"),
|
||||||
|
@ -162,7 +163,100 @@
|
||||||
return (retval == NSAlertDefaultReturn);
|
return (retval == NSAlertDefaultReturn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL) shouldLoadNewerArchive
|
||||||
|
{
|
||||||
|
NSInteger retval = NSRunAlertPanel(_(@"Gorm Build Mismatch"),
|
||||||
|
_(@"The file being loaded was created with a newer build, continue?"),
|
||||||
|
_(@"OK"),
|
||||||
|
_(@"Cancel"),
|
||||||
|
nil,
|
||||||
|
nil);
|
||||||
|
|
||||||
|
return (retval == NSAlertDefaultReturn);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) shouldBreakConnectionsForClassNamed: (NSString *)className
|
||||||
|
{
|
||||||
|
NSInteger retval = -1;
|
||||||
|
NSString *title = [NSString stringWithFormat: @"%@",_(@"Modifying Class")];
|
||||||
|
NSString *msg;
|
||||||
|
NSString *msgFormat = _(@"This will break all connections to "
|
||||||
|
@"actions/outlets to instances of class '%@' and it's subclasses. Continue?");
|
||||||
|
|
||||||
|
msg = [NSString stringWithFormat: msgFormat, className];
|
||||||
|
|
||||||
|
// ask the user if he/she wants to continue...
|
||||||
|
retval = NSRunAlertPanel(title, msg,_(@"OK"),_(@"Cancel"), nil, nil);
|
||||||
|
|
||||||
|
return (retval == NSAlertDefaultReturn);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) shouldRenameConnectionsForClassNamed: (NSString *)className toClassName: (NSString *)newName
|
||||||
|
{
|
||||||
|
NSInteger retval = -1;
|
||||||
|
NSString *title = [NSString stringWithFormat: @"%@", _(@"Modifying Class")];
|
||||||
|
NSString *msgFormat = _(@"Change class name '%@' to '%@'. Continue?");
|
||||||
|
NSString *msg = [NSString stringWithFormat:
|
||||||
|
msgFormat,
|
||||||
|
className, newName];
|
||||||
|
|
||||||
|
// ask the user if he/she wants to continue...
|
||||||
|
retval = NSRunAlertPanel(title, msg,_(@"OK"),_(@"Cancel"), nil, nil);
|
||||||
|
return (retval == NSAlertDefaultReturn);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) shouldBreakConnectionsModifyingLabel: (NSString *)name isAction: (BOOL)action prompted: (BOOL)prompted
|
||||||
|
{
|
||||||
|
NSString *title;
|
||||||
|
NSString *msg;
|
||||||
|
NSInteger retval = -1;
|
||||||
|
|
||||||
|
if(prompted == NO)
|
||||||
|
{
|
||||||
|
title = [NSString stringWithFormat:
|
||||||
|
@"Modifying %@",(action==YES?@"Action":@"Outlet")];
|
||||||
|
msg = [NSString stringWithFormat:
|
||||||
|
_(@"This will break all connections to '%@'. Continue?"), name];
|
||||||
|
retval = NSRunAlertPanel(title, msg,_(@"OK"),_(@"Cancel"), nil, nil);
|
||||||
|
// prompted = YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (retval == NSAlertDefaultReturn);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) couldNotParseClassAtPath: (NSString *)path
|
||||||
|
{
|
||||||
|
NSString *file = [path lastPathComponent];
|
||||||
|
NSString *message = [NSString stringWithFormat:
|
||||||
|
_(@"Unable to parse class in %@"),file];
|
||||||
|
NSRunAlertPanel(_(@"Problem parsing class"),
|
||||||
|
message,
|
||||||
|
nil, nil, nil);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) exceptionWhileParsingClass: (NSException *)localException
|
||||||
|
{
|
||||||
|
NSString *message = [localException reason];
|
||||||
|
NSRunAlertPanel(_(@"Problem parsing class"),
|
||||||
|
message,
|
||||||
|
nil, nil, nil);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) shouldBreakConnectionsReparsingClass: (NSString *)className
|
||||||
|
{
|
||||||
|
NSString *title = [NSString stringWithFormat: @"%@",
|
||||||
|
_(@"Reparsing Class")];
|
||||||
|
NSString *messageFormat = _(@"This may break connections to "
|
||||||
|
@"actions/outlets to instances of class '%@' "
|
||||||
|
@"and it's subclasses. Continue?");
|
||||||
|
NSString *msg = [NSString stringWithFormat: messageFormat,
|
||||||
|
className];
|
||||||
|
NSInteger retval = NSRunAlertPanel(title, msg,_(@"OK"),_(@"Cancel"), nil, nil);
|
||||||
|
|
||||||
|
return (retval == NSAlertDefaultReturn);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gorm specific methods...
|
||||||
- (BOOL) isInTool
|
- (BOOL) isInTool
|
||||||
{
|
{
|
||||||
return NO;
|
return NO;
|
||||||
|
|
|
@ -1910,26 +1910,9 @@
|
||||||
if([self isKnownClass: className])
|
if([self isKnownClass: className])
|
||||||
{
|
{
|
||||||
id<GormAppDelegate> delegate = (id<GormAppDelegate>)[NSApp delegate];
|
id<GormAppDelegate> delegate = (id<GormAppDelegate>)[NSApp delegate];
|
||||||
NSString *title = [NSString stringWithFormat: @"%@",
|
BOOL result = [delegate shouldBreakConnectionsReparsingClass: className];
|
||||||
_(@"Reparsing Class")];
|
|
||||||
NSString *messageFormat = _(@"This may break connections to "
|
|
||||||
@"actions/outlets to instances of class '%@' "
|
|
||||||
@"and it's subclasses. Continue?");
|
|
||||||
NSString *msg = [NSString stringWithFormat: messageFormat,
|
|
||||||
className];
|
|
||||||
NSInteger retval = 0;
|
|
||||||
|
|
||||||
if ([delegate isInTool])
|
if (result == YES)
|
||||||
{
|
|
||||||
retval = NSAlertDefaultReturn;
|
|
||||||
NSLog(@"Breaking any existing connections with instances of class %@", className);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
retval = NSRunAlertPanel(title, msg,_(@"OK"),_(@"Cancel"), nil, nil);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retval == NSAlertDefaultReturn)
|
|
||||||
{
|
{
|
||||||
// get the owner and reset the class name to NSApplication.
|
// get the owner and reset the class name to NSApplication.
|
||||||
GormFilesOwner *owner = [_document objectForName: @"NSOwner"];
|
GormFilesOwner *owner = [_document objectForName: @"NSOwner"];
|
||||||
|
|
|
@ -193,6 +193,7 @@ static NSImage *fileImage = nil;
|
||||||
{
|
{
|
||||||
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
||||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||||
|
id delegate = [NSApp delegate];
|
||||||
|
|
||||||
// initialize...
|
// initialize...
|
||||||
openEditors = [[NSMutableArray alloc] init];
|
openEditors = [[NSMutableArray alloc] init];
|
||||||
|
@ -271,20 +272,12 @@ static NSImage *fileImage = nil;
|
||||||
{
|
{
|
||||||
if(![classManager parseHeader: header])
|
if(![classManager parseHeader: header])
|
||||||
{
|
{
|
||||||
NSString *file = [header lastPathComponent];
|
[delegate couldNotParseClassAtPath: header];
|
||||||
NSString *message = [NSString stringWithFormat:
|
|
||||||
_(@"Unable to parse class in %@"),file];
|
|
||||||
NSRunAlertPanel(_(@"Problem parsing class"),
|
|
||||||
message,
|
|
||||||
nil, nil, nil);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NS_HANDLER
|
NS_HANDLER
|
||||||
{
|
{
|
||||||
NSString *message = [localException reason];
|
[delegate exceptionWhileParsingClass: localException];
|
||||||
NSRunAlertPanel(_(@"Problem parsing class"),
|
|
||||||
message,
|
|
||||||
nil, nil, nil);
|
|
||||||
}
|
}
|
||||||
NS_ENDHANDLER;
|
NS_ENDHANDLER;
|
||||||
}
|
}
|
||||||
|
@ -435,18 +428,13 @@ static NSImage *fileImage = nil;
|
||||||
{
|
{
|
||||||
NSInteger version = [filePrefsManager version];
|
NSInteger version = [filePrefsManager version];
|
||||||
NSInteger currentVersion = [GormFilePrefsManager currentVersion];
|
NSInteger currentVersion = [GormFilePrefsManager currentVersion];
|
||||||
|
id delegate = [NSApp delegate];
|
||||||
|
|
||||||
if(version > currentVersion)
|
if(version > currentVersion)
|
||||||
{
|
{
|
||||||
NSInteger retval = NSRunAlertPanel(_(@"Gorm Build Mismatch"),
|
BOOL result = [delegate shouldLoadNewerArchive];
|
||||||
_(@"The file being loaded was created with a newer build, continue?"),
|
if (result == NO)
|
||||||
_(@"OK"),
|
|
||||||
_(@"Cancel"),
|
|
||||||
nil,
|
|
||||||
nil);
|
|
||||||
if(retval != NSAlertDefaultReturn)
|
|
||||||
{
|
{
|
||||||
// close the document, if the user says "NO."
|
|
||||||
[self close];
|
[self close];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2641,6 +2629,7 @@ static void _real_close(GormDocument *self,
|
||||||
id<IBConnectors> c = nil;
|
id<IBConnectors> c = nil;
|
||||||
BOOL removed = YES;
|
BOOL removed = YES;
|
||||||
BOOL prompted = NO;
|
BOOL prompted = NO;
|
||||||
|
id delegate = [NSApp delegate];
|
||||||
|
|
||||||
// find connectors to be removed.
|
// find connectors to be removed.
|
||||||
while ((c = [en nextObject]) != nil)
|
while ((c = [en nextObject]) != nil)
|
||||||
|
@ -2679,33 +2668,12 @@ static void _real_close(GormDocument *self,
|
||||||
if ([label isEqualToString: name] && ([proxyClass isEqualToString: className] ||
|
if ([label isEqualToString: name] && ([proxyClass isEqualToString: className] ||
|
||||||
[classManager isSuperclass: className linkedToClass: proxyClass]))
|
[classManager isSuperclass: className linkedToClass: proxyClass]))
|
||||||
{
|
{
|
||||||
NSString *title;
|
removed = [delegate shouldBreakConnectionsModifyingLabel: name
|
||||||
NSString *msg;
|
isAction: action
|
||||||
NSInteger retval;
|
prompted: prompted];
|
||||||
|
if (removed)
|
||||||
if(prompted == NO)
|
|
||||||
{
|
{
|
||||||
title = [NSString stringWithFormat:
|
|
||||||
@"Modifying %@",(action==YES?@"Action":@"Outlet")];
|
|
||||||
msg = [NSString stringWithFormat:
|
|
||||||
_(@"This will break all connections to '%@'. Continue?"), name];
|
|
||||||
retval = NSRunAlertPanel(title, msg,_(@"OK"),_(@"Cancel"), nil, nil);
|
|
||||||
prompted = YES;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
removed = NO;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retval == NSAlertDefaultReturn)
|
|
||||||
{
|
|
||||||
removed = YES;
|
|
||||||
[removedConnections addObject: c];
|
[removedConnections addObject: c];
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
removed = NO;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2733,25 +2701,8 @@ static void _real_close(GormDocument *self,
|
||||||
{
|
{
|
||||||
NSEnumerator *en = nil;
|
NSEnumerator *en = nil;
|
||||||
id<IBConnectors> c = nil;
|
id<IBConnectors> c = nil;
|
||||||
BOOL removed = YES;
|
id delegate = [NSApp delegate];
|
||||||
NSInteger retval = -1;
|
BOOL removed = [delegate shouldBreakConnectionsForClassNamed: className];
|
||||||
NSString *title = [NSString stringWithFormat: @"%@",_(@"Modifying Class")];
|
|
||||||
NSString *msg;
|
|
||||||
NSString *msgFormat = _(@"This will break all connections to "
|
|
||||||
@"actions/outlets to instances of class '%@' and it's subclasses. Continue?");
|
|
||||||
|
|
||||||
msg = [NSString stringWithFormat: msgFormat, className];
|
|
||||||
|
|
||||||
// ask the user if he/she wants to continue...
|
|
||||||
retval = NSRunAlertPanel(title, msg,_(@"OK"),_(@"Cancel"), nil, nil);
|
|
||||||
if (retval == NSAlertDefaultReturn)
|
|
||||||
{
|
|
||||||
removed = YES;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
removed = NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove all.
|
// remove all.
|
||||||
if(removed)
|
if(removed)
|
||||||
|
@ -2847,24 +2798,9 @@ static void _real_close(GormDocument *self,
|
||||||
{
|
{
|
||||||
NSEnumerator *en = [connections objectEnumerator];
|
NSEnumerator *en = [connections objectEnumerator];
|
||||||
id<IBConnectors> c = nil;
|
id<IBConnectors> c = nil;
|
||||||
BOOL renamed = YES;
|
id delegate = [NSApp delegate];
|
||||||
NSInteger retval = -1;
|
BOOL renamed = [delegate shouldRenameConnectionsForClassNamed: className
|
||||||
NSString *title = [NSString stringWithFormat: @"%@", _(@"Modifying Class")];
|
toClassName: newName];
|
||||||
NSString *msgFormat = _(@"Change class name '%@' to '%@'. Continue?");
|
|
||||||
NSString *msg = [NSString stringWithFormat:
|
|
||||||
msgFormat,
|
|
||||||
className, newName];
|
|
||||||
|
|
||||||
// ask the user if he/she wants to continue...
|
|
||||||
retval = NSRunAlertPanel(title, msg,_(@"OK"),_(@"Cancel"), nil, nil);
|
|
||||||
if (retval == NSAlertDefaultReturn)
|
|
||||||
{
|
|
||||||
renamed = YES;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
renamed = NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove all.
|
// remove all.
|
||||||
if(renamed)
|
if(renamed)
|
||||||
|
|
|
@ -54,7 +54,16 @@
|
||||||
|
|
||||||
// Check if we are in the app or the tool
|
// Check if we are in the app or the tool
|
||||||
- (BOOL) isInTool;
|
- (BOOL) isInTool;
|
||||||
|
|
||||||
|
// Delegate methods to handle issues that may occur
|
||||||
- (BOOL) shouldUpgradeOlderArchive;
|
- (BOOL) shouldUpgradeOlderArchive;
|
||||||
|
- (BOOL) shouldLoadNewerArchive;
|
||||||
|
- (BOOL) shouldBreakConnectionsForClassNamed: (NSString *)className;
|
||||||
|
- (BOOL) shouldRenameConnectionsForClassNamed: (NSString *)className toClassName: (NSString *)newName;
|
||||||
|
- (BOOL) shouldBreakConnectionsModifyingLabel: (NSString *)name isAction: (BOOL)action prompted: (BOOL)prompted;
|
||||||
|
- (void) couldNotParseClassAtPath: (NSString *)path;
|
||||||
|
- (void) exceptionWhileParsingClass: (NSException *)localException;
|
||||||
|
- (BOOL) shouldBreakConnectionsReparsingClass: (NSString *)className;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -30,17 +30,61 @@
|
||||||
// AppDelegate...
|
// AppDelegate...
|
||||||
@implementation AppDelegate
|
@implementation AppDelegate
|
||||||
|
|
||||||
|
// Are we in a tool?
|
||||||
- (BOOL) isInTool
|
- (BOOL) isInTool
|
||||||
{
|
{
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle all alerts...
|
||||||
|
|
||||||
- (BOOL) shouldUpgradeOlderArchive
|
- (BOOL) shouldUpgradeOlderArchive
|
||||||
{
|
{
|
||||||
NSLog(@"Upgrading archive to latest version of .gorm format");
|
NSLog(@"Upgrading archive to latest version of .gorm format");
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL) shouldLoadNewerArchive
|
||||||
|
{
|
||||||
|
NSLog(@"Refusing to load archive since it is from a newer version of Gorm/gormtool");
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) shouldBreakConnectionsForClassNamed: (NSString *)className
|
||||||
|
{
|
||||||
|
NSLog(@"Breaking connections for instances of class: %@", className);
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) shouldRenameConnectionsForClassNamed: (NSString *)className toClassName: (NSString *)newName
|
||||||
|
{
|
||||||
|
NSLog(@"Renaming connections from class %@ to class %@", className, newName);
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) shouldBreakConnectionsModifyingLabel: (NSString *)name isAction: (BOOL)action prompted: (BOOL)prompted
|
||||||
|
{
|
||||||
|
NSLog(@"Breaking connections for %@ %@", action?@"action":@"outlet", name);
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) couldNotParseClassAtPath: (NSString *)path;
|
||||||
|
{
|
||||||
|
NSLog(@"Could not parse class at path: %@", path);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) exceptionWhileParsingClass: (NSException *)localException
|
||||||
|
{
|
||||||
|
NSLog(@"Exception while parsing class: %@", [localException reason]);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) shouldBreakConnectionsReparsingClass: (NSString *)className
|
||||||
|
{
|
||||||
|
NSLog(@"Breaking any existing connections with instances of class %@", className);
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
// Handle arguments
|
||||||
|
|
||||||
- (NSDictionary *) parseArguments
|
- (NSDictionary *) parseArguments
|
||||||
{
|
{
|
||||||
GormDocumentController *dc = [GormDocumentController sharedDocumentController];
|
GormDocumentController *dc = [GormDocumentController sharedDocumentController];
|
||||||
|
|
Loading…
Reference in a new issue