Intercepting the Cocoa contextual menu

I can’t seem to intercept “Paste” if chosen from the contextual menu in the Cocoa version of my app. In other words, the field’s ContextualMenuAction never seems to fire. Is there a trick? (This is the default contextual menu provided by Cocoa.)

Cut/Copy/Paste/Select All are all usually intercepted by the OS… and applied to what ever the active control is at the time.

One thing I have found… is you CAN intercept them if on the MAIN MENU you remove the short-cut keys (or the menu entries themself)

HOWEVER [fair warning]… IF YOU DO SO, THEN YOU MUST INTERCEPT THEM AND DEAL WITH ALL OF THEM…

And I have found that it is this way regardless of COCOA.

I have no trouble intercepting Cut/Copy/Paste/Select All from the menubar in any custom field, and can do it on all platforms.

I constructed my contextual menu under Carbon, but ran into problems doing that in Cocoa so I rely on the native one. As such, I can’t intercept it.

[quote=31045:@Kem Tekinay]I have no trouble intercepting Cut/Copy/Paste/Select All from the menubar in any custom field, and can do it on all platforms.

I constructed my contextual menu under Carbon, but ran into problems doing that in Cocoa so I rely on the native one. As such, I can’t intercept it.[/quote]

Forgive me if I’m not interpreting the question correctly, but it sounds like you want the native TextArea contextual menu and be able to customize it? This isn’t currently possible, but you can build your own in the ConstructContextualMenu event and return True to have the framework present that.

At the moment, I don’t need to customize it, but if I understand you correctly, I can’t intercept “Paste” from the native contextual menu , only from a customized one?

Correct.

Is that not possible even with declares? That seems like a common task. It’s something I will need in the future: my app has a few custom commands I want to show up on the contextual menu in a textArea, but I still want it to display the built-in Cocoa commands (that’s half the point of moving to Cocoa).

I don’t need to intercept the Paste command or others like Kem wants – let the OS handle those – but I would want access to my own contextual menu items.

I’ve been able to construct my own Cocoa contextual menu that also contains some important system items by using MacOSLib and cloning the EditSpellingandGrammar menu. Here’s an made-up example that would include options for spell checking in the ConstructContextualMenu event. (Ignore the childmenu, I use that to set the keyboard shortcuts, not shown here).

dim spellingMenu as MenuItem = EditSpellingandGrammar.clone
dim childMenu as MenuItem

childMenu = spellingMenu.child(“CocoSpellingandGrammarShowSpellingandGrammaraMenuItemEditSpellingLocalizedTextEditSpellingandGrammar”) //Show Spelling and Grammar

childMenu = spellingMenu.child(“SpellingandGrammarCheckDocumentNow”)

spellingMenu.Enabled = true //don’t know why, but this is necessary after the first invocation.
base.append (spellingMenu)

@Jonathan Ashwell
Hello I’m finding a way to customize the mac OSX contextual menu, like google drive or dropbox do. I need an how to realize for my apps custom items into the contexual menu when clicking on a file or folder.
Any help ?
Thanks
C

Sorry, I have no idea how to do that in the Finder. My code was for use in Xojo apps.

Maybe someone in this forum have and idea on how to customize the osx contextual menu by declares ?
Thanks
C

[quote=178282:@Carlo De Simone]Maybe someone in this forum have and idea on how to customize the osx contextual menu by declares ?
Thanks
C[/quote]

http://stackoverflow.com/questions/6515965/mac-contextual-menu/6516012#6516012

I know about the possibility to create menu item under services… and there are MBS plugin to do so, but I need another approach, like this:

I have an old project to do this. Let me see if I can dig it up.

it would be very helpfull for me and for all fourum too.
THanks
C

Ok, I just realized that my project only shows how to put something in the Services menu, not create your own menu next to Services like Google Drive. I’m not sure how that is possible.

Google Drive OSX client and DropBox client too have these features.
Any idea ?

Hello.
With the upcoming of 64bit compilation in Xojo , there is any way to integrate a custom item in the finder contextual menu ?
What kind of approach use google drive or dropbox application to do so ?

[quote=31306:@Jonathan Ashwell]I’ve been able to construct my own Cocoa contextual menu that also contains some important system items by using MacOSLib and cloning the EditSpellingandGrammar menu. Here’s an made-up example that would include options for spell checking in the ConstructContextualMenu event. (Ignore the childmenu, I use that to set the keyboard shortcuts, not shown here).

dim spellingMenu as MenuItem = EditSpellingandGrammar.clone
dim childMenu as MenuItem

childMenu = spellingMenu.child(“CocoSpellingandGrammarShowSpellingandGrammaraMenuItemEditSpellingLocalizedTextEditSpellingandGrammar”) //Show Spelling and Grammar

childMenu = spellingMenu.child(“SpellingandGrammarCheckDocumentNow”)

spellingMenu.Enabled = true //don’t know why, but this is necessary after the first invocation.
base.append (spellingMenu)[/quote]

Hi Jonathan,

Could you provide an example project?

I am not finding EditSpellingandGrammar in MacOSLib.

Thanks.

Lennox

Are those not just Contextual Menu Item plugins?

/Library/Contextual Menu Items
/User/YOU/Library/Contextual Menu Items