Help - Search - Members - Calendar
Full Version: Dynamically creating context menu commands
Hydrogenaudio Forums > Hosted Forums > foobar2000 > Development - (fb2k)
bubbleguuum
Is creating / removing context menus dynamically possible ?

I'm not talking about having menu with dynamic entries, but registering/unregistering menus.

Declaring statically a menu this way works:

CODE


class contextmenu : public  contextmenu_item_simple {
...
};

static contextmenu_item_factory_t<contextmenu> contextmenu_factory;



I'd like to be able to do the last line dynamically so I tried:

CODE


service_ptr_t<contextmenu > menu =
        new service_impl_single_t<contextmenu >();



This does not work, the menu interface (get_item_count(), etc) is never called

Any idea if this is possible ? Can there be several root context menu per plugin ?
foosion
QUOTE(bubbleguuum @ Jun 15 2007, 23:53) *
Is creating / removing context menus dynamically possible ?

As far as context menu commands are concerned, yes, that is definitely possible. However you cannot dynamically create instances of a contextmenu_item factories; the system will not even know that they are there. The same applies for all service factories, but there is a way to loosen the restriction that all service factories have to be defined at compile time. Since I assume this has to do with your Java bindings for the foobar2000 SDK, I will give you the details in the relevant thread.

QUOTE(bubbleguuum @ Jun 15 2007, 23:53) *
Can there be several root context menu per plugin ?

This is entirely possible (and legal).

I think the documentation does not explicitly mention this, but the return value of contextmenu_item::get_num_items() must be constant for a given instance. So if you use service_factory_t (instead of service_factory_single_t), you can vary the number of items you provide at runtime. You then need to keep data about available items in a global variable and take a snapshot of that data in the object's constructor.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.