diff options
Diffstat (limited to 'indra/newview/llfloatersaveprefpreset.cpp')
-rw-r--r-- | indra/newview/llfloatersaveprefpreset.cpp | 96 |
1 files changed, 78 insertions, 18 deletions
diff --git a/indra/newview/llfloatersaveprefpreset.cpp b/indra/newview/llfloatersaveprefpreset.cpp index 684778c93a..3142991704 100644 --- a/indra/newview/llfloatersaveprefpreset.cpp +++ b/indra/newview/llfloatersaveprefpreset.cpp @@ -32,46 +32,70 @@ #include "llcombobox.h" #include "llfloaterpreference.h" #include "llfloaterreg.h" +#include "lllineeditor.h" #include "llnotificationsutil.h" #include "llpresetsmanager.h" +#include "llradiogroup.h" #include "lltrans.h" LLFloaterSavePrefPreset::LLFloaterSavePrefPreset(const LLSD &key) -: LLFloater(key) + : LLModalDialog(key) { } // virtual BOOL LLFloaterSavePrefPreset::postBuild() -{ LLFloaterPreference* preferences = LLFloaterReg::getTypedInstance<LLFloaterPreference>("preferences"); +{ + LLFloaterPreference* preferences = LLFloaterReg::getTypedInstance<LLFloaterPreference>("preferences"); if (preferences) { preferences->addDependentFloater(this); } - getChild<LLComboBox>("preset_combo")->setTextEntryCallback(boost::bind(&LLFloaterSavePrefPreset::onPresetNameEdited, this)); - getChild<LLComboBox>("preset_combo")->setCommitCallback(boost::bind(&LLFloaterSavePrefPreset::onPresetNameEdited, this)); - getChild<LLButton>("save")->setCommitCallback(boost::bind(&LLFloaterSavePrefPreset::onBtnSave, this)); - getChild<LLButton>("cancel")->setCommitCallback(boost::bind(&LLFloaterSavePrefPreset::onBtnCancel, this)); + + mPresetCombo = getChild<LLComboBox>("preset_combo"); - LLPresetsManager::instance().setPresetListChangeCallback(boost::bind(&LLFloaterSavePrefPreset::onPresetsListChange, this)); + mNameEditor = getChild<LLLineEditor>("preset_txt_editor"); + mNameEditor->setKeystrokeCallback(boost::bind(&LLFloaterSavePrefPreset::onPresetNameEdited, this), NULL); mSaveButton = getChild<LLButton>("save"); - mPresetCombo = getChild<LLComboBox>("preset_combo"); + mSaveButton->setCommitCallback(boost::bind(&LLFloaterSavePrefPreset::onBtnSave, this)); + + mSaveRadioGroup = getChild<LLRadioGroup>("radio_save_preset"); + mSaveRadioGroup->setCommitCallback(boost::bind(&LLFloaterSavePrefPreset::onSwitchSaveReplace, this)); + + getChild<LLButton>("cancel")->setCommitCallback(boost::bind(&LLFloaterSavePrefPreset::onBtnCancel, this)); + + LLPresetsManager::instance().setPresetListChangeCallback(boost::bind(&LLFloaterSavePrefPreset::onPresetsListChange, this)); return TRUE; } void LLFloaterSavePrefPreset::onPresetNameEdited() { - // Disable saving a preset having empty name. - std::string name = mPresetCombo->getSimple(); - - mSaveButton->setEnabled(!name.empty()); + if (mSaveRadioGroup->getSelectedIndex() == 0) + { + // Disable saving a preset having empty name. + std::string name = mNameEditor->getValue(); + mSaveButton->setEnabled(!name.empty()); + } } void LLFloaterSavePrefPreset::onOpen(const LLSD& key) { - mSubdirectory = key.asString(); + LLModalDialog::onOpen(key); + S32 index = 0; + if (key.has("subdirectory")) + { + mSubdirectory = key["subdirectory"].asString(); + if (key.has("index")) + { + index = key["index"].asInteger(); + } + } + else + { + mSubdirectory = key.asString(); + } std::string floater_title = getString(std::string("title_") + mSubdirectory); @@ -80,22 +104,41 @@ void LLFloaterSavePrefPreset::onOpen(const LLSD& key) EDefaultOptions option = DEFAULT_HIDE; LLPresetsManager::getInstance()->setPresetNamesInComboBox(mSubdirectory, mPresetCombo, option); + mSaveRadioGroup->setSelectedIndex(index); onPresetNameEdited(); + onSwitchSaveReplace(); } void LLFloaterSavePrefPreset::onBtnSave() { - std::string name = mPresetCombo->getSimple(); + bool is_saving_new = mSaveRadioGroup->getSelectedIndex() == 0; + std::string name = is_saving_new ? mNameEditor->getText() : mPresetCombo->getSimple(); if ((name == LLTrans::getString(PRESETS_DEFAULT)) || (name == PRESETS_DEFAULT)) { LLNotificationsUtil::add("DefaultPresetNotSaved"); } - else if (!LLPresetsManager::getInstance()->savePreset(mSubdirectory, name)) + else { - LLSD args; - args["NAME"] = name; - LLNotificationsUtil::add("PresetNotSaved", args); + if (is_saving_new) + { + std::list<std::string> preset_names; + std::string presets_dir = LLPresetsManager::getInstance()->getPresetsDir(mSubdirectory); + LLPresetsManager::getInstance()->loadPresetNamesFromDir(presets_dir, preset_names, DEFAULT_HIDE); + if (std::find(preset_names.begin(), preset_names.end(), name) != preset_names.end()) + { + LLSD args; + args["NAME"] = name; + LLNotificationsUtil::add("PresetAlreadyExists", args); + return; + } + } + if (!LLPresetsManager::getInstance()->savePreset(mSubdirectory, name)) + { + LLSD args; + args["NAME"] = name; + LLNotificationsUtil::add("PresetNotSaved", args); + } } closeFloater(); @@ -111,3 +154,20 @@ void LLFloaterSavePrefPreset::onBtnCancel() { closeFloater(); } + +void LLFloaterSavePrefPreset::onSwitchSaveReplace() +{ + bool is_saving_new = mSaveRadioGroup->getSelectedIndex() == 0; + std::string label = is_saving_new ? getString("btn_label_save") : getString("btn_label_replace"); + mSaveButton->setLabel(label); + mNameEditor->setEnabled(is_saving_new); + mPresetCombo->setEnabled(!is_saving_new); + if (is_saving_new) + { + onPresetNameEdited(); + } + else + { + mSaveButton->setEnabled(true); + } +} |