views:

259

answers:

3

For some reason, an NSTextField isn't allowing me to paste anything into it using Command+V, though I can paste into it if I right-click and click 'Paste'. Why is this happening and how do I fix it?

+1  A: 

What happens when you select "Edit > Paste" from your application's main menu?

Darren
My application sits in the menu bar, it doesn't have a main menu. Could that be the reason? If so, how do I fix it?
Chetan
Yes, you need something map your keyboard commands to actions (like paste:), and to map the actions to the First Responder. Setting up a menu is the easiest way to do that. Even if you app's Dock icon and menu bar are hidden, you main menu will still receive keyboard commands.
Darren
I made a main menu for my application now, but now when I click "Edit", the "Paste" button and all others are grayed out even why my cursor is in a text field. How do I fix this?
Chetan
Chetan: You need to hook up the menu items to First Responder.
Peter Hosey
A: 

Did you:

  • Assign a key equivalent to any of your controls (NSButtons, NSMenuItems, ...) that are responding before the Main Menu

-- or --

  • Delete the whole Menu
  • the Edit NSMenuItem
  • the Paste NSMenuItem The "Paste" Shortcut is a key equivalent of the "Paste" NSMenuItem
weichsel
A: 

I fixed it by linking the "Paste" button in my NSMenu Main Menu to the First Responder's paste: command.

Chetan
That's a menu item (NSMenuItem), not a button (NSButton), and an action message selector, not a command (HICommand).
Peter Hosey