undo

package
v0.0.0-...-955f326 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2020 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CannotRedoTitle

func CannotRedoTitle() string

CannotRedoTitle returns the Cannot Redo title.

func CannotUndoTitle

func CannotUndoTitle() string

CannotUndoTitle returns the Cannot Undo title.

Types

type Edit

type Edit interface {
	// Name returns the localized name of the edit, suitable for displaying in
	// a user interface menu. Note that no leading "Undo " or "Redo " should
	// be part of this name, as the Manager will add this.
	Name() string
	// Cost returns a cost factor for this edit. When the cost values of the
	// edits within a given Manager exceed the Manager's defined cost limit,
	// the oldest edits will be discarded until the cost values are less than
	// or equal to the Manager's defined limit. Note that if this method
	// returns a value less than 1, it will be set to 1 for purposes of this
	// calculation.
	Cost() int
	// Undo the state.
	Undo()
	// Redo the state.
	Redo()
	// Absorb gives this edit a chance to absorb a new edit that is about to
	// be added to the manager. If this method returns true, it is assumed
	// this edit has incorporated any necessary state into itself to perform
	// an undo/redo and the other edit will be discarded.
	Absorb(other Edit) bool
	// Release is called when this edit is no longer needed by the Manager.
	Release()
}

Edit defines the required methods an undoable edit must implement.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager provides management of an undo/redo stack.

func NewManager

func NewManager(costLimit int, recoveryHandler errs.RecoveryHandler) *Manager

NewManager creates a new undo/redo manager.

func (*Manager) Add

func (m *Manager) Add(edit Edit)

Add an edit. If one or more undos have been performed, this will cause any redo capability beyond this point to be lost.

func (*Manager) CanRedo

func (m *Manager) CanRedo() bool

CanRedo returns true if Redo() can be called successfully.

func (*Manager) CanUndo

func (m *Manager) CanUndo() bool

CanUndo returns true if Undo() can be called successfully.

func (*Manager) Clear

func (m *Manager) Clear()

Clear removes all edits from this Manager.

func (*Manager) CostLimit

func (m *Manager) CostLimit() int

CostLimit returns the current cost limit permitted by this undo manager.

func (*Manager) Redo

func (m *Manager) Redo()

Redo re-applies the current state by one edit.

func (*Manager) RedoTitle

func (m *Manager) RedoTitle() string

RedoTitle returns the title for the current redo state.

func (*Manager) SetCostLimit

func (m *Manager) SetCostLimit(limit int)

SetCostLimit sets a new cost limit, potentially trimming existing edits to fit within the new limit. Note that if the most recent edit has a cost larger than the new limit, that last edit (and only that last edit) will still be retained.

func (*Manager) Undo

func (m *Manager) Undo()

Undo rewinds the current state by one edit.

func (*Manager) UndoTitle

func (m *Manager) UndoTitle() string

UndoTitle returns the title for the current undo state.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL