summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMerov Linden <merov@lindenlab.com>2011-09-27 20:51:26 -0700
committerMerov Linden <merov@lindenlab.com>2011-09-27 20:51:26 -0700
commitb234c23aa3c70ccac6d4332532a0da6184ec03db (patch)
tree18dd5b1928eb17c4c9a07cf0fd2435e75ff425a4
parent04a5c45020e72e7e24eed1cc1f53014da92594e5 (diff)
EXP-1211 : Factorize code a bit
-rw-r--r--indra/llui/lltoolbarview.cpp48
-rw-r--r--indra/llui/lltoolbarview.h1
2 files changed, 19 insertions, 30 deletions
diff --git a/indra/llui/lltoolbarview.cpp b/indra/llui/lltoolbarview.cpp
index 641c3eb0ab..73c8c99418 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 0f16b89ecc..208660da8e 100644
--- a/indra/llui/lltoolbarview.h
+++ b/indra/llui/lltoolbarview.h
@@ -78,6 +78,7 @@ protected:
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;