VWR-22690 FIXED Implemented save/load of bottomtray button order.

- Added methods responsible for saving and loading order of buttons to bottomtray. Order is saved after each drag'n'drop to
ensure user's customization of bottomtray is not lost because of crash.

- Added additional argument to layoutstack movePanel() method which tells it to move panel to the beginning of mPanels vector
without requiring a pointer to panel before which it should be inserted.

Reviewed by Vadim Savchuk.
meow-7.2.2
Andrew Dyukov 2010-09-06 22:56:14 +03:00
parent e04dabd2b3
commit a30bc718bb
4 changed files with 83 additions and 4 deletions

View File

@ -368,10 +368,10 @@ S32 LLLayoutStack::getDefaultWidth(S32 cur_width)
return cur_width;
}
void LLLayoutStack::movePanel(LLPanel* panel_to_move, LLPanel* target_panel)
void LLLayoutStack::movePanel(LLPanel* panel_to_move, LLPanel* target_panel, bool move_to_front)
{
LayoutPanel* embedded_panel_to_move = findEmbeddedPanel(panel_to_move);
LayoutPanel* embedded_target_panel = findEmbeddedPanel(target_panel);
LayoutPanel* embedded_target_panel = move_to_front ? *mPanels.begin() : findEmbeddedPanel(target_panel);
if (!embedded_panel_to_move || !embedded_target_panel || embedded_panel_to_move == embedded_target_panel)
{
@ -380,7 +380,7 @@ void LLLayoutStack::movePanel(LLPanel* panel_to_move, LLPanel* target_panel)
}
e_panel_list_t::iterator it = std::find(mPanels.begin(), mPanels.end(), embedded_panel_to_move);
mPanels.erase(it);
it = std::find(mPanels.begin(), mPanels.end(), embedded_target_panel);
it = move_to_front ? mPanels.begin() : std::find(mPanels.begin(), mPanels.end(), embedded_target_panel);
mPanels.insert(it, embedded_panel_to_move);
}

View File

@ -74,8 +74,9 @@ public:
S32 getNumPanels() { return mPanels.size(); }
/**
* Moves panel_to_move before target_panel inside layout stack (both panels should already be there).
* If move_to_front is true target_panel is ignored and panel_to_move is moved to the beginning of mPanels
*/
void movePanel(LLPanel* panel_to_move, LLPanel* target_panel);
void movePanel(LLPanel* panel_to_move, LLPanel* target_panel, bool move_to_front = false);
void updatePanelAutoResize(const std::string& panel_name, BOOL auto_resize);
void setPanelUserResize(const std::string& panel_name, BOOL user_resize);

View File

@ -50,10 +50,13 @@
#include "llviewerparcelmgr.h"
#include "llviewerwindow.h"
#include "llsdserialize.h"
// Distance from mouse down on which drag'n'drop should be started.
#define DRAG_START_DISTANCE 3
static const std::string SORTING_DATA_FILE_NAME = "bottomtray_buttons_order.xml";
LLDefaultChildRegistry::Register<LLBottomtrayButton> bottomtray_button("bottomtray_button");
// LLBottomtrayButton methods
@ -549,6 +552,8 @@ BOOL LLBottomTray::postBuild()
showWellButton(RS_IM_WELL, !LLIMWellWindow::getInstance()->isWindowEmpty());
showWellButton(RS_NOTIFICATION_WELL, !LLNotificationWellWindow::getInstance()->isWindowEmpty());
loadButtonsOrder();
LLViewerParcelMgr::getInstance()->addAgentParcelChangedCallback(boost::bind(&update_build_button_enable_state));
return TRUE;
@ -691,6 +696,74 @@ void LLBottomTray::updateButtonsOrdersAfterDnD()
++it2;
}
}
saveButtonsOrder();
}
void LLBottomTray::saveButtonsOrder()
{
std::string user_dir = gDirUtilp->getLindenUserDir();
if (user_dir.empty()) return;
std::string filename = gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, SORTING_DATA_FILE_NAME);
LLSD settings_llsd;
int i = 0;
const resize_state_vec_t::const_iterator it_end = mButtonsOrder.end();
// we use numbers as keys for map which is saved in file and contains resize states as its values
for (resize_state_vec_t::const_iterator it = mButtonsOrder.begin(); it != it_end; ++it, i++)
{
std::string str = llformat("%d", i);
settings_llsd[str] = *it;
}
llofstream file;
file.open(filename);
LLSDSerialize::toPrettyXML(settings_llsd, file);
}
void LLBottomTray::loadButtonsOrder()
{
// load per-resident sorting information
std::string filename = gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, SORTING_DATA_FILE_NAME);
LLSD settings_llsd;
llifstream file;
file.open(filename);
if (!file.is_open()) return;
LLSDSerialize::fromXML(settings_llsd, file);
mButtonsOrder.clear();
mButtonsProcessOrder.clear();
int i = 0;
// getting button order from file
for (LLSD::map_const_iterator iter = settings_llsd.beginMap();
iter != settings_llsd.endMap(); ++iter, ++i)
{
std::string str = llformat("%d", i);
EResizeState state = (EResizeState)settings_llsd[str].asInteger();
mButtonsOrder.push_back(state);
// RS_BUTTON_SPEAK is skipped, because it shouldn't be in mButtonsProcessOrder (it does not hide or shrink).
if (state != RS_BUTTON_SPEAK)
{
mButtonsProcessOrder.push_back(state);
}
}
// There are other panels in layout stack order of which is not saved. Also, panels order of which is saved,
// are already in layout stack but in wrong order. The most convenient way to place them is moving them
// to front one by one (because in this case we don't have to pass the panel before which we want to insert our
// panel to movePanel()). So panels are moved in order from the end of mButtonsOrder vector(reverse iterator is used).
const resize_state_vec_t::const_reverse_iterator it_end = mButtonsOrder.rend();
// placing panels in layout stack according to button order which we loaded in previous for
for (resize_state_vec_t::const_reverse_iterator it = mButtonsOrder.rbegin(); it != it_end; ++it, ++i)
{
LLPanel* panel_to_move = *it == RS_BUTTON_SPEAK ? mSpeakPanel : mStateProcessedObjectMap[*it];
mToolbarStack->movePanel(panel_to_move, NULL, true); // prepend
}
// Nearbychat is not stored in order settings file, but it must be the first of the panels, so moving it
// manually here
mToolbarStack->movePanel(mNearbyChatBar, NULL, true);
}
void LLBottomTray::onDraggableButtonMouseUp(LLUICtrl* ctrl, S32 x, S32 y, MASK mask)

View File

@ -188,6 +188,11 @@ private:
*/
void updateButtonsOrdersAfterDnD();
// saves order of buttons to file on disk
void saveButtonsOrder();
// reads order of buttons from file on disk
void loadButtonsOrder();
/**
* Updates child controls size and visibility when it is necessary to reduce total width.
*