[Solved] TextField with multiple sub elements

Creating a macro - Writing a Script - Using the API

[Solved] TextField with multiple sub elements

Postby arvchristos » Fri Jun 08, 2018 10:57 am

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   Expand viewCollapse view
         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
arvchristos
 
Posts: 14
Joined: Fri Jun 08, 2018 10:47 am

Re: TextField with multiple sub elements

Postby Lupp » Fri Jun 08, 2018 12:25 pm

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 6.2 and older versions, PortableOpenOffice 4.1.5 and older, StarOffice 5.2
---
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 2408
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: TextField with multiple sub elements

Postby arvchristos » Fri Jun 08, 2018 4:38 pm

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

Code: Select all   Expand viewCollapse view
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: 14
Joined: Fri Jun 08, 2018 10:47 am

Re: TextField with multiple sub elements

Postby arvchristos » Fri Jun 08, 2018 7:18 pm

Problem solved! I was completely unaware of UndoContext methods. Thanks a lot @Lupp for the useful directions!
Libreoffice 5 and openoffice 4 on Archlabs
arvchristos
 
Posts: 14
Joined: Fri Jun 08, 2018 10:47 am


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 4 guests