commit 1606ab02e6ec3687cfe1802eceeafb9f449f3b28
Author: Max Horn <max@quendi.de>
Date:   Mon Oct 15 14:30:18 2012 +0200

    OSX: Improve native OS X browser dialog

diff --git a/backends/platform/sdl/macosx/appmenu_osx.mm b/backends/platform/sdl/macosx/appmenu_osx.mm
index 97c7edb..970186d 100644
--- a/backends/platform/sdl/macosx/appmenu_osx.mm
+++ b/backends/platform/sdl/macosx/appmenu_osx.mm
@@ -36,8 +36,7 @@
 @end
 
 NSString *constructNSStringFromCString(const char* rawCString, NSStringEncoding stringEncoding) {
-        NSData *nsData = [NSData dataWithBytes:rawCString length:strlen(rawCString)];
-        return [[NSString alloc] initWithData:nsData encoding:stringEncoding];
+	return [[NSString alloc] initWithCString:rawCString encoding:stringEncoding];
 }
 
 void replaceApplicationMenuItems() {
@@ -59,7 +58,7 @@ void replaceApplicationMenuItems() {
 
 	// Get current encoding
 #ifdef USE_TRANSLATION
-	nsString = constructNSStringFromCString((TransMan.getCurrentCharset()).c_str(), NSASCIIStringEncoding);
+	nsString = constructNSStringFromCString(TransMan.getCurrentCharset().c_str(), NSASCIIStringEncoding);
 	NSStringEncoding stringEncoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef)nsString));
 	[nsString release];
 #else
diff --git a/gui/browser.h b/gui/browser.h
index e5cc12a..5cf091f 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 b8aa7c5..63a13fd 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
+	NSString *encStr = [NSString stringWithCString:TransMan.getCurrentCharset().c_str() encoding:NSASCIIStringEncoding];
+	CFStringEncoding stringEncoding = CFStringConvertIANACharSetNameToEncoding((CFStringRef)encStr);
+	//[encStr release];
+#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();
