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
|
b
|
|
36 | 36 | @end |
37 | 37 | |
38 | 38 | NSString *constructNSStringFromCString(const char* rawCString, NSStringEncoding stringEncoding) { |
39 | | NSData *nsData = [NSData dataWithBytes:rawCString length:strlen(rawCString)]; |
40 | | return [[NSString alloc] initWithData:nsData encoding:stringEncoding]; |
| 39 | return [[NSString alloc] initWithCString:rawCString encoding:stringEncoding]; |
41 | 40 | } |
42 | 41 | |
43 | 42 | void replaceApplicationMenuItems() { |
… |
… |
void replaceApplicationMenuItems() {
|
59 | 58 | |
60 | 59 | // Get current encoding |
61 | 60 | #ifdef USE_TRANSLATION |
62 | | nsString = constructNSStringFromCString((TransMan.getCurrentCharset()).c_str(), NSASCIIStringEncoding); |
| 61 | nsString = constructNSStringFromCString(TransMan.getCurrentCharset().c_str(), NSASCIIStringEncoding); |
63 | 62 | NSStringEncoding stringEncoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef)nsString)); |
64 | 63 | [nsString release]; |
65 | 64 | #else |
diff --git a/gui/browser.h b/gui/browser.h
index e5cc12a..5cf091f 100644
a
|
b
|
public:
|
48 | 48 | protected: |
49 | 49 | #ifdef MACOSX |
50 | 50 | const void *_titleRef; |
| 51 | const void *_chooseRef; |
51 | 52 | #else |
52 | 53 | ListWidget *_fileList; |
53 | 54 | StaticTextWidget *_currentPath; |
diff --git a/gui/browser_osx.mm b/gui/browser_osx.mm
index b8aa7c5..63a13fd 100644
a
|
b
|
|
28 | 28 | #include "common/config-manager.h" |
29 | 29 | #include "common/system.h" |
30 | 30 | #include "common/algorithm.h" |
| 31 | #include "common/translation.h" |
31 | 32 | |
32 | 33 | #include <AppKit/NSOpenPanel.h> |
33 | 34 | #include <Foundation/NSString.h> |
… |
… |
namespace GUI {
|
36 | 37 | |
37 | 38 | BrowserDialog::BrowserDialog(const char *title, bool dirBrowser) |
38 | 39 | : Dialog("Browser") { |
39 | | _titleRef = CFStringCreateWithCString(0, title, CFStringGetSystemEncoding()); |
| 40 | |
| 41 | // remember whether this is a file browser or a directory browser. |
40 | 42 | _isDirBrowser = dirBrowser; |
| 43 | |
| 44 | // Get current encoding |
| 45 | #ifdef USE_TRANSLATION |
| 46 | NSString *encStr = [NSString stringWithCString:TransMan.getCurrentCharset().c_str() encoding:NSASCIIStringEncoding]; |
| 47 | CFStringEncoding stringEncoding = CFStringConvertIANACharSetNameToEncoding((CFStringRef)encStr); |
| 48 | //[encStr release]; |
| 49 | #else |
| 50 | CFStringEncoding stringEncoding = kCFStringEncodingASCII; |
| 51 | #endif |
| 52 | |
| 53 | // Convert title to NSString |
| 54 | _titleRef = CFStringCreateWithCString(0, title, stringEncoding); |
| 55 | |
| 56 | // Convert button text to NSString |
| 57 | _chooseRef = CFStringCreateWithCString(0, _("Choose"), stringEncoding); |
41 | 58 | } |
42 | 59 | |
43 | 60 | BrowserDialog::~BrowserDialog() { |
44 | 61 | CFRelease(_titleRef); |
| 62 | CFRelease(_chooseRef); |
45 | 63 | } |
46 | 64 | |
47 | 65 | int BrowserDialog::runModal() { |
… |
… |
int BrowserDialog::runModal() {
|
58 | 76 | // Temporarily show the real mouse |
59 | 77 | CGDisplayShowCursor(kCGDirectMainDisplay); |
60 | 78 | |
61 | | |
62 | | NSOpenPanel * panel = [NSOpenPanel openPanel]; |
63 | | [panel setCanChooseDirectories:YES]; |
64 | | if ([panel runModalForTypes:nil] == NSOKButton) { |
65 | | const char *filename = [[panel filename] UTF8String]; |
66 | | _choice = Common::FSNode(filename); |
67 | | choiceMade = true; |
| 79 | NSOpenPanel *panel = [NSOpenPanel openPanel]; |
| 80 | [panel setCanChooseFiles:!_isDirBrowser]; |
| 81 | [panel setCanChooseDirectories:_isDirBrowser]; |
| 82 | [panel setTitle:(NSString *)_titleRef]; |
| 83 | [panel setPrompt:(NSString *)_chooseRef]; |
| 84 | if ([panel runModal] == NSOKButton) { |
| 85 | NSURL *url = [panel URL]; |
| 86 | if ([url isFileURL]) { |
| 87 | const char *filename = [[url path] UTF8String]; |
| 88 | _choice = Common::FSNode(filename); |
| 89 | choiceMade = true; |
| 90 | } |
68 | 91 | } |
69 | 92 | |
70 | | |
71 | 93 | // If we were in fullscreen mode, switch back |
72 | 94 | if (wasFullscreen) { |
73 | 95 | g_system->beginGFXTransaction(); |