IOW how do I make OOo's undo/redo work properly when a macro is executed?
This is related to my previous question: #853176
You can talk to the UndoManager, calling enterUndoContext()
at the very beginning of your macro and then leaveUndoContext()
at the end. For example:
Dim undo As Object
undo = ThisComponent.UndoManager
undo.enterUndoContext("MyAtomicTest")
...
[YOUR COMPLEX OPERATIONS HERE]
...
undo.leaveUndoContext
This creates an atomic undo operation that appears to the user as "MyAtomicTest".
for those among us who prefer a JavaScript to write OOo macros, here is a minimal snippet that should work (it's tested but I isolated this code from a bigger context):
importClass( Packages.com.sun.star.document.XUndoManager );
importClass( Packages.com.sun.star.document.XUndoManagerSupplier );
var doc = XSCRIPTCONTEXT.getDocument();
var undo_manager = UnoRuntime.queryInterface(XUndoManagerSupplier, doc).getUndoManager();
undo_manager.enterUndoContext( 'your descriptive title here' );
// get stuff done
undo_manager.leaveUndoContext();