Bug 214751 Clean up ReverseThreads and ReverseSort a bit more r+sr=bienvenu

This commit is contained in:
neil%parkwaycc.co.uk 2008-05-25 21:46:34 +00:00
Родитель bbf4165685
Коммит 11fe34f81e
2 изменённых файлов: 36 добавлений и 65 удалений

Просмотреть файл

@ -3153,92 +3153,74 @@ nsMsgDBView::DetermineActionsForJunkMsgs(PRBool* movingJunkMessages, PRBool* mar
// reversing threads involves reversing the threads but leaving the // reversing threads involves reversing the threads but leaving the
// expanded messages ordered relative to the thread, so we // expanded messages ordered relative to the thread, so we
// make a copy of each array and copy them over. // make a copy of each array and copy them over.
nsresult nsMsgDBView::ReverseThreads() void nsMsgDBView::ReverseThreads()
{ {
nsTArray<PRUint32> newFlagArray; nsTArray<PRUint32> newFlagArray;
nsTArray<nsMsgKey> newKeyArray; nsTArray<nsMsgKey> newKeyArray;
nsTArray<PRUint8> newLevelArray; nsTArray<PRUint8> newLevelArray;
PRInt32 sourceIndex, destIndex; PRUint32 viewSize = GetSize();
PRInt32 viewSize = GetSize(); PRUint32 startThread = viewSize;
PRUint32 nextThread = viewSize;
PRUint32 destIndex = 0;
newKeyArray.SetLength(m_keys.Length()); newKeyArray.SetLength(m_keys.Length());
newFlagArray.SetLength(m_flags.Length()); newFlagArray.SetLength(m_flags.Length());
newLevelArray.SetLength(m_levels.Length()); newLevelArray.SetLength(m_levels.Length());
for (sourceIndex = 0, destIndex = viewSize - 1; sourceIndex < viewSize;) while (startThread)
{ {
PRInt32 endThread; // find end of current thread. startThread--;
PRBool inExpandedThread = PR_FALSE;
for (endThread = sourceIndex; endThread < viewSize; endThread++)
{
PRUint32 flags = m_flags[endThread];
if (!inExpandedThread && (flags & (MSG_VIEW_FLAG_ISTHREAD|MSG_VIEW_FLAG_HASCHILDREN)) && !(flags & MSG_FLAG_ELIDED))
inExpandedThread = PR_TRUE;
else if (flags & MSG_VIEW_FLAG_ISTHREAD)
{
if (inExpandedThread)
endThread--;
break;
}
}
if (endThread == viewSize) if (m_flags[startThread] & MSG_VIEW_FLAG_ISTHREAD)
endThread--;
PRInt32 saveEndThread = endThread;
while (endThread >= sourceIndex)
{ {
newKeyArray[destIndex] = m_keys[endThread]; for (PRUint32 sourceIndex = startThread; sourceIndex < nextThread; sourceIndex++)
newFlagArray[destIndex] = m_flags[endThread]; {
newLevelArray[destIndex] = m_levels[endThread]; newKeyArray[destIndex] = m_keys[sourceIndex];
endThread--; newFlagArray[destIndex] = m_flags[sourceIndex];
destIndex--; newLevelArray[destIndex] = m_levels[sourceIndex];
destIndex++;
}
nextThread = startThread; // because we're copying in reverse order
} }
sourceIndex = saveEndThread + 1;
} }
m_keys.SwapElements(newKeyArray); m_keys.SwapElements(newKeyArray);
m_flags.SwapElements(newFlagArray); m_flags.SwapElements(newFlagArray);
m_levels.SwapElements(newLevelArray); m_levels.SwapElements(newLevelArray);
return NS_OK;
} }
nsresult nsMsgDBView::ReverseSort() void nsMsgDBView::ReverseSort()
{ {
PRUint32 num = GetSize(); PRUint32 topIndex = GetSize();
nsCOMPtr <nsISupportsArray> folders; nsCOMPtr <nsISupportsArray> folders;
GetFolders(getter_AddRefs(folders)); GetFolders(getter_AddRefs(folders));
// go up half the array swapping values // go up half the array swapping values
for (PRUint32 i = 0; i < (num / 2); i++) for (PRUint32 bottomIndex = 0; bottomIndex < --topIndex; bottomIndex++)
{ {
// swap flags // swap flags
PRUint32 end = num - i - 1; PRUint32 tempFlags = m_flags[bottomIndex];
PRUint32 tempFlags = m_flags[i]; m_flags[bottomIndex] = m_flags[topIndex];
m_flags[i] = m_flags[end]; m_flags[topIndex] = tempFlags;
m_flags[end] = tempFlags;
// swap keys // swap keys
nsMsgKey tempKey = m_keys[i]; nsMsgKey tempKey = m_keys[bottomIndex];
m_keys[i] = m_keys[end]; m_keys[bottomIndex] = m_keys[topIndex];
m_keys[end] = tempKey; m_keys[topIndex] = tempKey;
if (folders) if (folders)
{ {
// swap folders -- // swap folders --
// needed when search is done across multiple folders // needed when search is done across multiple folders
nsCOMPtr<nsISupports> tmpSupports = dont_AddRef(folders->ElementAt(i)); nsCOMPtr<nsISupports> tmpSupports = dont_AddRef(folders->ElementAt(bottomIndex));
nsCOMPtr<nsISupports> endSupports = dont_AddRef(folders->ElementAt(end)); nsCOMPtr<nsISupports> topSupports = dont_AddRef(folders->ElementAt(topIndex));
folders->SetElementAt(i, endSupports); folders->SetElementAt(bottomIndex, topSupports);
folders->SetElementAt(end, tmpSupports); folders->SetElementAt(topIndex, tmpSupports);
} }
// no need to swap elements in m_levels, // no need to swap elements in m_levels; since we only call
// since we won't call ReverseSort() if we // ReverseSort in non-threaded mode, m_levels are all the same.
// are in threaded mode, so m_levels are all the same.
} }
return NS_OK;
} }
struct IdDWord struct IdDWord
@ -3827,15 +3809,10 @@ NS_IMETHODIMP nsMsgDBView::Sort(nsMsgViewSortTypeValue sortType, nsMsgViewSortOr
if (m_sortColumns.Length()) if (m_sortColumns.Length())
m_sortColumns[0].mSortOrder = sortOrder; m_sortColumns[0].mSortOrder = sortOrder;
SaveSortInfo(sortType, sortOrder); SaveSortInfo(sortType, sortOrder);
if (! (m_viewFlags & nsMsgViewFlagsType::kThreadedDisplay)) if (m_viewFlags & nsMsgViewFlagsType::kThreadedDisplay)
{ ReverseThreads();
(void ) ReverseSort(); // doesn't fail.
}
else else
{ ReverseSort();
rv = ReverseThreads();
NS_ENSURE_SUCCESS(rv,rv);
}
m_sortOrder = sortOrder; m_sortOrder = sortOrder;
// we just reversed the sort order...we still need to invalidate the view // we just reversed the sort order...we still need to invalidate the view
@ -4043,12 +4020,6 @@ NS_IMETHODIMP nsMsgDBView::Sort(nsMsgViewSortTypeValue sortType, nsMsgViewSortOr
m_sortType = sortType; m_sortType = sortType;
m_sortOrder = sortOrder; m_sortOrder = sortOrder;
if (sortOrder == nsMsgViewSortOrder::descending)
{
// rv = ReverseSort();
NS_ASSERTION(NS_SUCCEEDED(rv),"failed to reverse sort");
}
// free all the memory we allocated // free all the memory we allocated
FreeAll(&ptrs); FreeAll(&ptrs);

Просмотреть файл

@ -247,8 +247,8 @@ protected:
nsMsgKey GetKeyOfFirstMsgInThread(nsMsgKey key); nsMsgKey GetKeyOfFirstMsgInThread(nsMsgKey key);
PRInt32 CountExpandedThread(nsMsgViewIndex index); PRInt32 CountExpandedThread(nsMsgViewIndex index);
virtual nsresult ExpansionDelta(nsMsgViewIndex index, PRInt32 *expansionDelta); virtual nsresult ExpansionDelta(nsMsgViewIndex index, PRInt32 *expansionDelta);
nsresult ReverseSort(); void ReverseSort();
nsresult ReverseThreads(); void ReverseThreads();
nsresult SaveSortInfo(nsMsgViewSortTypeValue sortType, nsMsgViewSortOrderValue sortOrder); nsresult SaveSortInfo(nsMsgViewSortTypeValue sortType, nsMsgViewSortOrderValue sortOrder);
nsresult PersistFolderInfo(nsIDBFolderInfo **dbFolderInfo); nsresult PersistFolderInfo(nsIDBFolderInfo **dbFolderInfo);
void SetMRUTimeForFolder(nsIMsgFolder *folder); void SetMRUTimeForFolder(nsIMsgFolder *folder);