Ticket #9462: osx-browser.patch

File osx-browser.patch, 3.8 KB (added by fingolfin, 12 years ago)
  • backends/platform/sdl/macosx/appmenu_osx.mm

    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  
    3636@end
    3737
    3838NSString *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];
    4140}
    4241
    4342void replaceApplicationMenuItems() {
    void replaceApplicationMenuItems() {  
    5958
    6059        // Get current encoding
    6160#ifdef USE_TRANSLATION
    62         nsString = constructNSStringFromCString((TransMan.getCurrentCharset()).c_str(), NSASCIIStringEncoding);
     61        nsString = constructNSStringFromCString(TransMan.getCurrentCharset().c_str(), NSASCIIStringEncoding);
    6362        NSStringEncoding stringEncoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef)nsString));
    6463        [nsString release];
    6564#else
  • 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..63a13fd 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        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);
    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();