From 347da180eb975a058173684f6e241a77000d95eb Mon Sep 17 00:00:00 2001 From: "blakeross%telocity.com" Date: Mon, 6 May 2002 01:14:27 +0000 Subject: [PATCH] 132013 - remove from list should be batched. r=hewitt sr=ben --- .../public/nsIDownloadManager.idl | 14 ++++++++++++- .../resources/downloadmanager.js | 6 +++++- .../src/nsDownloadManager.cpp | 20 ++++++++++++++++++- .../download-manager/src/nsDownloadManager.h | 1 + 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/xpfe/components/download-manager/public/nsIDownloadManager.idl b/xpfe/components/download-manager/public/nsIDownloadManager.idl index 75f4038071c..305ad2675b7 100644 --- a/xpfe/components/download-manager/public/nsIDownloadManager.idl +++ b/xpfe/components/download-manager/public/nsIDownloadManager.idl @@ -144,7 +144,19 @@ interface nsIDownloadManager : nsISupports { * third party managers to let us know when they've closed. */ - void onClose(); + void onClose(); + + /** + * Indicate that a batch update (e.g. mass removal) is about to start. + */ + + void startBatchUpdate(); + + /** + * Indicate that a batch update is ending. + */ + + void endBatchUpdate(); }; diff --git a/xpfe/components/download-manager/resources/downloadmanager.js b/xpfe/components/download-manager/resources/downloadmanager.js index df98f35540e..dc94fb41efe 100644 --- a/xpfe/components/download-manager/resources/downloadmanager.js +++ b/xpfe/components/download-manager/resources/downloadmanager.js @@ -199,8 +199,12 @@ var downloadViewController = { break; case "cmd_remove": selectedItems = getSelectedItems(); - for (i = 0; i < selectedItems.length; i++) + gDownloadManager.startBatchUpdate(); + for (i = 0; i < selectedItems.length; i++) { + if (i == selectedItems.length - 1) + gDownloadManager.endBatchUpdate(); gDownloadManager.removeDownload(selectedItems[i].id); + } window.updateCommands("tree-select"); break; case "cmd_selectAll": diff --git a/xpfe/components/download-manager/src/nsDownloadManager.cpp b/xpfe/components/download-manager/src/nsDownloadManager.cpp index 948569a7d5a..4f15a965b19 100644 --- a/xpfe/components/download-manager/src/nsDownloadManager.cpp +++ b/xpfe/components/download-manager/src/nsDownloadManager.cpp @@ -84,7 +84,8 @@ nsIRDFService* gRDFService; NS_IMPL_ISUPPORTS3(nsDownloadManager, nsIDownloadManager, nsIDOMEventListener, nsIObserver) -nsDownloadManager::nsDownloadManager() : mCurrDownloads(nsnull) +nsDownloadManager::nsDownloadManager() : mCurrDownloads(nsnull), + mBatches(0) { NS_INIT_ISUPPORTS(); } @@ -627,10 +628,27 @@ nsDownloadManager::RemoveDownload(const char* aPath) rv = downloads->RemoveElementAt(itemIndex, PR_TRUE, getter_AddRefs(node)); if (NS_FAILED(rv)) return rv; + // if a mass removal is being done, we don't want to flush every time + if (mBatches) return rv; + nsCOMPtr remote = do_QueryInterface(mDataSource); return remote->Flush(); } +NS_IMETHODIMP +nsDownloadManager::StartBatchUpdate() +{ + ++mBatches; + return NS_OK; +} + +NS_IMETHODIMP +nsDownloadManager::EndBatchUpdate() +{ + --mBatches; + return NS_OK; +} + NS_IMETHODIMP nsDownloadManager::Open(nsIDOMWindow* aParent) { diff --git a/xpfe/components/download-manager/src/nsDownloadManager.h b/xpfe/components/download-manager/src/nsDownloadManager.h index a9883708b24..305a1b21ef8 100644 --- a/xpfe/components/download-manager/src/nsDownloadManager.h +++ b/xpfe/components/download-manager/src/nsDownloadManager.h @@ -93,6 +93,7 @@ private: nsCOMPtr mListener; nsCOMPtr mRDFContainerUtils; nsCOMPtr mBundle; + PRInt32 mBatches; nsHashtable* mCurrDownloads; friend class nsDownload;