13
0

Add API to determine undo status

This is is useful to determine if an undoable action was
performed before adding additional information (e.g. selection
changes) to the undo transaction.
This commit is contained in:
Robin Gareus 2021-03-10 13:51:35 +01:00
parent 1ef4fc1140
commit 9fb21a0905
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
3 changed files with 34 additions and 0 deletions

View File

@ -1075,6 +1075,28 @@ public:
bool operation_in_progress (GQuark) const;
/**
* Test if any undo commands were added since the
* call to begin_reversible_command ()
*
* This is is useful to determine if an undoable
* action was performed before adding additional
* information (e.g. selection changes) to the
* undo transaction.
*
* @return true if undo operation is valid but empty
*/
bool collected_undo_commands () const {
return _current_trans && !_current_trans->empty ();
}
/**
* Abort reversible commend IFF no undo changes
* have been collected.
* @return true if undo operation was aborted.
*/
bool abort_empty_reversible_command ();
void add_commands (std::vector<Command*> const & cmds);
std::map<PBD::ID,PBD::StatefulDestructible*> registry;

View File

@ -2536,6 +2536,8 @@ LuaBindings::common (lua_State* L)
.addFunction ("begin_reversible_command", (void (Session::*)(const std::string&))&Session::begin_reversible_command)
.addFunction ("commit_reversible_command", &Session::commit_reversible_command)
.addFunction ("abort_reversible_command", &Session::abort_reversible_command)
.addFunction ("collected_undo_commands", &Session::collected_undo_commands)
.addFunction ("abort_empty_reversible_command", &Session::abort_empty_reversible_command)
.addFunction ("add_command", &Session::add_command)
.addFunction ("add_stateful_diff_command", &Session::add_stateful_diff_command)
.addFunction ("playlists", &Session::playlists)

View File

@ -3093,6 +3093,16 @@ Session::abort_reversible_command ()
}
}
bool
Session::abort_empty_reversible_command ()
{
if (!collected_undo_commands ()) {
abort_reversible_command ();
return true;
}
return false;
}
void
Session::commit_reversible_command (Command *cmd)
{