mirror of
https://github.com/gnustep/apps-gorm.git
synced 2025-02-23 19:51:00 +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];
|
||||
}
|
||||
|
||||
// Gorm specific methods...
|
||||
// Handle all alerts here...
|
||||
|
||||
- (BOOL) shouldUpgradeOlderArchive
|
||||
{
|
||||
NSInteger retval = NSRunAlertPanel(_(@"Compatibility Warning"),
|
||||
|
@ -162,7 +163,100 @@
|
|||
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
|
||||
{
|
||||
return NO;
|
||||
|
|
|
@ -1910,26 +1910,9 @@
|
|||
if([self isKnownClass: className])
|
||||
{
|
||||
id<GormAppDelegate> delegate = (id<GormAppDelegate>)[NSApp delegate];
|
||||
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 = 0;
|
||||
|
||||
if ([delegate isInTool])
|
||||
{
|
||||
retval = NSAlertDefaultReturn;
|
||||
NSLog(@"Breaking any existing connections with instances of class %@", className);
|
||||
}
|
||||
else
|
||||
{
|
||||
retval = NSRunAlertPanel(title, msg,_(@"OK"),_(@"Cancel"), nil, nil);
|
||||
}
|
||||
BOOL result = [delegate shouldBreakConnectionsReparsingClass: className];
|
||||
|
||||
if (retval == NSAlertDefaultReturn)
|
||||
if (result == YES)
|
||||
{
|
||||
// get the owner and reset the class name to NSApplication.
|
||||
GormFilesOwner *owner = [_document objectForName: @"NSOwner"];
|
||||
|
|
|
@ -193,6 +193,7 @@ static NSImage *fileImage = nil;
|
|||
{
|
||||
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||
id delegate = [NSApp delegate];
|
||||
|
||||
// initialize...
|
||||
openEditors = [[NSMutableArray alloc] init];
|
||||
|
@ -271,20 +272,12 @@ static NSImage *fileImage = nil;
|
|||
{
|
||||
if(![classManager parseHeader: header])
|
||||
{
|
||||
NSString *file = [header lastPathComponent];
|
||||
NSString *message = [NSString stringWithFormat:
|
||||
_(@"Unable to parse class in %@"),file];
|
||||
NSRunAlertPanel(_(@"Problem parsing class"),
|
||||
message,
|
||||
nil, nil, nil);
|
||||
[delegate couldNotParseClassAtPath: header];
|
||||
}
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
NSString *message = [localException reason];
|
||||
NSRunAlertPanel(_(@"Problem parsing class"),
|
||||
message,
|
||||
nil, nil, nil);
|
||||
[delegate exceptionWhileParsingClass: localException];
|
||||
}
|
||||
NS_ENDHANDLER;
|
||||
}
|
||||
|
@ -435,20 +428,15 @@ static NSImage *fileImage = nil;
|
|||
{
|
||||
NSInteger version = [filePrefsManager version];
|
||||
NSInteger currentVersion = [GormFilePrefsManager currentVersion];
|
||||
id delegate = [NSApp delegate];
|
||||
|
||||
if(version > currentVersion)
|
||||
{
|
||||
NSInteger retval = NSRunAlertPanel(_(@"Gorm Build Mismatch"),
|
||||
_(@"The file being loaded was created with a newer build, continue?"),
|
||||
_(@"OK"),
|
||||
_(@"Cancel"),
|
||||
nil,
|
||||
nil);
|
||||
if(retval != NSAlertDefaultReturn)
|
||||
BOOL result = [delegate shouldLoadNewerArchive];
|
||||
if (result == NO)
|
||||
{
|
||||
// close the document, if the user says "NO."
|
||||
[self close];
|
||||
}
|
||||
}
|
||||
}
|
||||
DESTROY(infoData);
|
||||
}
|
||||
|
@ -2641,7 +2629,8 @@ static void _real_close(GormDocument *self,
|
|||
id<IBConnectors> c = nil;
|
||||
BOOL removed = YES;
|
||||
BOOL prompted = NO;
|
||||
|
||||
id delegate = [NSApp delegate];
|
||||
|
||||
// find connectors to be removed.
|
||||
while ((c = [en nextObject]) != nil)
|
||||
{
|
||||
|
@ -2679,33 +2668,12 @@ static void _real_close(GormDocument *self,
|
|||
if ([label isEqualToString: name] && ([proxyClass isEqualToString: className] ||
|
||||
[classManager isSuperclass: className linkedToClass: proxyClass]))
|
||||
{
|
||||
NSString *title;
|
||||
NSString *msg;
|
||||
NSInteger retval;
|
||||
|
||||
if(prompted == NO)
|
||||
removed = [delegate shouldBreakConnectionsModifyingLabel: name
|
||||
isAction: action
|
||||
prompted: prompted];
|
||||
if (removed)
|
||||
{
|
||||
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];
|
||||
}
|
||||
else
|
||||
{
|
||||
removed = NO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -2733,26 +2701,9 @@ static void _real_close(GormDocument *self,
|
|||
{
|
||||
NSEnumerator *en = nil;
|
||||
id<IBConnectors> c = nil;
|
||||
BOOL removed = YES;
|
||||
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);
|
||||
if (retval == NSAlertDefaultReturn)
|
||||
{
|
||||
removed = YES;
|
||||
}
|
||||
else
|
||||
{
|
||||
removed = NO;
|
||||
}
|
||||
|
||||
id delegate = [NSApp delegate];
|
||||
BOOL removed = [delegate shouldBreakConnectionsForClassNamed: className];
|
||||
|
||||
// remove all.
|
||||
if(removed)
|
||||
{
|
||||
|
@ -2847,24 +2798,9 @@ static void _real_close(GormDocument *self,
|
|||
{
|
||||
NSEnumerator *en = [connections objectEnumerator];
|
||||
id<IBConnectors> c = nil;
|
||||
BOOL renamed = YES;
|
||||
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);
|
||||
if (retval == NSAlertDefaultReturn)
|
||||
{
|
||||
renamed = YES;
|
||||
}
|
||||
else
|
||||
{
|
||||
renamed = NO;
|
||||
}
|
||||
id delegate = [NSApp delegate];
|
||||
BOOL renamed = [delegate shouldRenameConnectionsForClassNamed: className
|
||||
toClassName: newName];
|
||||
|
||||
// remove all.
|
||||
if(renamed)
|
||||
|
|
|
@ -54,7 +54,16 @@
|
|||
|
||||
// Check if we are in the app or the tool
|
||||
- (BOOL) isInTool;
|
||||
|
||||
// Delegate methods to handle issues that may occur
|
||||
- (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
|
||||
|
||||
|
|
|
@ -30,17 +30,61 @@
|
|||
// AppDelegate...
|
||||
@implementation AppDelegate
|
||||
|
||||
// Are we in a tool?
|
||||
- (BOOL) isInTool
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
// Handle all alerts...
|
||||
|
||||
- (BOOL) shouldUpgradeOlderArchive
|
||||
{
|
||||
NSLog(@"Upgrading archive to latest version of .gorm format");
|
||||
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
|
||||
{
|
||||
GormDocumentController *dc = [GormDocumentController sharedDocumentController];
|
||||
|
|
Loading…
Reference in a new issue