--- hatari/src/gui-osx/AlertHooks.m 2019/04/01 07:13:04 1.1 +++ hatari/src/gui-osx/AlertHooks.m 2019/04/09 08:56:36 1.1.1.6 @@ -1,8 +1,8 @@ /* - Hatari - AlertHooks.c + Hatari - AlertHooks.m - This file is distributed under the GNU Public License, version 2 or at - your option any later version. Read the file gpl.txt for details. + This file is distributed under the GNU General Public License, version 2 + or at your option any later version. Read the file gpl.txt for details. Hooked alerts, to be used instead of SDL alert windows @@ -11,6 +11,7 @@ #import #import "AlertHooks.h" +#import "Shared.h" #ifdef ALERT_HOOKS @@ -20,16 +21,41 @@ */ int HookedAlertNotice(const char* szMessage) { - return (NSAlertDefaultReturn == NSRunInformationalAlertPanel(@"Hatari", [NSString stringWithCString:szMessage], nil, nil, nil)); + NSString *message ; + NSRange cantTOS, firstPv, lastPv ; + + message = [NSString stringWithCString:szMessage encoding:NSASCIIStringEncoding] ; + //NSLog(@"Notice: %@", message ) ; + cantTOS = [message rangeOfString:@"Can not load TOS file:"] ; + firstPv = [message rangeOfString:@"'"] ; + lastPv = [message rangeOfString:@"'" options:NSBackwardsSearch] ; + + if ((cantTOS.location == NSNotFound) || (firstPv.location==lastPv.location)) // TOS can be found + return ([NSApp myAlerte:NSInformationalAlertStyle Txt:nil firstB:localize(@"Ok") alternateB:localize(@"Cancel") + otherB:nil informativeTxt:message ] == NSAlertFirstButtonReturn + //NSAlertDefaultReturn + ); + else // TOS can be found + return ([NSApp myAlerte:NSCriticalAlertStyle Txt:nil firstB:localize(@"Ok") alternateB:nil otherB:nil + informativeTxt:localize(@"Can not load TOS file:") ] == NSAlertFirstButtonReturn) ; } -/*-----------------------------------------------------------------------*/ -/* - Displays a Cocoa alert with a choice (OK and Cancel buttons) -*/ +/*----------------------------------------------------------------------*/ +/* Displays a Cocoa alert with a choice (OK and Cancel buttons) */ +/*----------------------------------------------------------------------*/ + int HookedAlertQuery(const char* szMessage) { - return (NSAlertDefaultReturn == NSRunAlertPanel(@"Hatari", [NSString stringWithCString:szMessage], @"OK", @"Cancel", nil)); + NSString *message ; + int ret; + + message = localize([NSString stringWithCString:szMessage encoding:NSASCIIStringEncoding]) ; + ret= [NSApp myAlerte:NSInformationalAlertStyle Txt:nil firstB:localize(@"Ok") alternateB:localize(@"Cancel") + otherB:nil informativeTxt:message ] ; + if(ret==NSAlertFirstButtonReturn) + return true; //OK + else + return false; // otherwise false } #endif