diff options
Diffstat (limited to 'indra/newview/llpanellandmarks.cpp')
-rw-r--r-- | indra/newview/llpanellandmarks.cpp | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/indra/newview/llpanellandmarks.cpp b/indra/newview/llpanellandmarks.cpp index e8c8273a9d..80f6862169 100644 --- a/indra/newview/llpanellandmarks.cpp +++ b/indra/newview/llpanellandmarks.cpp @@ -71,6 +71,7 @@ static void collapse_all_folders(LLFolderView* root_folder); static void expand_all_folders(LLFolderView* root_folder); static bool has_expanded_folders(LLFolderView* root_folder); static bool has_collapsed_folders(LLFolderView* root_folder); +static void toggle_restore_menu(LLMenuGL* menu, BOOL visible, BOOL enabled); /** * Functor counting expanded and collapsed folders in folder view tree to know @@ -708,6 +709,9 @@ void LLLandmarksPanel::initListCommandsHandlers() mGearFolderMenu = LLUICtrlFactory::getInstance()->createFromFile<LLToggleableMenu>("menu_places_gear_folder.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance()); mMenuAdd = LLUICtrlFactory::getInstance()->createFromFile<LLMenuGL>("menu_place_add_button.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance()); + mGearLandmarkMenu->setVisibilityChangeCallback(boost::bind(&LLLandmarksPanel::onMenuVisibilityChange, this, _1, _2)); + mGearFolderMenu->setVisibilityChangeCallback(boost::bind(&LLLandmarksPanel::onMenuVisibilityChange, this, _1, _2)); + mListCommands->childSetAction(ADD_BUTTON_NAME, boost::bind(&LLLandmarksPanel::showActionMenu, this, mMenuAdd, ADD_BUTTON_NAME)); } @@ -1079,6 +1083,60 @@ void LLLandmarksPanel::onCustomAction(const LLSD& userdata) { doActionOnCurSelectedLandmark(boost::bind(&LLLandmarksPanel::doCreatePick, this, _1)); } + else if ("restore" == command_name && mCurrentSelectedList) + { + mCurrentSelectedList->doToSelected(userdata); + } +} + +void LLLandmarksPanel::onMenuVisibilityChange(LLUICtrl* ctrl, const LLSD& param) +{ + bool new_visibility = param["visibility"].asBoolean(); + + // We don't have to update items visibility if the menu is hiding. + if (!new_visibility) return; + + BOOL are_any_items_in_trash = FALSE; + BOOL are_all_items_in_trash = TRUE; + + LLFolderView* root_folder_view = mCurrentSelectedList ? mCurrentSelectedList->getRootFolder() : NULL; + if(root_folder_view) + { + const LLUUID trash_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH); + + std::set<LLUUID> selected_uuids = root_folder_view->getSelectionList(); + + // Iterate through selected items to find out if any of these items are in Trash + // or all the items are in Trash category. + for (std::set<LLUUID>::const_iterator iter = selected_uuids.begin(); iter != selected_uuids.end(); ++iter) + { + LLFolderViewItem* item = root_folder_view->getItemByID(*iter); + + // If no item is found it might be a folder id. + if (!item) + { + item = root_folder_view->getFolderByID(*iter); + } + if (!item) continue; + + LLFolderViewEventListener* listenerp = item->getListener(); + if(!listenerp) continue; + + // Trash category itself should not be included because it can't be + // actually restored from trash. + are_all_items_in_trash &= listenerp->isItemInTrash() && *iter != trash_id; + + // If there are any selected items in Trash including the Trash category itself + // we show "Restore Item" in context menu and hide other irrelevant items. + are_any_items_in_trash |= listenerp->isItemInTrash(); + } + } + + // Display "Restore Item" menu entry if at least one of the selected items + // is in Trash or the Trash category itself is among selected items. + // Hide other menu entries in this case. + // Enable this menu entry only if all selected items are in the Trash category. + toggle_restore_menu((LLMenuGL*)ctrl, are_any_items_in_trash, are_all_items_in_trash); } /* @@ -1414,4 +1472,31 @@ static bool has_collapsed_folders(LLFolderView* root_folder) return true; } + +// Displays "Restore Item" context menu entry while hiding +// all other entries or vice versa. +// Sets "Restore Item" enabled state. +void toggle_restore_menu(LLMenuGL *menu, BOOL visible, BOOL enabled) +{ + if (!menu) return; + + const LLView::child_list_t *list = menu->getChildList(); + for (LLView::child_list_t::const_iterator itor = list->begin(); + itor != list->end(); + ++itor) + { + LLView *menu_item = (*itor); + std::string name = menu_item->getName(); + + if ("restore_item" == name) + { + menu_item->setVisible(visible); + menu_item->setEnabled(enabled); + } + else + { + menu_item->setVisible(!visible); + } + } +} // EOF |