Skip to content
Snippets Groups Projects
Commit 7360f046 authored by Jonathan Yap's avatar Jonathan Yap
Browse files

STORM-2082 Better control on how (or if) to display Default preset

Make sure default preset is created when flyout panel is activated
Only display deleted notification upon successful deletion
parent 3e9c3b36
Branches
Tags
No related merge requests found
...@@ -58,7 +58,8 @@ void LLFloaterDeletePrefPreset::onOpen(const LLSD& key) ...@@ -58,7 +58,8 @@ void LLFloaterDeletePrefPreset::onOpen(const LLSD& key)
LLComboBox* combo = getChild<LLComboBox>("preset_combo"); LLComboBox* combo = getChild<LLComboBox>("preset_combo");
LLPresetsManager::getInstance()->setPresetNamesInComboBox(mSubdirectory, combo); EDefaultOptions option = DEFAULT_HIDE;
LLPresetsManager::getInstance()->setPresetNamesInComboBox(mSubdirectory, combo, option);
} }
void LLFloaterDeletePrefPreset::onBtnDelete() void LLFloaterDeletePrefPreset::onBtnDelete()
...@@ -66,19 +67,20 @@ void LLFloaterDeletePrefPreset::onBtnDelete() ...@@ -66,19 +67,20 @@ void LLFloaterDeletePrefPreset::onBtnDelete()
LLComboBox* combo = getChild<LLComboBox>("preset_combo"); LLComboBox* combo = getChild<LLComboBox>("preset_combo");
std::string name = combo->getSimple(); std::string name = combo->getSimple();
// Ignore return status if (LLPresetsManager::getInstance()->deletePreset(mSubdirectory, name))
LLPresetsManager::getInstance()->deletePreset(mSubdirectory, name); {
LLSD args; LLSD args;
args["NAME"] = name; args["NAME"] = name;
LLNotificationsUtil::add("PresetDeleted", args); LLNotificationsUtil::add("PresetDeleted", args);
} }
}
void LLFloaterDeletePrefPreset::onPresetsListChange() void LLFloaterDeletePrefPreset::onPresetsListChange()
{ {
LLComboBox* combo = getChild<LLComboBox>("preset_combo"); LLComboBox* combo = getChild<LLComboBox>("preset_combo");
LLPresetsManager::getInstance()->setPresetNamesInComboBox(mSubdirectory, combo); EDefaultOptions option = DEFAULT_HIDE;
LLPresetsManager::getInstance()->setPresetNamesInComboBox(mSubdirectory, combo, option);
} }
void LLFloaterDeletePrefPreset::onBtnCancel() void LLFloaterDeletePrefPreset::onBtnCancel()
......
...@@ -744,15 +744,7 @@ void LLFloaterPreference::onOpen(const LLSD& key) ...@@ -744,15 +744,7 @@ void LLFloaterPreference::onOpen(const LLSD& key)
saveSettings(); saveSettings();
// Make sure there is a default preference file // Make sure there is a default preference file
std::string default_file = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, PRESETS_DIR, PRESETS_GRAPHIC, "default.xml"); LLPresetsManager::getInstance()->createMissingDefault();
if (!gDirUtilp->fileExists(default_file))
{
LL_WARNS() << "No " << default_file << " found -- creating one" << LL_ENDL;
// Write current graphic settings to default.xml
// If this name is to be localized additional code will be needed to delete the old default
// when changing languages.
LLPresetsManager::getInstance()->savePreset(PRESETS_GRAPHIC, "Default");
}
bool started = (LLStartUp::getStartupState() == STATE_STARTED); bool started = (LLStartUp::getStartupState() == STATE_STARTED);
...@@ -2121,6 +2113,10 @@ void LLPanelPreference::onChangePreset(const LLSD& user_data) ...@@ -2121,6 +2113,10 @@ void LLPanelPreference::onChangePreset(const LLSD& user_data)
} }
} }
void LLPanelPreference::setHardwareDefaults()
{
}
class LLPanelPreferencePrivacy : public LLPanelPreference class LLPanelPreferencePrivacy : public LLPanelPreference
{ {
public: public:
...@@ -2183,7 +2179,8 @@ void LLPanelPreferenceGraphics::setPresetNamesInComboBox() ...@@ -2183,7 +2179,8 @@ void LLPanelPreferenceGraphics::setPresetNamesInComboBox()
{ {
LLComboBox* combo = getChild<LLComboBox>("graphic_preset_combo"); LLComboBox* combo = getChild<LLComboBox>("graphic_preset_combo");
LLPresetsManager::getInstance()->setPresetNamesInComboBox(PRESETS_GRAPHIC, combo); EDefaultOptions option = DEFAULT_POSITION_TOP;
LLPresetsManager::getInstance()->setPresetNamesInComboBox(PRESETS_GRAPHIC, combo, option);
} }
void LLPanelPreferenceGraphics::draw() void LLPanelPreferenceGraphics::draw()
......
...@@ -211,7 +211,7 @@ class LLPanelPreference : public LLPanel ...@@ -211,7 +211,7 @@ class LLPanelPreference : public LLPanel
virtual void apply(); virtual void apply();
virtual void cancel(); virtual void cancel();
void setControlFalse(const LLSD& user_data); void setControlFalse(const LLSD& user_data);
virtual void setHardwareDefaults(){}; virtual void setHardwareDefaults();
// Disables "Allow Media to auto play" check box only when both // Disables "Allow Media to auto play" check box only when both
// "Streaming Music" and "Media" are unchecked. Otherwise enables it. // "Streaming Music" and "Media" are unchecked. Otherwise enables it.
......
...@@ -70,7 +70,8 @@ void LLFloaterSavePrefPreset::onOpen(const LLSD& key) ...@@ -70,7 +70,8 @@ void LLFloaterSavePrefPreset::onOpen(const LLSD& key)
setTitle(floater_title); setTitle(floater_title);
LLPresetsManager::getInstance()->setPresetNamesInComboBox(mSubdirectory, mPresetCombo); EDefaultOptions option = DEFAULT_POSITION_TOP;
LLPresetsManager::getInstance()->setPresetNamesInComboBox(mSubdirectory, mPresetCombo, option);
onPresetNameEdited(); onPresetNameEdited();
} }
...@@ -88,7 +89,8 @@ void LLFloaterSavePrefPreset::onBtnSave() ...@@ -88,7 +89,8 @@ void LLFloaterSavePrefPreset::onBtnSave()
void LLFloaterSavePrefPreset::onPresetsListChange() void LLFloaterSavePrefPreset::onPresetsListChange()
{ {
LLPresetsManager::getInstance()->setPresetNamesInComboBox(mSubdirectory, mPresetCombo); EDefaultOptions option = DEFAULT_POSITION_TOP;
LLPresetsManager::getInstance()->setPresetNamesInComboBox(mSubdirectory, mPresetCombo, option);
} }
void LLFloaterSavePrefPreset::onBtnCancel() void LLFloaterSavePrefPreset::onBtnCancel()
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "lltabcontainer.h" #include "lltabcontainer.h"
#include "llfloaterreg.h" #include "llfloaterreg.h"
#include "llfloaterpreference.h" #include "llfloaterpreference.h"
#include "llpresetsmanager.h"
#include "llsliderctrl.h" #include "llsliderctrl.h"
/* static */ const F32 LLPanelPresetsPulldown::sAutoCloseFadeStartTimeSec = 4.0f; /* static */ const F32 LLPanelPresetsPulldown::sAutoCloseFadeStartTimeSec = 4.0f;
...@@ -56,6 +57,9 @@ LLPanelPresetsPulldown::LLPanelPresetsPulldown() ...@@ -56,6 +57,9 @@ LLPanelPresetsPulldown::LLPanelPresetsPulldown()
BOOL LLPanelPresetsPulldown::postBuild() BOOL LLPanelPresetsPulldown::postBuild()
{ {
// Make sure there is a default preference file
LLPresetsManager::getInstance()->createMissingDefault();
return LLPanel::postBuild(); return LLPanel::postBuild();
} }
......
...@@ -45,7 +45,19 @@ LLPresetsManager::~LLPresetsManager() ...@@ -45,7 +45,19 @@ LLPresetsManager::~LLPresetsManager()
{ {
} }
//std::string LLPresetsManager::getUserDir(const std::string& subdirectory) void LLPresetsManager::createMissingDefault()
{
std::string default_file = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, PRESETS_DIR, PRESETS_GRAPHIC, "default.xml");
if (!gDirUtilp->fileExists(default_file))
{
LL_WARNS() << "No " << default_file << " found -- creating one" << LL_ENDL;
// Write current graphic settings to default.xml
// If this name is to be localized additional code will be needed to delete the old default
// when changing languages.
LLPresetsManager::getInstance()->savePreset(PRESETS_GRAPHIC, PRESETS_DEFAULT);
}
}
std::string LLPresetsManager::getPresetsDir(const std::string& subdirectory) std::string LLPresetsManager::getPresetsDir(const std::string& subdirectory)
{ {
std::string presets_path = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, PRESETS_DIR); std::string presets_path = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, PRESETS_DIR);
...@@ -65,7 +77,7 @@ std::string LLPresetsManager::getPresetsDir(const std::string& subdirectory) ...@@ -65,7 +77,7 @@ std::string LLPresetsManager::getPresetsDir(const std::string& subdirectory)
return full_path; return full_path;
} }
void LLPresetsManager::loadPresetNamesFromDir(const std::string& dir, preset_name_list_t& presets) void LLPresetsManager::loadPresetNamesFromDir(const std::string& dir, preset_name_list_t& presets, EDefaultOptions default_option)
{ {
LL_INFOS("AppInit") << "Loading presets from " << dir << LL_ENDL; LL_INFOS("AppInit") << "Loading presets from " << dir << LL_ENDL;
...@@ -82,13 +94,26 @@ void LLPresetsManager::loadPresetNamesFromDir(const std::string& dir, preset_nam ...@@ -82,13 +94,26 @@ void LLPresetsManager::loadPresetNamesFromDir(const std::string& dir, preset_nam
{ {
std::string path = gDirUtilp->add(dir, file); std::string path = gDirUtilp->add(dir, file);
std::string name(gDirUtilp->getBaseFileName(LLURI::unescape(path), /*strip_exten = */ true)); std::string name(gDirUtilp->getBaseFileName(LLURI::unescape(path), /*strip_exten = */ true));
if ("Default" != name) if (PRESETS_DEFAULT != name)
{ {
mPresetNames.push_back(name); mPresetNames.push_back(name);
} }
else else
{ {
switch (default_option)
{
case DEFAULT_POSITION_TOP:
mPresetNames.insert(mPresetNames.begin(), name); mPresetNames.insert(mPresetNames.begin(), name);
break;
case DEFAULT_POSITION_NORMAL:
mPresetNames.push_back(name);
break;
case DEFAULT_HIDE:
default:
break;
}
} }
} }
} }
...@@ -177,7 +202,7 @@ void LLPresetsManager::savePreset(const std::string& subdirectory, const std::st ...@@ -177,7 +202,7 @@ void LLPresetsManager::savePreset(const std::string& subdirectory, const std::st
mPresetListChangeSignal(); mPresetListChangeSignal();
} }
void LLPresetsManager::setPresetNamesInComboBox(const std::string& subdirectory, LLComboBox* combo) void LLPresetsManager::setPresetNamesInComboBox(const std::string& subdirectory, LLComboBox* combo, EDefaultOptions default_option)
{ {
combo->clearRows(); combo->clearRows();
...@@ -186,7 +211,7 @@ void LLPresetsManager::setPresetNamesInComboBox(const std::string& subdirectory, ...@@ -186,7 +211,7 @@ void LLPresetsManager::setPresetNamesInComboBox(const std::string& subdirectory,
if (!presets_dir.empty()) if (!presets_dir.empty())
{ {
std::list<std::string> preset_names; std::list<std::string> preset_names;
loadPresetNamesFromDir(presets_dir, preset_names); loadPresetNamesFromDir(presets_dir, preset_names, default_option);
if (preset_names.begin() != preset_names.end()) if (preset_names.begin() != preset_names.end())
{ {
...@@ -212,6 +237,12 @@ void LLPresetsManager::loadPreset(const std::string& subdirectory, const std::st ...@@ -212,6 +237,12 @@ void LLPresetsManager::loadPreset(const std::string& subdirectory, const std::st
bool LLPresetsManager::deletePreset(const std::string& subdirectory, const std::string& name) bool LLPresetsManager::deletePreset(const std::string& subdirectory, const std::string& name)
{ {
if (PRESETS_DEFAULT == name)
{
LL_WARNS("Presets") << "You are not allowed to delete the default preset." << LL_ENDL;
return false;
}
if (gDirUtilp->deleteFilesInDir(getPresetsDir(subdirectory), LLURI::escape(name) + ".xml") < 1) if (gDirUtilp->deleteFilesInDir(getPresetsDir(subdirectory), LLURI::escape(name) + ".xml") < 1)
{ {
LL_WARNS("Presets") << "Error removing preset " << name << " from disk" << LL_ENDL; LL_WARNS("Presets") << "Error removing preset " << name << " from disk" << LL_ENDL;
......
...@@ -32,19 +32,29 @@ ...@@ -32,19 +32,29 @@
#include <list> #include <list>
#include <map> #include <map>
static const std::string PRESETS_DEFAULT = "Default";
static const std::string PRESETS_DIR = "presets"; static const std::string PRESETS_DIR = "presets";
static const std::string PRESETS_GRAPHIC = "graphic"; static const std::string PRESETS_GRAPHIC = "graphic";
static const std::string PRESETS_CAMERA = "camera"; static const std::string PRESETS_CAMERA = "camera";
enum EDefaultOptions
{
DEFAULT_POSITION_TOP, // Put "Default" as the first item in the combobox
DEFAULT_POSITION_NORMAL, // No special positioning
DEFAULT_HIDE // Do not display "Default" in the combobox
};
class LLPresetsManager : public LLSingleton<LLPresetsManager> class LLPresetsManager : public LLSingleton<LLPresetsManager>
{ {
public: public:
typedef std::list<std::string> preset_name_list_t; typedef std::list<std::string> preset_name_list_t;
typedef boost::signals2::signal<void()> preset_list_signal_t; typedef boost::signals2::signal<void()> preset_list_signal_t;
void createMissingDefault();
static std::string getPresetsDir(const std::string& subdirectory); static std::string getPresetsDir(const std::string& subdirectory);
void setPresetNamesInComboBox(const std::string& subdirectory, LLComboBox* combo); void setPresetNamesInComboBox(const std::string& subdirectory, LLComboBox* combo, EDefaultOptions default_option);
void loadPresetNamesFromDir(const std::string& dir, preset_name_list_t& presets); void loadPresetNamesFromDir(const std::string& dir, preset_name_list_t& presets, EDefaultOptions default_option);
void savePreset(const std::string& subdirectory, const std::string & name); void savePreset(const std::string& subdirectory, const std::string & name);
void loadPreset(const std::string& subdirectory, const std::string & name); void loadPreset(const std::string& subdirectory, const std::string & name);
bool deletePreset(const std::string& subdirectory, const std::string& name); bool deletePreset(const std::string& subdirectory, const std::string& name);
......
...@@ -962,7 +962,7 @@ ...@@ -962,7 +962,7 @@
<button <button
follows="left|bottom" follows="left|bottom"
height="23" height="23"
label="Reset" label="Undo"
layout="topleft" layout="topleft"
left_pad="5" left_pad="5"
name="Defaults" name="Defaults"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment