diff --git a/mail/base/content/msgMail3PaneWindow.js b/mail/base/content/msgMail3PaneWindow.js index f62beafc0157..42e1d4b6703e 100644 --- a/mail/base/content/msgMail3PaneWindow.js +++ b/mail/base/content/msgMail3PaneWindow.js @@ -100,6 +100,49 @@ function SelectAndScrollToKey(aMsgKey) return true; } +// A helper routine called after a folder is loaded to make sure +// we select and scroll to the correct message (could be the first new message, +// could be the last displayed message, etc.) +// returns true if we ended up scrolling to a message +function ScrollToMessageAfterFolderLoad (folder) +{ + var scrolled = ScrollToMessage(nsMsgNavigationType.firstNew, true, false /* selectMessage */); + if (!scrolled && folder && pref.getBoolPref("mailnews.remember_selected_message")) + { + // if we failed to scroll to a new message, + // reselect the last selected message + var lastMessageLoaded = folder.lastMessageLoaded; + + if (lastMessageLoaded != nsMsgKey_None) + scrolled = SelectAndScrollToKey(lastMessageLoaded); + } + + if (!scrolled) + { + // if we still haven't scrolled, + // scroll to the newest, which might be the top or the bottom + // depending on our sort order and sort type + if (gDBView.sortOrder == nsMsgViewSortOrder.ascending) + { + switch (gDBView.sortType) + { + case nsMsgViewSortType.byDate: + case nsMsgViewSortType.byId: + case nsMsgViewSortType.byThread: + scrolled = ScrollToMessage(nsMsgNavigationType.lastMessage, true, false /* selectMessage */); + break; + } + } + + // if still we haven't scrolled, + // scroll to the top. + if (!scrolled) + EnsureRowInThreadTreeIsVisible(0); + } + + return scrolled; +} + // the folderListener object var folderListener = { OnItemAdded: function(parentItem, item) { }, @@ -128,7 +171,7 @@ var folderListener = { var uri = folder.URI; var rerootingFolder = (uri == gCurrentFolderToReroot); if (rerootingFolder) { - viewDebug("uri = gCurrentFolderToReroot, setting gQSViewIsDirty\n"); + viewDebug("uri = gCurrentFolderToReroot, setting gQSViewIsDirty\n"); gQSViewIsDirty = true; gCurrentFolderToReroot = null; var msgFolder = folder.QueryInterface(Components.interfaces.nsIMsgFolder); @@ -181,53 +224,10 @@ var folderListener = { } } if (uri == gCurrentLoadingFolderURI) { - // NOTE, - // if you change the scrolling code below, - // double check the scrolling logic in - // searchBar.js, restorePreSearchView() viewDebug("uri == current loading folder uri\n"); gCurrentLoadingFolderURI = ""; - // if we didn't just scroll, - // scroll to the first new message - // but don't select it - if (!scrolled && pref.getBoolPref("mailnews.scroll_to_new_message")) - scrolled = ScrollToMessage(nsMsgNavigationType.firstNew, true, false /* selectMessage */); - - if (!scrolled && pref.getBoolPref("mailnews.remember_selected_message")) { - // if we failed to scroll to a new message, - // reselect the last selected message - var lastMessageLoaded = msgFolder.lastMessageLoaded; - - if (lastMessageLoaded != nsMsgKey_None) { - scrolled = SelectAndScrollToKey(lastMessageLoaded); - } - } - - if (!scrolled) { - // if we still haven't scrolled, - // scroll to the newest, which might be the top or the bottom - // depending on our sort order and sort type - if (gDBView.sortOrder == nsMsgViewSortOrder.ascending) { - switch (gDBView.sortType) { - case nsMsgViewSortType.byDate: - case nsMsgViewSortType.byId: - case nsMsgViewSortType.byThread: - scrolled = ScrollToMessage(nsMsgNavigationType.lastMessage, true, false /* selectMessage */); - break; - } - } - - // if still we haven't scrolled, - // scroll to the top. - if (!scrolled) - EnsureRowInThreadTreeIsVisible(0); - } - - // NOTE, - // if you change the scrolling code above, - // double check the scrolling logic in - // searchBar.js, restorePreSearchView() + scrolled = ScrollToMessageAfterFolderLoad(msgFolder); SetBusyCursor(window, false); } diff --git a/mail/base/content/searchBar.js b/mail/base/content/searchBar.js index 68b80e06ae61..a76a6c79f153 100644 --- a/mail/base/content/searchBar.js +++ b/mail/base/content/searchBar.js @@ -119,6 +119,9 @@ var gSearchNotificationListener = vFolder.updateSummaryTotals(true); // force update from db. var msgdb = vFolder.getMsgDatabase(msgWindow); msgdb.Commit(MSG_DB_LARGE_COMMIT); + + // now that we have finished loading a virtual folder, scroll to the correct message + ScrollToMessageAfterFolderLoad(vFolder); } }, @@ -315,43 +318,8 @@ function restorePreSearchView() ClearMessagePane(); } - // NOTE, - // if you change the scrolling code below, - // double check the scrolling logic in - // msgMail3PaneWindow.js, "FolderLoaded" event code if (!scrolled) - { - // if we didn't just scroll, - // scroll to the first new message - // but don't select it - if (pref.getBoolPref("mailnews.scroll_to_new_message")) - scrolled = ScrollToMessage(nsMsgNavigationType.firstNew, true, false /* selectMessage */); - if (!scrolled) - { - // if we still haven't scrolled, - // scroll to the newest, which might be the top or the bottom - // depending on our sort order and sort type - if (sortOrder == nsMsgViewSortOrder.ascending) - { - switch (sortType) - { - case nsMsgViewSortType.byDate: - case nsMsgViewSortType.byId: - case nsMsgViewSortType.byThread: - scrolled = ScrollToMessage(nsMsgNavigationType.lastMessage, true, false /* selectMessage */); - break; - } - } - // if still we haven't scrolled, - // scroll to the top. - if (!scrolled) - EnsureRowInThreadTreeIsVisible(0); - } - } - // NOTE, - // if you change the scrolling code above, - // double check the scrolling logic in - // msgMail3PaneWindow.js, "FolderLoaded" event code + ScrollToMessageAfterFolderLoad(null); } function onSearch(aSearchTerms) diff --git a/mailnews/base/src/nsMsgDBView.cpp b/mailnews/base/src/nsMsgDBView.cpp index 361a86bde18f..08c6bde0e04e 100644 --- a/mailnews/base/src/nsMsgDBView.cpp +++ b/mailnews/base/src/nsMsgDBView.cpp @@ -981,8 +981,6 @@ nsresult nsMsgDBView::UpdateDisplayMessage(nsMsgViewIndex viewPosition) nsCOMPtr msgHdr; rv = GetMsgHdrForViewIndex(viewPosition, getter_AddRefs(msgHdr)); NS_ENSURE_SUCCESS(rv,rv); - nsCOMPtr folder; - GetMsgFolder(getter_AddRefs(folder)); nsXPIDLString subject; FetchSubject(msgHdr, m_flags[viewPosition], getter_Copies(subject)); @@ -991,11 +989,11 @@ nsresult nsMsgDBView::UpdateDisplayMessage(nsMsgViewIndex viewPosition) rv = msgHdr->GetStringProperty("keywords", getter_Copies(keywords)); NS_ENSURE_SUCCESS(rv,rv); - mCommandUpdater->DisplayMessageChanged(folder, subject, keywords); + mCommandUpdater->DisplayMessageChanged(m_viewFolder, subject, keywords); - if (folder) + if (m_viewFolder) { - rv = folder->SetLastMessageLoaded(m_keys[viewPosition]); + rv = m_viewFolder->SetLastMessageLoaded(m_keys[viewPosition]); NS_ENSURE_SUCCESS(rv,rv); } } // if view position is valid