Page 1 of 1

Toggle the image on a extension toolbar button

Posted: Thu Dec 21, 2023 11:25 am
by northshaman
Hi!
Is there any way to implement toggle the image on a extension toolbar button when you click on it? In few topics on this forum that I find, it's not possible to get properties of the buttons from this panel in runtime. Maybe there is some other way? For example, through an xcu file?
I appreciate your help in advance.

Re: Toggle the image on a extension toolbar button

Posted: Thu Dec 21, 2023 7:40 pm
by JeJe
Have your extension create a non-extension toolbar after installation.

(Edit: if that would work)

Re: Toggle the image on a extension toolbar button

Posted: Fri Dec 22, 2023 11:39 am
by northshaman
I can add or remove buttons on a standardBar. But I want to do the same with my extended panel. For example, in runtime, add or remove a button, change the button image, hide or show buttons.

Re: Toggle the image on a extension toolbar button

Posted: Fri Dec 22, 2023 1:19 pm
by JeJe
Is the button on a toolbar or a panel?

Edit: A panel is something like the navigator or the sidebar panels. A Toolbar is like the formatting toolbar.

Re: Toggle the image on a extension toolbar button

Posted: Fri Dec 22, 2023 3:37 pm
by northshaman
in the configuration file it's called toolbar.
Here's part of my xcu configuration:

Code: Select all

<node oor:name="OfficeToolBar">
	<node oor:name="sumra.dataunit.DataUnitExtension.toolbar" oor:op="replace">
		<prop oor:name="Title" oor:type="xs:string">
			<value>Data Unit Extension</value>
		</prop>
		<node oor:name="t01" oor:op="replace">
			<prop oor:name="URL" oor:type="xs:string">
				<value>com.data.Data?CONNECTION_SETTING</value>
			</prop>
			<prop oor:name="Target" oor:type="xs:string">
				<value>_self</value>
			</prop>
			<prop oor:name="Context" oor:type="xs:string">
				<value>com.sun.star.text.TextDocument</value>
			</prop>
			<prop oor:name="Title" oor:type="xs:string">
				<value xml:lang="en-US">Connection settings</value>
			</prop>
		</node>
		<node oor:name="t02" oor:op="replace">
			<prop oor:name="URL" oor:type="xs:string">
				<value>service:com.data.ChangeMode</value>
			</prop>
			<prop oor:name="Target" oor:type="xs:string">
				<value>_self</value>
			</prop>
			<prop oor:name="Context" oor:type="xs:string">
				<value>com.sun.star.sheet.TextDocument</value>
			</prop>
			<prop oor:name="Title" oor:type="xs:string">
				<value xml:lang="en-US">Change view mode</value>
			</prop>
		</node>
	</node>
</node>
And this how it's looks in office:
Image

Re: Toggle the image on a extension toolbar button

Posted: Fri Dec 22, 2023 11:41 pm
by JeJe
My suggestion is instead of creating a toolbar tied in with the extension - add a normal toolbar after the extension is installed to calc - and then via the toolbar's settings in the frame's layout manager you can modify the buttons at runtime.

The normal way of showing a change in the button is to highlite it though, not change the icon.

Another easy way of showing a changed button state would be to change the text color for the toolbar... eg red text signifying "on". This change would apply to all buttons on the toolbar though, so not suitable if you have more than that one button.

Re: Toggle the image on a extension toolbar button

Posted: Mon Dec 25, 2023 8:24 am
by northshaman
Thanks for your answers!
Dynamically add buttons to standard toolbar works. To change the button icon, I use two different urls and two buttons with the same command but different arguments. When you click on the button, I delete button and insert another one in its place. But with this approach i get proplems with "jumping" buttons on the toolbar. After inserting button, a gap appears between the previous button and the inserted one, which collapse when the window size is changed. Can you tell me what interface or method can be used to update the window display after replacing the button?
I tried to use this code, but it doesn't work =(

Code: Select all

/****/
XUIElementSettings xuiElementSettings = UnoRuntime.queryInterface(XUIElementSettings.class, element);
/****/
xuiElementSettings.setSettings(settings);
xuiElementSettings.updateSettings();
/****/
XUpdatable updatable = UnoRuntime.queryInterface(XUpdatable.class, e);
updatable.update();

Re: Toggle the image on a extension toolbar button

Posted: Mon Dec 25, 2023 11:53 am
by JeJe
There are two ways of changing the toolbar - one is to change it for the current controller/frame's layout manager which doesn't affect other frames or new frames. The other is to change the toolbar for the module (eg Writer module) so all frames are affected.

In either case MRI should help you explore the layout manager to find a way of refreshing the current toolbar

viewtopic.php?t=49294

Re: Toggle the image on a extension toolbar button

Posted: Mon Dec 25, 2023 11:56 am
by northshaman
Thank you!