Ticket #9462: osx-browser2.patch

File osx-browser2.patch, 4.5 KB (added by fingolfin, 12 years ago)

Revised patch

  • backends/platform/sdl/macosx/appmenu_osx.mm

    From ada3e3019beddca66362baed7e5bd1b7035533e8 Mon Sep 17 00:00:00 2001
    From: Max Horn <max@quendi.de>
    Date: Mon, 15 Oct 2012 14:30:18 +0200
    Subject: [PATCH] OSX: Improve native OS X browser dialog
    
    ---
     backends/platform/sdl/macosx/appmenu_osx.mm | 11 ++++----
     gui/browser.h                               |  1 +
     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 97c7edb..0d2a2ab 100644
    a b  
    3535- (void)setAppleMenu:(NSMenu *)menu;
    3636@end
    3737
    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];
     38NSString *constructNSStringFromCString(const char *rawCString, CFStringEncoding stringEncoding) {
     39        return (NSString *)CFStringCreateWithCString(NULL, rawCString, stringEncoding);
    4140}
    4241
    4342void replaceApplicationMenuItems() {
    void replaceApplicationMenuItems() {  
    5958
    6059        // Get current encoding
    6160#ifdef USE_TRANSLATION
    62         nsString = constructNSStringFromCString((TransMan.getCurrentCharset()).c_str(), NSASCIIStringEncoding);
    63         NSStringEncoding stringEncoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef)nsString));
     61        nsString = constructNSStringFromCString(TransMan.getCurrentCharset().c_str(), NSASCIIStringEncoding);
     62        CFStringEncoding stringEncoding = CFStringConvertIANACharSetNameToEncoding((CFStringRef)nsString);
    6463        [nsString release];
    6564#else
    66         NSStringEncoding stringEncoding = NSASCIIStringEncoding;
     65        CFStringEncoding stringEncoding = kCFStringEncodingASCII;
    6766#endif
    6867
    6968        // Add "About ScummVM" menu item
  • gui/browser.h

    diff --git a/gui/browser.h b/gui/browser.h
    index e5cc12a..5cf091f 100644
    a b public:  
    4848protected:
    4949#ifdef MACOSX
    5050        const void *_titleRef;
     51        const void *_chooseRef;
    5152#else
    5253        ListWidget              *_fileList;
    5354        StaticTextWidget        *_currentPath;
  • gui/browser_osx.mm

    diff --git a/gui/browser_osx.mm b/gui/browser_osx.mm
    index b8aa7c5..1d5e6f2 100644
    a b  
    2828#include "common/config-manager.h"
    2929#include "common/system.h"
    3030#include "common/algorithm.h"
     31#include "common/translation.h"
    3132
    3233#include <AppKit/NSOpenPanel.h>
    3334#include <Foundation/NSString.h>
    namespace GUI {  
    3637
    3738BrowserDialog::BrowserDialog(const char *title, bool dirBrowser)
    3839        : Dialog("Browser") {
    39         _titleRef = CFStringCreateWithCString(0, title, CFStringGetSystemEncoding());
     40
     41        // remember whether this is a file browser or a directory browser.
    4042        _isDirBrowser = dirBrowser;
     43
     44        // Get current encoding
     45#ifdef USE_TRANSLATION
     46        CFStringRef encStr = CFStringCreateWithCString(NULL, TransMan.getCurrentCharset().c_str(), kCFStringEncodingASCII);
     47        CFStringEncoding stringEncoding = CFStringConvertIANACharSetNameToEncoding(encStr);
     48        CFRelease(encStr);
     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);
    4158}
    4259
    4360BrowserDialog::~BrowserDialog() {
    4461        CFRelease(_titleRef);
     62        CFRelease(_chooseRef);
    4563}
    4664
    4765int BrowserDialog::runModal() {
    int BrowserDialog::runModal() {  
    5876        // Temporarily show the real mouse
    5977        CGDisplayShowCursor(kCGDirectMainDisplay);
    6078
    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                }
    6891        }
    6992
    70 
    7193        // If we were in fullscreen mode, switch back
    7294        if (wasFullscreen) {
    7395                g_system->beginGFXTransaction();