From 5dc2f9c5fe4039c7d5e0dee1c872de5de39af6bd Mon Sep 17 00:00:00 2001
From: Sergei Litovchuk <slitovchuk@productengine.com>
Date: Thu, 26 Aug 2010 21:42:40 +0300
Subject: [PATCH] VWR-20696, VWR-20697 WIP Added undocking/redocking tabs from
 Side Tray.

Reviewed by Vadim Savchuk at https://codereview.productengine.com/secondlife/r/877/.
---
 indra/newview/llsidetray.cpp                  | 62 ++++++++++++++++++-
 indra/newview/llsidetray.h                    |  1 +
 indra/newview/llviewerfloaterreg.cpp          |  1 +
 .../default/xui/en/floater_side_bar_tab.xml   |  5 ++
 .../xui/en/panel_side_tray_tab_caption.xml    | 14 ++++-
 5 files changed, 81 insertions(+), 2 deletions(-)
 create mode 100644 indra/newview/skins/default/xui/en/floater_side_bar_tab.xml

diff --git a/indra/newview/llsidetray.cpp b/indra/newview/llsidetray.cpp
index 78890fae93..f1bd2f3027 100644
--- a/indra/newview/llsidetray.cpp
+++ b/indra/newview/llsidetray.cpp
@@ -31,6 +31,7 @@
 #include "llagentcamera.h"
 #include "llappviewer.h"
 #include "llbottomtray.h"
+#include "llfloaterreg.h"
 #include "llsidetray.h"
 #include "llviewerwindow.h"
 #include "llaccordionctrl.h"
@@ -125,7 +126,9 @@ public:
 	const std::string& getTabTitle() const { return mTabTitle;}
 	
 	void			onOpen		(const LLSD& key);
-	
+
+	void			toggleTabDocked();
+
 	LLPanel *getPanel();
 private:
 	std::string mTabTitle;
@@ -171,6 +174,8 @@ BOOL LLSideTrayTab::postBuild()
 	
 	title_panel->getChild<LLTextBox>(TAB_PANEL_CAPTION_TITLE_BOX)->setValue(mTabTitle);
 
+	getChild<LLButton>("dock")->setCommitCallback(boost::bind(&LLSideTrayTab::toggleTabDocked, this));
+
 	return true;
 }
 
@@ -203,6 +208,48 @@ void	LLSideTrayTab::onOpen		(const LLSD& key)
 		panel->onOpen(key);
 }
 
+void LLSideTrayTab::toggleTabDocked()
+{
+	LLFloater* floater_tab = LLFloaterReg::getInstance("side_bar_tab", LLSD().with("name", mTabTitle));
+	if (!floater_tab) return;
+
+	LLFloaterReg::toggleInstance("side_bar_tab", LLSD().with("name", mTabTitle));
+
+	LLSideTray* side_tray = LLSideTray::getInstance();
+
+	if (LLFloater::isShown(floater_tab))
+	{
+		// Remove the tab from Side Tray's tabs list.
+		// We have to do it despite removing the tab from Side Tray's child view tree
+		// by addChild(). Otherwise the tab could be accessed by the pointer in LLSideTray::mTabs.
+		side_tray->removeTab(this);
+
+		floater_tab->addChild(this);
+		floater_tab->setTitle(mTabTitle);
+
+		LLRect rect = side_tray->getLocalRect();
+		floater_tab->reshape(rect.getWidth(), rect.getHeight());
+
+		rect.mTop -= floater_tab->getHeaderHeight();
+		setRect(rect);
+		reshape(rect.getWidth(), rect.getHeight());
+
+		// Set FOLLOWS_ALL flag for the tab to follow floater dimensions upon resizing.
+		setFollowsAll();
+
+		side_tray->collapseSideBar();
+	}
+	else
+	{
+		side_tray->addChild(this, 0);
+
+		setRect(side_tray->getLocalRect());
+		reshape(getRect().getWidth(), getRect().getHeight());
+
+		side_tray->expandSideBar();
+	}
+}
+
 LLPanel*	LLSideTrayTab::getPanel()
 {
 	LLPanel* panel = dynamic_cast<LLPanel*>(mMainPanel);
@@ -400,6 +447,19 @@ bool LLSideTray::addChild(LLView* view, S32 tab_group)
 	return LLUICtrl::addChild(view, tab_group);
 }
 
+void LLSideTray::removeTab(LLView* child)
+{
+	for (child_vector_iter_t child_it = mTabs.begin(); child_it != mTabs.end(); ++child_it)
+	{
+		if (*child_it == child)
+		{
+			mTabs.erase(child_it);
+			break;
+		}
+	}
+
+	mActiveTab = getTab("sidebar_openclose");
+}
 
 void	LLSideTray::createButtons	()
 {
diff --git a/indra/newview/llsidetray.h b/indra/newview/llsidetray.h
index 4ff560d83b..7475d5f7fb 100644
--- a/indra/newview/llsidetray.h
+++ b/indra/newview/llsidetray.h
@@ -144,6 +144,7 @@ public:
 	void		onToggleCollapse();
 
 	bool		addChild		(LLView* view, S32 tab_group);
+	void		removeTab		(LLView* view);
 
 	BOOL		handleMouseDown	(S32 x, S32 y, MASK mask);
 	
diff --git a/indra/newview/llviewerfloaterreg.cpp b/indra/newview/llviewerfloaterreg.cpp
index b572a8cff6..8728298575 100644
--- a/indra/newview/llviewerfloaterreg.cpp
+++ b/indra/newview/llviewerfloaterreg.cpp
@@ -234,6 +234,7 @@ void LLViewerFloaterReg::registerFloaters()
 	LLFloaterReg::add("script_limits", "floater_script_limits.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterScriptLimits>);
 	LLFloaterReg::add("sell_land", "floater_sell_land.xml", &LLFloaterSellLand::buildFloater);
 	LLFloaterReg::add("settings_debug", "floater_settings_debug.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterSettingsDebug>);
+	LLFloaterReg::add("side_bar_tab", "floater_side_bar_tab.xml",&LLFloaterReg::build<LLFloater>);
 	LLFloaterReg::add("stats", "floater_stats.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloater>);
 	LLFloaterReg::add("start_queue", "floater_script_queue.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterRunQueue>);
 	LLFloaterReg::add("stop_queue", "floater_script_queue.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterNotRunQueue>);
diff --git a/indra/newview/skins/default/xui/en/floater_side_bar_tab.xml b/indra/newview/skins/default/xui/en/floater_side_bar_tab.xml
new file mode 100644
index 0000000000..1466c2d2a5
--- /dev/null
+++ b/indra/newview/skins/default/xui/en/floater_side_bar_tab.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<floater
+ can_close="false"
+ can_resize="true">
+</floater>
diff --git a/indra/newview/skins/default/xui/en/panel_side_tray_tab_caption.xml b/indra/newview/skins/default/xui/en/panel_side_tray_tab_caption.xml
index 0a9c70303e..60c2e0830c 100644
--- a/indra/newview/skins/default/xui/en/panel_side_tray_tab_caption.xml
+++ b/indra/newview/skins/default/xui/en/panel_side_tray_tab_caption.xml
@@ -20,7 +20,19 @@
      value="Side Panel"
      width="255" />
      <button
-     follows="left|right|top"
+     follows="right|top"
+     height="16"
+     image_selected="Icon_Dock_Press"
+     image_unselected="Icon_Dock_Foreground"
+     image_disabled="Icon_Dock_Press"
+     layout="topleft"
+     name="dock"
+     top="10"
+     right="-28"
+     width="16"
+     tool_tip="Dock/Undock tab" />
+     <button
+     follows="right|top"
      height="16"
      image_selected="Icon_Help_Press"
      image_unselected="Icon_Help_Foreground"
-- 
GitLab