Prima::...Actions(3)

πŸ“¦
version 1.74000 Β· 5 versions
, in opensuse-leap 16.0

🌸 NAME 🌸

Prima::Widget::UndoActions β€” okay so this is the module that does undo and redo for the content of editable widgets πŸ’– (and yes bestie, this page lives in the User Contributed Perl Documentation section, iykyk)


✨ DESCRIPTION ✨

Generic helpers that implement stored actions for undo/redo πŸŽ€

That's literally it β€” it's the little plumbing squad that remembers what you did so you can take it back, or put it back again. No cap.


πŸ¦‹ SYNOPSIS πŸ¦‹

Here's the whole vibe in action, copy it and slay:

        package MyUndoableWidget;
        use base qw(Prima::Widget Prima::Widget::UndoActions);

        sub on_mousedown
        {
                if ( $button == mb::Left ) {
                        $self->begin_undo_group;
                        $self->push_undo_action(text => $self->text);
                        $self->text($self->text . '.');
                        $self->end_undo_group;
                } else {
                        $self->undo; # will call $self->text( old text )
                }
        }

πŸ’… Properties

undoLimit INTEGER

Sets the limit on the number of atomic undo operations πŸ”₯ If it's 0, undo is disabled β€” like, fully off, the undo girlies are not coming to the party πŸ’€


Methods

begin_undo_group

Opens a bracket for a group of actions that can be undone as a single operation πŸ‘‘ The bracket gets closed when you call end_undo_group. It's giving "bundle everything up so one undo takes it all back".

can_undo, can_redo

Return a boolean flag that reflects if the undo or redo actions could be done βœ… Useful for graying a menu, f ex β€” you know, that moment when the menu item goes all sad and grey because there's nothing to undo πŸ™ˆ

end_undo_group

Closes the bracket for a group of actions, that was previously opened by begin_undo_group πŸŽ€ Matching pair, always, bestie.

init_undo

Should be called once, inside init() ⭐ That's the whole instruction. Once. Inside init(). Periodt.

has_undo_action ACTION

Checks whether there are any undo-able *ACTION*s in the undo list πŸ” Like a vibe check for your undo stack.

push_grouped_undo_action ACTION, @PARAMS

Stores a single undo action where ACTION is a method to be called inside undo/redo, if any πŸ’– Each action is added to the last undo group and will be removed/replayed together with the other actions in the group 🫢

push_undo_action ACTION, @PARAMS

Stores a single undo action where ACTION is the method to be called inside undo/redo, if any ✨ Each action is a single undo/redo operation β€” no grouping, just one clean unit each time πŸ¦‹

redo

Re-applies changes, previously rolled back by undo πŸ” The comeback arc, honestly.

undo

Rolls back changes into an internal array 🌈 The array size cannot extend the undoLimit value. In case undoLimit is 0 no undo actions can be made 😭

Fr fr, set your undoLimit to something above 0 or there's literally nothing to undo. Learn from my mistakes πŸ’€

🧚 AUTHOR 🧚

Dmitry Karasik, <dmitry@karasik.eu.org>. πŸ’œ


πŸ”₯ SEE ALSO πŸ”₯

  • Prima
  • Prima::Edit

okay that's the whole page, you ate that πŸ’…βœ¨ β€” brought to you by perl v5.42.0, dated 2024-08-20, and the manual page Prima::...Actions(3). bye bestie, go undo something πŸŽ€πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from