UndoRedoToolbarHelper

class UndoRedoToolbarHelper @JvmOverloads constructor(host: UndoRedoToolbarHelper.UndoRedoToolbarHost, groupId: Int, undoItemId: Int, redoItemId: Int, ioDispatcher: CoroutineDispatcher = Dispatchers.IO)

Helper class that encapsulates all undo/redo functionality for toolbars. This class handles undo/redo menu item creation, async button state updates, and undo/redo action execution.

This helper implements ANR prevention patterns to avoid blocking on Pdfium mutexes:

Constructors

Link copied to clipboard
constructor(host: UndoRedoToolbarHelper.UndoRedoToolbarHost, groupId: Int, undoItemId: Int, redoItemId: Int, ioDispatcher: CoroutineDispatcher = Dispatchers.IO)

Types

Link copied to clipboard
object Companion

Companion object containing constants for the undo/redo helper.

Link copied to clipboard

Interface that must be implemented by toolbars using this helper.

Functions

Link copied to clipboard
fun bindProvider(provider: UndoProvider)

Binds a custom undo/redo provider. Must be called when the toolbar's controller is bound. Use this for non-UndoManager providers (e.g., DocumentEditorUndoProvider). Note: Manual calls to updateUndoRedoButtons are required when the undo/redo state changes.

Link copied to clipboard
fun bindUndoManager(pdfFragment: PdfFragment)

Binds the undo manager from the given fragment. Must be called when the toolbar's controller is bound. Creates a UndoManagerUndoProvider wrapper automatically.

Link copied to clipboard

Executes a redo action on a background thread to prevent ANRs from Pdfium mutex blocking. The button enabled state should already ensure this is only called when redo is available and no other undo/redo operation is currently executing. This method is thread-safe and can be called from any thread.

Link copied to clipboard

Executes an undo action on a background thread to prevent ANRs from Pdfium mutex blocking. The button enabled state should already ensure this is only called when undo is available and no other undo/redo operation is currently executing. This method is thread-safe and can be called from any thread.

Link copied to clipboard

Unbinds the provider and cancels any pending state updates or executions. Must be called when the toolbar's controller is unbound.

Link copied to clipboard
fun updateUndoRedoButtons(onStateUpdated: (canUndo: Boolean, canRedo: Boolean) -> Unit? = null)

Recomputes undo/redo availability from the bound provider (on a background thread, since canUndo/canRedo might block) and applies it to the toolbar buttons.