From 2c19e7ddc9bebf9ad59b298644c1b3366b191d3c Mon Sep 17 00:00:00 2001
From: Sergei Litovchuk <slitovchuk@productengine.com>
Date: Wed, 30 Dec 2009 21:06:45 +0200
Subject: Fixed low bug (EXT-3769) Expand/Collpase All Folders menuitem in the
 Teleport History is enabled when nothing to expand/collapse - Added
 expanded/collapsed folders check.

--HG--
branch : product-engine
---
 indra/newview/llpanelteleporthistory.cpp           | 44 ++++++++++++++++++++++
 indra/newview/llpanelteleporthistory.h             |  1 +
 .../default/xui/en/menu_teleport_history_gear.xml  |  6 +++
 3 files changed, 51 insertions(+)

(limited to 'indra')

diff --git a/indra/newview/llpanelteleporthistory.cpp b/indra/newview/llpanelteleporthistory.cpp
index 77c2fb7c8c..245f694ac6 100644
--- a/indra/newview/llpanelteleporthistory.cpp
+++ b/indra/newview/llpanelteleporthistory.cpp
@@ -452,6 +452,7 @@ BOOL LLTeleportHistoryPanel::postBuild()
 	registrar.add("TeleportHistory.ExpandAllFolders",  boost::bind(&LLTeleportHistoryPanel::onExpandAllFolders,  this));
 	registrar.add("TeleportHistory.CollapseAllFolders",  boost::bind(&LLTeleportHistoryPanel::onCollapseAllFolders,  this));
 	registrar.add("TeleportHistory.ClearTeleportHistory",  boost::bind(&LLTeleportHistoryPanel::onClearTeleportHistory,  this));
+	mEnableCallbackRegistrar.add("TeleportHistory.GearMenu.Enable", boost::bind(&LLTeleportHistoryPanel::isActionEnabled, this, _2));
 
 	LLMenuGL* gear_menu  = LLUICtrlFactory::getInstance()->createFromFile<LLMenuGL>("menu_teleport_history_gear.xml",  gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
 	if(gear_menu)
@@ -979,6 +980,49 @@ void LLTeleportHistoryPanel::onGearButtonClicked()
 	LLMenuGL::showPopup(this, menu, menu_x, menu_y);
 }
 
+bool LLTeleportHistoryPanel::isActionEnabled(const LLSD& userdata) const
+{
+	S32 tabs_cnt = mItemContainers.size();
+
+	bool has_expanded_tabs = false;
+	bool has_collapsed_tabs = false;
+
+	for (S32 n = 0; n < tabs_cnt; n++)
+	{
+		LLAccordionCtrlTab* tab = mItemContainers.get(n);
+		if (!tab->getVisible())
+			continue;
+
+		if (tab->getDisplayChildren())
+		{
+			has_expanded_tabs = true;
+		}
+		else
+		{
+			has_collapsed_tabs = true;
+		}
+
+		if (has_expanded_tabs && has_collapsed_tabs)
+		{
+			break;
+		}
+	}
+
+	std::string command_name = userdata.asString();
+
+	if (has_expanded_tabs && command_name == "collapse_all")
+	{
+		return true;
+	}
+
+	if (has_collapsed_tabs && command_name ==  "expand_all")
+	{
+		return true;
+	}
+
+	return false;
+}
+
 void LLTeleportHistoryPanel::setAccordionCollapsedByUser(LLUICtrl* acc_tab, bool collapsed)
 {
 	LLSD param = acc_tab->getValue();
diff --git a/indra/newview/llpanelteleporthistory.h b/indra/newview/llpanelteleporthistory.h
index 0c0f891f32..4eeaec7705 100644
--- a/indra/newview/llpanelteleporthistory.h
+++ b/indra/newview/llpanelteleporthistory.h
@@ -97,6 +97,7 @@ private:
 	void handleItemSelect(LLFlatListView* );
 	LLFlatListView* getFlatListViewFromTab(LLAccordionCtrlTab *);
 	void onGearButtonClicked();
+	bool isActionEnabled(const LLSD& userdata) const;
 
 	void setAccordionCollapsedByUser(LLUICtrl* acc_tab, bool collapsed);
 	bool isAccordionCollapsedByUser(LLUICtrl* acc_tab);
diff --git a/indra/newview/skins/default/xui/en/menu_teleport_history_gear.xml b/indra/newview/skins/default/xui/en/menu_teleport_history_gear.xml
index 6768d7fccb..134b331514 100644
--- a/indra/newview/skins/default/xui/en/menu_teleport_history_gear.xml
+++ b/indra/newview/skins/default/xui/en/menu_teleport_history_gear.xml
@@ -13,12 +13,18 @@
      name="Expand all folders">
         <menu_item_call.on_click
          function="TeleportHistory.ExpandAllFolders" />
+        <on_enable
+         function="TeleportHistory.GearMenu.Enable"
+         parameter="expand_all" />
     </menu_item_call>
     <menu_item_call
      label="Collapse all folders"
      name="Collapse all folders">
         <menu_item_call.on_click
          function="TeleportHistory.CollapseAllFolders" />
+        <on_enable
+         function="TeleportHistory.GearMenu.Enable"
+         parameter="collapse_all" />
     </menu_item_call>
     <menu_item_separator layout="topleft" />
     <menu_item_call
-- 
cgit v1.2.3