Dock Menu

I was wondering if Xojo could put up some example code using declares to implement a dock menu, since isn’t this base functionality we should be getting?

Thank you

It should be doable through declares… There is nothing in macoslib, but it looks like there is something (NSApplicationDelegateMBS) in the MBS plugins to allow you to do it, hopefully Christian can direct you better through his documentation…

I’m assuming this is for OSX. You will have to dynamically implement the delegate method here:
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/NSApplicationDelegate_Protocol/#//apple_ref/occ/intfm/NSApplicationDelegate/applicationDockMenu:
And the appropriate handlers for each of the options. MacOSLib should make this easier but any solution will involve hacking the Xojo provided delegate object and will be advised against by Xojo because it could break.

I really don’t think we should have to purchase a plugin for this. It’s not like we’re trying to do something nonstandard or super fancy here.

Technically if you have to replace the application delegate, then it is quite a bit of work and a PITA! It will break some of the existing application events that Xojo already handles.

I use Christian’s excellent MBS plugins for this (NSStatusItem family). You should also sign on to this feature request in Feedback:

<https://xojo.com/issue/1792>

As in “could break your app entirely and because you’ve done this its NOT a bug” kind of don’t do this warning

What do you mean exactly by “dock menu” ?

From Joe Ranieri on the old forum http://forums.realsoftware.com/viewtopic.php?p=223109#p223109

[quote]…you have to create a new Objective-C class that implements the specific NSApplication delegate methods you care about (applicationDockMenu:). Then you need to set that class as the NSApplication’s delegate. Oh, and that Objective-C class has to forward all messages it doesn’t explicitly handle on to the original delegate the RB framework installed.

Also note that this isn’t explicitly supported and you might run into issues …[/quote]

This is a rare case where a Xojo employee actually mentions the hack :slight_smile:

The built in delegate is a class named XOJApplicationController and only has these 5 methods you’d need to forward
0) applicationDidFinishLaunching:

  1. applicationOpenUntitledFile:
  2. application:openFile:
  3. applicationDidBecomeActive:
  4. applicationDidResignActive:

Since applicationDockMenu: isn’t there I took the easier approach of simply adding it to XOJApplicationController. Then in the implementation make an NSMenu with items and return it.

I won’t post the code but here’s the messy proof of concept experiment
http://home.comcast.net/~trochoid/dockMenu.zip

This link helped: http://cocoadevcentral.com/articles/000036.php

For a real implementation I’d first check if applicationDockMenu: is already present and alert yourself. Then if Xojo ever adds it you’ll see the change and have to refactor. I’d assume if it gets added you’d have access directly in Xojo and can drop the declares.

If you go the forwarding route you can implement all the methods or just the 5 with a check for them ever changing.

And use macoslib for the NSMenu.

On OS X, click down on an app in the dock for a second and a menu pops up.

You should forward everything, including messages that aren’t part of NSApplicationDelegate.

I see. I thought the said menu appeared only with Right click. Given the deep down nature of everything finder, not mentioning the highly off limit nature of anything in there, what one thinks as ‘not super fancy’ must indeed be quite a hack.

What seems possible is to display a small window containing the elements of a menu in App.HandleAppleEvent, after verifying that was a click. Since it will be displayed before the one second hold, it may do. It will work only with left click.

If one is not too cheap, though, the ideal and easiest seems to be to use NSApplicationDelegateMBS, since Christian has already suffered to produce a working solution…

[quote=199131:@Michel Bujardet]I see. I thought the said menu appeared only with Right click. Given the deep down nature of everything finder, not mentioning the highly off limit nature of anything in there, what one thinks as ‘not super fancy’ must indeed be quite a hack.
[/quote]

Indeed, and a hack it should not be.

[quote=199131:@Michel Bujardet]
If one is not too cheap, though, the ideal and easiest seems to be to use NSApplicationDelegateMBS, since Christian has already suffered to produce a working solution…[/quote]

If one purchased Xojo instead of using Xcode and Swift for free, one is not too cheap.

I put a lot of work into my delegate classes for NSApplication and NSWindow to make sure they properly forward things and only do their own stuff if you need it.
I want it to be compatible to all Xojo/Real Studio versions and not cause trouble.

And believe me, the way to a good implementation takes time and has a lot of pitfalls.

XCode is nice, but also comes with a very steep learning curve. So in effect it is not really free : it costs a lot of time to master. Depending on how much you value your time, Xcode costs in fact at least thousands of dollars.

Xojo costs 100 dollars to start with. But one can produce a program in days.

Declares and other free developing solutions are nice. MacOSLib and declares posted in the forum are a solution, until you find something that does not exist yet (as you did). Nothing wrong about deciphering patiently the Mac developer Library and spend a few hours or weeks to make that work in Xojo. I do when I have no choice. Otherwise, it is way faster to buy MBS Complete which Christian has spent years perfecting and have an instant success.

Third party tools allows you to purchase countless hours of development and rip the result in minutes. IMHO, that is pretty cheap.

and if you all don’t buy third party stuff, there will be no stuff…

I really would like to continue doing my plugins for another ten years instead of getting a real job.

You have one: Plugin Builder @ MBS

Choose a job you love, and you will never have to work a day in your life.

Confucius

Christian, I appreciate all the support you give to this community. Thank you

[quote=199101:@Tim Jones]I use Christian’s excellent MBS plugins for this (NSStatusItem family). You should also sign on to this feature request in Feedback:

<https://xojo.com/issue/1792>[/quote]

Is a Dock menu part of the NSStatusItem family?

it’s part of Cocoa plugins.
See example projects.

And needs only a license for Cocoa plugin.