--- hatari/src/gui-osx/Shared.m 2019/04/09 08:55:20 1.1.1.9 +++ hatari/src/gui-osx/Shared.m 2019/04/09 08:56:36 1.1.1.10 @@ -7,7 +7,7 @@ Helper code used by the other Cocoa code files June 2006, Sébastien Molines - Created - 2013, M. SARO + 2013, 2016 M. SARO */ #import @@ -27,7 +27,7 @@ [window setDelegate:self]; // Change emulation and UI state - GuiOsx_Pause(); + GuiOsx_Pause(true); // Run it as modal [NSApp runModalForWindow:window]; @@ -39,7 +39,7 @@ // On closure of the NSWindow, end the modal session - (void) windowWillClose:(NSNotification *)notification { - NSWindow *windowAboutToClose = [notification object]; + NSWindow *windowAboutToClose = notification.object ; // Is this our modal window? if (windowAboutToClose == modalWindow) @@ -52,9 +52,8 @@ @end /*-----------------------------------------------------------------------*/ -/* - Helper function to write the contents of a path as an NSString to a string -*/ +/*Helper function to write the contents of a path as an NSString to a string*/ +/*----------------------------------------------------------------------*/ void GuiOsx_ExportPathString(NSString* path, char* szTarget, size_t cchTarget) { NSCAssert((szTarget), @"Target buffer must not be null."); @@ -64,28 +63,28 @@ void GuiOsx_ExportPathString(NSString* p [path getCString:szTarget maxLength:cchTarget-1 encoding:NSASCIIStringEncoding] ; } -/*-----------------------------------------------------------------------*/ -/* - Pauses emulation -*/ -void GuiOsx_Pause(void) +/*----------------------------------------------------------------------*/ +/*Pauses emulation */ +/* Added the visualize option for 2.0.0 */ +/*----------------------------------------------------------------------*/ +void GuiOsx_Pause(bool visualize) { // Pause emulation - Main_PauseEmulation(false); + Main_PauseEmulation(visualize); } /*-----------------------------------------------------------------------*/ -/* - Switches back to emulation mode -*/ +/*Switches back to emulation mode */ +/*----------------------------------------------------------------------*/ void GuiOsx_Resume(void) { // Resume emulation Main_UnPauseEmulation(); } -//----------------------------------------------------------------------------------------------------------- +/*----------------------------------------------------------------------*/ // Add global services. 6 methods +/*----------------------------------------------------------------------*/ @implementation NSApplication (service) @@ -96,7 +95,7 @@ void GuiOsx_Resume(void) return [self hopenfile:chooseDir defoDir:defoDir defoFile:defoFile types:types titre:nil] ; } - +/*----------------------------------------------------------------------*/ - (NSString *)hopenfile:(BOOL)chooseDir defoDir:(NSString *)defoDir defoFile:(NSString *)defoFile types:(NSArray *)types titre:(NSString *)titre { NSOpenPanel *openPanel ; @@ -104,37 +103,38 @@ NSOpenPanel *openPanel ; BOOL btOk ; openPanel = [NSOpenPanel openPanel]; - [openPanel setCanChooseDirectories: chooseDir]; - [openPanel setCanChooseFiles: !chooseDir]; - [openPanel setAllowsMultipleSelection:NO] ; + openPanel.canChooseDirectories = chooseDir ; + openPanel.canChooseFiles = !chooseDir; + openPanel.allowsMultipleSelection = NO ; if (types != nil) - { [openPanel setAllowedFileTypes:types] ; - [openPanel setAllowsOtherFileTypes:YES] ; } ; - if (titre != nil) [openPanel setTitle:titre] ; - - if ([openPanel respondsToSelector:@selector(setDirectoryURL:)]) - { if (defoDir!=nil) [openPanel setDirectoryURL:[NSURL fileURLWithPath:defoDir isDirectory:YES]] ; // A partir de 10.6 - if (defoFile!=nil) [openPanel setNameFieldStringValue:defoFile] ; - btOk = [openPanel runModal] == NSOKButton ; // Ok ? + { openPanel.allowedFileTypes = types ; + openPanel.allowsOtherFileTypes = YES ; } ; + if (titre != nil) openPanel.title = titre ; + +// if ([openPanel respondsToSelector:@selector(setDirectoryURL:)]) + { if (defoDir!=nil) openPanel.directoryURL = [NSURL fileURLWithPath:defoDir isDirectory:YES] ; // A partir de 10.6 + if (defoFile!=nil) openPanel.nameFieldStringValue = defoFile ; + btOk = [openPanel runModal] == NSModalResponseOK ; // Ok ? } - else - btOk = [openPanel runModalForDirectory:defoDir file:defoFile] == NSOKButton ; // avant 10.6 +// else +// btOk = [openPanel runModalForDirectory:defoDir file:defoFile] == NSModalResponseOK; // avant 10.6 if (btOk) - { lesURLs = [openPanel URLs] ; - if ((lesURLs != nil) && ([lesURLs count] != 0)) + { lesURLs = openPanel.URLs ; + if ((lesURLs != nil) && (lesURLs.count != 0)) return [[lesURLs objectAtIndex:0] path] ; } ; return @"" ; } +/*----------------------------------------------------------------------*/ // Save file // - (NSString *)hsavefile:(BOOL)creatDir defoDir:(NSString *)defoDir defoFile:(NSString *)defoFile types:(NSArray *)types { return [self hsavefile:creatDir defoDir:defoDir defoFile:defoFile types:types titre:nil] ; } - +/*----------------------------------------------------------------------*/ - (NSString *)hsavefile:(BOOL)creatDir defoDir:(NSString *)defoDir defoFile:(NSString *)defoFile types:(NSArray *)types titre:(NSString *)titre { NSSavePanel *savPanel ; @@ -142,28 +142,28 @@ NSOpenPanel *openPanel ; BOOL btOk ; savPanel = [NSSavePanel savePanel]; - [savPanel setCanCreateDirectories:creatDir]; + savPanel.canCreateDirectories = creatDir ; if (types != nil) - { [savPanel setAllowedFileTypes:types] ; - [savPanel setAllowsOtherFileTypes:YES] ; } ; - if (titre != nil) [savPanel setTitle:titre] ; - - if ([savPanel respondsToSelector:@selector(setDirectoryURL:)]) - { if (defoDir!=nil) [savPanel setDirectoryURL:[NSURL fileURLWithPath:defoDir isDirectory:YES]] ; // A partir de 10.6 - if (defoFile!=nil) [savPanel setNameFieldStringValue:defoFile] ; - btOk = [savPanel runModal] == NSOKButton ; // Ok? + { savPanel.allowedFileTypes = types ; + savPanel.allowsOtherFileTypes = YES ; } ; + if (titre != nil) savPanel.title = titre ; + +// if ([savPanel respondsToSelector:@selector(setDirectoryURL:)]) + { if (defoDir!=nil) savPanel.directoryURL = [NSURL fileURLWithPath:defoDir isDirectory:YES] ; // A partir de 10.6 + if (defoFile!=nil) savPanel.nameFieldStringValue = defoFile ; + btOk = [savPanel runModal] == NSModalResponseOK; // Ok? } - else - btOk = [savPanel runModalForDirectory:defoDir file:defoFile] == NSOKButton ; // Ok ? deprecated en 10.6 +// else +// btOk = [savPanel runModalForDirectory:defoDir file:defoFile] == NSOKButton ; // Ok ? deprecated en 10.6 if (btOk) - { lURL = [savPanel URL] ; + { lURL = savPanel.URL ; if (lURL != nil) - return [lURL path] ; + return lURL.path ; } ; return @"" ; } - +/*----------------------------------------------------------------------*/ // Returne localized path // - (NSString *)localpath:(NSString *)thepath :(NSFileManager *)afilemanager @@ -172,13 +172,13 @@ NSOpenPanel *openPanel ; NSArray *thelist ; if (thepath == nil) return @"" ; - if ([thepath length] == 0) return @"" ; + if (thepath.length == 0) return @"" ; if (![afilemanager fileExistsAtPath:thepath]) - { thend = [thepath lastPathComponent] ; - return [[self localpath:[thepath stringByDeletingLastPathComponent] :afilemanager] stringByAppendingPathComponent:thend] ; + { thend = thepath.lastPathComponent ; + return [[self localpath:thepath.stringByDeletingLastPathComponent :afilemanager] stringByAppendingPathComponent:thend] ; } ; thelist = [afilemanager componentsToDisplayForPath:thepath] ; // convert in matrix - if ( [thelist count] != 0) + if ( thelist.count != 0) return [NSString pathWithComponents:thelist] ; // return localized path else return thepath ; @@ -189,7 +189,7 @@ NSOpenPanel *openPanel ; NSFileManager *afilemanager = [NSFileManager defaultManager] ; // call "default manager" return [self localpath:thepath :afilemanager] ; } - +/*----------------------------------------------------------------------*/ // return a localized path related to user home directoryr ~/ // - (NSString *)pathUser:(NSString *)thepath @@ -198,14 +198,14 @@ NSOpenPanel *openPanel ; NSString *apath ; apath = [self localpath:thepath] ; - if ([apath length] == 0) return @"" ; - here = [self localpath:[@"~/" stringByExpandingTildeInPath]] ; + if (apath.length == 0) return @"" ; + here = [self localpath: @"~/".stringByExpandingTildeInPath ] ; if (([apath rangeOfString:here].location) != NSNotFound) - return [NSString stringWithFormat:@"~%@", [apath substringFromIndex:[here length]]] ; + return [NSString stringWithFormat:@"~%@", [apath substringFromIndex:here.length ]] ; return apath; } - -// NSAlert available 10.3 to 10.9 +/*----------------------------------------------------------------------*/ +// NSAlert available 10.3 to 10.9 ..... 10.11 // - (NSInteger)myAlerte:(NSUInteger)style Txt:(NSString *)Txt firstB:(NSString *)firstB alternateB:(NSString *)alternateB otherB:(NSString *)otherB informativeTxt:(NSString *)informativeT @@ -214,11 +214,8 @@ NSOpenPanel *openPanel ; NSInteger ret ; lalerte = [[NSAlert alloc] init] ; - [lalerte setAlertStyle:style] ; - if (Txt == nil) - [lalerte setMessageText:@"Hatari"] ; - else - [lalerte setMessageText:Txt] ; + lalerte.alertStyle = style ; + lalerte.messageText = Txt == nil ? @"Hatari" : Txt ; [lalerte addButtonWithTitle:firstB] ; if (alternateB != nil) [lalerte addButtonWithTitle:alternateB] ; if (otherB != nil) [lalerte addButtonWithTitle:otherB] ; @@ -226,11 +223,12 @@ NSOpenPanel *openPanel ; ret = [lalerte runModal] ; [lalerte release] ; switch (ret) { - case NSAlertFirstButtonReturn : return NSAlertDefaultReturn ; - break ; - case NSAlertSecondButtonReturn: return NSAlertAlternateReturn ; - break ; - default : return NSAlertOtherReturn ; + case NSAlertFirstButtonReturn : + return NSAlertFirstButtonReturn; + case NSAlertSecondButtonReturn: + return NSAlertSecondButtonReturn; + default: + return NSAlertFirstButtonReturn; } ; }