[Solved] TextField with multiple sub elements

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
arvchristos
Posts: 15
Joined: Fri Jun 08, 2018 10:47 am

[Solved] TextField with multiple sub elements

Post by arvchristos »

Hello,
I am currrently developing an extension that at some point includes the insertion of text and a PageNumber element in a document. This is done using the following calls:

Code: Select all

			Num_Position.insertString(NumCursor, "-", False)
			Num_Position.insertTextContent(NumCursor, PageNumber, False)
			Num_Position.insertString(NumCursor, "-", False)
However, when i undo this actions, I have to do this three times because each insertion is considered independent of the others.
Is there any way to combine these three calls to one to avoid the aformentioned behaviour?

Thanks in advance
Last edited by Hagar Delest on Fri Jun 08, 2018 10:53 pm, edited 1 time in total.
Reason: tagged [Solved].
Libreoffice 5 and openoffice 4 on Archlabs
User avatar
Lupp
Volunteer
Posts: 3542
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: TextField with multiple sub elements

Post by Lupp »

What type is your variable PageNumber?
If it is an object having a property .String you may prefix / suffix your dashes there.

(Please post codes in sequences allowing for some understanding. Otherwise your question will only be "Is there a way to make act any sequence of api calls as if it's just one call?" - and I'm afraid the answer might be "No!". Of course, there may be a way unknown to me to directly manage the undo queue. You may start with studying https://api.libreoffice.org/docs/idl/re ... 9bdbec8571 e.g.)
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
arvchristos
Posts: 15
Joined: Fri Jun 08, 2018 10:47 am

Re: TextField with multiple sub elements

Post by arvchristos »

Sorry for the lazy post! PageNumber is a texfield and a more complete example is the following:

Code: Select all

PageNumber = Doc.createInstance("com.sun.star.text.textfield.PageNumber")
NumCursor = Num_Position.Text.createTextCursor()
Num_Position.insertString(NumCursor, "-", False)
Num_Position.insertTextContent(NumCursor, PageNumber, False)
Num_Position.insertString(NumCursor, "-", False)
Libreoffice 5 and openoffice 4 on Archlabs
arvchristos
Posts: 15
Joined: Fri Jun 08, 2018 10:47 am

Re: TextField with multiple sub elements

Post by arvchristos »

Problem solved! I was completely unaware of UndoContext methods. Thanks a lot @Lupp for the useful directions!
Libreoffice 5 and openoffice 4 on Archlabs
Post Reply