From b5fb426956a407d360959c67506e6f426fd35c2e Mon Sep 17 00:00:00 2001 From: "tbogard%aol.net" Date: Tue, 28 Mar 2000 00:19:05 +0000 Subject: [PATCH] Added the concept of a replaceable entry. This is an entry which when a new item is added will get overwritten rather than adding the entry to the end of the list. --- .../shistory/public/nsISHTransaction.idl | 8 ++- .../shistory/public/nsISHistory.idl | 6 +- .../shistory/src/nsSHTransaction.cpp | 19 +++++- .../components/shistory/src/nsSHTransaction.h | 4 +- xpfe/components/shistory/src/nsSHistory.cpp | 58 ++++++++++--------- 5 files changed, 64 insertions(+), 31 deletions(-) diff --git a/xpfe/components/shistory/public/nsISHTransaction.idl b/xpfe/components/shistory/public/nsISHTransaction.idl index 46cd40426a3d..6120feeedad7 100644 --- a/xpfe/components/shistory/public/nsISHTransaction.idl +++ b/xpfe/components/shistory/public/nsISHTransaction.idl @@ -36,7 +36,7 @@ interface nsISHTransaction : nsISupports /** * The nsISHEntry for the current transaction */ - readonly attribute nsISHEntry sHEntry; + attribute nsISHEntry sHEntry; /** * The parent of this transaction @@ -53,6 +53,12 @@ interface nsISHTransaction : nsISupports */ readonly attribute nsISHTransaction lrvList; + /** + * Specifies if this transaction should persist. If not it will be replaced + * by new additions to the list. + */ + attribute boolean persist; + /** * Create a transaction with parent and History Entry */ diff --git a/xpfe/components/shistory/public/nsISHistory.idl b/xpfe/components/shistory/public/nsISHistory.idl index 9cba8e9bedc3..1c932f587b9b 100644 --- a/xpfe/components/shistory/public/nsISHistory.idl +++ b/xpfe/components/shistory/public/nsISHistory.idl @@ -38,8 +38,12 @@ interface nsISHistory: nsISupports { /** * Add a new Entry to the History List + * @param aEntry - The entry to add + * @param aPersist - If true this specifies that the entry should persist + * in the list. If false, this means that when new entries are added + * this element will not appear in the session history list. */ - void addEntry(in nsISHEntry aEntry); + void addEntry(in nsISHEntry aEntry, in boolean aPersist); /** * Get the size of the History list diff --git a/xpfe/components/shistory/src/nsSHTransaction.cpp b/xpfe/components/shistory/src/nsSHTransaction.cpp index 70da7ace4a3b..b0843f4be3ec 100644 --- a/xpfe/components/shistory/src/nsSHTransaction.cpp +++ b/xpfe/components/shistory/src/nsSHTransaction.cpp @@ -40,7 +40,8 @@ NS_IMPL_ISUPPORTS1(nsSHTransaction, nsISHTransaction) -nsSHTransaction::nsSHTransaction() : mParent(nsnull), mChild(nsnull),mLRVList(nsnull), mSHEntry(nsnull) +nsSHTransaction::nsSHTransaction() : mPersist(PR_TRUE), mParent(nsnull), + mChild(nsnull), mLRVList(nsnull), mSHEntry(nsnull) { NS_INIT_REFCNT(); } @@ -157,6 +158,22 @@ nsSHTransaction::GetLrvList(nsISHTransaction ** aResult) return NS_OK; } +NS_IMETHODIMP +nsSHTransaction::SetPersist(PRBool aPersist) +{ + mPersist = aPersist; + return NS_OK; +} + +NS_IMETHODIMP +nsSHTransaction::GetPersist(PRBool* aPersist) +{ + NS_ENSURE_ARG_POINTER(aPersist); + + *aPersist = mPersist; + return NS_OK; +} + NS_IMETHODIMP NS_NewSHTransaction(nsISupports* aOuter, REFNSIID aIID, void** aResult) diff --git a/xpfe/components/shistory/src/nsSHTransaction.h b/xpfe/components/shistory/src/nsSHTransaction.h index c395529cdffc..6ef82cddd9cc 100644 --- a/xpfe/components/shistory/src/nsSHTransaction.h +++ b/xpfe/components/shistory/src/nsSHTransaction.h @@ -43,9 +43,11 @@ private: NS_NewSHTransaction(nsISupports * aOuter, REFNSIID aIID, void** aResult); nsresult SetChild(nsISHTransaction * aChild); nsresult SetParent(nsISHTransaction * aParent); - nsresult SetSHEntry(nsISHEntry * aSHEntry); + //nsresult SetSHEntry(nsISHEntry * aSHEntry); //nsresult SetLRVList(nsISHTransaction * aLRVList); + PRBool mPersist; + /* Weak reference to parent */ nsISHTransaction * mParent; nsISHTransaction * mChild; diff --git a/xpfe/components/shistory/src/nsSHistory.cpp b/xpfe/components/shistory/src/nsSHistory.cpp index 80169af354c7..6e7f53a02ae7 100644 --- a/xpfe/components/shistory/src/nsSHistory.cpp +++ b/xpfe/components/shistory/src/nsSHistory.cpp @@ -57,37 +57,41 @@ nsSHistory::~nsSHistory() * increment the index to point to the new entry */ NS_IMETHODIMP -nsSHistory::AddEntry(nsISHEntry * aSHEntry) +nsSHistory::AddEntry(nsISHEntry * aSHEntry, PRBool aPersist) { - nsresult rv; + NS_ENSURE_ARG(aSHEntry); - NS_PRECONDITION(aSHEntry != nsnull, "null ptr"); - if (! aSHEntry) - return NS_ERROR_NULL_POINTER; + nsCOMPtr currentTxn; - nsCOMPtr txn; - rv = nsComponentManager::CreateInstance(NS_SHTRANSACTION_PROGID, - nsnull, - NS_GET_IID(nsISHTransaction), - getter_AddRefs(txn)); - nsCOMPtr parent; + if(mListRoot) + GetTransactionAtIndex(mIndex, getter_AddRefs(currentTxn)); + + PRBool currentPersist = PR_TRUE; + if(currentTxn) + currentTxn->GetPersist(¤tPersist); + + if(!currentPersist) + { + NS_ENSURE_SUCCESS(currentTxn->SetSHEntry(aSHEntry), + NS_ERROR_FAILURE); + return NS_OK; + } + + nsCOMPtr txn(do_CreateInstance(NS_SHTRANSACTION_PROGID)); + NS_ENSURE_TRUE(txn, NS_ERROR_FAILURE); + + // Set the ShEntry and parent for the transaction. setting the + // parent will properly set the parent child relationship + txn->SetPersist(aPersist); + NS_ENSURE_SUCCESS(txn->Create(aSHEntry, currentTxn), NS_ERROR_FAILURE); + + mLength++; + mIndex++; + // If this is the very first transaction, initialize the list + if(!mListRoot) + mListRoot = txn; + PrintHistory(); - if (NS_SUCCEEDED(rv) && txn) { - if (mListRoot) { - GetTransactionAtIndex(mIndex, getter_AddRefs(parent)); - } - // Set the ShEntry and parent for the transaction. setting the - // parent will properly set the parent child relationship - rv = txn->Create(aSHEntry, parent); - if (NS_SUCCEEDED(rv)) { - mLength++; - mIndex++; - // If this is the very first transaction, initialize the list - if (!mListRoot) - mListRoot = txn; - PrintHistory(); - } - } return NS_OK; }