2021-04-04

56: Basics of Creating Your LibreOffice or OpenOffice Extension

<The previous article in this series | The table of contents of this series | The next article in this series>

For registering macros (Python, Basic, etc.), UNO interfaces, UNO components, UNO services, key bindings, menu items, and/or tool buttons.

Topics


About: LibreOffice
About: Apache OpenOffice

The table of contents of this article


Starting Context



Target Context


  • The reader will know the basics of how to create any LibreOffice or Apache OpenOffice extension.

Orientation


There is an article on creating any LibreOffice or Apache OpenOffice extension that contains any Python macros.

There is an article on invoking any LibreOffice or Apache OpenOffice macro (including ones that are contained in extensions) from your program.

There will be some articles on how to put in specific ingredients into any extension.


Main Body

Stage Direction
Here are Hypothesizer 7, Objector 56A, and Objector 56B in front of a computer.


1: Why Does One Want to Create an Extension?


Hypothesizer 7
You have noticed that there is a menu item, "Tools" -> "Extension Manager...", in the LibreOffice or Apache OpenOffice GUI, do you not?

Objector 56A
Ah, I can install an extension that has been created by someone else, can't I?

Hypothesizer 7
Sir, it does not have to be "someone else" but you.

Objector 56A
Me? Who do you think I am?

Hypothesizer 7
I do not know, sir, an emperor, perhaps?

Objector 56A
I am a bachelor.

Hypothesizer 7
. . . Congratulations! But be assured that even bachelors can create extensions.

Objector 56B
I have recently got divorced . . .

Hypothesizer 7
Well, madam, I do not know whether I should offer my congratulations or my condolences, but anyway, that will not prevent you from creating an extension.

Objector 56A
But why should I create an extension?

Hypothesizer 7
Your extension can contain macros, UNO interfaces, UNO components, UNO services, key bindings, menu items, and/or tool buttons.

Objector 56A
So? I can create macros without any help from any extension.

Hypothesizer 7
You may, but packaging a set of some macros into an extension will be expedient for distributing them or even for managing them for yourself.

Objector 56A
Will it?

Hypothesizer 7
I think it will, and some things like key bindings will be best registered via extensions.

Objector 56A
"best" . . .?, so it does not have to be via extensions . . .

Hypothesizer 7
They will be able to be registered by tinkering some configuration files of LibreOffice or Apache OpenOffice, but such a way will not be any better than registering them via extensions, in any way.

Objector 56B
Did you say that I could register key bindings?

Hypothesizer 7
Yes I did, madam.

Objector 56B
You know, I have got divorced . . .

Hypothesizer 7
Even divorcees can register key bindings all right.

Objector 56B
"key binding" means that when I press 'Ctrl' + 'D', my corresponding macro is executed, does it not?

Hypothesizer 7
Yes, it can be 'Shift' + 'Ctrl', 'Alt', or 'Shift' + ’Alt’, instead of 'Ctrl', or a function key can be used, to be sure, and it can be any usual key instead of 'D'.

Objector 56B
'D' is for 'Divorce' . . .


2: The Structure of Extension File


Hypothesizer 7
Any LibreOffice or Apache OpenOffice extension file is a ZIP file.

Objector 56A
What do you mean by "extension file"?

Hypothesizer 7
As extension is a functionality comprised of some files, those files are packaged into a file, which is an extension file, which is distributed and used in order to install the extension.

Objector 56A
So, creating an extension means creating an extension file.

Hypothesizer 7
The structure of the ingredients of the extension file is like this.

META-INF
	manifest.xml
KeyBindings.xml
GuiItems.xml
UnoServiceComponents.xml
forLinux64Bits.UnoServiceComponents.xml
. . .
Scripts
	python
		. . .
	java
		. . .
	javascript
		. . .
	beanshell
		. . .
basicLibraries
	. . .
%Jar file name%
%UNO datum types merged file name%
linux64Bits
	%shared library name%
. . .
images
	. . .


Objector 56A
Um? Hmm . . .

Hypothesizer 7
'manifest.xml' is mandatory with the exact location and the exact file name.

Objector 56A
It's a manifest, obviously.

Hypothesizer 7
Yes, it is the main configuration file that lists the other ingredients of the extension.

Each of the other ingredients is not required if it is not wanted, and the location and the file name can be changed at least somewhat as you like, as the file path is specified in the manifest.

Objector 56A
"at least somewhat"?

Hypothesizer 7
I mean, at least, the files except the manifest should not be put under 'META-INF'.

Objector 56B
What are those other "xml" files?

Hypothesizer 7
"KeyBindings.xml" is a configuration file for key bindings.

"GuiItems.xml" is a configuration file for menu items and tool buttons.

"UnoServiceComponents.xml" is a configuration file for UNO components and UNO services, made in Java.

"forLinux64Bits.UnoServiceComponents.xml" is a configuration file for UNO components and UNO services for Linux 64bit platforms, made in C++.

Objector 56A
Um? Ah, as C++ libraries are platform-dependent, such a platform-dependent configuration is required . . .

Objector 56B
While I want to register a key binding, what should I write in that "KeyBindings.xml" thing?

Hypothesizer 7
Actually, as this is an article for the basics of creating any extension as a whole, we will not delve into how to specify key bindings, but we will delve into the contents of the manifest, in the next section.


3: The Contents of the Manifest


The contents of the manifest are like this.

@XML Source Code
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE manifest:manifest PUBLIC "-//OpenOffice.org//DTD Manifest 1.0//EN" "Manifest.dtd">
<manifest:manifest xmlns:manifest="http://openoffice.org/2001/manifest">
	<manifest:file-entry manifest:media-type="application/vnd.sun.star.configuration-data" manifest:full-path="KeyBindings.xml"/>
	<manifest:file-entry manifest:media-type="application/vnd.sun.star.configuration-data" manifest:full-path="GuiItems.xml"/>
	<manifest:file-entry manifest:media-type="application/vnd.sun.star.uno-components" manifest:full-path="UnoServiceComponents.xml"/>
	<manifest:file-entry manifest:media-type="application/vnd.sun.star.uno-components;platform=Linux_x86_64" manifest:full-path="forLinux64Bits.UnoServiceComponents.xml"/>
	<manifest:file-entry manifest:media-type="application/vnd.sun.star.uno-typelibrary;type=RDB" manifest:full-path="theBiasPlanet.hiUnoExtensions.rdb"/>
	<manifest:file-entry manifest:media-type="application/vnd.sun.star.framework-script" manifest:full-path="Scripts/python"/>
	<manifest:file-entry manifest:media-type="application/vnd.sun.star.basic-library" manifest:full-path="basicLibraries/theBiasPlanetHiUnoExtensions"/>
</manifest:manifest>

Objector 56A
Hmm . . .

Hypothesizer 7
As they are just specifying the paths of the ingredients of the extension, I guess that the code is self-explanatory.

Objector 56A
Can unnecessary nodes be just deleted?

Hypothesizer 7
Yes, they can.


4: Archiving the Structure into a ZIP file


Hypothesizer 7
After you have the structure prepared, you can archive it into a ZIP file.

Objector 56B
With what?

Hypothesizer 7
With whatever ZIP tool.

Objector 56B
What should the file name be?

Hypothesizer 7
Any name should do, but usually, the file name extension is 'oxt'.


References


<The previous article in this series | The table of contents of this series | The next article in this series>