diff options
Diffstat (limited to 'indra/newview')
-rw-r--r-- | indra/newview/llfolderview.cpp | 13 | ||||
-rw-r--r-- | indra/newview/llfolderview.h | 11 | ||||
-rw-r--r-- | indra/newview/llfolderviewitem.cpp | 140 | ||||
-rw-r--r-- | indra/newview/llfolderviewitem.h | 63 |
4 files changed, 160 insertions, 67 deletions
diff --git a/indra/newview/llfolderview.cpp b/indra/newview/llfolderview.cpp index bbcd3fa652..387e300b74 100644 --- a/indra/newview/llfolderview.cpp +++ b/indra/newview/llfolderview.cpp @@ -350,6 +350,10 @@ BOOL LLFolderView::addFolder( LLFolderViewFolder* folder) { mFolders.insert(mFolders.begin(), folder); } + if (folder->numSelected()) + { + recursiveIncrementNumDescendantsSelected(folder->numSelected()); + } folder->setShowLoadStatus(true); folder->setOrigin(0, 0); folder->reshape(getRect().getWidth(), 0); @@ -692,29 +696,24 @@ BOOL LLFolderView::changeSelection(LLFolderViewItem* selection, BOOL selected) return rv; } -S32 LLFolderView::extendSelection(LLFolderViewItem* selection, LLFolderViewItem* last_selected, LLDynamicArray<LLFolderViewItem*>& items) +void LLFolderView::extendSelection(LLFolderViewItem* selection, LLFolderViewItem* last_selected, LLDynamicArray<LLFolderViewItem*>& items) { - S32 rv = 0; - // now store resulting selection if (mAllowMultiSelect) { LLFolderViewItem *cur_selection = getCurSelectedItem(); - rv = LLFolderViewFolder::extendSelection(selection, cur_selection, items); + LLFolderViewFolder::extendSelection(selection, cur_selection, items); for (S32 i = 0; i < items.count(); i++) { addToSelectionList(items[i]); - rv++; } } else { setSelection(selection, FALSE, FALSE); - rv++; } mSignalSelectCallback = SIGNAL_KEYBOARD_FOCUS; - return rv; } void LLFolderView::sanitizeSelection() diff --git a/indra/newview/llfolderview.h b/indra/newview/llfolderview.h index 980f9a34a6..f9c48c3ca7 100644 --- a/indra/newview/llfolderview.h +++ b/indra/newview/llfolderview.h @@ -74,7 +74,6 @@ public: virtual void doItem(LLFolderViewItem* item) = 0; }; - //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Class LLFolderView // @@ -146,18 +145,18 @@ public: // Record the selected item and pass it down the hierachy. virtual BOOL setSelection(LLFolderViewItem* selection, BOOL openitem, BOOL take_keyboard_focus); - + // Used by menu callbacks void setSelectionByID(const LLUUID& obj_id, BOOL take_keyboard_focus); - + // Called once a frame to update the selection if mSelectThisID has been set - void updateSelection(); - + void updateSelection(); + // This method is used to toggle the selection of an item. Walks // children, and keeps track of selected objects. virtual BOOL changeSelection(LLFolderViewItem* selection, BOOL selected); - virtual S32 extendSelection(LLFolderViewItem* selection, LLFolderViewItem* last_selected, LLDynamicArray<LLFolderViewItem*>& items); + virtual void extendSelection(LLFolderViewItem* selection, LLFolderViewItem* last_selected, LLDynamicArray<LLFolderViewItem*>& items); virtual std::set<LLUUID> getSelectionList() const; diff --git a/indra/newview/llfolderviewitem.cpp b/indra/newview/llfolderviewitem.cpp index 04b690b903..316f78d1e2 100644 --- a/indra/newview/llfolderviewitem.cpp +++ b/indra/newview/llfolderviewitem.cpp @@ -489,27 +489,34 @@ void LLFolderViewItem::dirtyFilter() // together. BOOL LLFolderViewItem::setSelection(LLFolderViewItem* selection, BOOL openitem, BOOL take_keyboard_focus) { - if( selection == this ) + if (selection == this && !mIsSelected) { - mIsSelected = TRUE; - if(mListener) + selectItem(); + if (mListener) { mListener->selectItem(); } } - else + else if (mIsSelected) // Deselect everything else. { - mIsSelected = FALSE; + deselectItem(); } return mIsSelected; } BOOL LLFolderViewItem::changeSelection(LLFolderViewItem* selection, BOOL selected) { - if(selection == this && mIsSelected != selected) + if (selection == this && mIsSelected != selected) { - mIsSelected = selected; - if(mListener) + if (mIsSelected) + { + deselectItem(); + } + else + { + selectItem(); + } + if (mListener) { mListener->selectItem(); } @@ -518,6 +525,33 @@ BOOL LLFolderViewItem::changeSelection(LLFolderViewItem* selection, BOOL selecte return FALSE; } +void LLFolderViewItem::deselectItem(void) +{ + llassert(mIsSelected); + + mIsSelected = FALSE; + + // Update ancestors' count of selected descendents. + LLFolderViewFolder* parent_folder = getParentFolder(); + if (parent_folder) + { + parent_folder->recursiveIncrementNumDescendantsSelected(-1); + } +} + +void LLFolderViewItem::selectItem(void) +{ + llassert(!mIsSelected); + + mIsSelected = TRUE; + + // Update ancestors' count of selected descendents. + LLFolderViewFolder* parent_folder = getParentFolder(); + if (parent_folder) + { + parent_folder->recursiveIncrementNumDescendantsSelected(1); + } +} BOOL LLFolderViewItem::isMovable() { @@ -1073,6 +1107,7 @@ void LLFolderViewItem::draw() LLFolderViewFolder::LLFolderViewFolder( const LLFolderViewItem::Params& p ): LLFolderViewItem( p ), // 0 = no create time + mNumDescendantsSelected(0), mIsOpen(FALSE), mExpanderHighlighted(FALSE), mCurHeight(0.f), @@ -1458,16 +1493,34 @@ BOOL LLFolderViewFolder::hasFilteredDescendants() return mMostFilteredDescendantGeneration >= getRoot()->getFilter()->getCurrentGeneration(); } +void LLFolderViewFolder::recursiveIncrementNumDescendantsSelected(S32 increment) +{ + LLFolderViewFolder* parent_folder = this; + do + { + parent_folder->mNumDescendantsSelected += increment; + + // Make sure we don't have negative values. + llassert(parent_folder->mNumDescendantsSelected >= 0); + + parent_folder = parent_folder->getParentFolder(); + } + while(parent_folder); +} + // Passes selection information on to children and record selection // information if necessary. BOOL LLFolderViewFolder::setSelection(LLFolderViewItem* selection, BOOL openitem, BOOL take_keyboard_focus) { BOOL rv = FALSE; - if( selection == this ) + if (selection == this) { - mIsSelected = TRUE; - if(mListener) + if (!isSelected()) + { + selectItem(); + } + if (mListener) { mListener->selectItem(); } @@ -1475,7 +1528,10 @@ BOOL LLFolderViewFolder::setSelection(LLFolderViewItem* selection, BOOL openitem } else { - mIsSelected = FALSE; + if (isSelected()) + { + deselectItem(); + } rv = FALSE; } BOOL child_selected = FALSE; @@ -1507,21 +1563,31 @@ BOOL LLFolderViewFolder::setSelection(LLFolderViewItem* selection, BOOL openitem return rv; } -// This method is used to change the selection of an item. If -// selection is 'this', then note selection as true. Returns TRUE -// if this or a child is now selected. -BOOL LLFolderViewFolder::changeSelection(LLFolderViewItem* selection, - BOOL selected) +// This method is used to change the selection of an item. +// Recursively traverse all children; if 'selection' is 'this' then change +// the select status if necessary. +// Returns TRUE if the selection state of this folder, or of a child, was changed. +BOOL LLFolderViewFolder::changeSelection(LLFolderViewItem* selection, BOOL selected) { BOOL rv = FALSE; if(selection == this) { - mIsSelected = selected; - if(mListener && selected) + if (isSelected() != selected) + { + rv = TRUE; + if (selected) + { + selectItem(); + } + else + { + deselectItem(); + } + } + if (mListener && selected) { mListener->selectItem(); } - rv = TRUE; } for (folders_t::iterator iter = mFolders.begin(); @@ -1545,16 +1611,14 @@ BOOL LLFolderViewFolder::changeSelection(LLFolderViewItem* selection, return rv; } -S32 LLFolderViewFolder::extendSelection(LLFolderViewItem* selection, LLFolderViewItem* last_selected, LLDynamicArray<LLFolderViewItem*>& selected_items) +void LLFolderViewFolder::extendSelection(LLFolderViewItem* selection, LLFolderViewItem* last_selected, LLDynamicArray<LLFolderViewItem*>& selected_items) { - S32 num_selected = 0; - // pass on to child folders first for (folders_t::iterator iter = mFolders.begin(); iter != mFolders.end();) { folders_t::iterator fit = iter++; - num_selected += (*fit)->extendSelection(selection, last_selected, selected_items); + (*fit)->extendSelection(selection, last_selected, selected_items); } // handle selection of our immediate children... @@ -1647,7 +1711,6 @@ S32 LLFolderViewFolder::extendSelection(LLFolderViewItem* selection, LLFolderVie if (item->changeSelection(item, TRUE)) { selected_items.put(item); - num_selected++; } } } @@ -1657,11 +1720,8 @@ S32 LLFolderViewFolder::extendSelection(LLFolderViewItem* selection, LLFolderVie if (selection->changeSelection(selection, TRUE)) { selected_items.put(selection); - num_selected++; } } - - return num_selected; } void LLFolderViewFolder::destroyView() @@ -1711,6 +1771,10 @@ void LLFolderViewFolder::removeView(LLFolderViewItem* item) return; } // deselect without traversing hierarchy + if (item->isSelected()) + { + item->deselectItem(); + } getRoot()->removeFromSelectionList(item); extractItem(item); delete item; @@ -1726,16 +1790,24 @@ void LLFolderViewFolder::extractItem( LLFolderViewItem* item ) // This is an evil downcast. However, it's only doing // pointer comparison to find if (which it should be ) the // item is in the container, so it's pretty safe. - LLFolderViewFolder* f = reinterpret_cast<LLFolderViewFolder*>(item); + LLFolderViewFolder* f = static_cast<LLFolderViewFolder*>(item); folders_t::iterator ft; ft = std::find(mFolders.begin(), mFolders.end(), f); - if(ft != mFolders.end()) + if (ft != mFolders.end()) { + if ((*ft)->numSelected()) + { + recursiveIncrementNumDescendantsSelected(-(*ft)->numSelected()); + } mFolders.erase(ft); } } else { + if ((*it)->isSelected()) + { + recursiveIncrementNumDescendantsSelected(-1); + } mItems.erase(it); } //item has been removed, need to update filter @@ -1899,6 +1971,10 @@ BOOL LLFolderViewFolder::isRemovable() BOOL LLFolderViewFolder::addItem(LLFolderViewItem* item) { mItems.push_back(item); + if (item->isSelected()) + { + recursiveIncrementNumDescendantsSelected(1); + } item->setRect(LLRect(0, 0, getRect().getWidth(), 0)); item->setVisible(FALSE); addChild( item ); @@ -1912,6 +1988,10 @@ BOOL LLFolderViewFolder::addItem(LLFolderViewItem* item) BOOL LLFolderViewFolder::addFolder(LLFolderViewFolder* folder) { mFolders.push_back(folder); + if (folder->numSelected()) + { + recursiveIncrementNumDescendantsSelected(folder->numSelected()); + } folder->setOrigin(0, 0); folder->reshape(getRect().getWidth(), 0); folder->setVisible(FALSE); diff --git a/indra/newview/llfolderviewitem.h b/indra/newview/llfolderviewitem.h index 11b644e3aa..9e819aaaaa 100644 --- a/indra/newview/llfolderviewitem.h +++ b/indra/newview/llfolderviewitem.h @@ -121,6 +121,9 @@ public: // Mostly for debugging printout purposes. const std::string& getSearchableLabel() { return mSearchableLabel; } +private: + BOOL mIsSelected; + protected: friend class LLUICtrlFactory; friend class LLFolderViewEventListener; @@ -134,7 +137,6 @@ protected: time_t mCreationDate; LLFolderViewFolder* mParentFolder; LLFolderViewEventListener* mListener; - BOOL mIsSelected; BOOL mIsCurSelection; BOOL mSelectPending; LLFontGL::StyleFlags mLabelStyle; @@ -212,20 +214,24 @@ public: virtual void dirtyFilter(); - // If the selection is 'this' then note that otherwise - // ignore. Returns TRUE if this object was affected. If open is - // TRUE, then folders are opened up along the way to the - // selection. - virtual BOOL setSelection(LLFolderViewItem* selection, BOOL openitem, - BOOL take_keyboard_focus); - - // This method is used to toggle the selection of an item. If - // selection is 'this', then note selection, and return TRUE. + // If 'selection' is 'this' then note that otherwise ignore. + // Returns TRUE if this item ends up being selected. + virtual BOOL setSelection(LLFolderViewItem* selection, BOOL openitem, BOOL take_keyboard_focus); + + // This method is used to set the selection state of an item. + // If 'selection' is 'this' then note selection. + // Returns TRUE if the selection state of this item was changed. virtual BOOL changeSelection(LLFolderViewItem* selection, BOOL selected); - + // this method is used to group select items - virtual S32 extendSelection(LLFolderViewItem* selection, LLFolderViewItem* last_selected, LLDynamicArray<LLFolderViewItem*>& items){ return FALSE; } - + virtual void extendSelection(LLFolderViewItem* selection, LLFolderViewItem* last_selected, LLDynamicArray<LLFolderViewItem*>& items) { } + + // this method is used to deselect this element + void deselectItem(); + + // this method is used to select this element + void selectItem(); + // gets multiple-element selection virtual std::set<LLUUID> getSelectionList() const; @@ -238,7 +244,7 @@ public: // destroys this item recursively virtual void destroyView(); - BOOL isSelected() { return mIsSelected; } + BOOL isSelected() const { return mIsSelected; } void setUnselected() { mIsSelected = FALSE; } @@ -359,6 +365,13 @@ public: UNKNOWN, TRASH, NOT_TRASH } ETrash; +private: + S32 mNumDescendantsSelected; + +public: // Accessed needed by LLFolderViewItem + void recursiveIncrementNumDescendantsSelected(S32 increment); + S32 numSelected(void) const { return mNumDescendantsSelected + (isSelected() ? 1 : 0); } + protected: typedef std::list<LLFolderViewItem*> items_t; typedef std::list<LLFolderViewFolder*> folders_t; @@ -420,18 +433,19 @@ public: virtual void dirtyFilter(); // Passes selection information on to children and record - // selection information if necessary. Returns TRUE if this object - // (or a child) was affected. - virtual BOOL setSelection(LLFolderViewItem* selection, BOOL openitem, - BOOL take_keyboard_focus); - - // This method is used to change the selection of an item. If - // selection is 'this', then note selection as true. Returns TRUE - // if this or a child is now selected. + // selection information if necessary. + // Returns TRUE if this object (or a child) ends up being selected. + // If 'openitem' is TRUE then folders are opened up along the way to the selection. + virtual BOOL setSelection(LLFolderViewItem* selection, BOOL openitem, BOOL take_keyboard_focus); + + // This method is used to change the selection of an item. + // Recursively traverse all children; if 'selection' is 'this' then change + // the select status if necessary. + // Returns TRUE if the selection state of this folder, or of a child, was changed. virtual BOOL changeSelection(LLFolderViewItem* selection, BOOL selected); - + // this method is used to group select items - virtual S32 extendSelection(LLFolderViewItem* selection, LLFolderViewItem* last_selected, LLDynamicArray<LLFolderViewItem*>& items); + virtual void extendSelection(LLFolderViewItem* selection, LLFolderViewItem* last_selected, LLDynamicArray<LLFolderViewItem*>& items); // Returns true is this object and all of its children can be removed. virtual BOOL isRemovable(); @@ -521,6 +535,7 @@ public: time_t getCreationDate() const; bool isTrash() const; + S32 getNumSelectedDescendants(void) const { return mNumDescendantsSelected; } }; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |