/* Copyright (c) 2006-2007 Christopher J. W. Lloyd 2009 Markus Hitter Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #import #import #import #import #import #import #import #import #import #import #import #import #import #import @implementation NSAlert /* NSWarningAlertStyle - app icon NSInformationalAlertStyle - app icon NSCriticalAlertStyle - large yellow /!\ triangle w/ small app icon */ -init { _style=NSWarningAlertStyle; _icon=[[NSImage imageNamed:@"NSAlertPanelExclamation"] retain]; _messageText=[NSLocalizedString(@"Alert",@"Default message text for NSAlert") copy]; _informativeText=@""; _accessoryView=nil; _showsHelp=NO; _showsSuppressionButton=NO; _helpAnchor=nil; _buttons=[NSMutableArray new]; _window=[[NSPanel alloc] initWithContentRect:NSMakeRect(0,0,10,10) styleMask:NSTitledWindowMask backing:NSBackingStoreBuffered defer:NO]; _supressionButton=[[NSButton alloc] init]; // [_supressionButton setButtonType:NSSwitchButton]; [_supressionButton setTitle:NSLocalizedString(@"Do not show this message again",@"Default NSAlert supression button title")]; _needsLayout=YES; return self; } -(void)dealloc { [_icon release]; [_messageText release]; [_informativeText release]; [_accessoryView release]; [_helpAnchor release]; [_buttons release]; [_supressionButton release]; [_window release]; [super dealloc]; } +(NSAlert *)alertWithError:(NSError *)error { NSArray *titles=[error localizedRecoveryOptions]; NSString *defaultTitle=([titles count]>0)?[titles objectAtIndex:0]:nil; NSString *alternateTitle=([titles count]>1)?[titles objectAtIndex:1]:nil; NSString *otherTitle=([titles count]>2)?[titles objectAtIndex:2]:nil; NSAlert *result=[[[self alloc] init] autorelease]; [result setMessageText:[error localizedDescription]]; [result setInformativeText:[error localizedRecoverySuggestion]]; int i,count=[titles count]; for(i=0;i