diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index a43639f833..838510f403 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -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 const & cmds); std::map registry; diff --git a/libs/ardour/luabindings.cc b/libs/ardour/luabindings.cc index 466e650e26..2025e365ff 100644 --- a/libs/ardour/luabindings.cc +++ b/libs/ardour/luabindings.cc @@ -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) diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 3e4cc1e094..e0058f04c1 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -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) {