3535#include < set>
3636#include < map>
3737#include < string>
38+ #include < optional>
3839
3940#include < Base/Observer.h>
4041#include < Base/Parameter.h>
4142#include < Base/ProgressIndicator.h>
43+ #include " TransactionDefs.h"
4244
4345// forward declarations
4446using PyObject = struct _object ;
@@ -203,6 +205,8 @@ class AppExport Application
203205 */
204206 App::Document* getDocument (const char *Name) const ;
205207
208+ App::Document* getDocumentOrActive (const char *Name) const ;
209+
206210 // / %Path matching modes for getDocumentByPath()
207211 enum class PathMatchMode
208212 {
@@ -289,9 +293,11 @@ class AppExport Application
289293 /* *
290294 * @brief Setup a pending application-wide active transaction.
291295 *
292- * Call this function to setup an application-wide transaction. All current
293- * pending transactions of opening documents will be committed first.
294- * However, no new transaction is created by this call. Any subsequent
296+ * Call this function to setup a transaction in the currently active document
297+ * if no document is active, a global transaction is created. If the current
298+ * active document already has a transaction setup it will either commit the
299+ * current transaction or rename it, depending on the tmpName flag of the
300+ * currently setup transaction. No new transaction is created by this call. Any subsequent
295301 * changes in any current opening document will auto create a transaction
296302 * with the given name and ID. If more than one document is changed, the
297303 * transactions will share the same ID, and will be undo/redo together.
@@ -303,32 +309,45 @@ class AppExport Application
303309 *
304310 * @return The new transaction ID.
305311 */
306- int setActiveTransaction (const char * name, bool persist = false );
307312
308- /* *
309- * @brief Get the current active transaction name and ID.
313+ int setActiveTransaction (TransactionName name);
314+
315+ // / Return the current global transaction name and ID if such a global transaction is
316+ // / setup (uncommon)
317+ std::string getActiveTransaction (int *tid=nullptr ) const ;
318+
319+ int openGlobalTransaction (TransactionName name);
320+ int getGlobalTransaction () const ;
321+
322+ bool transactionIsActive (int tid) const ;
323+ std::string getTransactionName (int tid) const ;
324+ bool transactionTmpName (int tid) const ;
325+ Document* transactionInitiator (int tid) const ;
326+ std::optional<TransactionDescription> transactionDescription (int tid) const ;
327+ void setTransactionDescription (int tid, const TransactionDescription& desc);
328+ void setTransactionName (int tid, const TransactionName& name);
329+
330+ /* * Commit/abort current active transactions
310331 *
311332 * If there is no active transaction, an empty string is returned.
312333 *
313- * @param[out] tid If not `nullptr`, the current active transaction ID is
314- * returned through this pointer.
315- * @return The current active transaction name.
316- */
317- const char * getActiveTransaction (int * tid = nullptr ) const ;
318-
319- /* *
320- * @brief Commit/abort current active transactions.
321- *
322334 * @param[in] abort: whether to abort or commit the transactions
323- * @param[in] id: by default 0 meaning that the current active transaction ID is used.
324- *
325- * Besides calling this function directly, it will be called by
326- * automatically if 1) any new transaction is created with a different ID,
327- * or 2) any transaction with the current active transaction ID is either
328- * committed or aborted.
335+ * @param[in] id: by default 0 meaning that the current global transaction ID is used.
336+ *
337+ * Bsides calling this function directly, it will be called by automatically
338+ * if 1) any new transaction is created with a different ID, or 2) any
339+ * transaction with the current active transaction ID is either committed or
340+ * aborted
341+ * returns true if it succeeded in closing the transaction
329342 */
330- void closeActiveTransaction (bool abort=false , int id=0 );
331- // / @}
343+ bool closeActiveTransaction (TransactionCloseMode mode = TransactionCloseMode::Commit, int id=0 );
344+
345+ // / Internally call closeActiveTransaction(), but it makes the call site clearer
346+ bool commitTransaction (int tid);
347+ bool abortTransaction (int tid);
348+
349+
350+ // @}
332351
333352 // NOLINTBEGIN
334353 // clang-format off
@@ -1040,10 +1059,16 @@ class AppExport Application
10401059
10411060 friend class AutoTransaction ;
10421061
1043- std::string _activeTransactionName;
1044- int _activeTransactionID{0 };
1045- int _activeTransactionGuard{0 };
1046- bool _activeTransactionTmpName{false };
1062+ std::map<int , TransactionDescription> _activeTransactionDescriptions; // Maps transaction ID to transaction name
1063+
1064+ int currentlyClosingID {0 };
1065+
1066+ // This is the transaction ID for a global transaction
1067+ // Documents will take this ID if it is non-zero
1068+ // and generate their own otherwise
1069+ int _globalTransactionID { 0 };
1070+ bool _globalTransactionTmpName {false };
1071+ std::string _globalTransactionName;
10471072
10481073 Base::ProgressIndicator _progressIndicator;
10491074
0 commit comments