fix undoing delete from virtual folder when unread is search criteria, sr=mscott 383743

This commit is contained in:
bienvenu%nventure.com 2007-06-10 22:24:21 +00:00
Родитель 034d0bb127
Коммит 1a1ac26705
6 изменённых файлов: 69 добавлений и 6 удалений

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

@ -156,6 +156,7 @@ nsMsgDBView::nsMsgDBView()
mCommandsNeedDisablingBecauseOfSelection = PR_FALSE;
mRemovingRow = PR_FALSE;
m_saveRestoreSelectionDepth = 0;
mRecentlyDeletedArrayIndex = 0;
// initialize any static atoms or unicode strings
if (gInstanceCount == 0)
{
@ -1539,6 +1540,31 @@ NS_IMETHODIMP nsMsgDBView::GetCellValue(PRInt32 aRow, nsITreeColumn* aCol, nsASt
return rv;
}
void nsMsgDBView::RememberDeletedMsgHdr(nsIMsgDBHdr *msgHdr)
{
nsCString messageId;
msgHdr->GetMessageId(getter_Copies(messageId));
if (mRecentlyDeletedArrayIndex >= mRecentlyDeletedMsgIds.Count())
mRecentlyDeletedMsgIds.AppendCString(messageId);
else
mRecentlyDeletedMsgIds.ReplaceCStringAt(messageId, mRecentlyDeletedArrayIndex);
// only remember last 20 deleted msgs.
mRecentlyDeletedArrayIndex = ++mRecentlyDeletedArrayIndex % 20;
}
PRBool nsMsgDBView::WasHdrRecentlyDeleted(nsIMsgDBHdr *msgHdr)
{
nsCString messageId;
msgHdr->GetMessageId(getter_Copies(messageId));
PRInt32 arrayCount;
for (PRInt32 i = 0; i < mRecentlyDeletedMsgIds.Count(); i++)
{
if (messageId.Equals(*(mRecentlyDeletedMsgIds[i])))
return PR_TRUE;
}
return PR_FALSE;
}
//add a custom column handler
NS_IMETHODIMP nsMsgDBView::AddColumnHandler(const nsAString& column, nsIMsgCustomColumnHandler* handler)
{

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

@ -388,6 +388,16 @@ protected:
nsUInt32Array mIndicesToNoteChange;
// the saved search views keep track of the XX most recently deleted msg ids, so that if the
// delete is undone, we can add the msg back to the search results, even if it no longer
// matches the search criteria (e.g., a saved search over unread messages).
// We use mRecentlyDeletedArrayIndex to treat the array as a list of the XX
// most recently deleted msgs.
nsCStringArray mRecentlyDeletedMsgIds;
PRInt32 mRecentlyDeletedArrayIndex;
void RememberDeletedMsgHdr(nsIMsgDBHdr *msgHdr);
PRBool WasHdrRecentlyDeleted(nsIMsgDBHdr *msgHdr);
//these hold pointers (and IDs) for the nsIMsgCustomColumnHandler object that constitutes the custom column handler
nsCOMArray <nsIMsgCustomColumnHandler> m_customColumnHandlers;
nsStringArray m_customColumnHandlerIDs;

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

@ -72,6 +72,19 @@ NS_IMETHODIMP nsMsgQuickSearchDBView::Open(nsIMsgFolder *folder, nsMsgViewSortTy
return InitThreadedView(pCount);
}
nsresult nsMsgQuickSearchDBView::DeleteMessages(nsIMsgWindow *window, nsMsgViewIndex *indices, PRInt32 numIndices, PRBool deleteStorage)
{
for (nsMsgViewIndex i = 0; i < (nsMsgViewIndex) numIndices; i++)
{
nsCOMPtr<nsIMsgDBHdr> msgHdr;
(void) GetMsgHdrForViewIndex(indices[i],getter_AddRefs(msgHdr));
if (msgHdr)
RememberDeletedMsgHdr(msgHdr);
}
return nsMsgDBView::DeleteMessages(window, indices, numIndices, deleteStorage);
}
NS_IMETHODIMP nsMsgQuickSearchDBView::DoCommand(nsMsgViewCommandTypeValue aCommand)
{
if (aCommand == nsMsgViewCommandType::markAllRead)

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

@ -73,6 +73,7 @@ protected:
PRBool m_cacheEmpty;
nsCOMArray <nsIMsgDBHdr> m_hdrHits;
virtual nsresult OnNewHeader(nsIMsgDBHdr *newHdr, nsMsgKey aParentKey, PRBool ensureListed);
virtual nsresult DeleteMessages(nsIMsgWindow *window, nsMsgViewIndex *indices, PRInt32 numIndices, PRBool deleteStorage);
virtual nsresult SortThreads(nsMsgViewSortTypeValue sortType, nsMsgViewSortOrderValue sortOrder);
virtual nsresult GetFirstMessageHdrToDisplayInThread(nsIMsgThread *threadHdr, nsIMsgDBHdr **result);
virtual nsresult ExpansionDelta(nsMsgViewIndex index, PRInt32 *expansionDelta);

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

@ -343,10 +343,21 @@ nsresult nsMsgSearchDBView::RemoveByIndex(nsMsgViewIndex index)
nsresult nsMsgSearchDBView::DeleteMessages(nsIMsgWindow *window, nsMsgViewIndex *indices, PRInt32 numIndices, PRBool deleteStorage)
{
nsresult rv;
GetFoldersAndHdrsForSelection(indices, numIndices);
if (mDeleteModel != nsMsgImapDeleteModels::MoveToTrash)
deleteStorage = PR_TRUE;
nsresult rv;
GetFoldersAndHdrsForSelection(indices, numIndices);
if (mDeleteModel != nsMsgImapDeleteModels::MoveToTrash)
deleteStorage = PR_TRUE;
// remember the deleted messages in case the user undoes the delete,
// and we want to restore the hdr to the view, even if it no
// longer matches the search criteria.
for (nsMsgViewIndex i = 0; i < (nsMsgViewIndex) numIndices; i++)
{
nsCOMPtr<nsIMsgDBHdr> msgHdr;
(void) GetMsgHdrForViewIndex(indices[i],getter_AddRefs(msgHdr));
if (msgHdr)
RememberDeletedMsgHdr(msgHdr);
}
if (!deleteStorage)
rv = ProcessRequestsInOneFolder(window);
else
@ -499,7 +510,7 @@ nsMsgSearchDBView::OnStopCopy(nsresult aStatus)
mCurIndex++;
PRUint32 numFolders =0;
rv = m_uniqueFoldersSelected->Count(&numFolders);
if ( mCurIndex < numFolders)
if ( mCurIndex < (PRUint32) numFolders)
ProcessRequestsInOneFolder(mMsgWindow);
}

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

@ -131,10 +131,12 @@ nsresult nsMsgXFVirtualFolderDBView::OnNewHeader(nsIMsgDBHdr *newHdr, nsMsgKey a
{
if (newHdr)
{
PRBool match=PR_FALSE;
PRBool match = PR_FALSE;
nsCOMPtr <nsIMsgSearchSession> searchSession = do_QueryReferent(m_searchSession);
if (searchSession)
searchSession->MatchHdr(newHdr, m_db, &match);
if (!match)
match = WasHdrRecentlyDeleted(newHdr);
if (match)
{
nsCOMPtr <nsIMsgFolder> folder;