From 7816dfd5ac8ebb92f66c738d7f0ed61bbf7c0282 Mon Sep 17 00:00:00 2001
From: Merov Linden <merov@lindenlab.com>
Date: Fri, 15 May 2015 20:10:45 -0700
Subject: [PATCH] DD-403: Make the sort order persistent in marketplace
 listings floater

---
 indra/newview/app_settings/settings.xml       | 11 ++++++
 .../newview/llfloatermarketplacelistings.cpp  | 37 ++++++++++++-------
 indra/newview/llfloatermarketplacelistings.h  |  2 +
 3 files changed, 36 insertions(+), 14 deletions(-)

diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml
index 1b53a06a851..778020a92ec 100755
--- a/indra/newview/app_settings/settings.xml
+++ b/indra/newview/app_settings/settings.xml
@@ -4790,6 +4790,17 @@
       <key>Value</key>
       <integer>7</integer>
     </map>
+    <key>MarketplaceListingsSortOrder</key>
+    <map>
+      <key>Comment</key>
+      <string>Specifies sort for marketplace listings</string>
+      <key>Persist</key>
+      <integer>1</integer>
+      <key>Type</key>
+      <string>U32</string>
+      <key>Value</key>
+      <integer>2</integer>
+    </map>
     <key>InvertMouse</key>
     <map>
       <key>Comment</key>
diff --git a/indra/newview/llfloatermarketplacelistings.cpp b/indra/newview/llfloatermarketplacelistings.cpp
index eb7601f67e1..b2d36479cd0 100755
--- a/indra/newview/llfloatermarketplacelistings.cpp
+++ b/indra/newview/llfloatermarketplacelistings.cpp
@@ -118,6 +118,9 @@ void LLPanelMarketplaceListings::buildAllPanels()
 	tabs_panel->setCommitCallback(boost::bind(&LLPanelMarketplaceListings::onTabChange, this));
     tabs_panel->selectTabPanel(panel_all_items);      // All panel selected by default
     mRootFolder = panel_all_items->getRootFolder();   // Keep the root of the all panel
+    
+    // Set the default sort order
+    setSortOrder(gSavedSettings.getU32("MarketplaceListingsSortOrder"));
 }
 
 LLInventoryPanel* LLPanelMarketplaceListings::buildInventoryPanel(const std::string& childname, const std::string& filename)
@@ -134,6 +137,23 @@ LLInventoryPanel* LLPanelMarketplaceListings::buildInventoryPanel(const std::str
     return panel;
 }
 
+void LLPanelMarketplaceListings::setSortOrder(U32 sort_order)
+{
+    mSortOrder = sort_order;
+    gSavedSettings.setU32("MarketplaceListingsSortOrder", sort_order);
+    
+    // Set each panel with that sort order
+    LLTabContainer* tabs_panel = getChild<LLTabContainer>("marketplace_filter_tabs");
+    LLInventoryPanel* panel = (LLInventoryPanel*)tabs_panel->getPanelByName("All Items");
+    panel->setSortOrder(mSortOrder);
+    panel = (LLInventoryPanel*)tabs_panel->getPanelByName("Active Items");
+    panel->setSortOrder(mSortOrder);
+    panel = (LLInventoryPanel*)tabs_panel->getPanelByName("Inactive Items");
+    panel->setSortOrder(mSortOrder);
+    panel = (LLInventoryPanel*)tabs_panel->getPanelByName("Unassociated Items");
+    panel->setSortOrder(mSortOrder);
+}
+
 void LLPanelMarketplaceListings::onFilterEdit(const std::string& search_string)
 {
 	// Find active panel
@@ -234,27 +254,16 @@ void LLPanelMarketplaceListings::onViewSortMenuItemClicked(const LLSD& userdata)
         // We're making sort options exclusive, default is SO_FOLDERS_BY_NAME
         if (chosen_item == "sort_by_stock_amount")
         {
-            mSortOrder = LLInventoryFilter::SO_FOLDERS_BY_WEIGHT;
+            setSortOrder(LLInventoryFilter::SO_FOLDERS_BY_WEIGHT);
         }
         else if (chosen_item == "sort_by_name")
         {
-            mSortOrder = LLInventoryFilter::SO_FOLDERS_BY_NAME;
+            setSortOrder(LLInventoryFilter::SO_FOLDERS_BY_NAME);
         }
         else if (chosen_item == "sort_by_recent")
         {
-            mSortOrder = LLInventoryFilter::SO_DATE;
+            setSortOrder(LLInventoryFilter::SO_DATE);
         }
-        //mSortOrder = (mSortOrder == LLInventoryFilter::SO_FOLDERS_BY_NAME ? LLInventoryFilter::SO_FOLDERS_BY_WEIGHT : LLInventoryFilter::SO_FOLDERS_BY_NAME);
-        // Set each panel with that sort order
-        LLTabContainer* tabs_panel = getChild<LLTabContainer>("marketplace_filter_tabs");
-        LLInventoryPanel* panel = (LLInventoryPanel*)tabs_panel->getPanelByName("All Items");
-        panel->setSortOrder(mSortOrder);
-        panel = (LLInventoryPanel*)tabs_panel->getPanelByName("Active Items");
-        panel->setSortOrder(mSortOrder);
-        panel = (LLInventoryPanel*)tabs_panel->getPanelByName("Inactive Items");
-        panel->setSortOrder(mSortOrder);
-        panel = (LLInventoryPanel*)tabs_panel->getPanelByName("Unassociated Items");
-        panel->setSortOrder(mSortOrder);
 	}
     // Filter option
     else if (chosen_item == "show_only_listing_folders")
diff --git a/indra/newview/llfloatermarketplacelistings.h b/indra/newview/llfloatermarketplacelistings.h
index 9fad31c4560..ffc098e28a2 100755
--- a/indra/newview/llfloatermarketplacelistings.h
+++ b/indra/newview/llfloatermarketplacelistings.h
@@ -75,6 +75,8 @@ class LLPanelMarketplaceListings : public LLPanel
     void onTabChange();
     void onFilterEdit(const std::string& search_string);
     
+    void setSortOrder(U32 sort_order);
+    
     LLFolderView*     mRootFolder;
     LLButton*         mAuditBtn;
 	LLFilterEditor*	  mFilterEditor;
-- 
GitLab