more work on #73868. converting ab from tree to outliner.

restore selection after sorting. NOT PART OF THE BUILD.
This commit is contained in:
sspitzer%netscape.com 2001-11-16 07:53:43 +00:00
parent 7c514e0bd3
commit a5c16ce813
2 changed files with 109 additions and 32 deletions

View File

@ -609,7 +609,29 @@ NS_IMETHODIMP nsAbView::SortBy(const PRUnichar *colID, const PRUnichar *sortDir)
SortClosure closure;
SetSortClosure(sortColumn.get(), sortDirection.get(), this, &closure);
nsCOMPtr <nsISupportsArray> selectedCards;
rv = GetSelectedCards(getter_AddRefs(selectedCards));
NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr<nsIAbCard> indexCard;
if (mOutlinerSelection) {
PRInt32 currentIndex = -1;
rv = mOutlinerSelection->GetCurrentIndex(&currentIndex);
NS_ENSURE_SUCCESS(rv,rv);
if (currentIndex != -1) {
rv = GetCardFromRow(currentIndex, getter_AddRefs(indexCard));
NS_ENSURE_SUCCESS(rv,rv);
}
}
mCards.Sort(inplaceSortCallback, (void *)(&closure));
rv = ReselectCards(selectedCards, indexCard);
NS_ENSURE_SUCCESS(rv,rv);
mSortColumn = sortColumn.get();
mSortDirection = sortDirection.get();
}
@ -966,19 +988,76 @@ NS_IMETHODIMP nsAbView::GetSortColumn(PRUnichar **column)
return NS_OK;
}
nsresult nsAbView::ReselectCards(nsISupportsArray *cards, nsIAbCard *indexCard)
{
PRUint32 count;
PRUint32 i;
if (!mOutlinerSelection)
return NS_OK;
nsresult rv = mOutlinerSelection->ClearSelection();
NS_ENSURE_SUCCESS(rv,rv);
rv = cards->Count(&count);
NS_ENSURE_SUCCESS(rv, rv);
for (i = 0; i < count; i++) {
nsCOMPtr<nsISupports> cardSupports;
cardSupports = getter_AddRefs(cards->ElementAt(i));
nsCOMPtr <nsIAbCard> card = do_QueryInterface(cardSupports);
if (card) {
PRInt32 index = FindIndexForCard(card);
if (index != CARD_NOT_FOUND) {
mOutlinerSelection->RangedSelect(index, index, PR_TRUE /* augment */);
}
}
}
// reset the index card, and ensure it is visible
if (indexCard) {
PRInt32 currentIndex = FindIndexForCard(indexCard);
rv = mOutlinerSelection->SetCurrentIndex(currentIndex);
NS_ENSURE_SUCCESS(rv, rv);
if (mOutliner) {
rv = mOutliner->EnsureRowIsVisible(currentIndex);
NS_ENSURE_SUCCESS(rv, rv);
}
}
return NS_OK;
}
NS_IMETHODIMP nsAbView::DeleteSelectedCards()
{
if (mOutlinerSelection)
{
nsCOMPtr <nsISupportsArray> cardsToDelete;
nsresult rv = GetSelectedCards(getter_AddRefs(cardsToDelete));
NS_ENSURE_SUCCESS(rv,rv);
rv = mDirectory->DeleteCards(cardsToDelete);
NS_ENSURE_SUCCESS(rv,rv);
return NS_OK;
}
nsresult nsAbView::GetSelectedCards(nsISupportsArray **selectedCards)
{
*selectedCards = nsnull;
if (!mOutlinerSelection)
return NS_OK;
nsresult rv = NS_NewISupportsArray(selectedCards);
NS_ENSURE_SUCCESS(rv,rv);
PRInt32 selectionCount;
nsresult rv = mOutlinerSelection->GetRangeCount(&selectionCount);
rv = mOutlinerSelection->GetRangeCount(&selectionCount);
NS_ENSURE_SUCCESS(rv,rv);
if (!selectionCount)
return NS_OK;
nsCOMPtr <nsISupportsArray> cardsToDelete;
NS_NewISupportsArray(getter_AddRefs(cardsToDelete));
NS_NewISupportsArray(selectedCards);
for (PRInt32 i = 0; i < selectionCount; i++)
{
@ -997,14 +1076,10 @@ NS_IMETHODIMP nsAbView::DeleteSelectedCards()
nsCOMPtr<nsISupports> supports = do_QueryInterface(abCard, &rv);
NS_ENSURE_SUCCESS(rv,rv);
rv = cardsToDelete->AppendElement(supports);
rv = (*selectedCards)->AppendElement(supports);
NS_ENSURE_SUCCESS(rv,rv);
}
}
}
rv = mDirectory->DeleteCards(cardsToDelete);
NS_ENSURE_SUCCESS(rv,rv);
}
return NS_OK;
}

View File

@ -91,6 +91,8 @@ private:
nsresult AddPrefObservers();
nsresult RemovePrefObservers();
nsresult SetGeneratedNameFormatFromPrefs();
nsresult GetSelectedCards(nsISupportsArray **cards);
nsresult ReselectCards(nsISupportsArray *cards, nsIAbCard *indexCard);
nsCString mURI;
nsCOMPtr <nsIAbDirectory> mDirectory;