From ce17ae8a182cf8b1acd88bbbb3dceb7ff39fd0ff Mon Sep 17 00:00:00 2001
From: Oz Linden <oz@lindenlab.com>
Date: Sat, 12 May 2012 07:29:25 -0400
Subject: [PATCH] STORM-1738: get autoreplace preferences working, clean up
 some coding and naming conventions

---
 indra/newview/CMakeLists.txt                  |   4 +-
 ...r.cpp => llfloaterautoreplacesettings.cpp} | 114 ++++++++----------
 ...oater.h => llfloaterautoreplacesettings.h} |  21 ++--
 indra/newview/llfloaterpreference.cpp         |  12 +-
 indra/newview/llfloaterpreference.h           |   1 +
 indra/newview/llviewerfloaterreg.cpp          |   4 +-
 .../default/xui/en/floater_autoreplace.xml    |   4 +-
 .../default/xui/en/panel_preferences_chat.xml |   2 +-
 8 files changed, 78 insertions(+), 84 deletions(-)
 rename indra/newview/{llautoreplacefloater.cpp => llfloaterautoreplacesettings.cpp} (79%)
 rename indra/newview/{llautoreplacefloater.h => llfloaterautoreplacesettings.h} (78%)

diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt
index 90468ccbef4..a45467324bc 100644
--- a/indra/newview/CMakeLists.txt
+++ b/indra/newview/CMakeLists.txt
@@ -99,7 +99,6 @@ set(viewer_SOURCE_FILES
     llattachmentsmgr.cpp
     llaudiosourcevo.cpp
     llautoreplace.cpp
-    llautoreplacefloater.cpp
     llavataractions.cpp
     llavatariconctrl.cpp
     llavatarlist.cpp
@@ -171,6 +170,7 @@ set(viewer_SOURCE_FILES
     llfloaterabout.cpp
     llfloaterbvhpreview.cpp
     llfloaterauction.cpp
+    llfloaterautoreplacesettings.cpp
     llfloateravatar.cpp
     llfloateravatarpicker.cpp
     llfloateravatartextures.cpp
@@ -657,7 +657,6 @@ set(viewer_HEADER_FILES
     llattachmentsmgr.h
     llaudiosourcevo.h
     llautoreplace.h
-    llautoreplacefloater.h
     llavataractions.h
     llavatariconctrl.h
     llavatarlist.h
@@ -729,6 +728,7 @@ set(viewer_HEADER_FILES
     llfloaterabout.h
     llfloaterbvhpreview.h
     llfloaterauction.h
+    llfloaterautoreplacesettings.h
     llfloateravatar.h
     llfloateravatarpicker.h
     llfloateravatartextures.h
diff --git a/indra/newview/llautoreplacefloater.cpp b/indra/newview/llfloaterautoreplacesettings.cpp
similarity index 79%
rename from indra/newview/llautoreplacefloater.cpp
rename to indra/newview/llfloaterautoreplacesettings.cpp
index c2d7be269be..3dfcfba9364 100644
--- a/indra/newview/llautoreplacefloater.cpp
+++ b/indra/newview/llfloaterautoreplacesettings.cpp
@@ -24,7 +24,7 @@
 
 #include "llviewerprecompiledheaders.h"
 
-#include "llautoreplacefloater.h"
+#include "llfloaterautoreplacesettings.h"
 
 #include "llagentdata.h"
 #include "llcommandhandler.h"
@@ -64,16 +64,20 @@
 #include "llnotificationmanager.h"
 
 
-AutoReplaceFloater::AutoReplaceFloater(const LLSD& key) :
-LLFloater(key)
+LLFloaterAutoReplaceSettings::LLFloaterAutoReplaceSettings(const LLSD& key)
+ : LLFloater(key)
+ , namesList(NULL)
+ , entryList(NULL)
+ , mOldText(NULL)
+ , mNewText(NULL)   
 {
 }
-void AutoReplaceFloater::onClose(bool app_quitting)
+void LLFloaterAutoReplaceSettings::onClose(bool app_quitting)
 {
 	destroy();
 }
 
-BOOL AutoReplaceFloater::postBuild(void)
+BOOL LLFloaterAutoReplaceSettings::postBuild(void)
 {
 
 	namesList = getChild<LLScrollListCtrl>("ac_list_name");
@@ -88,12 +92,9 @@ BOOL AutoReplaceFloater::postBuild(void)
 	childSetCommitCallback("ac_list_style",onEntrySettingChange,this);
 	childSetCommitCallback("ac_priority",onEntrySettingChange,this);
 	
-
-	
 	updateEnabledStuff();
 	updateNamesList();	
 
-
 	namesList->setCommitOnSelectionChange(TRUE);
 	childSetCommitCallback("ac_list_name", onSelectName, this);
 	
@@ -106,22 +107,22 @@ BOOL AutoReplaceFloater::postBuild(void)
 	return true;
 }
 
-void AutoReplaceFloater::onSelectName(LLUICtrl* ctrl, void* user_data)
+void LLFloaterAutoReplaceSettings::onSelectName(LLUICtrl* ctrl, void* user_data)
 {
 	if ( user_data )
 	{
-		AutoReplaceFloater* self = ( AutoReplaceFloater* )user_data;
+		LLFloaterAutoReplaceSettings* self = ( LLFloaterAutoReplaceSettings* )user_data;
 		if ( self )
+		{
 			self->updateItemsList();
+		}
 	}
-
 }
-void AutoReplaceFloater::updateItemsList()
+void LLFloaterAutoReplaceSettings::updateItemsList()
 {
 	entryList->deleteAllItems();
 	if((namesList->getAllSelected().size())<=0)
 	{
-
 		updateListControlsEnabled(FALSE);
 		return;
 	}
@@ -142,8 +143,6 @@ void AutoReplaceFloater::updateItemsList()
 		const std::string& wrong = (*loc_it).first;
 		const std::string& right = (*loc_it).second;
 
-		//std::string lentry(wrong+"=>"+right);
-
 		LLSD element;
 		element["id"] = wrong;
 		LLSD& s_column = element["columns"][0];
@@ -159,7 +158,7 @@ void AutoReplaceFloater::updateItemsList()
 	}
 	
 }
-void AutoReplaceFloater::updateNamesList()
+void LLFloaterAutoReplaceSettings::updateNamesList()
 {
 	namesList->deleteAllItems();
 	if(!gSavedSettings.getBOOL("AutoReplace"))
@@ -182,17 +181,21 @@ void AutoReplaceFloater::updateNamesList()
 		//friend_column["font"] = "SANSSERIF";
 		const LLSD& loc_map = (*loc_it).second;
 		if(loc_map["enabled"].asBoolean())
+		{
 			friend_column["font"] = "SANSSERIF";
-			//friend_column["style"] = "BOLD";
+		}
 		else
+		{
 			friend_column["font"] = "SANSSERIF_SMALL";
-			//friend_column["style"] = "NORMAL";
+		}
 		if(namesList)
-		namesList->addElement(element, ADD_BOTTOM);
+		{
+			namesList->addElement(element, ADD_BOTTOM);
+		}
 	}
 	updateItemsList();
 }
-void AutoReplaceFloater::updateListControlsEnabled(BOOL selected)
+void LLFloaterAutoReplaceSettings::updateListControlsEnabled(BOOL selected)
 {
 
 		childSetEnabled("ac_text1",selected);
@@ -208,7 +211,7 @@ void AutoReplaceFloater::updateListControlsEnabled(BOOL selected)
 		childSetEnabled("ac_priority",selected);
 	
 }
-void AutoReplaceFloater::updateEnabledStuff()
+void LLFloaterAutoReplaceSettings::updateEnabledStuff()
 {
 	BOOL autoreplace = gSavedSettings.getBOOL("AutoReplace");
 	if(autoreplace)
@@ -216,7 +219,8 @@ void AutoReplaceFloater::updateEnabledStuff()
 		LLCheckBoxCtrl *enBox = getChild<LLCheckBoxCtrl>("ac_enable");
 		enBox->setDisabledColor(LLColor4::red);
 		getChild<LLCheckBoxCtrl>("ac_enable")->setEnabledColor(LLColor4(1.0f,0.0f,0.0f,1.0f));		
-	}else
+	}
+	else
 	{
 		getChild<LLCheckBoxCtrl>("ac_enable")->setEnabledColor(
 			LLUIColorTable::instance().getColor( "LabelTextColor" ));
@@ -229,25 +233,25 @@ void AutoReplaceFloater::updateEnabledStuff()
 	AutoReplace::getInstance()->save();
 
 }
-void AutoReplaceFloater::setData(void * data)
+void LLFloaterAutoReplaceSettings::setData(void * data)
 {
 }
-void AutoReplaceFloater::onBoxCommitEnabled(LLUICtrl* caller, void* user_data)
+void LLFloaterAutoReplaceSettings::onBoxCommitEnabled(LLUICtrl* caller, void* user_data)
 {
 	if ( user_data )
 	{
-		AutoReplaceFloater* self = ( AutoReplaceFloater* )user_data;
+		LLFloaterAutoReplaceSettings* self = ( LLFloaterAutoReplaceSettings* )user_data;
 		if ( self )
 		{
 			self->updateEnabledStuff();
 		}
 	}
 }
-void AutoReplaceFloater::onEntrySettingChange(LLUICtrl* caller, void* user_data)
+void LLFloaterAutoReplaceSettings::onEntrySettingChange(LLUICtrl* caller, void* user_data)
 {
 	if ( user_data )
 	{
-		AutoReplaceFloater* self = ( AutoReplaceFloater* )user_data;
+		LLFloaterAutoReplaceSettings* self = ( LLFloaterAutoReplaceSettings* )user_data;
 		if ( self )
 		{
 			std::string listName= self->namesList->getFirstSelected()->getColumn(0)->getValue().asString();
@@ -260,11 +264,11 @@ void AutoReplaceFloater::onEntrySettingChange(LLUICtrl* caller, void* user_data)
 		}
 	}
 }
-void AutoReplaceFloater::deleteEntry(void* data)
+void LLFloaterAutoReplaceSettings::deleteEntry(void* data)
 {
 	if ( data )
 	{
-		AutoReplaceFloater* self = ( AutoReplaceFloater* )data;
+		LLFloaterAutoReplaceSettings* self = ( LLFloaterAutoReplaceSettings* )data;
 		if ( self )
 		{
 
@@ -280,12 +284,13 @@ void AutoReplaceFloater::deleteEntry(void* data)
 		}
 	}
 }
-void AutoReplaceFloater::loadList(void* data)
+void LLFloaterAutoReplaceSettings::loadList(void* data)
 {
 	LLFilePicker& picker = LLFilePicker::instance();
 
 	if(!picker.getOpenFile( LLFilePicker::FFLOAD_XML) )
-	{return;
+	{
+		return;
 	}	
 	llifstream file;
 	file.open(picker.getFirstFile().c_str());
@@ -299,16 +304,18 @@ void AutoReplaceFloater::loadList(void* data)
 	AutoReplace::getInstance()->addReplacementList(blankllsd);
 	if ( data )
 	{
-		AutoReplaceFloater* self = ( AutoReplaceFloater* )data;
+		LLFloaterAutoReplaceSettings* self = ( LLFloaterAutoReplaceSettings* )data;
 		if ( self )
+		{
 			self->updateEnabledStuff();
+		}
 	}
 }
-void AutoReplaceFloater::removeList(void* data)
+void LLFloaterAutoReplaceSettings::removeList(void* data)
 {
 	if ( data )
 	{
-		AutoReplaceFloater* self = ( AutoReplaceFloater* )data;
+		LLFloaterAutoReplaceSettings* self = ( LLFloaterAutoReplaceSettings* )data;
 		if ( self )
 		{
 			std::string listName= self->namesList->getFirstSelected()->getColumn(0)->getValue().asString();
@@ -318,33 +325,31 @@ void AutoReplaceFloater::removeList(void* data)
 
 	}
 }
-void AutoReplaceFloater::exportList(void *data)
+void LLFloaterAutoReplaceSettings::exportList(void *data)
 {
 	if ( data )
 	{
-		AutoReplaceFloater* self = ( AutoReplaceFloater* )data;
+		LLFloaterAutoReplaceSettings* self = ( LLFloaterAutoReplaceSettings* )data;
 		if ( self )
 		{
 			std::string listName=self->namesList->getFirstSelected()->getColumn(0)->getValue().asString();
 
 			LLFilePicker& picker = LLFilePicker::instance();
-
-			if(!picker.getSaveFile( LLFilePicker::FFSAVE_XML) )
-			{return;
+			if(picker.getSaveFile( LLFilePicker::FFSAVE_XML) )
+			{
+				llofstream file;
+				file.open(picker.getFirstFile().c_str());
+				LLSDSerialize::toPrettyXML(AutoReplace::getInstance()->exportList(listName), file);
+				file.close();	
 			}	
-			llofstream file;
-			file.open(picker.getFirstFile().c_str());
-			LLSDSerialize::toPrettyXML(AutoReplace::getInstance()->exportList(listName), file);
-			file.close();	
 		}
-	
 	}
 }
-void AutoReplaceFloater::addEntry(void* data)
+void LLFloaterAutoReplaceSettings::addEntry(void* data)
 {
 	if ( data )
 	{
-		AutoReplaceFloater* self = ( AutoReplaceFloater* )data;
+		LLFloaterAutoReplaceSettings* self = ( LLFloaterAutoReplaceSettings* )data;
 		if ( self )
 		{
 			std::string listName= self->namesList->getFirstSelected()->getColumn(0)->getValue().asString();
@@ -359,19 +364,4 @@ void AutoReplaceFloater::addEntry(void* data)
 		}
 	}
 }
-AutoReplaceFloater* AutoReplaceFloater::showFloater()
-{
-	AutoReplaceFloater *floater = dynamic_cast<AutoReplaceFloater*>(LLFloaterReg::getInstance("autoreplace"));
-	if(floater)
-	{
-		floater->setVisible(true);
-		floater->setFrontmost(true);
-		floater->center();
-		return floater;
-	}
-	else
-	{
-		LL_WARNS("AutoReplace") << "Can't find floater!" << LL_ENDL;
-		return NULL;
-	}
-}
+
diff --git a/indra/newview/llautoreplacefloater.h b/indra/newview/llfloaterautoreplacesettings.h
similarity index 78%
rename from indra/newview/llautoreplacefloater.h
rename to indra/newview/llfloaterautoreplacesettings.h
index 213cf93a300..dd0acb613bb 100644
--- a/indra/newview/llautoreplacefloater.h
+++ b/indra/newview/llfloaterautoreplacesettings.h
@@ -1,5 +1,5 @@
 /** 
- * @file llautoreplacefloater.h
+ * @file llfloaterautoreplacesettings.h
  * @brief Auto Replace List floater
  * @copyright Copyright (c) 2011 LordGregGreg Back
  *
@@ -23,8 +23,8 @@
  * $/LicenseInfo$
  */
 
-#ifndef AUTOREPLACEFLOATER_H
-#define AUTOREPLACEFLOATER_H
+#ifndef LLFLOATERAUTOREPLACESETTINGS_H
+#define LLFLOATERAUTOREPLACESETTINGS_H
 
 #include "llfloater.h"
 #include "llmediactrl.h"
@@ -34,17 +34,15 @@
 #include "llviewerinventory.h"
 #include <boost/bind.hpp>
 
-class AutoReplaceFloater : 
+class LLFloaterAutoReplaceSettings : 
 public LLFloater
 {
 public:
-	AutoReplaceFloater(const LLSD& key);
+	LLFloaterAutoReplaceSettings(const LLSD& key);
 
 	/*virtual*/ BOOL postBuild();
 	/*virtual*/ void onClose(bool app_quitting);
 
-	static AutoReplaceFloater* showFloater();
-
 	void setData(void * data);
 	void updateEnabledStuff();
 	void updateNamesList();
@@ -55,15 +53,12 @@ public LLFloater
 	LLScrollListCtrl *entryList;
 	LLLineEditor* mOldText;
 	LLLineEditor* mNewText;
-	//LLPanel * empanel;
+
 private:
-	//static JCInvDropTarget* mNotecardDropTarget;
+
 	static void onBoxCommitEnabled(LLUICtrl* caller, void* user_data);
 	static void onEntrySettingChange(LLUICtrl* caller, void* user_data);
 	static void onSelectName(LLUICtrl* caller, void* user_data);
-	//static void ResponseItemDrop(LLViewerInventoryItem* item);
-	//static void onNotecardLoadComplete(LLVFS *vfs,const LLUUID& asset_uuid,LLAssetType::EType type,void* user_data, S32 status, LLExtStat ext_status);
-
 
 	static void deleteEntry(void* data);
 	static void addEntry(void* data);
@@ -72,4 +67,4 @@ public LLFloater
 	static void loadList(void* data);
 };
 
-#endif  // AUTOREPLACEFLOATER_H
+#endif  // LLFLOATERAUTOREPLACESETTINGS_H
diff --git a/indra/newview/llfloaterpreference.cpp b/indra/newview/llfloaterpreference.cpp
index 7ef81258967..2c383f09ba9 100755
--- a/indra/newview/llfloaterpreference.cpp
+++ b/indra/newview/llfloaterpreference.cpp
@@ -35,7 +35,7 @@
 #include "llfloaterpreference.h"
 
 #include "message.h"
-#include "llautoreplacefloater.h"
+#include "llfloaterautoreplacesettings.h"
 #include "llagent.h"
 #include "llavatarconstants.h"
 #include "llcheckboxctrl.h"
@@ -346,7 +346,7 @@ LLFloaterPreference::LLFloaterPreference(const LLSD& key)
 	mCommitCallbackRegistrar.add("Pref.BlockList",				boost::bind(&LLFloaterPreference::onClickBlockList, this));
 	mCommitCallbackRegistrar.add("Pref.Proxy",					boost::bind(&LLFloaterPreference::onClickProxySettings, this));
 	mCommitCallbackRegistrar.add("Pref.TranslationSettings",	boost::bind(&LLFloaterPreference::onClickTranslationSettings, this));
-	mCommitCallbackRegistrar.add("Pref.AutoReplace.",           boost::bind(&AutoReplaceFloater::showFloater, this));
+	mCommitCallbackRegistrar.add("Pref.AutoReplace",            boost::bind(&LLFloaterPreference::onClickAutoReplace, this));
 
 	sSkin = gSavedSettings.getString("SkinCurrent");
 
@@ -605,6 +605,9 @@ void LLFloaterPreference::cancel()
 	// hide translation settings floater
 	LLFloaterReg::hideInstance("prefs_translation");
 	
+	// hide translation settings floater
+	LLFloaterReg::hideInstance("prefs_autoreplace");
+	
 	// cancel hardware menu
 	LLFloaterHardwareSettings* hardware_settings = LLFloaterReg::getTypedInstance<LLFloaterHardwareSettings>("prefs_hardware_settings");
 	if (hardware_settings)
@@ -1516,6 +1519,11 @@ void LLFloaterPreference::onClickTranslationSettings()
 	LLFloaterReg::showInstance("prefs_translation");
 }
 
+void LLFloaterPreference::onClickAutoReplace()
+{
+	LLFloaterReg::showInstance("prefs_autoreplace");
+}
+
 void LLFloaterPreference::onClickActionChange()
 {
 	mClickActionDirty = true;
diff --git a/indra/newview/llfloaterpreference.h b/indra/newview/llfloaterpreference.h
index ec5994e9175..0b630023452 100644
--- a/indra/newview/llfloaterpreference.h
+++ b/indra/newview/llfloaterpreference.h
@@ -157,6 +157,7 @@ class LLFloaterPreference : public LLFloater, public LLAvatarPropertiesObserver
 	void onClickBlockList();
 	void onClickProxySettings();
 	void onClickTranslationSettings();
+	void onClickAutoReplace();
 	void applyUIColor(LLUICtrl* ctrl, const LLSD& param);
 	void getUIColor(LLUICtrl* ctrl, const LLSD& param);
 	
diff --git a/indra/newview/llviewerfloaterreg.cpp b/indra/newview/llviewerfloaterreg.cpp
index b2480a18051..d66f742a70d 100644
--- a/indra/newview/llviewerfloaterreg.cpp
+++ b/indra/newview/llviewerfloaterreg.cpp
@@ -30,7 +30,7 @@
 #include "llfloaterreg.h"
 
 #include "llviewerfloaterreg.h"
-#include "llautoreplacefloater.h"
+#include "llfloaterautoreplacesettings.h"
 #include "llcompilequeue.h"
 #include "llcallfloater.h"
 #include "llfasttimerview.h"
@@ -170,7 +170,6 @@ void LLViewerFloaterReg::registerFloaters()
 	LLFloaterReg::add("about_land", "floater_about_land.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterLand>);
 	LLFloaterReg::add("appearance", "floater_my_appearance.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterSidePanelContainer>);
 	LLFloaterReg::add("auction", "floater_auction.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterAuction>);
-	LLFloaterReg::add("settings_autoreplace", "floater_autoreplace.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<AutoReplaceFloater>);
 	LLFloaterReg::add("avatar", "floater_avatar.xml",  (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterAvatar>);
 	LLFloaterReg::add("avatar_picker", "floater_avatar_picker.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterAvatarPicker>);
 	LLFloaterReg::add("avatar_textures", "floater_avatar_textures.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterAvatarTextures>);
@@ -250,6 +249,7 @@ void LLViewerFloaterReg::registerFloaters()
 	LLFloaterReg::add("prefs_proxy", "floater_preferences_proxy.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterPreferenceProxy>);
 	LLFloaterReg::add("prefs_hardware_settings", "floater_hardware_settings.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterHardwareSettings>);
 	LLFloaterReg::add("prefs_translation", "floater_translation_settings.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterTranslationSettings>);
+	LLFloaterReg::add("prefs_autoreplace", "floater_autoreplace.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterAutoReplaceSettings>);
 	LLFloaterReg::add("perm_prefs", "floater_perm_prefs.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterPerms>);
 	LLFloaterReg::add("picks", "floater_picks.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterSidePanelContainer>);
 	LLFloaterReg::add("pref_joystick", "floater_joystick.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterJoystick>);
diff --git a/indra/newview/skins/default/xui/en/floater_autoreplace.xml b/indra/newview/skins/default/xui/en/floater_autoreplace.xml
index f68aeacb974..17f64c14337 100644
--- a/indra/newview/skins/default/xui/en/floater_autoreplace.xml
+++ b/indra/newview/skins/default/xui/en/floater_autoreplace.xml
@@ -96,7 +96,7 @@
   <scroll_list
    top_delta="0"
    left_delta="199"
-   height="180"
+   height="230"
    width="198"
    follows="left|top"
    column_padding="0"
@@ -128,7 +128,7 @@
   </text>
   <check_box
    bottom_delta="20"
-   left_delta="-32"
+   left_delta="0"
    height="16"
    width="100"
    enabled="true"
diff --git a/indra/newview/skins/default/xui/en/panel_preferences_chat.xml b/indra/newview/skins/default/xui/en/panel_preferences_chat.xml
index 33a9a8e6322..727d1794208 100644
--- a/indra/newview/skins/default/xui/en/panel_preferences_chat.xml
+++ b/indra/newview/skins/default/xui/en/panel_preferences_chat.xml
@@ -223,7 +223,7 @@
    top_pad="-23"
    left_pad="5"
    name="ac_showgui"
-   commit_callback.function="Pref.AutoReplace
+   commit_callback.function="Pref.AutoReplace"
    label="AutoReplace Settings"
    width="150">
   </button>
-- 
GitLab