How does MacVim enable ⌘A for the call to NSOpenPanel

32 views
Skip to first unread message

Jeff Holt

unread,
Jan 31, 2024, 5:00:49 PMJan 31
to vim_mac
I'm looking at the source for the fileOpen method and I cannot figure out how it tells NSOpenPanel to respect ⌘A to select all files in the dialog.

Does anyone know how it's done?

Yee Cheng Chin

unread,
Jan 31, 2024, 8:01:56 PMJan 31
to vim...@googlegroups.com
It's done in MMAppController.m's fileOpen: method. I think you just need to enable "allowsMultipleSelection" (https://developer.apple.com/documentation/appkit/nsopenpanel/1530786-allowsmultipleselection) if you are trying to debug your own app.

On Wed, Jan 31, 2024 at 2:00 PM Jeff Holt <jeffrey...@gmail.com> wrote:
I'm looking at the source for the fileOpen method and I cannot figure out how it tells NSOpenPanel to respect ⌘A to select all files in the dialog.

Does anyone know how it's done?

--
--
You received this message from the "vim_mac" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_mac+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_mac/f959c994-3e15-4184-accf-8163bea9ccd2n%40googlegroups.com.

Jeff Holt

unread,
Jan 31, 2024, 8:52:23 PMJan 31
to vim...@googlegroups.com
The code I wrote does indeed set that attribute to true but ⌘ A is not working. Here's my MCV example that does everything except allow me to select all items. BTW, if I use "true" instead of "YES", then it behaves the same way.

Multiple selections work but it won't let me select all. I would have expected select all to work even in the context below.

#import <Cocoa/Cocoa.h>

void openDialog () {
    @try {
        NSOpenPanel *panel = [NSOpenPanel openPanel];
        [panel setCanChooseFiles:YES];
        [panel setCanChooseDirectories:YES];
        [panel setAllowsMultipleSelection:YES];
        if ([panel runModal] == NSModalResponseOK) {
            for ( NSURL* URL in [panel URLs] ) {
                NSLog( @"%@", [URL path] );
            }
        } else {
            NSLog( @"ok button not pressed");
        }
    } @catch (NSException *exception) {
        NSLog(@"%@", [exception callStackSymbols]);
    }
}

void setup () {
    NSWindow *myWindow;
    NSRect    graphicsRect = NSMakeRect(100.0, 350.0, 400.0, 400.0);

    myWindow = [ [NSWindow alloc]
               initWithContentRect: graphicsRect
                         styleMask:NSWindowStyleMaskTitled
                                  |NSWindowStyleMaskClosable
                                  |NSWindowStyleMaskMiniaturizable
                           backing:NSBackingStoreBuffered
                             defer:NO ];

    [myWindow setTitle:@"Open File App"];
    [myWindow makeKeyAndOrderFront: nil];
openDialog();
}

int main (  ) {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    NSApp = [NSApplication sharedApplication];
    setup();
    [NSApp run];
    [NSApp release];
    [pool release];
    return(EXIT_SUCCESS);
}

Yee Cheng Chin

unread,
Feb 4, 2024, 5:27:22 PMFeb 4
to vim...@googlegroups.com
Sorry, I'm not sure then. Feel free to debug MacVim itself and see if you could bridge the difference to see why the two work differently. The code is in MMAppController.m's fileOpen: method as I mentioned.

It's also possible that your app is eating the Cmd-A somehow. You should make sure nothing in your app is doing key handling just for testing.


Reply all
Reply to author
Forward
0 new messages