Pitivi Undo System

Ethan Fox
1 min readApr 27, 2021

Pitivi’s undo system consists of three main parts: UndoableAction, UndoableActionStack, and UndoableActionLog. An UndoableAction is an action that occurs during runtime. It is the parent class to every other action class. The three methods that every action has are do, undo, and expand. Expand is used for merging actions and will be explained later. An UndoableActionStack is a stack of UndoableAction objects. It stores a single type of action, like a clip transformation property change, and whether it is mergeable. The UndoableActionLog manages the undo/redo system and contains stacks of UndoableActionStack objects. UndoableActionStack objects are split between stacks for undo and redo. A new stack is added to the log by using with self.app.action_log.started() and passing arguments for UndoableActionStack’s constructor. The new stack will be added to the undo stacks. When undo or redo is called, the top of the undo or redo stack respectively will be popped, performed, and appended to the opposite stack.

If a stack’s mergeable field is set to true, then when a new action is received, it will attempt a merge. The attempt_merge() method will be called on the previous stack in the log, passing the new stacks action as an argument. If the stack is not empty and the action and stack are mergeable and of the same type, then the last action in the stack will call expand() and the new action. Each subclass of UndoableAction has its own implementation of expand().

--

--