XUndoManager for SpreadsheetDocument service
Posted: Fri Feb 12, 2016 5:29 pm
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.
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.