Lately I'm working a lot on the menus of my program. There is
something that I want to do and I don't know if it's possible or if
I'm thinking in the right direction.
In my menu bar I have a Node menu and a Block menu. The node menu lets
you do all kinds of things to the active node, the block menu lets you
do all kinds of things to the active block. (A block is something that
contains a lot of nodes, so "the active block" means "the block that
the active node is a part of, if it is a part of one".)
Now, in the menu bar these two menus are separate. But when you right
click a node on one of the widgets, I want a context menu to pop up,
with both the node and the block menus. I could make one which has
these as submenus in the context menu, but I think it will be a bit
weird. (Because context menus usually don't have a complex tree
structure like menu bars.)
What I'd like to have is the node menu and the block menu concatenated
to each other in the same menu. So if the node menu has 4 items, and
the block menu has 3 items, the context menu will have 7 items.
So sure, I could create it manually. But is there some way to
concatenate them automatically? I don't want to set up the button
bindings/enablings twice.
No, you're going to have to make a new menu anyway since the others are in use in the menubar so they can't be used for the popup. Just create a function for each that adds the items (and binds the events) to a menu. When making the menu bar call those functions with a separate menu for each of them, and when making the popup call them with the same menu so the items for both sets end up on the same menu.
···
On 5/5/10 6:08 AM, cool-RR wrote:
So sure, I could create it manually. But is there some way to
concatenate them automatically? I don't want to set up the button
bindings/enablings twice.
Why will I have to create a new menu anyway? Is there a problem using the same menu for both popup and menu bar? Because I tried doing it now and it seems to work.
So sure, I could create it manually. But is there some way to
concatenate them automatically? I don’t want to set up the button
bindings/enablings twice.
No, you’re going to have to make a new menu anyway since the others are in use in the menubar so they can’t be used for the popup. Just create a function for each that adds the items (and binds the events) to a menu. When making the menu bar call those functions with a separate menu for each of them, and when making the popup call them with the same menu so the items for both sets end up on the same menu.
So sure, I could create it manually. But is there some way to
concatenate them automatically? I don't want to set up the button
bindings/enablings twice.
No, you're going to have to make a new menu anyway since the others
are in use in the menubar so they can't be used for the popup. Just
create a function for each that adds the items (and binds the
events) to a menu. When making the menu bar call those functions
with a separate menu for each of them, and when making the popup
call them with the same menu so the items for both sets end up on
the same menu.
--
Robin Dunn
Why will I have to create a new menu anyway? Is there a problem using
the same menu for both popup and menu bar?
Yes. Menus on the menubar or submenus are owned by the menubar or the parent menu, and will be destroyed when the owner is. Popup menus have a different lifetime. If you reuse the menu as a popup then it is possible that the menu could be destroyed twice which will result in a crash.
Because I tried doing it now
and it seems to work.
That would be what I call a happy accident.
···
On 5/5/10 12:43 PM, cool-RR wrote:
On Wed, May 5, 2010 at 5:30 PM, Robin Dunn <robin@alldunn.com > <mailto:robin@alldunn.com>> wrote:
On 5/5/10 6:08 AM, cool-RR wrote:
On 5/5/10 6:08 AM, cool-RR wrote:
So sure, I could create it manually. But is there some way to
concatenate them automatically? I don't want to set up the button
bindings/enablings twice.
No, you're going to have to make a new menu anyway since the others
are in use in the menubar so they can't be used for the popup. Just
create a function for each that adds the items (and binds the
events) to a menu. When making the menu bar call those functions
with a separate menu for each of them, and when making the popup
call them with the same menu so the items for both sets end up on
the same menu.
--
Robin Dunn
Why will I have to create a new menu anyway? Is there a problem using
the same menu for both popup and menu bar?
Yes. Menus on the menubar or submenus are owned by the menubar or the parent menu, and will be destroyed when the owner is. Popup menus have a different lifetime. If you reuse the menu as a popup then it is possible that the menu could be destroyed twice which will result in a crash.