From cc3482723065f3782e365ff84b086c13379cc358 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Tue, 18 Jul 2023 14:01:13 -0400 Subject: [PATCH] Replace connections alert panel and move logic to delegate --- GormCore/GormAbstractDelegate.m | 24 +++++++++++++++++------- GormCore/GormDocument.m | 23 +++-------------------- GormCore/GormProtocol.h | 1 + Tools/gormtool/AppDelegate.m | 6 ++++++ 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/GormCore/GormAbstractDelegate.m b/GormCore/GormAbstractDelegate.m index 82b6e0fa..0a94b977 100644 --- a/GormCore/GormAbstractDelegate.m +++ b/GormCore/GormAbstractDelegate.m @@ -170,13 +170,23 @@ _(@"Cancel"), nil, nil); - /* - if(retval != NSAlertDefaultReturn) - { - // close the document, if the user says "NO." - [self close]; - } - */ + + 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); } diff --git a/GormCore/GormDocument.m b/GormCore/GormDocument.m index 66038802..1759dff1 100644 --- a/GormCore/GormDocument.m +++ b/GormCore/GormDocument.m @@ -2728,26 +2728,9 @@ static void _real_close(GormDocument *self, { NSEnumerator *en = nil; id 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) { diff --git a/GormCore/GormProtocol.h b/GormCore/GormProtocol.h index f8f99fc3..37023f03 100644 --- a/GormCore/GormProtocol.h +++ b/GormCore/GormProtocol.h @@ -56,6 +56,7 @@ - (BOOL) isInTool; - (BOOL) shouldUpgradeOlderArchive; - (BOOL) shouldLoadNewerArchive; +- (BOOL) shouldBreakConnectionsForClassNamed: (NSString *)className; @end diff --git a/Tools/gormtool/AppDelegate.m b/Tools/gormtool/AppDelegate.m index 3c1ee051..911916c7 100644 --- a/Tools/gormtool/AppDelegate.m +++ b/Tools/gormtool/AppDelegate.m @@ -47,6 +47,12 @@ return NO; } +- (BOOL) shouldBreakConnectionsForClassNamed: (NSString *)className +{ + NSLog(@"Breaking connections for instances of class: %@", className); + return YES; +} + - (NSDictionary *) parseArguments { GormDocumentController *dc = [GormDocumentController sharedDocumentController];