Insert Position
Controlling where a Menu Entry is inserted
Menus are added to the bottom of the Menu list when created by default. With a slight change, it is possible to control where our menus are inserted. This can be especially helpful when adding menu entries to existing menus.
The New __init__
We'll need to change our __init__ function in order to take advantage of the insert position:
The big change here is that if an insert_policy
is provided, we need to use a slightly different method to insert the menu in our desired location
Creating the Insert Position Object
The Insert Position class is a bit basic, we just need to tell it:
An existing Menu's name that we want this insert to be in reference of
The Insert Type, which is how we want our new menu inserted in relation to the given entry's name
Note: While the section
is not required on the insert policy, we will need to make sure we're adding our Menu to the same section as the existing Menu Entry.
Run it!
In this example, we're adding our menu to the Editor's Edit dropdown menu AFTER the existing Paste menu option:
The results:
Last updated