Ask Your Question
1

Can Libreoffice basic macros listen loading a file?

asked 2016-11-23 19:19:59 +0200

gulsah gravatar image

I am trying to write a basic macro (After i'll convert it an extension) for writer which listens exist file's loading/opening. While i read Andrew Pitonyak's book about macros i've learned about Listeners. But there is no listener for com.sun.star.frame.XComponentLoader service. I want to see a dialog box when any document loaded /opened to writer. Is it possible? If yes could anyone help me to find a document about it?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
2

answered 2016-11-24 03:46:40 +0200

karolus gravatar image

Hallo

sub example
    msgbox( thisComponent.Title )
end sub

adopt the code to your needs, store it into ……MyMakros→Standard→…

and bind it to →Tools→Customize→Events→→Open Document (choose LibreOffice in the Optionbox below )

edit flag offensive delete link more

Comments

@karolus - simple but effective - Very Nice!

Ratslinger gravatar imageRatslinger ( 2016-11-24 04:26:52 +0200 )edit

we need first to check if we just open writer:

sub example
doc = thisComponent
if doc.Identifier = "com.sun.star.text.TextDocument" then
    msgbox( doc.Title )
end if
end sub
karolus gravatar imagekarolus ( 2016-11-24 05:10:25 +0200 )edit

Hey \o/ Thanks for that simple and handy solution. It works for open a file while libreoffice running. But when i double click an odt document when libreoffce is off i see "Basic Runtime Error: Property or method not found:Identifier". I think that cause of ThisComponent What can i use instead of ThisComponent to specify writer component?

gulsah gravatar imagegulsah ( 2016-11-24 09:36:46 +0200 )edit

I cannot reproduce the Issue, it works for me also with completely closed LO and double clicking some LO-file.
to restrict your code running only on writer-docs see the example in my last comment above yours.

karolus gravatar imagekarolus ( 2016-11-24 15:28:43 +0200 )edit

That error was cause of my fault. I works now correctly. Thanks.

gulsah gravatar imagegulsah ( 2016-11-25 10:21:06 +0200 )edit
1

answered 2016-11-23 23:13:24 +0200

Ratslinger gravatar image

Actually the basic information you need is in Pitonyak's OOME book. I have only created one listener (see this link - click here ) and it appears you need to do the same.

Running the code from the link mentioned produced:

image description

Based upon that you would have three routines to set up - StartHandler, StopHandler, and loadComponentFromURL. This last routine is where you would determine the type of document being opened (Writer, Calc, Base etc.) and if it's the one you want (Writer in your case) display your Dialog.

Only having done this once, can't be too much help but this may give you a start.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-11-23 19:19:59 +0200

Seen: 185 times

Last updated: Nov 24 '16