From abcf8261a426a2e52cc75ab8288f3ef4411884f9 Mon Sep 17 00:00:00 2001 From: "kin%netscape.com" Date: Fri, 20 Nov 1998 00:43:07 +0000 Subject: [PATCH] Updated nsITransaction and nsITransactionManager to match current spec. --- editor/txmgr/public/nsITransaction.h | 40 +++++++--- editor/txmgr/public/nsITransactionManager.h | 81 +++++++++++---------- editor/txmgr/src/nsTransactionManager.cpp | 38 +++++++++- editor/txmgr/src/nsTransactionManager.h | 15 ++-- 4 files changed, 114 insertions(+), 60 deletions(-) diff --git a/editor/txmgr/public/nsITransaction.h b/editor/txmgr/public/nsITransaction.h index 1b6959a22f7..a36e4c9b3f3 100644 --- a/editor/txmgr/public/nsITransaction.h +++ b/editor/txmgr/public/nsITransaction.h @@ -18,8 +18,11 @@ #ifndef nsITransaction_h__ #define nsITransaction_h__ + #include "nsISupports.h" #include "nsIOutputStream.h" +#include "nsString.h" + /* Transaction interface to outside world */ @@ -33,34 +36,49 @@ Transaction interface to outside world /** * A transaction specific interface. *

- * It's implemented by an object that executes some behavior that must be tracked - * by the transaction manager. + * It's implemented by an object that executes some behavior that must be + * tracked by the transaction manager. */ class nsITransaction : public nsISupports{ public: /** - * Execute() tells the implementation of nsITransaction to execute itself. + * Executes the transaction. */ - virtual nsresult Execute(void) = 0; + virtual nsresult Do(void) = 0; /** - * Undo() tells the implementation of nsITransaction to undo it's execution. + * Restores the state to what it was before the transaction was executed. */ virtual nsresult Undo(void) = 0; /** - * Redo() tells the implementation of nsITransaction to redo it's execution. + * Executes the transaction again. Can only be called on a transaction that + * was previously undone. + *

+ * In most cases, the Redo() method will actually call the Do() method to + * execute the transaction again. */ virtual nsresult Redo(void) = 0; /** - * Write() tells the implementation of nsITransaction to write a representation - * of itself. - * @param nsIOutputStream * + * Write a stream representation of the current state of the transaction. + * @param aOutputStream the stream to write to. */ - virtual nsresult Write(nsIOutputStream *) = 0; + virtual nsresult Write(nsIOutputStream *aOutputStream) = 0; + + /** + * Returns the string to display for the undo menu item. + * @param aString will point to string to display. + */ + virtual nsresult GetUndoString(nsString **aString) = 0; + + /** + * Returns the string to display for the redo menu item. + * @param aString will point to string to display. + */ + virtual nsresult GetRedoString(nsString **aString) = 0; }; -#endif // nsITransaction +#endif // nsITransaction_h__ diff --git a/editor/txmgr/public/nsITransactionManager.h b/editor/txmgr/public/nsITransactionManager.h index 5f2b9e1d2ff..c53af3dfd90 100644 --- a/editor/txmgr/public/nsITransactionManager.h +++ b/editor/txmgr/public/nsITransactionManager.h @@ -18,10 +18,11 @@ #ifndef nsITransactionManager_h__ #define nsITransactionManager_h__ + #include "nsISupports.h" #include "nsIOutputStream.h" #include "nsITransaction.h" -// #include "nsITransactionListener.h" +#include "nsITransactionListener.h" /* Transaction Manager interface to outside world @@ -42,62 +43,64 @@ class nsITransactionManager : public nsISupports{ public: /** - * Execute() calls the transaction's Execute() method and pushes it - * on the undo queue. Execute() calls the transaction's AddRef() method. + * Places a transaction on the do stack and calls it's Do() method. + *

+ * This method calls the transaction's AddRef() method. * The transaction's Release() method will be called when the undo or redo * stack is pruned or when the transaction manager is destroyed. - * - * @param nsITransaction *tx the transaction to execute. + * @param aTransaction the transaction to do. */ - virtual nsresult Execute(nsITransaction *tx) = 0; + virtual nsresult Do(nsITransaction *aTransaction) = 0; /** - * Undo() pops the specified number of transactions off the undo stack, - * calls their Undo() method, and pushes them onto the redo stack. - * - * @param PRInt32 n number of transactions to undo. n <= 0 means undo all - * transactions. + * Pops the topmost transaction on the do stack, pushes it on the undo + * stack, then calls it's Undo() method. */ - virtual nsresult Undo(PRInt32 n) = 0; + virtual nsresult Undo(void) = 0; /** - * Redo() pops the specified number of transactions off the redo stack, - * calls their Redo() method, and pushes them onto the undo stack. - * - * @param PRInt32 n number of transactions to redo. n <= 0 means redo all - * transactions previously undone. + * Pops the topmost transaction on the undo stack, pushes it on the redo + * stack, then calls it's Redo() method. */ - virtual nsresult Redo(PRInt32 n) = 0; + virtual nsresult Redo(void) = 0; /** - * Write() allows the transaction manager to output a stream representation - * of itself, it then calls the Write() method of each transaction on the - * undo and redo stacks. - * - * @param nsIOutputStream *os output stream for writing. + * Returns the number of items on the undo stack. + * @param aNumItems will contain number of items. */ - virtual nsresult Write(nsIOutputStream *os) = 0; + virtual nsresult GetNumberOfUndoItems(PRInt32 *aNumItems) = 0; /** - * AddListener() adds the specified listener to the transaction manager's - * list of listeners. The listener is notified whenever a transaction is - * executed, undone, or redone. AddListener() calls the listener's AddRef() - * method. - * - * @param nsITransactionListener *l the lister to add. + * Returns the number of items on the redo stack. + * @param aNumItems will contain number of items. */ - // virtual nsresult AddListener(nsITransactionListener *l) = 0; + virtual nsresult GetNumberOfRedoItems(PRInt32 *aNumItems) = 0; /** - * RemoveListener() removes the specified listener from the transaction - * manager's list of listeners. Removing a listener that is not on the - * transaction manager's list does nothing. RemoveListener() calls the - * listener's Release() method. - * - * @param nsITransactionListener *l the lister to add. + * Writes a stream representation of the transaction manager and it's + * execution stacks. Calls the Write() method of each transaction on the + * execution stacks. + * @param aOutputStream the stream to write to. */ - // virtual nsresult RemoveListener(nsITransactionListener *l) = 0; + virtual nsresult Write(nsIOutputStream *aOutputStream) = 0; + + /** + * Adds a listener to the transaction manager's notification list. Listeners + * are notified whenever a transaction is done, undone, or redone. + *

+ * The listener's AddRef() method is called. + * @param aListener the lister to add. + */ + virtual nsresult AddListener(nsITransactionListener *aListener) = 0; + + /** + * Removes a listener from the transaction manager's notification list. + *

+ * The listener's Release() method is called. + * @param aListener the lister to remove. + */ + virtual nsresult RemoveListener(nsITransactionListener *aListener) = 0; }; -#endif // nsITransactionManager +#endif // nsITransactionManager_h__ diff --git a/editor/txmgr/src/nsTransactionManager.cpp b/editor/txmgr/src/nsTransactionManager.cpp index 9763ec5f949..9e4eba4083f 100644 --- a/editor/txmgr/src/nsTransactionManager.cpp +++ b/editor/txmgr/src/nsTransactionManager.cpp @@ -31,25 +31,55 @@ NS_IMPL_ADDREF(nsTransactionManager) NS_IMPL_RELEASE(nsTransactionManager) nsresult -nsTransactionManager::Execute(nsITransaction *tx) +nsTransactionManager::Do(nsITransaction *aTransaction) { return NS_OK; } nsresult -nsTransactionManager::Undo(PRInt32 n) +nsTransactionManager::Undo() { return NS_OK; } nsresult -nsTransactionManager::Redo(PRInt32 n) +nsTransactionManager::Redo() { return NS_OK; } nsresult -nsTransactionManager::Write(nsIOutputStream *os) +nsTransactionManager::GetNumberOfUndoItems(PRInt32 *aNumItems) +{ + if (aNumItems) + *aNumItems = 0; + + return NS_OK; +} + +nsresult +nsTransactionManager::GetNumberOfRedoItems(PRInt32 *aNumItems) +{ + if (aNumItems) + *aNumItems = 0; + + return NS_OK; +} + +nsresult +nsTransactionManager::Write(nsIOutputStream *aOutputStream) +{ + return NS_OK; +} + +nsresult +nsTransactionManager::AddListener(nsITransactionListener *aListener) +{ + return NS_OK; +} + +nsresult +nsTransactionManager::RemoveListener(nsITransactionListener *aListener) { return NS_OK; } diff --git a/editor/txmgr/src/nsTransactionManager.h b/editor/txmgr/src/nsTransactionManager.h index e902b04d9f5..0bbb2441939 100644 --- a/editor/txmgr/src/nsTransactionManager.h +++ b/editor/txmgr/src/nsTransactionManager.h @@ -39,12 +39,15 @@ public: /* Macro for AddRef(), Release(), and QueryInterface() */ NS_DECL_ISUPPORTS - virtual nsresult Execute(nsITransaction *tx); - virtual nsresult Undo(PRInt32 n); - virtual nsresult Redo(PRInt32 n); - virtual nsresult Write(nsIOutputStream *os); - // virtual nsresult AddListener(nsITransactionListener *l); - // virtual nsresult RemoveListener(nsITransactionListener *l); + /* nsITransactionManager method implementations. */ + virtual nsresult Do(nsITransaction *aTransaction); + virtual nsresult Undo(void); + virtual nsresult Redo(void); + virtual nsresult GetNumberOfUndoItems(PRInt32 *aNumItems); + virtual nsresult GetNumberOfRedoItems(PRInt32 *aNumItems); + virtual nsresult Write(nsIOutputStream *aOutputStream); + virtual nsresult AddListener(nsITransactionListener *aListener); + virtual nsresult RemoveListener(nsITransactionListener *aListener); }; #endif // nsTransactionManager_h__