summaryrefslogtreecommitdiff
path: root/indra/llui
diff options
context:
space:
mode:
authorLeyla Farazha <leyla@lindenlab.com>2011-09-27 15:42:37 -0700
committerLeyla Farazha <leyla@lindenlab.com>2011-09-27 15:42:37 -0700
commit18b3afe11a59b3fae85bc803c6afc95c8689a84b (patch)
tree07f0e6175b856f346ac4a5d0b1717746ca13ae49 /indra/llui
parentc7f5aebbb71228b705059be248e82e83ee0f9475 (diff)
parent442350a6a5ef1537f2998796c61b0f1053b455c8 (diff)
merge
Diffstat (limited to 'indra/llui')
-rw-r--r--indra/llui/lltoolbar.cpp23
-rw-r--r--indra/llui/lltoolbarview.cpp99
-rw-r--r--indra/llui/lltoolbarview.h32
3 files changed, 141 insertions, 13 deletions
diff --git a/indra/llui/lltoolbar.cpp b/indra/llui/lltoolbar.cpp
index 2fb9f249d4..8249df3e9d 100644
--- a/indra/llui/lltoolbar.cpp
+++ b/indra/llui/lltoolbar.cpp
@@ -123,12 +123,16 @@ void LLToolBar::createContextMenu()
{
if (!mPopupMenuHandle.get())
{
+ // Setup bindings specific to this instance for the context menu options
+
LLUICtrl::CommitCallbackRegistry::Registrar& commit_reg = LLUICtrl::CommitCallbackRegistry::defaultRegistrar();
commit_reg.add("Toolbars.EnableSetting", boost::bind(&LLToolBar::onSettingEnable, this, _2));
LLUICtrl::EnableCallbackRegistry::Registrar& enable_reg = LLUICtrl::EnableCallbackRegistry::defaultRegistrar();
enable_reg.add("Toolbars.CheckSetting", boost::bind(&LLToolBar::isSettingChecked, this, _2));
+ // Create the context menu
+
LLContextMenu* menu = LLUICtrlFactory::instance().createFromFile<LLContextMenu>("menu_toolbars.xml", LLMenuGL::sMenuContainer, LLMenuHolderGL::child_registry_t::instance());
if (menu)
@@ -141,6 +145,10 @@ void LLToolBar::createContextMenu()
{
llwarns << "Unable to load toolbars context menu." << llendl;
}
+
+ // Remove this instance's bindings
+ commit_reg.remove("Toolbars.EnableSetting");
+ enable_reg.remove("Toolbars.CheckSetting");
}
}
@@ -187,12 +195,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 +204,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;
}
@@ -251,11 +256,13 @@ BOOL LLToolBar::handleRightMouseDown(S32 x, S32 y, MASK mask)
if (handle_it_here)
{
createContextMenu();
+
LLContextMenu * menu = (LLContextMenu *) mPopupMenuHandle.get();
if (menu)
{
menu->show(x, y);
+
LLMenuGL::showPopup(this, menu, x, y);
}
}
diff --git a/indra/llui/lltoolbarview.cpp b/indra/llui/lltoolbarview.cpp
index 9df6f4946f..7047cca948 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;
}
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;