Adding a new button in other toolbars in extension

I’m trying to write an extension, providing a button beside “Justified” in the Formatting toolbar, making the paragraph aligned justified but the last line is justified as well, instead of align to the left. So far the button of “Justified” in Formatting toolbar only makes paragraph justified with the last line align to the left.

No problem with the macro and created the extension. However, I couldn’t put a button in the Formatting toolbar. I could add a button in the end of standardbar with the following code in Addons.xcu:

<node oor:name="N001" oor:op="replace">
					<prop oor:name="MergeContext" oor:type="xs:string">
						<value/>
					</prop>
					<prop oor:name="MergeToolBar" oor:type="xs:string">
						<value>standardbar</value>
					</prop>
					<prop oor:name="MergePoint" oor:type="xs:string">
						<value>.uno:ExtendedHelp</value>
					</prop>
					<prop oor:name="MergeCommand" oor:type="xs:string">
						<value>AddAfter</value>
					</prop>
					<prop oor:name="MergeFallback" oor:type="xs:string">
						<value>AddFirst</value>
					</prop>
					<node oor:name="ToolBarItems">
						<node oor:name="N002" oor:op="replace">
							<prop oor:name="Context" oor:type="xs:string">
								<value/>
							</prop>
							<prop oor:name="Title">
								<value xml:lang="en-US">Distributed Justified</value>
								<value xml:lang="zh-TW">分散對齊</value>
							</prop>
							<prop oor:name="URL" oor:type="xs:string">
								<value>vnd.sun.star.script:DistributedJustified.distributed-justified.main?language=Basic&amp;location=application</value>
							</prop>
							<prop oor:name="Target" oor:type="xs:string">
								<value>_self</value>
							</prop>
						</node> <!-- N002 -->
					</node> <!-- ToolBarItems -->
				</node> <!-- N001 -->

The button is created and can perform what I want.

However I didn’t find any document telling me the name of other toolbars.

I dug into the code, and found that the standardbar.xml is in sw/uiconfig/swriter/toolbar/ . Then I found the “Justified” button is defined in textstylebar.xml :

 <toolbar:toolbaritem xlink:href=".uno:LeftPara" toolbar:visible="false"/>
 <toolbar:toolbaritem xlink:href=".uno:CenterPara" toolbar:visible="false"/>
 <toolbar:toolbaritem xlink:href=".uno:RightPara" toolbar:visible="false"/>
 <toolbar:toolbaritem xlink:href=".uno:JustifyPara" toolbar:visible="false"/>

So I tried to change my code in Addons.xcu as:

					<prop oor:name="MergeContext" oor:type="xs:string">
						<value/>
					</prop>
					<prop oor:name="MergeToolBar" oor:type="xs:string">
						<value>textstylebar</value>
					</prop>
					<prop oor:name="MergePoint" oor:type="xs:string">
						<value>.uno:JustifyPara</value>
					</prop>
					<prop oor:name="MergeCommand" oor:type="xs:string">
						<value>AddAfter</value>
					</prop>

But it didn’t work. The button was not there.

So my question here is:

  1. Where can I find out the name of other toolbars, used in MergeToolBar ? Any document talking about it? I didn’t find one.
  2. If the name follows the filename defined in uiconfig/swriter/toolbar, why did my change not work? Anything I missed?


IIUC you want to add a button to the Formatting bar. The textstylebar.xml file refers to the Formatting (Styles) bar.



Try using textobjectbar.xml in your Addons.xcu.

Look:
https://wiki.documentfoundation.org/Framework/Article/Addon_Menu_Toolbar_Merging

Try with:
textobjectbar

@elmau
Thank you for your vigilance! You’re absolutely right: it should simply read
textobjectbar
(mindless copy-paste got me lost). :flushed:

On the wiki page we talk about a .xcs file, but I have seen the Merge instruction in .xcu files

  • Is a .xcs file necessary or is it an ancient file extension that is replaced with .xcu?
  • Should the extension with .xcs and .xcu files be distributed?

An .xcs file is a schema configuration file (to be used to deeper integrate into the LibreOffice settings pages for instance). Adding buttons or menu entries do not require any such file, AFAIK.