[Solved] Build an OXT which intercepts event

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
Mr.Dandy
Posts: 427
Joined: Tue Dec 11, 2012 4:22 pm

[Solved] Build an OXT which intercepts event

Post by Mr.Dandy »

Hello forum,

I try to build an OXT named Dandy which intercepts OnLoad event in Writer.
It must run a macro OpenMeFirst in Main module.

This is my job.xcu

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<oor:component-data oor:name="Jobs"
	oor:package="org.openoffice.Office" 
	xmlns:oor="http://openoffice.org/2001/registry" > 
  <node oor:name="Jobs">
    <node oor:name="InterceptJob" oor:op="replace">
      <prop oor:name="Service">
        <value>org.openoffice.extensions.dandy</value>
      </prop>
    </node>
  </node>
  <node oor:name="Events">
    <node oor:name="OnLoad" oor:op="replace">
      <node oor:name="JobList">
        <node oor:name="InterceptJob" oor:op="replace"/>
      </node>
    </node>
  </node>
</oor:component-data>
This is the associated manifest.xml

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<manifest:manifest>
 <manifest:file-entry manifest:full-path="Dandy/" manifest:media-type="application/vnd.sun.star.basic-library"/>
 <manifest:file-entry manifest:full-path="job.xcu" manifest:media-type="application/vnd.sun.star.configuration-data"/>
</manifest:manifest>
Install my OXT, restart AOO and check Tools > Customize > Events: no macro triggered.

Any idea welcome
Last edited by Mr.Dandy on Fri Dec 16, 2016 6:22 pm, edited 1 time in total.
OpenOffice 4.1.12 - Windows 10
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Build an OXT which intercepts event

Post by Villeroy »

This does not work with Basic because in Basic you can not implement InterceptJob or any service. A Basic library in an extension is just another way to add macro modules. However, Basic can not add nor implement any services.

Look at the Basic module of the MRI add-on. The Mri Basic macro creates an oMRI object

Code: Select all

oMRI = CreateUnoService( "mytools.Mri" )
  oMRI.inspect( MriTargetObject )
and in MRI's module component.py the Mri class is defined line this:

Code: Select all

class Mri(unohelper.Base, XServiceInfo, XJobExecutor, XIntrospection):

......

    # XJobExecutor
    def trigger(self, args=''):
        ........

    # XIntrospection
    def inspect(self, target):
        return self._run_mri(target)

The class implements UNO class XJobExecutor and XIntrospection and the inspect method that is called by the Basic snippet.
The Mri class behaves just like an ordinary UNO component. A macro (script) that appears under Tools>Macros>... does not add any UNO classes.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Mr.Dandy
Posts: 427
Joined: Tue Dec 11, 2012 4:22 pm

Re: Build an OXT which intercepts event

Post by Mr.Dandy »

OK understand that Basic is limited
OpenOffice 4.1.12 - Windows 10
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Build an OXT which intercepts event

Post by Villeroy »

You know this one http://berma.pagesperso-orange.fr/Files ... mpiler.ott :?:
Of course you can intercept the onLoad script event with Basic. However, I think this will triggered when loading any sort of document so your code has to test if it is interested in the document, e.g. if it is a Writer document.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Mr.Dandy
Posts: 427
Joined: Tue Dec 11, 2012 4:22 pm

Re: [Solved] Build an OXT which intercepts event

Post by Mr.Dandy »

I read this document.
But I don't know which setting parameter can do it.
OpenOffice 4.1.12 - Windows 10
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Build an OXT which intercepts event

Post by Villeroy »

Sorry, I gave up packaging extensions. Too complicated.
If my macros are document specific, then I distribute them in templates or documents.
If they provide component/application wide features then I leave it to the user to set up his own menues, shortcuts, toolbars and events.
The only extension I ever made was inspired by another extension. I looked how others did it, copied their config files and adjusted the names and hierarchies.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
jrbaconcheez
Posts: 1
Joined: Fri Jan 13, 2017 12:25 am

Re: [Solved] Build an OXT which intercepts event

Post by jrbaconcheez »

I realize this was already marked as solved, but this thread came up as the first result in a Google search about the same issue, so I wanted to share the solution.

In order to bind/assign a Basic macro to an event through an extension installer, you just need to include a file called "Events.xcu" in your .oxt package that looks something like the following:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<oor:component-data
 xmlns:oor="http://openoffice.org/2001/registry"
 xmlns:xs="http://www.w3.org/2001/XMLSchema"
 oor:name="Events"
 oor:package="org.openoffice.Office">
    <node oor:name="ApplicationEvents">
        <node oor:name="Bindings">
            <node oor:name="OnLoad" oor:op="replace">
                <prop oor:name="BindingURL" oor:type="xs:string">
                    <value>vnd.sun.star.script:LibraryNameHere.ModuleNameHere.SubNameHere?language=Basic&location=application</value>
                </prop>
            </node>
        </node>
    </node>
</oor:component-data>
In addition, you'll need to add this Events.xcu file to your manifest.xml like so:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<manifest:manifest>
<manifest:file-entry manifest:full-path="Dandy/" manifest:media-type="application/vnd.sun.star.basic-library"/>
<manifest:file-entry manifest:full-path="Events.xcu" manifest:media-type="application/vnd.sun.star.configuration-data"/>
</manifest:manifest>
After you install the extension, restart Office and look into Tools > Customize > Events and your macro should have been automatically assigned to the "Open Document" event.
LibreOffice v5.2 on Ubuntu 16.04
Post Reply