part of fix for bug 293088, expose ability to turn off view changes through xpidl, and turn off for mark all read r=neil
authorDavid Bienvenu <bienvenu@nventure.com>
Mon, 11 Apr 2011 14:57:32 -0700
changeset 7545 9d13d57f4f48ac3fc171c8f03c1b55578664023a
parent 7544 896dc129f9b54f54f59dcfa128ef08514e4623f0
child 7546 cc71bd856f9f4636d8e313d43ab167d85f735df6
push idunknown
push userunknown
push dateunknown
reviewersneil
bugs293088
part of fix for bug 293088, expose ability to turn off view changes through xpidl, and turn off for mark all read r=neil
mailnews/base/public/nsIMsgDBView.idl
mailnews/base/src/nsMsgDBView.cpp
mailnews/base/src/nsMsgDBView.h
mailnews/base/src/nsMsgGroupView.cpp
mailnews/base/src/nsMsgSearchDBView.cpp
mailnews/base/src/nsMsgThreadedDBView.cpp
--- a/mailnews/base/public/nsIMsgDBView.idl
+++ b/mailnews/base/public/nsIMsgDBView.idl
@@ -241,17 +241,17 @@ interface nsMsgNavigationType
   const nsMsgNavigationTypeValue previousFlagged = 19;
   const nsMsgNavigationTypeValue firstNew = 20;
   const nsMsgNavigationTypeValue editUndo = 21;
   const nsMsgNavigationTypeValue editRedo = 22;
   const nsMsgNavigationTypeValue toggleSubthreadKilled = 23;
 };
 
 
-[scriptable, uuid(da89fc17-92b0-43db-9df1-cbd112fdfea8)]
+[scriptable, uuid(cc1fb1d8-b033-478f-be73-982aff2248ef)]
 interface nsIMsgDBView : nsISupports
 {
   void open(in nsIMsgFolder folder, in nsMsgViewSortTypeValue sortType, in nsMsgViewSortOrderValue sortOrder, in nsMsgViewFlagsTypeValue viewFlags, out long count);
   void openWithHdrs(in nsISimpleEnumerator aHeaders, in nsMsgViewSortTypeValue aSortType, 
                       in nsMsgViewSortOrderValue aSortOrder, 
                       in nsMsgViewFlagsTypeValue aViewFlags, out long aCount);
   void close();
 
@@ -382,16 +382,23 @@ interface nsIMsgDBView : nsISupports
 
   void selectFolderMsgByKey(in nsIMsgFolder aFolder, in nsMsgKey aKey);
   // we'll suppress displaying messages if the message pane is collapsed
   attribute boolean suppressMsgDisplay;
 
   // we'll suppress command updating during folder loading
   attribute boolean suppressCommandUpdating;
 
+  /**
+   * Suppress change notifications. This is faster than Begin/EndUpdateBatch
+   * on the tree, but less safe in that you're responsible for row invalidation
+   * and row count changes.
+   */
+  attribute boolean suppressChangeNotifications;
+
   //to notify tree that rows are going away
   void onDeleteCompleted(in boolean succeeded);
 
   readonly attribute nsIMsgDatabase db;
 
   readonly attribute boolean supportsThreading;
 
   attribute nsIMsgSearchSession searchSession;
--- a/mailnews/base/src/nsMsgDBView.cpp
+++ b/mailnews/base/src/nsMsgDBView.cpp
@@ -2635,17 +2635,23 @@ NS_IMETHODIMP nsMsgDBView::DoCommand(nsM
         if (m_flags[curIndex] & nsMsgMessageFlags::Marked)
           mTreeSelection->ToggleSelect(curIndex);
       }
       mTreeSelection->SetSelectEventsSuppressed(PR_FALSE);
     }
     break;
   case nsMsgViewCommandType::markAllRead:
     if (m_folder)
+    {
+      SetSuppressChangeNotifications(PR_TRUE);
       rv = m_folder->MarkAllMessagesRead(msgWindow);
+      SetSuppressChangeNotifications(PR_FALSE);
+      if (mTree)
+        mTree->Invalidate();
+    }
     break;
   case nsMsgViewCommandType::toggleThreadWatched:
     rv = ToggleWatched(indices,  numIndices);
     break;
   case nsMsgViewCommandType::expandAll:
     rv = ExpandAll();
     m_viewFlags |= nsMsgViewFlagsType::kExpandAll;
     SetViewFlags(m_viewFlags);
@@ -5972,25 +5978,29 @@ NS_IMETHODIMP nsMsgDBView::OnJunkScoreCh
 }
 
 void nsMsgDBView::ClearHdrCache()
 {
   m_cachedHdr = nsnull;
   m_cachedMsgKey = nsMsgKey_None;
 }
 
-void nsMsgDBView::EnableChangeUpdates()
-{
-  mSuppressChangeNotification = PR_FALSE;
-}
-
-void nsMsgDBView::DisableChangeUpdates()
-{
-  mSuppressChangeNotification = PR_TRUE;
-}
+NS_IMETHODIMP nsMsgDBView::SetSuppressChangeNotifications(PRBool aSuppressChangeNotifications)
+{
+  mSuppressChangeNotification = aSuppressChangeNotifications;
+  return NS_OK;
+}
+
+NS_IMETHODIMP nsMsgDBView::GetSuppressChangeNotifications(PRBool * aSuppressChangeNotifications)
+{
+  NS_ENSURE_ARG_POINTER(aSuppressChangeNotifications);
+  *aSuppressChangeNotifications = mSuppressChangeNotification;
+  return NS_OK;
+}
+
 
 void nsMsgDBView::NoteChange(nsMsgViewIndex firstLineChanged, PRInt32 numChanged,
                              nsMsgViewNotificationCodeValue changeType)
 {
   if (mTree && !mSuppressChangeNotification)
   {
     switch (changeType)
     {
--- a/mailnews/base/src/nsMsgDBView.h
+++ b/mailnews/base/src/nsMsgDBView.h
@@ -331,18 +331,16 @@ protected:
   nsMsgViewIndex FindParentInThread(nsMsgKey parentKey, nsMsgViewIndex startOfThreadViewIndex);
   virtual nsresult ListIdsInThreadOrder(nsIMsgThread *threadHdr,
                                         nsMsgKey parentKey, PRInt32 level,
                                         nsMsgViewIndex *viewIndex,
                                         PRUint32 *pNumListed);
   PRUint32 GetSize(void) {return(m_keys.Length());}
 
   // notification api's
-  void  EnableChangeUpdates();
-  void  DisableChangeUpdates();
   void  NoteChange(nsMsgViewIndex firstlineChanged, PRInt32 numChanged,
                     nsMsgViewNotificationCodeValue changeType);
   void  NoteStartChange(nsMsgViewIndex firstlineChanged, PRInt32 numChanged,
                         nsMsgViewNotificationCodeValue changeType);
   void  NoteEndChange(nsMsgViewIndex firstlineChanged, PRInt32 numChanged,
                         nsMsgViewNotificationCodeValue changeType);
 
   // for commands
--- a/mailnews/base/src/nsMsgGroupView.cpp
+++ b/mailnews/base/src/nsMsgGroupView.cpp
@@ -545,19 +545,19 @@ nsresult nsMsgGroupView::RebuildView(nsM
     m_keys.Clear();
     // be consistent
     m_flags.Clear();
     m_levels.Clear();
 
     // this needs to happen after we remove all the keys, since RowCountChanged() will call our GetRowCount()
     if (mTree)
       mTree->RowCountChanged(0, -oldSize);
-    DisableChangeUpdates();
+    SetSuppressChangeNotifications(PR_TRUE);
     nsresult rv = OpenWithHdrs(headers, m_sortType, m_sortOrder, newFlags, &count);
-    EnableChangeUpdates();
+    SetSuppressChangeNotifications(PR_FALSE);
     if (mTree)
       mTree->RowCountChanged(0, GetSize());
 
     NS_ENSURE_SUCCESS(rv,rv);
 
     // now, restore our desired selection
     nsAutoTArray<nsMsgKey, 1> keyArray;
     keyArray.AppendElement(curSelectedKey);
--- a/mailnews/base/src/nsMsgSearchDBView.cpp
+++ b/mailnews/base/src/nsMsgSearchDBView.cpp
@@ -569,17 +569,17 @@ nsresult nsMsgSearchDBView::AddHdrFromFo
 // This method removes the thread at threadIndex from the view 
 // and puts it back in its new position, determined by the sort order.
 // And, if the selection is affected, save and restore the selection.
 void nsMsgSearchDBView::MoveThreadAt(nsMsgViewIndex threadIndex)
 {
   PRBool updatesSuppressed = mSuppressChangeNotification;
   // Turn off tree notifications so that we don't reload the current message.
   if (!updatesSuppressed)
-    DisableChangeUpdates();
+    SetSuppressChangeNotifications(PR_TRUE);
 
   nsCOMPtr<nsIMsgDBHdr> threadHdr;
   GetMsgHdrForViewIndex(threadIndex, getter_AddRefs(threadHdr));
 
   PRUint32 saveFlags = m_flags[threadIndex];
   PRBool threadIsExpanded = !(saveFlags & nsMsgMessageFlags::Elided);
   PRInt32 childCount = 0;
   nsMsgKey preservedKey;
@@ -644,17 +644,17 @@ void nsMsgSearchDBView::MoveThreadAt(nsM
     m_folders.InsertObjectsAt(threadFolders, newIndex + 1);
   }
   m_flags[newIndex] = saveFlags;
   // unfreeze selection.
   if (hasSelection)
     RestoreSelection(preservedKey, preservedSelection);
 
   if (!updatesSuppressed)
-    EnableChangeUpdates();
+    SetSuppressChangeNotifications(PR_FALSE);
   nsMsgViewIndex lowIndex = threadIndex < newIndex ? threadIndex : newIndex;
   nsMsgViewIndex highIndex = lowIndex == threadIndex ? newIndex : threadIndex;
   NoteChange(lowIndex, highIndex - lowIndex + childCount + 1,
              nsMsgViewNotificationCode::changed);
 }
 
 nsresult
 nsMsgSearchDBView::GetMessageEnumerator(nsISimpleEnumerator **enumerator)
--- a/mailnews/base/src/nsMsgThreadedDBView.cpp
+++ b/mailnews/base/src/nsMsgThreadedDBView.cpp
@@ -190,17 +190,17 @@ nsresult nsMsgThreadedDBView::SortThread
   }
   m_keys.SetLength(numThreads);
   m_flags.SetLength(numThreads);
   m_levels.SetLength(numThreads);
   //m_viewFlags &= ~nsMsgViewFlagsType::kThreadedDisplay;
   m_sortType = nsMsgViewSortType::byNone; // sort from scratch
   nsMsgDBView::Sort(sortType, sortOrder);
   m_viewFlags |= nsMsgViewFlagsType::kThreadedDisplay;
-  DisableChangeUpdates();
+  SetSuppressChangeNotifications(PR_TRUE);
   // Loop through the original array, for each thread that's expanded, find it in the new array
   // and expand the thread. We have to update MSG_VIEW_FLAG_HAS_CHILDREN because
   // we may be going from a flat sort, which doesn't maintain that flag,
   // to a threaded sort, which requires that flag.
   for (PRUint32 j = 0; j < m_keys.Length(); j++)
   {
     PRUint32 flags = m_flags[j];
     if ((flags & (MSG_VIEW_FLAG_HASCHILDREN | nsMsgMessageFlags::Elided)) == MSG_VIEW_FLAG_HASCHILDREN)
@@ -225,17 +225,17 @@ nsresult nsMsgThreadedDBView::SortThread
           PRUint32 numChildren;
           pThread->GetNumChildren(&numChildren);
           if (numChildren > 1)
             m_flags[j] = flags | MSG_VIEW_FLAG_HASCHILDREN | nsMsgMessageFlags::Elided;
         }
       }
     }
   }
-  EnableChangeUpdates();
+  SetSuppressChangeNotifications(PR_FALSE);
 
   return NS_OK;
 }
 
 nsresult nsMsgThreadedDBView::AddKeys(nsMsgKey *pKeys, PRInt32 *pFlags, const char *pLevels, nsMsgViewSortTypeValue sortType, PRInt32 numKeysToAdd)
 
 {
   PRInt32	numAdded = 0;
@@ -759,17 +759,17 @@ void nsMsgThreadedDBView::MoveThreadAt(n
 {
   // we need to check if the thread is collapsed or not...
   // We want to turn off tree notifications so that we don't
   // reload the current message.
   // We also need to invalidate the range between where the thread was
   // and where it ended up.
   PRBool changesDisabled = mSuppressChangeNotification;
   if (!changesDisabled)
-    DisableChangeUpdates();
+    SetSuppressChangeNotifications(PR_TRUE);
 
   nsCOMPtr <nsIMsgDBHdr> threadHdr;
 
   GetMsgHdrForViewIndex(threadIndex, getter_AddRefs(threadHdr));
   PRInt32 childCount = 0;
 
   nsMsgKey preservedKey;
   nsAutoTArray<nsMsgKey, 1> preservedSelection;
@@ -830,17 +830,17 @@ void nsMsgThreadedDBView::MoveThreadAt(n
      newIndex = 0;
   }
   m_flags[newIndex] = saveFlags;
   // unfreeze selection.
   if (hasSelection)
     RestoreSelection(preservedKey, preservedSelection);
 
   if (!changesDisabled)
-    EnableChangeUpdates();
+    SetSuppressChangeNotifications(PR_FALSE);
   nsMsgViewIndex lowIndex = threadIndex < newIndex ? threadIndex : newIndex;
   nsMsgViewIndex highIndex = lowIndex == threadIndex ? newIndex : threadIndex;
   NoteChange(lowIndex, highIndex - lowIndex + childCount + 1,
              nsMsgViewNotificationCode::changed);
 }
 nsresult nsMsgThreadedDBView::AddMsgToThreadNotInView(nsIMsgThread *threadHdr, nsIMsgDBHdr *msgHdr, PRBool ensureListed)
 {
   nsresult rv = NS_OK;