[uae] Re: Cocoa floppy loading bug

  • From: anarkhos@xxxxxxxxxxx
  • To: uae@xxxxxxxxxxxxx
  • Date: Thu, 12 May 2005 02:38:50 -0700

>Yeah, I have this working in some changes I'm working on to make the
>cocoa version into a application bundle. I assume you used
>beginSheetForDirectory:... and the NSApplication's mainWindow? That's
>the way I did it, at least. It's definitely nicer than the other way.

Yup, and I made a small change to SDLMain.m so I actually had a global 
NSApplication instance to call:

mainApp = [SDLApplication sharedApplication];

In the following code you'll notice I inherit from NSSavePanel and initialize 
the instance of ModalOpenPanel as an NSOpenPanel. I don't know why, but if I 
inherit from NSOpenPanel and initialize with [ModalOpenPanel savePanel] the 
events aren't handled correctly and make the app beep. <shrug>


@interface ModalOpenPanel : NSSavePanel
- (int)runModalForDirectory:(NSString *)path file:(NSString *)name 
types:(NSArray *)types
                   relativeToWindow:(NSWindow*)window;
@end

@implementation ModalOpenPanel
- (int)runModalForDirectory:(NSString *)path file:(NSString *)name 
types:(NSArray *)types
                   relativeToWindow:(NSWindow*)window;
{
     int result;
     [super beginSheetForDirectory: path
                              file: name
                             types: types
                    modalForWindow: window
                     modalDelegate: self
                    didEndSelector: NULL
                       contextInfo: nil];
     result = [NSApp runModalForWindow:self];
     [NSApp endSheet:self];
     return result;
}@end


void gui_display (int shortcut)
{
    int result;
    int originallyFullscreen = ensureNotFullscreen ();

    if ((shortcut >= 0) && (shortcut < 4)) {
        NSArray *fileTypes = [NSArray arrayWithObjects:@"adf", @"adz",
            @"zip", @"dms", @"fdi", nil];
           
        ModalOpenPanel *oPanel = [NSOpenPanel openPanel];
        [oPanel setTitle:[NSString stringWithFormat:
            @"Select a disk image file for DF%d", shortcut]];
           
        [oPanel setCanChooseDirectories:NO];
        [oPanel setCanChooseFiles:YES];

result = [oPanel runModalForDirectory:nil file:nil types:fileTypes 
relativeToWindow:[mainApp mainWindow]];

        /*result = [oPanel runModalForTypes:fileTypes];*/
        /*result = [oPanel runModalForDirectory:nil file:nil
            types:fileTypes];*/

Other related posts: