mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-14 18:51:28 +00:00
Bug 186999 Fix RestoreSelection so that sorting scrolls the selected message back into view and selecting messages by key works even when a message is already selected r=bienvenu sr=mscott
This commit is contained in:
parent
369750021e
commit
36d497e924
@ -768,7 +768,7 @@ nsresult nsMsgDBView::FetchLabel(nsIMsgHdr *aHdr, PRUnichar ** aLabelString)
|
||||
/*if you call SaveAndClearSelection make sure to call RestoreSelection otherwise
|
||||
m_saveRestoreSelectionDepth will be incorrect and will lead to selection msg problems*/
|
||||
|
||||
nsresult nsMsgDBView::SaveAndClearSelection(nsMsgKeyArray *aMsgKeyArray)
|
||||
nsresult nsMsgDBView::SaveAndClearSelection(nsMsgKey *aCurrentMsgKey, nsMsgKeyArray *aMsgKeyArray)
|
||||
{
|
||||
// we don't do anything on nested Save / Restore calls.
|
||||
m_saveRestoreSelectionDepth++;
|
||||
@ -781,7 +781,17 @@ nsresult nsMsgDBView::SaveAndClearSelection(nsMsgKeyArray *aMsgKeyArray)
|
||||
// first, freeze selection.
|
||||
mTreeSelection->SetSelectEventsSuppressed(PR_TRUE);
|
||||
|
||||
// second, get an array of view indices for the selection..
|
||||
// second, save the current index.
|
||||
if (aCurrentMsgKey)
|
||||
{
|
||||
PRInt32 currentIndex;
|
||||
if (NS_SUCCEEDED(mTreeSelection->GetCurrentIndex(¤tIndex)) && currentIndex >= 0 && currentIndex < GetSize())
|
||||
*aCurrentMsgKey = m_keys.GetAt(currentIndex);
|
||||
else
|
||||
*aCurrentMsgKey = nsMsgKey_None;
|
||||
}
|
||||
|
||||
// third, get an array of view indices for the selection.
|
||||
nsUInt32Array selection;
|
||||
GetSelectedIndices(&selection);
|
||||
PRInt32 numIndices = selection.GetSize();
|
||||
@ -801,7 +811,7 @@ nsresult nsMsgDBView::SaveAndClearSelection(nsMsgKeyArray *aMsgKeyArray)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsMsgDBView::RestoreSelection(nsMsgKeyArray * aMsgKeyArray)
|
||||
nsresult nsMsgDBView::RestoreSelection(nsMsgKey aCurrentMsgKey, nsMsgKeyArray *aMsgKeyArray)
|
||||
{
|
||||
// we don't do anything on nested Save / Restore calls.
|
||||
m_saveRestoreSelectionDepth--;
|
||||
@ -827,30 +837,24 @@ nsresult nsMsgDBView::RestoreSelection(nsMsgKeyArray * aMsgKeyArray)
|
||||
}
|
||||
}
|
||||
|
||||
// make sure the currentView was preserved....
|
||||
if (m_currentlyDisplayedMsgKey != nsMsgKey_None)
|
||||
{
|
||||
currentViewPosition = FindKey(m_currentlyDisplayedMsgKey, PR_FALSE);
|
||||
if (currentViewPosition != nsMsgViewIndex_None)
|
||||
{
|
||||
mTreeSelection->SetCurrentIndex(currentViewPosition);
|
||||
mTreeSelection->RangedSelect(currentViewPosition, currentViewPosition, PR_TRUE /* augment */);
|
||||
|
||||
// make sure the current message is once again visible in the thread pane
|
||||
// so we don't have to go search for it in the thread pane
|
||||
if (mTree) mTree->EnsureRowIsVisible(currentViewPosition);
|
||||
}
|
||||
}
|
||||
|
||||
for (PRInt32 index = 0; index < arraySize; index ++)
|
||||
{
|
||||
newViewPosition = FindKey(aMsgKeyArray->GetAt(index), PR_FALSE);
|
||||
// check to make sure newViewPosition is valid.
|
||||
// add the index back to the selection.
|
||||
if (newViewPosition != currentViewPosition) // don't re-add the current view
|
||||
mTreeSelection->RangedSelect(newViewPosition, newViewPosition, PR_TRUE /* augment */);
|
||||
mTreeSelection->ToggleSelect(newViewPosition);
|
||||
}
|
||||
|
||||
// make sure the currentView was preserved....
|
||||
if (aCurrentMsgKey != nsMsgKey_None)
|
||||
currentViewPosition = FindKey(aCurrentMsgKey, PR_TRUE);
|
||||
|
||||
mTreeSelection->SetCurrentIndex(currentViewPosition);
|
||||
|
||||
// make sure the current message is once again visible in the thread pane
|
||||
// so we don't have to go search for it in the thread pane
|
||||
if (mTree && currentViewPosition != nsMsgViewIndex_None)
|
||||
mTree->EnsureRowIsVisible(currentViewPosition);
|
||||
|
||||
// unfreeze selection.
|
||||
mTreeSelection->SetSelectEventsSuppressed(PR_FALSE);
|
||||
return NS_OK;
|
||||
@ -5663,7 +5667,7 @@ NS_IMETHODIMP nsMsgDBView::SelectMsgByKey(nsMsgKey aKey)
|
||||
// select (and load) the desired message
|
||||
|
||||
nsMsgKeyArray preservedSelection;
|
||||
nsresult rv = SaveAndClearSelection(&preservedSelection);
|
||||
nsresult rv = SaveAndClearSelection(nsnull, &preservedSelection);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
// now, restore our desired selection
|
||||
@ -5673,7 +5677,7 @@ NS_IMETHODIMP nsMsgDBView::SelectMsgByKey(nsMsgKey aKey)
|
||||
// if the key was not found
|
||||
// (this can happen with "remember last selected message")
|
||||
// nothing will be selected
|
||||
rv = RestoreSelection(&keyArray);
|
||||
rv = RestoreSelection(aKey, &keyArray);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -174,8 +174,8 @@ protected:
|
||||
// When you are done changing the view,
|
||||
// call RestoreSelection passing in the same array
|
||||
// and we'll restore the selection AND unfreeze selection in the UI.
|
||||
nsresult SaveAndClearSelection(nsMsgKeyArray * aMsgKeyArray);
|
||||
nsresult RestoreSelection(nsMsgKeyArray * aMsgKeyArray);
|
||||
nsresult SaveAndClearSelection(nsMsgKey *aCurrentMsgKey, nsMsgKeyArray *aMsgKeyArray);
|
||||
nsresult RestoreSelection(nsMsgKey aCurrentmsgKey, nsMsgKeyArray *aMsgKeyArray);
|
||||
|
||||
// this is not safe to use when you have a selection
|
||||
// RowCountChanged() will call AdjustSelection()
|
||||
|
@ -213,10 +213,11 @@ nsMsgQuickSearchDBView::OnNewSearch()
|
||||
NS_IMETHODIMP
|
||||
nsMsgQuickSearchDBView::Sort(nsMsgViewSortTypeValue sortType, nsMsgViewSortOrderValue sortOrder)
|
||||
{
|
||||
nsMsgKey preservedKey;
|
||||
nsMsgKeyArray preservedSelection;
|
||||
SaveAndClearSelection(&preservedSelection);
|
||||
SaveAndClearSelection(&preservedKey, &preservedSelection);
|
||||
nsMsgDBView::Sort(sortType, sortOrder);
|
||||
RestoreSelection(&preservedSelection);
|
||||
RestoreSelection(preservedKey, &preservedSelection);
|
||||
if (mTree)
|
||||
mTree->Invalidate();
|
||||
return NS_OK;
|
||||
|
@ -444,8 +444,9 @@ NS_IMETHODIMP nsMsgSearchDBView::Sort(nsMsgViewSortTypeValue sortType, nsMsgView
|
||||
if (!rowCountBeforeSort)
|
||||
return NS_OK;
|
||||
|
||||
nsMsgKey preservedKey;
|
||||
nsMsgKeyArray preservedSelection;
|
||||
SaveAndClearSelection(&preservedSelection);
|
||||
SaveAndClearSelection(&preservedKey, &preservedSelection);
|
||||
|
||||
rv = nsMsgDBView::Sort(sortType,sortOrder);
|
||||
|
||||
@ -455,7 +456,7 @@ NS_IMETHODIMP nsMsgSearchDBView::Sort(nsMsgViewSortTypeValue sortType, nsMsgView
|
||||
// this is safe when there is no selection.
|
||||
rv = AdjustRowCount(rowCountBeforeSort, GetSize());
|
||||
|
||||
RestoreSelection(&preservedSelection);
|
||||
RestoreSelection(preservedKey, &preservedSelection);
|
||||
if (mTree) mTree->Invalidate();
|
||||
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
@ -281,8 +281,9 @@ NS_IMETHODIMP nsMsgThreadedDBView::Sort(nsMsgViewSortTypeValue sortType, nsMsgVi
|
||||
if (sortType == nsMsgViewSortType::byThread && (m_viewFlags & nsMsgViewFlagsType::kThreadedDisplay) != 0)
|
||||
sortType = nsMsgViewSortType::byId;
|
||||
|
||||
nsMsgKey preservedKey;
|
||||
nsMsgKeyArray preservedSelection;
|
||||
SaveAndClearSelection(&preservedSelection);
|
||||
SaveAndClearSelection(&preservedKey, &preservedSelection);
|
||||
// if the client wants us to forget our cached id arrays, they
|
||||
// should build a new view. If this isn't good enough, we
|
||||
// need a method to do that.
|
||||
@ -310,7 +311,7 @@ NS_IMETHODIMP nsMsgThreadedDBView::Sort(nsMsgViewSortTypeValue sortType, nsMsgVi
|
||||
// this is safe when there is no selection.
|
||||
rv = AdjustRowCount(rowCountBeforeSort, GetSize());
|
||||
|
||||
RestoreSelection(&preservedSelection);
|
||||
RestoreSelection(preservedKey, &preservedSelection);
|
||||
if (mTree) mTree->Invalidate();
|
||||
return NS_OK;
|
||||
}
|
||||
@ -327,7 +328,7 @@ NS_IMETHODIMP nsMsgThreadedDBView::Sort(nsMsgViewSortTypeValue sortType, nsMsgVi
|
||||
// this is safe when there is no selection.
|
||||
rv = AdjustRowCount(rowCountBeforeSort, GetSize());
|
||||
|
||||
RestoreSelection(&preservedSelection);
|
||||
RestoreSelection(preservedKey, &preservedSelection);
|
||||
if (mTree) mTree->Invalidate();
|
||||
return NS_OK;
|
||||
}
|
||||
@ -374,7 +375,7 @@ NS_IMETHODIMP nsMsgThreadedDBView::Sort(nsMsgViewSortTypeValue sortType, nsMsgVi
|
||||
// this is safe when there is no selection.
|
||||
rv = AdjustRowCount(rowCountBeforeSort, GetSize());
|
||||
|
||||
RestoreSelection(&preservedSelection);
|
||||
RestoreSelection(preservedKey, &preservedSelection);
|
||||
if (mTree) mTree->Invalidate();
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
return NS_OK;
|
||||
|
Loading…
Reference in New Issue
Block a user