EXP-1211, EXP-1257 : Save and load the button type along with the toolbars, add a force default load option, enforce consistency between menus and toolbars

meow-7.2.2
Merov Linden 2011-09-29 15:01:15 -07:00
parent 71ed326f51
commit b07e7c7198
6 changed files with 79 additions and 19 deletions

View File

@ -213,6 +213,14 @@ bool LLToolBar::addCommand(const LLCommandId& commandId)
return add_command;
}
void LLToolBar::clearCommandsList()
{
// Clears the commands list
mButtonCommands.clear();
// This will clear the buttons
createButtons();
}
bool LLToolBar::hasCommand(const LLCommandId& commandId) const
{
bool has_command = false;
@ -278,7 +286,7 @@ BOOL LLToolBar::isSettingChecked(const LLSD& userdata)
const std::string setting_name = userdata.asString();
if (setting_name == "icons_and_labels")
if (setting_name == "icons_with_text")
{
retval = (mButtonType == BTNTYPE_ICONS_WITH_TEXT);
}
@ -296,18 +304,23 @@ void LLToolBar::onSettingEnable(const LLSD& userdata)
const std::string setting_name = userdata.asString();
const ButtonType current_button_type = mButtonType;
if (setting_name == "icons_and_labels")
if (setting_name == "icons_with_text")
{
mButtonType = BTNTYPE_ICONS_WITH_TEXT;
setButtonType(BTNTYPE_ICONS_WITH_TEXT);
}
else if (setting_name == "icons_only")
{
mButtonType = BTNTYPE_ICONS_ONLY;
setButtonType(BTNTYPE_ICONS_ONLY);
}
}
if(current_button_type != mButtonType)
void LLToolBar::setButtonType(LLToolBarEnums::ButtonType button_type)
{
bool regenerate_buttons = (mButtonType != button_type);
mButtonType = button_type;
if (regenerate_buttons)
{
createButtons();
}

View File

@ -123,7 +123,6 @@ 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;
@ -132,6 +131,13 @@ protected:
void initFromParams(const Params&);
public:
// Methods used in loading and saving toolbar settings
void setButtonType(LLToolBarEnums::ButtonType button_type);
LLToolBarEnums::ButtonType getButtonType() { return mButtonType; }
command_id_list_t& getCommandsList() { return mButtonCommands; }
void clearCommandsList();
private:
void createContextMenu();
void updateLayoutAsNeeded();

View File

@ -41,7 +41,8 @@ LLToolBarView* gToolBarView = NULL;
static LLDefaultChildRegistry::Register<LLToolBarView> r("toolbar_view");
LLToolBarView::Toolbar::Toolbar()
: commands("command")
: button_display_mode("button_display_mode"),
commands("command")
{}
LLToolBarView::ToolbarSet::ToolbarSet()
@ -112,13 +113,17 @@ bool LLToolBarView::addCommand(const LLCommandId& command, LLToolBar* toolbar)
return true;
}
bool LLToolBarView::loadToolbars()
bool LLToolBarView::loadToolbars(bool force_default)
{
LLToolBarView::ToolbarSet toolbar_set;
// Load the default toolbars.xml file
// Load the toolbars.xml file
std::string toolbar_file = gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, "toolbars.xml");
if (!gDirUtilp->fileExists(toolbar_file))
if (force_default)
{
toolbar_file = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "toolbars.xml");
}
else if (!gDirUtilp->fileExists(toolbar_file))
{
llwarns << "User toolbars def not found -> use default" << llendl;
toolbar_file = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "toolbars.xml");
@ -145,9 +150,28 @@ bool LLToolBarView::loadToolbars()
return false;
}
// Clear the toolbars now before adding the loaded commands and settings
if (mToolbarLeft)
{
mToolbarLeft->clearCommandsList();
}
if (mToolbarRight)
{
mToolbarRight->clearCommandsList();
}
if (mToolbarBottom)
{
mToolbarBottom->clearCommandsList();
}
// Add commands to each toolbar
if (toolbar_set.left_toolbar.isProvided() && mToolbarLeft)
{
if (toolbar_set.left_toolbar.button_display_mode.isProvided())
{
U32 button_type = toolbar_set.left_toolbar.button_display_mode;
mToolbarLeft->setButtonType((LLToolBarEnums::ButtonType)(button_type));
}
BOOST_FOREACH(LLCommandId::Params& command, toolbar_set.left_toolbar.commands)
{
addCommand(LLCommandId(command),mToolbarLeft);
@ -155,6 +179,11 @@ bool LLToolBarView::loadToolbars()
}
if (toolbar_set.right_toolbar.isProvided() && mToolbarRight)
{
if (toolbar_set.right_toolbar.button_display_mode.isProvided())
{
U32 button_type = toolbar_set.right_toolbar.button_display_mode;
mToolbarRight->setButtonType((LLToolBarEnums::ButtonType)(button_type));
}
BOOST_FOREACH(LLCommandId::Params& command, toolbar_set.right_toolbar.commands)
{
addCommand(LLCommandId(command),mToolbarRight);
@ -162,6 +191,11 @@ bool LLToolBarView::loadToolbars()
}
if (toolbar_set.bottom_toolbar.isProvided() && mToolbarBottom)
{
if (toolbar_set.bottom_toolbar.button_display_mode.isProvided())
{
U32 button_type = toolbar_set.bottom_toolbar.button_display_mode;
mToolbarBottom->setButtonType((LLToolBarEnums::ButtonType)(button_type));
}
BOOST_FOREACH(LLCommandId::Params& command, toolbar_set.bottom_toolbar.commands)
{
addCommand(LLCommandId(command),mToolbarBottom);
@ -176,14 +210,17 @@ void LLToolBarView::saveToolbars() const
LLToolBarView::ToolbarSet toolbar_set;
if (mToolbarLeft)
{
toolbar_set.left_toolbar.button_display_mode = (int)(mToolbarLeft->getButtonType());
addToToolset(mToolbarLeft->getCommandsList(),toolbar_set.left_toolbar);
}
if (mToolbarRight)
{
toolbar_set.right_toolbar.button_display_mode = (int)(mToolbarRight->getButtonType());
addToToolset(mToolbarRight->getCommandsList(),toolbar_set.right_toolbar);
}
if (mToolbarBottom)
{
toolbar_set.bottom_toolbar.button_display_mode = (int)(mToolbarBottom->getButtonType());
addToToolset(mToolbarBottom->getCommandsList(),toolbar_set.bottom_toolbar);
}

View File

@ -50,7 +50,8 @@ public:
// the user folder for the user specific (saved) settings
struct Toolbar : public LLInitParam::Block<Toolbar>
{
Multiple<LLCommandId::Params> commands;
Mandatory<U32> button_display_mode;
Multiple<LLCommandId::Params> commands;
Toolbar();
};
struct ToolbarSet : public LLInitParam::Block<ToolbarSet>
@ -70,7 +71,8 @@ public:
// Checks if the commandId is being used somewhere in one of the toolbars
bool hasCommand(const LLCommandId& commandId) const;
// Loads the toolbars from the existing user or default settings
bool loadToolbars(); // return false if load fails
bool loadToolbars(bool force_default = false); // return false if load fails
bool loadDefaultToolbars() { return loadToolbars(true); }
protected:
friend class LLUICtrlFactory;

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<toolbars>
<bottom_toolbar>
<bottom_toolbar
button_display_mode="0">
<command name="chat"/>
<command name="speak"/>
<command name="places"/>
@ -10,7 +11,8 @@
<command name="move"/>
<command name="howto"/>
</bottom_toolbar>
<left_toolbar>
<left_toolbar
button_display_mode="1">
<command name="avatar"/>
<command name="inventory"/>
<command name="snapshot"/>

View File

@ -12,11 +12,11 @@
<menu_item_separator layout="topleft" />
<menu_item_check label="Icons and labels"
layout="topleft"
name="icons_and_labels">
name="icons_with_text">
<on_click function="Toolbars.EnableSetting"
parameter="icons_and_labels" />
parameter="icons_with_text" />
<on_check function="Toolbars.CheckSetting"
parameter="icons_and_labels" />
parameter="icons_with_text" />
</menu_item_check>
<menu_item_check label="Icons only"
layout="topleft"