diff options
-rw-r--r-- | backends/platform/sdl/macosx/appmenu_osx.mm | 11 | ||||
-rw-r--r-- | gui/browser.h | 1 | ||||
-rw-r--r-- | gui/browser_osx.mm | 40 |
3 files changed, 37 insertions, 15 deletions
diff --git a/backends/platform/sdl/macosx/appmenu_osx.mm b/backends/platform/sdl/macosx/appmenu_osx.mm index 97c7edba3e..0d2a2ab7f2 100644 --- a/backends/platform/sdl/macosx/appmenu_osx.mm +++ b/backends/platform/sdl/macosx/appmenu_osx.mm @@ -35,9 +35,8 @@ - (void)setAppleMenu:(NSMenu *)menu; @end -NSString *constructNSStringFromCString(const char* rawCString, NSStringEncoding stringEncoding) { - NSData *nsData = [NSData dataWithBytes:rawCString length:strlen(rawCString)]; - return [[NSString alloc] initWithData:nsData encoding:stringEncoding]; +NSString *constructNSStringFromCString(const char *rawCString, CFStringEncoding stringEncoding) { + return (NSString *)CFStringCreateWithCString(NULL, rawCString, stringEncoding); } void replaceApplicationMenuItems() { @@ -59,11 +58,11 @@ void replaceApplicationMenuItems() { // Get current encoding #ifdef USE_TRANSLATION - nsString = constructNSStringFromCString((TransMan.getCurrentCharset()).c_str(), NSASCIIStringEncoding); - NSStringEncoding stringEncoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef)nsString)); + nsString = constructNSStringFromCString(TransMan.getCurrentCharset().c_str(), NSASCIIStringEncoding); + CFStringEncoding stringEncoding = CFStringConvertIANACharSetNameToEncoding((CFStringRef)nsString); [nsString release]; #else - NSStringEncoding stringEncoding = NSASCIIStringEncoding; + CFStringEncoding stringEncoding = kCFStringEncodingASCII; #endif // Add "About ScummVM" menu item diff --git a/gui/browser.h b/gui/browser.h index e5cc12ad8e..5cf091fbf4 100644 --- a/gui/browser.h +++ b/gui/browser.h @@ -48,6 +48,7 @@ public: protected: #ifdef MACOSX const void *_titleRef; + const void *_chooseRef; #else ListWidget *_fileList; StaticTextWidget *_currentPath; diff --git a/gui/browser_osx.mm b/gui/browser_osx.mm index b8aa7c50ee..1d5e6f2f57 100644 --- a/gui/browser_osx.mm +++ b/gui/browser_osx.mm @@ -28,6 +28,7 @@ #include "common/config-manager.h" #include "common/system.h" #include "common/algorithm.h" +#include "common/translation.h" #include <AppKit/NSOpenPanel.h> #include <Foundation/NSString.h> @@ -36,12 +37,29 @@ namespace GUI { BrowserDialog::BrowserDialog(const char *title, bool dirBrowser) : Dialog("Browser") { - _titleRef = CFStringCreateWithCString(0, title, CFStringGetSystemEncoding()); + + // remember whether this is a file browser or a directory browser. _isDirBrowser = dirBrowser; + + // Get current encoding +#ifdef USE_TRANSLATION + CFStringRef encStr = CFStringCreateWithCString(NULL, TransMan.getCurrentCharset().c_str(), kCFStringEncodingASCII); + CFStringEncoding stringEncoding = CFStringConvertIANACharSetNameToEncoding(encStr); + CFRelease(encStr); +#else + CFStringEncoding stringEncoding = kCFStringEncodingASCII; +#endif + + // Convert title to NSString + _titleRef = CFStringCreateWithCString(0, title, stringEncoding); + + // Convert button text to NSString + _chooseRef = CFStringCreateWithCString(0, _("Choose"), stringEncoding); } BrowserDialog::~BrowserDialog() { CFRelease(_titleRef); + CFRelease(_chooseRef); } int BrowserDialog::runModal() { @@ -58,16 +76,20 @@ int BrowserDialog::runModal() { // Temporarily show the real mouse CGDisplayShowCursor(kCGDirectMainDisplay); - - NSOpenPanel * panel = [NSOpenPanel openPanel]; - [panel setCanChooseDirectories:YES]; - if ([panel runModalForTypes:nil] == NSOKButton) { - const char *filename = [[panel filename] UTF8String]; - _choice = Common::FSNode(filename); - choiceMade = true; + NSOpenPanel *panel = [NSOpenPanel openPanel]; + [panel setCanChooseFiles:!_isDirBrowser]; + [panel setCanChooseDirectories:_isDirBrowser]; + [panel setTitle:(NSString *)_titleRef]; + [panel setPrompt:(NSString *)_chooseRef]; + if ([panel runModal] == NSOKButton) { + NSURL *url = [panel URL]; + if ([url isFileURL]) { + const char *filename = [[url path] UTF8String]; + _choice = Common::FSNode(filename); + choiceMade = true; + } } - // If we were in fullscreen mode, switch back if (wasFullscreen) { g_system->beginGFXTransaction(); |