diff options
-rw-r--r-- | indra/llui/llcommandmanager.h | 2 | ||||
-rw-r--r-- | indra/llui/lltoolbar.h | 3 | ||||
-rw-r--r-- | indra/llui/lltoolbarview.cpp | 172 | ||||
-rw-r--r-- | indra/llui/lltoolbarview.h | 3 |
4 files changed, 124 insertions, 56 deletions
diff --git a/indra/llui/llcommandmanager.h b/indra/llui/llcommandmanager.h index 8435d915f3..4781f77177 100644 --- a/indra/llui/llcommandmanager.h +++ b/indra/llui/llcommandmanager.h @@ -81,6 +81,8 @@ private: std::string mName; }; +typedef std::list<LLCommandId> command_id_list_t; + class LLCommand { public: diff --git a/indra/llui/lltoolbar.h b/indra/llui/lltoolbar.h index 02db58128c..8e484c7e13 100644 --- a/indra/llui/lltoolbar.h +++ b/indra/llui/lltoolbar.h @@ -123,6 +123,7 @@ public: bool addCommand(const LLCommandId& commandId); bool hasCommand(const LLCommandId& commandId) const; bool enableCommand(const LLCommandId& commandId, bool enabled); + command_id_list_t& getCommandsList() { return mButtonCommands; } protected: friend class LLUICtrlFactory; @@ -143,7 +144,7 @@ private: const bool mReadOnly; std::list<LLToolBarButton*> mButtons; - std::list<LLCommandId> mButtonCommands; + command_id_list_t mButtonCommands; LLToolBarEnums::ButtonType mButtonType; LLLayoutStack* mCenteringStack; LLLayoutStack* mWrapStack; diff --git a/indra/llui/lltoolbarview.cpp b/indra/llui/lltoolbarview.cpp index 73c8c99418..aee7ffa517 100644 --- a/indra/llui/lltoolbarview.cpp +++ b/indra/llui/lltoolbarview.cpp @@ -50,59 +50,6 @@ LLToolBarView::ToolbarSet::ToolbarSet() 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 - if (toolbar_set.left_toolbar.isProvided() && mToolbarLeft) - { - BOOST_FOREACH(LLCommandId::Params& command, toolbar_set.left_toolbar.commands) - { - addCommand(LLCommandId(command),mToolbarLeft); - } - } - if (toolbar_set.right_toolbar.isProvided() && mToolbarRight) - { - BOOST_FOREACH(LLCommandId::Params& command, toolbar_set.right_toolbar.commands) - { - addCommand(LLCommandId(command),mToolbarRight); - } - } - if (toolbar_set.bottom_toolbar.isProvided() && mToolbarBottom) - { - BOOST_FOREACH(LLCommandId::Params& command, toolbar_set.bottom_toolbar.commands) - { - addCommand(LLCommandId(command),mToolbarBottom); - } - } - return true; -} LLToolBarView::LLToolBarView(const LLToolBarView::Params& p) : LLUICtrl(p), @@ -120,6 +67,7 @@ void LLToolBarView::initFromParams(const LLToolBarView::Params& p) LLToolBarView::~LLToolBarView() { + saveToolbars(); } BOOL LLToolBarView::postBuild() @@ -129,7 +77,7 @@ BOOL LLToolBarView::postBuild() mToolbarBottom = getChild<LLToolBar>("toolbar_bottom"); // Load the toolbars from the settings - load(); + loadToolbars(); return TRUE; } @@ -167,6 +115,122 @@ bool LLToolBarView::addCommand(const LLCommandId& command, LLToolBar* toolbar) return true; } +bool LLToolBarView::loadToolbars() +{ + 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 + if (toolbar_set.left_toolbar.isProvided() && mToolbarLeft) + { + BOOST_FOREACH(LLCommandId::Params& command, toolbar_set.left_toolbar.commands) + { + addCommand(LLCommandId(command),mToolbarLeft); + } + } + if (toolbar_set.right_toolbar.isProvided() && mToolbarRight) + { + BOOST_FOREACH(LLCommandId::Params& command, toolbar_set.right_toolbar.commands) + { + addCommand(LLCommandId(command),mToolbarRight); + } + } + if (toolbar_set.bottom_toolbar.isProvided() && mToolbarBottom) + { + BOOST_FOREACH(LLCommandId::Params& command, toolbar_set.bottom_toolbar.commands) + { + addCommand(LLCommandId(command),mToolbarBottom); + } + } + return true; +} + +void LLToolBarView::saveToolbars() const +{ + // Build the parameter tree from the toolbar data + LLToolBarView::ToolbarSet toolbar_set; + + // *TODO : factorize that code a bit... + if (mToolbarLeft) + { + command_id_list_t& command_list = mToolbarLeft->getCommandsList(); + for (command_id_list_t::const_iterator it = command_list.begin(); + it != command_list.end(); + ++it) + { + LLCommandId::Params command; + command.name = it->name(); + toolbar_set.left_toolbar.commands.add(command); + } + } + if (mToolbarRight) + { + command_id_list_t& command_list = mToolbarRight->getCommandsList(); + for (command_id_list_t::const_iterator it = command_list.begin(); + it != command_list.end(); + ++it) + { + LLCommandId::Params command; + command.name = it->name(); + toolbar_set.right_toolbar.commands.add(command); + } + } + if (mToolbarBottom) + { + command_id_list_t& command_list = mToolbarBottom->getCommandsList(); + for (command_id_list_t::const_iterator it = command_list.begin(); + it != command_list.end(); + ++it) + { + LLCommandId::Params command; + command.name = it->name(); + toolbar_set.bottom_toolbar.commands.add(command); + } + } + + // Serialize the parameter tree + LLXMLNodePtr output_node = new LLXMLNode("toolbars", false); + LLXUIParser parser; + parser.writeXUI(output_node, toolbar_set); + + // Write the resulting XML to file + if(!output_node->isNull()) + { + const std::string& filename = gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, "toolbars.xml"); + LLFILE *fp = LLFile::fopen(filename, "w"); + if (fp != NULL) + { + LLXMLNode::writeHeaderToFile(fp); + output_node->writeToFile(fp); + fclose(fp); + } + } +} + void LLToolBarView::draw() { static bool debug_print = true; diff --git a/indra/llui/lltoolbarview.h b/indra/llui/lltoolbarview.h index 208660da8e..646a1fd636 100644 --- a/indra/llui/lltoolbarview.h +++ b/indra/llui/lltoolbarview.h @@ -77,7 +77,8 @@ protected: private: // Loads the toolbars from the existing user or default settings - bool load(); // return false if load fails + bool loadToolbars(); // return false if load fails + void saveToolbars() const; bool addCommand(const LLCommandId& commandId, LLToolBar* toolbar); // Pointers to the toolbars handled by the toolbar view |