Applying formatting to multiple text ranges at once

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
paul.m
Posts: 1
Joined: Tue Dec 21, 2010 10:46 am

Applying formatting to multiple text ranges at once

Post by paul.m »

Hello everyone,

I need some insight on the following problem.

In Writer, you have the ability to do the following:
- Select several, non-contiguous, text ranges using the Ctrl key.
- Apply a formatting to the selection.

Then, if you undo your last action (ie. going exactly one step backward in the selection history), the entire selected text will be bring back to its previous state.

Now, my question is: how do you achieve the same behavior with an add-on?

Basically, you can select part of the text using for example a XTextCursor. But as far as I now, all XTextRanges could only be expanded to contiguous range (right?).

So, in order to apply formatting on non-contiguous text range, you will actually need to do it segment by segment, by retrieving and modifying each time the XPropertySet of the current selection. In addition to the induced performance cost, at the end, you will have one entry in the undo history for each text segment.

If you have to apply different styles on a relatively big amount of text, the undo history will eventually be overloaded. Which is a big usability issue for an add-on.

Does someone have an idea how we can solve (or mitigate) this issue?

Thanks!
Paul

PS: Actually, the perfect workaround would be to consider all actions triggered by a specific add-on call as a single step in the undo history. There is an actual discussion on the dev ML about the improvement of the undo API that would permit that (among other things): http://www.mail-archive.com/dev@api.ope ... 10649.html
OpenOffice 3.2.1
Debian Sid
Post Reply