summaryrefslogtreecommitdiff
path: root/indra/llui
diff options
context:
space:
mode:
authorMerov Linden <merov@lindenlab.com>2011-09-27 14:58:20 -0700
committerMerov Linden <merov@lindenlab.com>2011-09-27 14:58:20 -0700
commit0e4f226b56cb2dea1e8d5e9f1267a16c302bb5a9 (patch)
treed3f8361917943ff801e38c5bc42c3c66c441546d /indra/llui
parentcc56958452b8c10e1de176edb1924179ad04768a (diff)
EXP-1211 : Read toolbar default settings from toolbars.xml, no saving of settings done yet.
Diffstat (limited to 'indra/llui')
-rw-r--r--indra/llui/lltoolbar.cpp13
-rw-r--r--indra/llui/lltoolbarview.cpp101
-rw-r--r--indra/llui/lltoolbarview.h32
3 files changed, 132 insertions, 14 deletions
diff --git a/indra/llui/lltoolbar.cpp b/indra/llui/lltoolbar.cpp
index 2fb9f249d4..f8effb5bb6 100644
--- a/indra/llui/lltoolbar.cpp
+++ b/indra/llui/lltoolbar.cpp
@@ -187,12 +187,6 @@ void LLToolBar::initFromParams(const LLToolBar::Params& p)
mCenteringStack->addChild(LLUICtrlFactory::create<LLLayoutPanel>(border_panel_p));
- BOOST_FOREACH (const LLCommandId::Params& command_id, p.commands)
- {
- mButtonCommands.push_back(command_id);
- }
- createButtons();
-
mNeedsLayout = true;
}
@@ -202,8 +196,11 @@ bool LLToolBar::addCommand(const LLCommandId& commandId)
bool add_command = (command != NULL);
- mButtonCommands.push_back(commandId);
- createButtons();
+ if (add_command)
+ {
+ mButtonCommands.push_back(commandId);
+ createButtons();
+ }
return add_command;
}
diff --git a/indra/llui/lltoolbarview.cpp b/indra/llui/lltoolbarview.cpp
index 6ae10fbf1d..139a26a251 100644
--- a/indra/llui/lltoolbarview.cpp
+++ b/indra/llui/lltoolbarview.cpp
@@ -29,13 +29,108 @@
#include "lltoolbarview.h"
+#include "lldir.h"
+#include "llxmlnode.h"
#include "lltoolbar.h"
#include "llbutton.h"
+#include <boost/foreach.hpp>
+
LLToolBarView* gToolBarView = NULL;
static LLDefaultChildRegistry::Register<LLToolBarView> r("toolbar_view");
+LLToolBarView::Toolbar::Toolbar()
+: commands("command")
+{}
+
+LLToolBarView::ToolbarSet::ToolbarSet()
+: left_toolbar("left_toolbar"),
+ right_toolbar("right_toolbar"),
+ bottom_toolbar("bottom_toolbar")
+{}
+
+bool LLToolBarView::load()
+{
+ LLToolBarView::ToolbarSet toolbar_set;
+
+ // Load the default toolbars.xml file
+ // *TODO : pick up the user's toolbar setting if existing
+ std::string toolbar_file = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "toolbars.xml");
+
+ LLXMLNodePtr root;
+ if(!LLXMLNode::parseFile(toolbar_file, root, NULL))
+ {
+ llerrs << "Unable to load toolbars from file: " << toolbar_file << llendl;
+ return false;
+ }
+ if(!root->hasName("toolbars"))
+ {
+ llwarns << toolbar_file << " is not a valid toolbars definition file" << llendl;
+ return false;
+ }
+
+ // Parse the toolbar settings
+ LLXUIParser parser;
+ parser.readXUI(root, toolbar_set, toolbar_file);
+ if (!toolbar_set.validateBlock())
+ {
+ llerrs << "Unable to validate toolbars from file: " << toolbar_file << llendl;
+ return false;
+ }
+
+ // 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;
+ }
+ }
+ }
+ 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;
+ }
+ }
+ }
+ 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;
+ }
+ }
+ }
+ return true;
+}
+
LLToolBarView::LLToolBarView(const LLToolBarView::Params& p)
: LLUICtrl(p),
mToolbarLeft(NULL),
@@ -59,6 +154,10 @@ BOOL LLToolBarView::postBuild()
mToolbarLeft = getChild<LLToolBar>("toolbar_left");
mToolbarRight = getChild<LLToolBar>("toolbar_right");
mToolbarBottom = getChild<LLToolBar>("toolbar_bottom");
+
+ // Load the toolbars from the settings
+ load();
+
return TRUE;
}
@@ -86,7 +185,7 @@ void LLToolBarView::draw()
static S32 old_width = 0;
static S32 old_height = 0;
- LLPanel* sizer_left = getChild<LLPanel>("sizer_left");
+// LLPanel* sizer_left = getChild<LLPanel>("sizer_left");
LLRect bottom_rect, left_rect, right_rect;
diff --git a/indra/llui/lltoolbarview.h b/indra/llui/lltoolbarview.h
index 2e7885f391..0f16b89ecc 100644
--- a/indra/llui/lltoolbarview.h
+++ b/indra/llui/lltoolbarview.h
@@ -39,18 +39,36 @@ class LLUICtrlFactory;
class LLToolBarView : public LLUICtrl
{
public:
+ // Xui structure of the toolbar panel
struct Params : public LLInitParam::Block<Params, LLUICtrl::Params> {};
+
+ // Note: valid children for LLToolBarView are stored in this registry
+ typedef LLDefaultChildRegistry child_registry_t;
- virtual ~LLToolBarView();
- /*virtual*/ BOOL postBuild();
+ // Xml structure of the toolbars.xml setting
+ // Those live in a toolbars.xml found in app_settings (for the default) and in
+ // the user folder for the user specific (saved) settings
+ struct Toolbar : public LLInitParam::Block<Toolbar>
+ {
+ Multiple<LLCommandId::Params> commands;
+ Toolbar();
+ };
+ struct ToolbarSet : public LLInitParam::Block<ToolbarSet>
+ {
+ Optional<Toolbar> left_toolbar,
+ right_toolbar,
+ bottom_toolbar;
+ ToolbarSet();
+ };
+ // Derived methods
+ virtual ~LLToolBarView();
+ virtual BOOL postBuild();
virtual void draw();
+ // Toolbar view interface with the rest of the world
bool hasCommand(const LLCommandId& commandId) const;
- // valid children for LLToolBarView are stored in this registry
- typedef LLDefaultChildRegistry child_registry_t;
-
protected:
friend class LLUICtrlFactory;
LLToolBarView(const Params&);
@@ -58,6 +76,10 @@ protected:
void initFromParams(const Params&);
private:
+ // Loads the toolbars from the existing user or default settings
+ bool load(); // return false if load fails
+
+ // Pointers to the toolbars handled by the toolbar view
LLToolBar* mToolbarLeft;
LLToolBar* mToolbarRight;
LLToolBar* mToolbarBottom;