NSOpenPanel Do not allow shortcut key like cmd+v

Discussion in 'Mac Programming' started by ychaturvedi, Oct 13, 2011.

  1. ychaturvedi, Oct 13, 2011
    Last edited by a moderator: Oct 13, 2011

    ychaturvedi macrumors newbie

    May 23, 2011

    I am using a simple code that open a file open dialog and i am working in wxWidgets so i make a file test.mm file.

    NSOpenPanel*		openPanel = [NSOpenPanel openPanel];
    	// ask the user for file
    	[openPanel setAllowsMultipleSelection:YES];
    	[openPanel setDelegate:self];
    	[openPanel setTitle:@"Choose some AIFF files to burn onto CD."];
    	[openPanel setPrompt:@"Select"];
    	if ([openPanel runModalForTypes:nil] == NSOKButton)
    /// Some code here 
    but i have problem here that when get open dialog and try to press / to paste a file path it do not allow me to paste path using key cmd+v
    What may be the reason do not know ?
    Please help

  2. jiminaus, Oct 13, 2011
    Last edited: Oct 13, 2011

    jiminaus macrumors 65816


    Dec 16, 2010
    In Mac OS X, key equivalents like Cmd+V are driven by the main menu bar. That's why they're called key equivalents. They're the keyboard equivalent to clicking an item in the main menu bar at top of the screen.

    To get Cmd+V working in an NSOpenPanel, you need a menu item in your main menu bar with a Cmd+V key equivalent. This typically (if not always) is the Paste menu item in the Edit menu.

    To get pasting to work when Cmd+V is hit, organise for a paste message to be sent to the text field that has focus. We do that when writing native Mac OS X Cocoa by connecting the Paste menu item to the first responder pseudo-object and having it send a paste message when clicked. The first responder pseudo-object in Cocoa is placeholder for whichever control has the focus at the time the menu item is activated.

    Perhaps you need to find the equivalent to all of this in wxWidgets.

    EDIT: I've just read on the wxMac port page of the wxWidgets documentation that wxWidgets uses the C-based Carbon API in the Max OS X port and not the Objective-C-based Cocoa API. I don't know Carbon. Perhaps there's a different strategy in Carbon.

Share This Page