How to change an entry of a self-created menus via macro

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to change an entry of a self-created menus via macro

Jörg Schmidt-2
Hello,

I have a menu, _created by a addons.xcu-file_ in a extension.

Is it possible to change an entry of a self-created menus via macro?


With this, i 'catch' only the 'normal' menus, _not my self-created menu_:

sMenuBar = "private:resource/menubar/menubar"
oModuleCfgMgrSupplier = createUnoService("com.sun.star.ui.ModuleUIConfigurationManagerSupplier")
oModuleCfgMgr = oModuleCfgMgrSupplier.getUIConfigurationManager( "com.sun.star.text.TextDocument" )
oMenuBarSettings = oModuleCfgMgr.getSettings( sMenuBar, true )

(from: https://wiki.openoffice.org/wiki/API/Samples/StarBasic/Favorites-Menu)


What I want to achieve?

In my self-created menu entry labeled "my_item" and linked to macro "my_macro ()", I want to change this to "my_item2" and "my_macro2 ()".

It would be important that this change takes place immediately, so I do not have to open a new window to update the menu.




Greetings,
Jörg


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to change an entry of a self-created menus via macro

Keith Alcock
Jorg,

Below is code to do such a thing with C++.  Basically you need to work with
a FeatureStateEvent and set the State to the text you want.  The
documentation does not say that this is what State is used for, but looking
up that class and XStatusListener should help.

Keith

void SAL_CALL MyMenu::addStatusListener(const Reference<XStatusListener>&
xStatusListener,
const URL& url) throw (RuntimeException) {
FeatureStateEvent featureStateEvent;

featureStateEvent.Source = (XDispatch*) this;
if (url.Complete.equals(MY_MENU_LOGOUT_URL)) {
OUString state = OUSTRING("Logout ~<");
state += OUSTRING(": ") + getFirstAndLast();
featureStateEvent.State = Any(state);
}
xStatusListener->statusChanged(featureStateEvent);
}

2015-09-10 1:43 GMT-07:00 Jörg Schmidt <[hidden email]>:

> Hello,
>
> I have a menu, _created by a addons.xcu-file_ in a extension.
>
> Is it possible to change an entry of a self-created menus via macro?
>
>
> With this, i 'catch' only the 'normal' menus, _not my self-created menu_:
>
> sMenuBar = "private:resource/menubar/menubar"
> oModuleCfgMgrSupplier =
> createUnoService("com.sun.star.ui.ModuleUIConfigurationManagerSupplier")
> oModuleCfgMgr = oModuleCfgMgrSupplier.getUIConfigurationManager(
> "com.sun.star.text.TextDocument" )
> oMenuBarSettings = oModuleCfgMgr.getSettings( sMenuBar, true )
>
> (from:
> https://wiki.openoffice.org/wiki/API/Samples/StarBasic/Favorites-Menu)
>
>
> What I want to achieve?
>
> In my self-created menu entry labeled "my_item" and linked to macro
> "my_macro ()", I want to change this to "my_item2" and "my_macro2 ()".
>
> It would be important that this change takes place immediately, so I do
> not have to open a new window to update the menu.
>
>
>
>
> Greetings,
> Jörg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: How to change an entry of a self-created menus via macro

Jörg Schmidt-2
Hello,

> From: Keith Alcock [mailto:[hidden email]]
> Sent: Thursday, September 10, 2015 7:50 PM
> To: [hidden email]
> Subject: Re: How to change an entry of a self-created menus via macro
>
> Jorg,
>
> Below is code to do such a thing with C++.  Basically you
> need to work with
> a FeatureStateEvent and set the State to the text you want.  The
> documentation does not say that this is what State is used
> for, but looking
> up that class and XStatusListener should help.
>
> Keith
>
> void SAL_CALL MyMenu::addStatusListener(const
> Reference<XStatusListener>&
> xStatusListener,
> const URL& url) throw (RuntimeException) {
> FeatureStateEvent featureStateEvent;
>
> featureStateEvent.Source = (XDispatch*) this;
> if (url.Complete.equals(MY_MENU_LOGOUT_URL)) {
> OUString state = OUSTRING("Logout ~<");
> state += OUSTRING(": ") + getFirstAndLast();
> featureStateEvent.State = Any(state);
> }
> xStatusListener->statusChanged(featureStateEvent);
> }

Thank you, but excuse me, i think that does not help me.

My problem is that I can not access the specific menu bar. And to register a listener I need access to the specific menu bar.

In my understanding (I do not speak C++) is "const Reference" or "const URL" this reference (the specific menu bars object), only that I have not.


For example:
in my code would be:

oMenuBarSettings.Count = 9

And:
oMenuBarSettings.GetByIndex(1)

one specific menu bar (in this Case "1" the edit menu)

But none of the 9 menu's is the menu that I have added my addon.xcu. My menu is therefore not part of "oMenuBarSettings". Why? How can I still access my menu?




Greetings,
Jörg


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]