[haiku-development] Re: Help regarding Dynamic Menu in Tracker

  • From: "Adrien Destugues" <pulkomandy@xxxxxxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Thu, 26 Apr 2018 12:44:02 +0000

26 avril 2018 14:31 "Hrishi Hiraskar" <hrishihiraskar@xxxxxxxxx> a écrit:

Hie

For my GSoC project, I'm experimenting with creating a Dymanic menu which 
will be added to the
Tracker's Root Menu be an addon.

I was able to pass the BMenu pointer in order to populate menu and I was also 
able to populate
menu.
But I wasn't able to do implement what happens on clicking the menu item. 
(Basically on click event
of the items added).

I first created a Fake Window and overrided it's MessageReceived function to 
call my function. And
then SetTarget of menu to this window.
This didn't work.

Then I created a class inherited from BMenu and overrided the MessageReceived 
function. And
SetTargetForItems as this.
This also didn't work.

In both the cases, MessageReceived is not being called. I think I'm missing 
something.

You don't need a "fake" window for receiving messages, you need a BHandler, and 
possibly a BLooper (unless you can attach your handler to an existing looper - 
usually the be_app, which is the main application looper.

Possible problems with your solution:
- The window looper is not running. This would be the case if you never call 
Show() (which starts the looper for a window and makes it possible to receive 
messages)
- The menu items are re-targetted at some later point (some code in Tracker is 
using SetTargetForItems to get all the messages from the menu sent to its own 
handler).

The first is easily solved by using the be_app looper (have a look at the 
BLooper and BApplication documentation in the be book).
The second is less easily solved, as one would need to somehow exclude these 
items from the retargetting.

-- 
Adrien.

Other related posts: