From 5040a726755939704a3de14187d9d020caea4d9d Mon Sep 17 00:00:00 2001 From: Rick Pasetto Date: Mon, 30 Nov 2009 16:01:20 -0800 Subject: DEV-43041 DEV-41648 - disable OK and Apply if the media data is the same as the initial Review #48 This change kills two birds with one stone: every frame, we check to see if the media data is the same as the one we 'initialize' with. If it is, we disable OK and Cancel. Otherwise we enable them. This makes it very difficult to set empty media data, as well as fixing the "apply button doesn't grey out" bug. --- indra/newview/llfloatermediasettings.cpp | 55 ++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 9 deletions(-) (limited to 'indra/newview/llfloatermediasettings.cpp') diff --git a/indra/newview/llfloatermediasettings.cpp b/indra/newview/llfloatermediasettings.cpp index 44e68d7745..f7ce826a39 100644 --- a/indra/newview/llfloatermediasettings.cpp +++ b/indra/newview/llfloatermediasettings.cpp @@ -41,6 +41,7 @@ #include "lluictrlfactory.h" #include "llbutton.h" #include "llselectmgr.h" +#include "llsdutil.h" LLFloaterMediaSettings* LLFloaterMediaSettings::sInstance = NULL; @@ -145,15 +146,15 @@ LLFloaterMediaSettings* LLFloaterMediaSettings::getInstance() //static void LLFloaterMediaSettings::apply() { - LLSD settings; + LLSD settings; sInstance->mPanelMediaSettingsGeneral->preApply(); - sInstance->mPanelMediaSettingsGeneral->getValues( settings ); + sInstance->mPanelMediaSettingsGeneral->getValues( settings ); sInstance->mPanelMediaSettingsSecurity->preApply(); sInstance->mPanelMediaSettingsSecurity->getValues( settings ); sInstance->mPanelMediaSettingsPermissions->preApply(); - sInstance->mPanelMediaSettingsPermissions->getValues( settings ); + sInstance->mPanelMediaSettingsPermissions->getValues( settings ); LLSelectMgr::getInstance()->selectionSetMedia( LLTextureEntry::MF_HAS_MEDIA ); - LLSelectMgr::getInstance()->selectionSetMediaData(settings); + LLSelectMgr::getInstance()->selectionSetMediaData(settings); sInstance->mPanelMediaSettingsGeneral->postApply(); sInstance->mPanelMediaSettingsSecurity->postApply(); sInstance->mPanelMediaSettingsPermissions->postApply(); @@ -183,7 +184,12 @@ void LLFloaterMediaSettings::initValues( const LLSD& media_settings, bool editab sInstance->mPanelMediaSettingsPermissions-> initValues( sInstance->mPanelMediaSettingsPermissions, media_settings, editable ); - + + // Squirrel away initial values + sInstance->mInitialValues.clear(); + sInstance->mPanelMediaSettingsGeneral->getValues( sInstance->mInitialValues ); + sInstance->mPanelMediaSettingsSecurity->getValues( sInstance->mInitialValues ); + sInstance->mPanelMediaSettingsPermissions->getValues( sInstance->mInitialValues ); } //////////////////////////////////////////////////////////////////////////////// @@ -206,7 +212,7 @@ void LLFloaterMediaSettings::clearValues( bool editable) { // clean up all panels before updating sInstance->mPanelMediaSettingsGeneral ->clearValues(sInstance->mPanelMediaSettingsGeneral, editable); - sInstance->mPanelMediaSettingsSecurity ->clearValues(sInstance->mPanelMediaSettingsSecurity, editable); + sInstance->mPanelMediaSettingsSecurity ->clearValues(sInstance->mPanelMediaSettingsSecurity, editable); sInstance->mPanelMediaSettingsPermissions->clearValues(sInstance->mPanelMediaSettingsPermissions, editable); } @@ -235,7 +241,7 @@ void LLFloaterMediaSettings::onBtnApply( void* userdata ) // static void LLFloaterMediaSettings::onBtnCancel( void* userdata ) { - sInstance->closeFloater(); + sInstance->closeFloater(); } //////////////////////////////////////////////////////////////////////////////// @@ -250,7 +256,6 @@ void LLFloaterMediaSettings::onTabChanged(void* user_data, bool from_click) // void LLFloaterMediaSettings::enableOkApplyBtns( bool enable ) { - setCtrlsEnabled( enable ); childSetEnabled( "OK", enable ); childSetEnabled( "Apply", enable ); } @@ -265,7 +270,6 @@ const std::string LLFloaterMediaSettings::getHomeUrl() return std::string( "" ); } - //////////////////////////////////////////////////////////////////////////////// // bool LLFloaterMediaSettings::passesWhiteList( const std::string& test_url ) @@ -279,3 +283,36 @@ bool LLFloaterMediaSettings::passesWhiteList( const std::string& test_url ) // this is all we can do return false; } + +//////////////////////////////////////////////////////////////////////////////// +// virtual +void LLFloaterMediaSettings::draw() +{ + // *NOTE: The code below is very inefficient. Better to do this + // only when data change. + // Every frame, check to see what the values are. If they are not + // the same as the default media data, enable the OK/Apply buttons + LLSD settings; + sInstance->mPanelMediaSettingsGeneral->getValues( settings ); + sInstance->mPanelMediaSettingsSecurity->getValues( settings ); + sInstance->mPanelMediaSettingsPermissions->getValues( settings ); + + bool values_changed = false; + + LLSD::map_const_iterator iter = settings.beginMap(); + LLSD::map_const_iterator end = settings.endMap(); + for ( ; iter != end; ++iter ) + { + const std::string ¤t_key = iter->first; + const LLSD ¤t_value = iter->second; + if ( ! llsd_equals(current_value, mInitialValues[current_key])) + { + values_changed = true; + break; + } + } + + enableOkApplyBtns(values_changed); + + LLFloater::draw(); +} -- cgit v1.2.3