From b234c23aa3c70ccac6d4332532a0da6184ec03db Mon Sep 17 00:00:00 2001
From: Merov Linden <merov@lindenlab.com>
Date: Tue, 27 Sep 2011 20:51:26 -0700
Subject: [PATCH] EXP-1211 : Factorize code a bit

---
 indra/llui/lltoolbarview.cpp | 48 ++++++++++++++----------------------
 indra/llui/lltoolbarview.h   |  1 +
 2 files changed, 19 insertions(+), 30 deletions(-)

diff --git a/indra/llui/lltoolbarview.cpp b/indra/llui/lltoolbarview.cpp
index 641c3eb0ab9..73c8c994185 100644
--- a/indra/llui/lltoolbarview.cpp
+++ b/indra/llui/lltoolbarview.cpp
@@ -80,52 +80,25 @@ bool LLToolBarView::load()
 	}
 	
 	// Add commands to each toolbar
-	// *TODO: factorize that code : tricky with Blocks though, simple lexical approach fails
-	LLCommandManager& mgr = LLCommandManager::instance();
-
 	if (toolbar_set.left_toolbar.isProvided() && mToolbarLeft)
 	{
 		BOOST_FOREACH(LLCommandId::Params& command, toolbar_set.left_toolbar.commands)
 		{
-			LLCommandId* commandId = new LLCommandId(command);
-			if (mgr.getCommand(*commandId))
-			{
-				mToolbarLeft->addCommand(*commandId);
-			}
-			else 
-			{
-				llwarns	<< "Toolbars creation : the command " << commandId->name() << " cannot be found in the command manager" << llendl;
-			}
+			addCommand(LLCommandId(command),mToolbarLeft);
 		}
 	}
 	if (toolbar_set.right_toolbar.isProvided() && mToolbarRight)
 	{
 		BOOST_FOREACH(LLCommandId::Params& command, toolbar_set.right_toolbar.commands)
 		{
-			LLCommandId* commandId = new LLCommandId(command);
-			if (mgr.getCommand(*commandId))
-			{
-				mToolbarRight->addCommand(*commandId);
-			}
-			else 
-			{
-				llwarns	<< "Toolbars creation : the command " << commandId->name() << " cannot be found in the command manager" << llendl;
-			}
+			addCommand(LLCommandId(command),mToolbarRight);
 		}
 	}
 	if (toolbar_set.bottom_toolbar.isProvided() && mToolbarBottom)
 	{
 		BOOST_FOREACH(LLCommandId::Params& command, toolbar_set.bottom_toolbar.commands)
 		{
-			LLCommandId* commandId = new LLCommandId(command);
-			if (mgr.getCommand(*commandId))
-			{
-				mToolbarBottom->addCommand(*commandId);
-			}
-			else 
-			{
-				llwarns	<< "Toolbars creation : the command " << commandId->name() << " cannot be found in the command manager" << llendl;
-			}
+			addCommand(LLCommandId(command),mToolbarBottom);
 		}
 	}
 	return true;
@@ -179,6 +152,21 @@ bool LLToolBarView::hasCommand(const LLCommandId& commandId) const
 	return has_command;
 }
 
+bool LLToolBarView::addCommand(const LLCommandId& command, LLToolBar* toolbar)
+{
+	LLCommandManager& mgr = LLCommandManager::instance();
+	if (mgr.getCommand(command))
+	{
+		toolbar->addCommand(command);
+	}
+	else 
+	{
+		llwarns	<< "Toolbars creation : the command " << command.name() << " cannot be found in the command manager" << llendl;
+		return false;
+	}
+	return true;
+}
+
 void LLToolBarView::draw()
 {
 	static bool debug_print = true;
diff --git a/indra/llui/lltoolbarview.h b/indra/llui/lltoolbarview.h
index 0f16b89ecc8..208660da8e3 100644
--- a/indra/llui/lltoolbarview.h
+++ b/indra/llui/lltoolbarview.h
@@ -78,6 +78,7 @@ class LLToolBarView : public LLUICtrl
 private:
 	// Loads the toolbars from the existing user or default settings
 	bool	load();	// return false if load fails
+	bool	addCommand(const LLCommandId& commandId, LLToolBar*	toolbar);
 
 	// Pointers to the toolbars handled by the toolbar view
 	LLToolBar*	mToolbarLeft;
-- 
GitLab