Re: Thesaurus plugin, dynamic menu help needed


Subject: Re: Thesaurus plugin, dynamic menu help needed
From: Joaquín Cuenca Abela (cuenca@pacaterie.u-psud.fr)
Date: Wed Sep 12 2001 - 07:30:12 CDT


On 11 Sep 2001 16:44:19 -0500, Jared Davis wrote:
[snip]
>
> The plugin idea is working out as slick as can be, but we are
> running into a problem: we don't know how to add a "thesaurus"
> entry to the Tools menu when the plugin is activated, nor do we
> know how to create a keyboard shortcut (shift+f7) to activate the
> thesaurus with.

I will try to explain it here (how to add a new menu item at runtime,
right now there is no way that I'm aware of to add a keyboard shortcut):

Abi menus are contained in three objects, which are instances of:

        * EV_Menu_ActionSet
        * EV_Menu_Layout
        * EV_Menu_LabelSet

Each class is a kind of container, and each contained item has also an
index that lies them together. (Each menu item is composed by 3 objects
EV_Menu_LayoutItem, EV_Menu_Label & EV_Menu_Action, and the 3 objects
that refer to the same menu item have the same XAP_Menu_Id)

EV_Menu_Action contains the "stuff that an item menu can do" (their
contained items says things like: "this menu item is not checkable, it
raises a dialog box, and when it's clicked, it calls the method "blah"")

EV_Menu_Layout contains items that says if we are speaking about a
Normal item, a BeginSubMenu item, a EndSubMenu item, etc. and the order
in which these items should be showed.

EV_Menu_LabelSet contains items that says what it's the label and status
bar label of each menu item.

So, in order to add a new menu item you should use the new functions of
these objects:

EV_Menu_Layout::addLayoutItem
EV_Menu_ActionSet::addAction
EV_Menu_LabelSet::addLabel

You will pass to addLayoutItem an integer saying what is the desired
position in the menu[*] and the kind (Normal, BeginSubMenu, etc.) of
item that you want to create, and it will give you back an UT_Menu_Id
that you should use to create their brothers Action & Label.

btw, the process becomes quickly hard, specially if you want to
dynamically create a new submenu, or something like that.

In order to make the process easier I also added a new method:

EV_Menu::addPath(const UT_String& path)

So you can do something as:

// ... code that activates AikSaurus
...

m_pUnixMenu->addPath("/&Tools/P&lugins/AikSaurus");

...

The problem is that this method will bind the new AikSaurus menu entry
with the action named "scriptPlay". You may want to add another
argument to addPath to parametrize the name of the called action. I not
did that because there are some other issues: the name of the action is
not the only thing hardcoded in this method, but also the parameters of
the action, etc., anyway just adding this new parameter may be
everything you need.

[*]: If you don't know what is the exact number of the position in the
menu that you want, you may iterate through EV_Menu_LabelSet until you
find a know label item (for instance, if you want to put a new item
after the item named "P&lugins", you should first search for
"P&lugins"), then you pick its XAP_Menu_Id, and you ask EV_Menu_Layout
for the layout pos of the item with the same XAP_Menu_Id. You add 1 to
this number (because you want to put your new item *after* "P&lugins"),
and this will be the layout number that you should use.

Note that I've not worked in the i18n issues (for instance, the search
looking for a known name will fail if the user is non english. Also I
don't know how you can provide internacionalized names for your new menu
item). One way to solve that problem may be to just put
"/&Tools/P&lugins/AikSaurus" in the list of translatable strings instead
of hardcoding it.

Hope that it helps

Cheers,

-- 
Joaquín Cuenca Abela (still shocked by the NY news)
cuenca@celium.net



This archive was generated by hypermail 2b25 : Wed Sep 12 2001 - 08:14:37 CDT