Page 1 of 1

XUndoManager for SpreadsheetDocument service

Posted: Fri Feb 12, 2016 5:29 pm
by cgalli
Hi everybody.

I am developing a calc add-on in Java, and I need to manage the undo stack when some operations on the document's sheets are executed by this extension.
I can't find documentation about undo management (besides the javadoc html's, which are not enough to clarify the use of XUndoManager), nor good examples.

For example, I can't explain this behavior:

- Initially, an XUndoManager interface is obtained using the XUndoManagerSupplier interface queried from the document (a XSpreadsheetDocument, to be accurate).
- Also, a XLockable is queryed from the XUndoManger, to lock/unlock the XUndoManager.
- Then, the XUndoManager is used to create an undo context (thru XUndoManager::enterUndoContext method).
- Inmediately after, the undo context created is blocked (thru the XLockable::lock method). I verifyed it using XLockable::isLocked method. The idea here is to block the context in order to prevent the operations to perform automatically by the extension are added to the stack.
- Then, the add-on fires a sheet's insertion (i.e. a new sheet is inserted into the document). Unexpectedly, this action removes the lock over the undo context, (i.e., somebody else is unlocking the context), so the insertion and all subsequent operations are added to the stack.
- After that, any call to XLockable::lock method fails to lock the context.

Does anybody knows why is that, and how to fix it?

Regards to all.

Re: XUndoManager for SpreadsheetDocument service

Posted: Sat Feb 13, 2016 1:13 am
by cgalli
Update:

it seems that undo locks are "consummed", i.e.: once locked, the lock is valid just for 1 action on the document, meaning that only that action is skipped in the undo stack.
Also, to lock the undo manager again, before calling the lock() method it is necessary calling unlock() method 2 times per modification (don't know why).
It's insane!