diff --git a/indra/llui/lltabcontainer.cpp b/indra/llui/lltabcontainer.cpp
index b423de77c990beb392032cfc699011ef98f78590..024444e1c963ae158d038885a17582e080760e64 100644
--- a/indra/llui/lltabcontainer.cpp
+++ b/indra/llui/lltabcontainer.cpp
@@ -1517,25 +1517,23 @@ BOOL LLTabContainer::selectTab(S32 which)
 
 	LLTabTuple* selected_tuple = getTab(which);
 	if (!selected_tuple)
-	{
 		return FALSE;
-	}
-	
+
 	LLSD cbdata;
 	if (selected_tuple->mTabPanel)
 		cbdata = selected_tuple->mTabPanel->getName();
 
-	BOOL res = FALSE;
-	if( !mValidateSignal || (*mValidateSignal)( this, cbdata ) )
+	BOOL result = FALSE;
+	if (!mValidateSignal || (*mValidateSignal)(this, cbdata))
 	{
-		res = setTab(which);
-		if (res && mCommitSignal)
+		result = setTab(which);
+		if (result && mCommitSignal)
 		{
 			(*mCommitSignal)(this, cbdata);
 		}
 	}
-	
-	return res;
+
+	return result;
 }
 
 // private
diff --git a/indra/newview/llinventorybridge.cpp b/indra/newview/llinventorybridge.cpp
index 385a2569a5a844d640d9d394130af081438f4a64..661db13baa33551534139617965200ca60d7d3c5 100644
--- a/indra/newview/llinventorybridge.cpp
+++ b/indra/newview/llinventorybridge.cpp
@@ -1765,7 +1765,7 @@ void LLItemBridge::performAction(LLInventoryModel* model, std::string action)
 	}
 	else if ("show_in_main_panel" == action)
 	{
-		LLInventoryPanel::openInventoryPanelAndSetSelection(TRUE, mUUID, TRUE);
+		LLInventoryPanel::openInventoryPanelAndSetSelection(true, mUUID, true);
 		return;
 	}
 	else if ("cut" == action)
@@ -3396,7 +3396,7 @@ void LLFolderBridge::performAction(LLInventoryModel* model, std::string action)
 	}
 	else if ("show_in_main_panel" == action)
 	{
-		LLInventoryPanel::openInventoryPanelAndSetSelection(TRUE, mUUID, TRUE);
+		LLInventoryPanel::openInventoryPanelAndSetSelection(true, mUUID, true);
 		return;
 	}
 	else if ("cut" == action)
diff --git a/indra/newview/llinventorypanel.cpp b/indra/newview/llinventorypanel.cpp
index 54f91451acf5ed39a2af39e5f906b741913ffbc0..a7d39b1ef6a4be6c7602f0dd42fd5b946d4e6577 100644
--- a/indra/newview/llinventorypanel.cpp
+++ b/indra/newview/llinventorypanel.cpp
@@ -1922,46 +1922,52 @@ LLInventoryPanel* LLInventoryPanel::getActiveInventoryPanel(BOOL auto_open)
 }
 
 //static
-void LLInventoryPanel::openInventoryPanelAndSetSelection(BOOL auto_open, const LLUUID& obj_id, BOOL use_main_panel, BOOL take_keyboard_focus, BOOL reset_filter)
+void LLInventoryPanel::openInventoryPanelAndSetSelection(bool auto_open, const LLUUID& obj_id,
+	bool use_main_panel, bool take_keyboard_focus, bool reset_filter)
 {
 	LLSidepanelInventory* sidepanel_inventory = LLFloaterSidePanelContainer::getPanel<LLSidepanelInventory>("inventory");
 	sidepanel_inventory->showInventoryPanel();
 
-	bool in_inbox = (gInventory.isObjectDescendentOf(obj_id, gInventory.findCategoryUUIDForType(LLFolderType::FT_INBOX)));
-
-	if (!in_inbox && (use_main_panel || !sidepanel_inventory->getMainInventoryPanel()->isRecentItemsPanelSelected()))
+	LLUUID cat_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_INBOX);
+	bool in_inbox = gInventory.isObjectDescendentOf(obj_id, cat_id);
+	if (!in_inbox && use_main_panel)
 	{
 		sidepanel_inventory->selectAllItemsPanel();
 	}
 
-    LLFloater* inventory_floater = LLFloaterSidePanelContainer::getTopmostInventoryFloater();
-    if(!auto_open && inventory_floater && inventory_floater->getVisible())
+    if (!auto_open)
     {
-        LLSidepanelInventory *inventory_panel = inventory_floater->findChild<LLSidepanelInventory>("main_panel");
-        LLPanelMainInventory* main_panel = inventory_panel->getMainInventoryPanel();
-        if(main_panel->isSingleFolderMode() && main_panel->isGalleryViewMode())
+        LLFloater* inventory_floater = LLFloaterSidePanelContainer::getTopmostInventoryFloater();
+        if (inventory_floater && inventory_floater->getVisible())
         {
-            LL_DEBUGS("Inventory") << "Opening gallery panel for item" << obj_id << LL_ENDL;
-            main_panel->setGallerySelection(obj_id);
-            return;
+            LLSidepanelInventory *inventory_panel = inventory_floater->findChild<LLSidepanelInventory>("main_panel");
+            LLPanelMainInventory* main_panel = inventory_panel->getMainInventoryPanel();
+            if (main_panel->isSingleFolderMode() && main_panel->isGalleryViewMode())
+            {
+                LL_DEBUGS("Inventory") << "Opening gallery panel for item" << obj_id << LL_ENDL;
+                main_panel->setGallerySelection(obj_id);
+                return;
+            }
         }
     }
 
-    LLPanelMainInventory* main_inventory = sidepanel_inventory->getMainInventoryPanel();
-    if (main_inventory && main_inventory->isSingleFolderMode()
-        && use_main_panel)
+    if (use_main_panel)
     {
-        const LLInventoryObject *obj = gInventory.getObject(obj_id);
-        if (obj)
+        LLPanelMainInventory* main_inventory = sidepanel_inventory->getMainInventoryPanel();
+        if (main_inventory && main_inventory->isSingleFolderMode())
         {
-            LL_DEBUGS("Inventory") << "Opening main inventory panel for item" << obj_id << LL_ENDL;
-            main_inventory->setSingleFolderViewRoot(obj->getParentUUID(), false);
-            main_inventory->setGallerySelection(obj_id);
-            return;
+            const LLInventoryObject *obj = gInventory.getObject(obj_id);
+            if (obj)
+            {
+                LL_DEBUGS("Inventory") << "Opening main inventory panel for item" << obj_id << LL_ENDL;
+                main_inventory->setSingleFolderViewRoot(obj->getParentUUID(), false);
+                main_inventory->setGallerySelection(obj_id);
+                return;
+            }
         }
     }
-	LLInventoryPanel *active_panel = LLInventoryPanel::getActiveInventoryPanel(auto_open);
 
+	LLInventoryPanel *active_panel = LLInventoryPanel::getActiveInventoryPanel(auto_open);
 	if (active_panel)
 	{
 		LL_DEBUGS("Messaging", "Inventory") << "Highlighting" << obj_id  << LL_ENDL;
@@ -1973,11 +1979,8 @@ void LLInventoryPanel::openInventoryPanelAndSetSelection(BOOL auto_open, const L
 
 		if (in_inbox)
 		{
-			
-			LLInventoryPanel * inventory_panel = NULL;
 			sidepanel_inventory->openInbox();
-			inventory_panel = sidepanel_inventory->getInboxPanel();
-
+			LLInventoryPanel* inventory_panel = sidepanel_inventory->getInboxPanel();
 			if (inventory_panel)
 			{
 				inventory_panel->setSelection(obj_id, take_keyboard_focus);
@@ -2002,7 +2005,6 @@ void LLInventoryPanel::openInventoryPanelAndSetSelection(BOOL auto_open, const L
 
 void LLInventoryPanel::setSFViewAndOpenFolder(const LLInventoryPanel* panel, const LLUUID& folder_id)
 {
-
     LLFloaterReg::const_instance_list_t& inst_list = LLFloaterReg::getFloaterList("inventory");
     for (LLFloaterReg::const_instance_list_t::const_iterator iter = inst_list.begin(); iter != inst_list.end(); ++iter)
     {
diff --git a/indra/newview/llinventorypanel.h b/indra/newview/llinventorypanel.h
index 341be0cf86f59dbf0d946fc89c07674b76f909d9..2c35bdcd11a1deddb4be58dec49855184aa50ca0 100644
--- a/indra/newview/llinventorypanel.h
+++ b/indra/newview/llinventorypanel.h
@@ -244,12 +244,12 @@ class LLInventoryPanel : public LLPanel
 	// "Auto_open" determines if we open an inventory panel if none are open.
 	static LLInventoryPanel *getActiveInventoryPanel(BOOL auto_open = TRUE);
 
-	static void openInventoryPanelAndSetSelection(BOOL auto_open,
+	static void openInventoryPanelAndSetSelection(bool auto_open,
 													const LLUUID& obj_id,
-													BOOL use_main_panel = FALSE,
-													BOOL take_keyboard_focus = TAKE_FOCUS_YES,
-													BOOL reset_filter = FALSE);
-    static void setSFViewAndOpenFolder(const LLInventoryPanel* panel, const LLUUID& folder_id);
+													bool use_main_panel = false,
+													bool take_keyboard_focus = true,
+													bool reset_filter = false);
+	static void setSFViewAndOpenFolder(const LLInventoryPanel* panel, const LLUUID& folder_id);
 	void addItemID(const LLUUID& id, LLFolderViewItem* itemp);
 	void removeItemID(const LLUUID& id);
 	LLFolderViewItem* getItemByID(const LLUUID& id);
diff --git a/indra/newview/llmeshrepository.cpp b/indra/newview/llmeshrepository.cpp
index d6eba6b4bf2a27e447c1cce933ac4b8264ce0922..549962ea865be84588d279d1b3e433df79a72d6c 100644
--- a/indra/newview/llmeshrepository.cpp
+++ b/indra/newview/llmeshrepository.cpp
@@ -5446,7 +5446,7 @@ void on_new_single_inventory_upload_complete(
         }
         else
         {
-            LLInventoryPanel::openInventoryPanelAndSetSelection(TRUE, server_response["new_inventory_item"].asUUID(), TRUE, TAKE_FOCUS_NO, TRUE);
+            LLInventoryPanel::openInventoryPanelAndSetSelection(true, server_response["new_inventory_item"].asUUID(), true, false, true);
         }
 
         // restore keyboard focus
diff --git a/indra/newview/llviewerassetupload.cpp b/indra/newview/llviewerassetupload.cpp
index 13491114b9b6ee0a802ba2a72ead69eaecbdb35b..036cef5c9437263d226d6b4b4ab075d04907fc18 100644
--- a/indra/newview/llviewerassetupload.cpp
+++ b/indra/newview/llviewerassetupload.cpp
@@ -847,7 +847,7 @@ void LLViewerAssetUpload::AssetInventoryUploadCoproc(LLCoreHttpUtil::HttpCorouti
             // Show the preview panel for textures and sounds to let
             // user know that the image (or snapshot) arrived intact.
             LLInventoryPanel* panel = LLInventoryPanel::getActiveInventoryPanel(FALSE);
-            LLInventoryPanel::openInventoryPanelAndSetSelection(TRUE, serverInventoryItem, FALSE, TAKE_FOCUS_NO, (panel == NULL));
+            LLInventoryPanel::openInventoryPanelAndSetSelection(true, serverInventoryItem, false, false, !panel);
 
             // restore keyboard focus
             gFocusMgr.setKeyboardFocus(focus);
diff --git a/indra/newview/llviewermessage.cpp b/indra/newview/llviewermessage.cpp
index bca7fbac339c7ecd863eb0f73555b7e982a0edee..17b56c9d1d7d3939caf6abc21f0c3cd8ff24bae6 100644
--- a/indra/newview/llviewermessage.cpp
+++ b/indra/newview/llviewermessage.cpp
@@ -1557,15 +1557,22 @@ void open_inventory_offer(const uuid_vec_t& objects, const std::string& from_nam
         }
         else
         {
-		// Highlight item
-		const BOOL auto_open = 
-			gSavedSettings.getBOOL("ShowInInventory") && // don't open if showininventory is false
-			!from_name.empty(); // don't open if it's not from anyone.
-            if(auto_open)
+            // Highlight item
+            bool show_in_inventory = gSavedSettings.get<bool>("ShowInInventory");
+            bool auto_open =
+                show_in_inventory && // don't open if ShowInInventory is FALSE
+                !from_name.empty();  // don't open if it's not from anyone
+
+            // SL-20419 : Don't change active tab if floater is visible
+            LLFloater* instance = LLFloaterReg::findInstance("inventory");
+            bool use_main_panel = instance && instance->getVisible();
+
+            if (auto_open)
             {
                 LLFloaterReg::showInstance("inventory");
             }
-		LLInventoryPanel::openInventoryPanelAndSetSelection(auto_open, obj_id, true);
+
+            LLInventoryPanel::openInventoryPanelAndSetSelection(auto_open, obj_id, use_main_panel);
         }
 	}
 }
diff --git a/indra/newview/llwearableitemslist.cpp b/indra/newview/llwearableitemslist.cpp
index 83d2b16a860ae17330517bc143afbb9583fe4a88..948fe55e0dfd8ab2ba7ca109b82b9b8867a3f5ab 100644
--- a/indra/newview/llwearableitemslist.cpp
+++ b/indra/newview/llwearableitemslist.cpp
@@ -797,7 +797,7 @@ void LLWearableItemsList::updateChangedItems(const uuid_vec_t& changed_items_uui
 		if (!inv_item)
 			continue;
 
-		LLUUID linked_uuid = inv_item->getLinkedUUID();
+        const LLUUID& linked_uuid = inv_item->getLinkedUUID();
         if (std::find(uuids_begin, uuids_end, linked_uuid) != uuids_end)
         {
             item->setNeedsRefresh(true);