From 366a7f2325d4e1fedcea47a4de0c1f00cf89e74c Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Sat, 14 Jan 2023 18:57:36 -0500
Subject: [PATCH] Add double click wear/attach in inventory Fix middle mouse
 control scaling from FS

---
 .../newview/app_settings/settings_alchemy.xml | 22 ++++++++++++
 indra/newview/llinventorybridge.cpp           | 34 +++++++++++++++---
 indra/newview/lltoolcomp.cpp                  | 12 +++++++
 indra/newview/lltoolcomp.h                    |  3 ++
 .../xui/en/panel_preferences_interface.xml    | 35 ++++++++++++++++++-
 5 files changed, 101 insertions(+), 5 deletions(-)

diff --git a/indra/newview/app_settings/settings_alchemy.xml b/indra/newview/app_settings/settings_alchemy.xml
index 92baa20706e..a69201150c1 100644
--- a/indra/newview/app_settings/settings_alchemy.xml
+++ b/indra/newview/app_settings/settings_alchemy.xml
@@ -904,6 +904,28 @@
       <key>Value</key>
       <string />
     </map>
+    <key>DoubleClickAttachmentAdd</key>
+    <map>
+      <key>Comment</key>
+      <string>Double-clicking an attachment in inventory will add wear it rather than replace wear it</string>
+      <key>Persist</key>
+      <integer>1</integer>
+      <key>Type</key>
+      <string>Boolean</string>
+      <key>Value</key>
+      <boolean>1</boolean>
+    </map>
+    <key>DoubleClickWearableAdd</key>
+    <map>
+      <key>Comment</key>
+      <string>Double-clicking a clothing wearable in inventory will add wear it rather than replace wear it</string>
+      <key>Persist</key>
+      <integer>1</integer>
+      <key>Type</key>
+      <string>Boolean</string>
+      <key>Value</key>
+      <boolean>1</boolean>
+    </map>
     <key>GroupSnoozeTime</key>
     <map>
       <key>Comment</key>
diff --git a/indra/newview/llinventorybridge.cpp b/indra/newview/llinventorybridge.cpp
index dfab29e470a..efa459bdd5e 100644
--- a/indra/newview/llinventorybridge.cpp
+++ b/indra/newview/llinventorybridge.cpp
@@ -6829,8 +6829,16 @@ void LLObjectBridge::performAction(LLInventoryModel* model, std::string action)
 void LLObjectBridge::openItem()
 {
 	// object double-click action is to wear/unwear object
-	performAction(getInventoryModel(),
-		      get_is_item_worn(mUUID) ? "detach" : "attach");
+// [SL:KB] - Patch: Inventory-MultiAttach | Checked: 2011-10-04 (Catznip-3.0)
+	MASK mask = gKeyboard->currentMask(TRUE);
+	bool fCtrlDown = (MASK_CONTROL == mask);
+	bool fOpenAdd = gSavedSettings.getBOOL("DoubleClickAttachmentAdd");
+
+	const char* pstrAction = get_is_item_worn(mUUID) ? "detach" : ((fCtrlDown ^ fOpenAdd) ? "wear_add" : "attach");
+	performAction(getInventoryModel(), pstrAction);
+// [/SL:KB]
+//	performAction(getInventoryModel(),
+//		      get_is_item_worn(mUUID) ? "detach" : "attach");
 }
 
 std::string LLObjectBridge::getLabelSuffix() const
@@ -7211,8 +7219,26 @@ void LLWearableBridge::performAction(LLInventoryModel* model, std::string action
 
 void LLWearableBridge::openItem()
 {
-	performAction(getInventoryModel(),
-			      get_is_item_worn(mUUID) ? "take_off" : "wear");
+	LLViewerInventoryItem* item = getItem();
+
+// [SL:KB] - Patch: Inventory-MultiWear | Checked: 2011-10-04 (Catznip-3.0)
+	if ( (item) && (item->isWearableType()) )
+	{
+		// Wearable double-click action should match attachment double-click action (=wear/unwear but don't attempt to unwear body parts)
+		bool fIsWorn = get_is_item_worn(mUUID);
+		if ( (!fIsWorn) || (LLAssetType::AT_BODYPART != item->getType()) )
+		{
+			MASK mask = gKeyboard->currentMask(TRUE); 
+			bool fCtrlDown = (MASK_CONTROL == mask);
+			bool fOpenAdd = gSavedSettings.getBOOL("DoubleClickWearableAdd");
+
+			const char* pstrAction = (fIsWorn) ? "take_off" : ((fCtrlDown ^ fOpenAdd) && (LLAssetType::AT_BODYPART != item->getType())) ? "wear_add" : "wear";
+			performAction(getInventoryModel(), pstrAction);
+		}
+	}
+// [/SL:KB]
+//	performAction(getInventoryModel(),
+//			      get_is_item_worn(mUUID) ? "take_off" : "wear");
 }
 
 void LLWearableBridge::buildContextMenu(LLMenuGL& menu, U32 flags)
diff --git a/indra/newview/lltoolcomp.cpp b/indra/newview/lltoolcomp.cpp
index 6bb55d584f5..1fb97948cab 100644
--- a/indra/newview/lltoolcomp.cpp
+++ b/indra/newview/lltoolcomp.cpp
@@ -485,6 +485,18 @@ void LLToolCompScale::render()
 	}
 }
 
+BOOL LLToolCompScale::handleMiddleMouseDown(S32 x, S32 y, MASK mask)
+{
+	LLToolCompScale::getInstance()->mManip->handleMiddleMouseDown(x,y,mask);
+	return handleMouseDown(x,y,mask);
+}
+
+BOOL LLToolCompScale::handleMiddleMouseUp(S32 x, S32 y, MASK mask)
+{
+	LLToolCompScale::getInstance()->mManip->handleMiddleMouseUp(x,y,mask);
+	return handleMouseUp(x,y,mask);
+}
+
 //-----------------------------------------------------------------------
 // LLToolCompCreate
 
diff --git a/indra/newview/lltoolcomp.h b/indra/newview/lltoolcomp.h
index 37c65412b4a..178d48e2aa0 100644
--- a/indra/newview/lltoolcomp.h
+++ b/indra/newview/lltoolcomp.h
@@ -164,6 +164,9 @@ class LLToolCompScale final : public LLToolComposite, public LLSingleton<LLToolC
 	virtual LLTool*		getOverrideTool(MASK mask) override;
 	
 	static void pickCallback(const LLPickInfo& pick_info);
+
+	virtual BOOL		handleMiddleMouseDown(S32 x, S32 y, MASK mask) override;
+	virtual BOOL		handleMiddleMouseUp(S32 x, S32 y, MASK mask) override;
 };
 
 
diff --git a/indra/newview/skins/default/xui/en/panel_preferences_interface.xml b/indra/newview/skins/default/xui/en/panel_preferences_interface.xml
index e2b7a386fea..71702a00270 100644
--- a/indra/newview/skins/default/xui/en/panel_preferences_interface.xml
+++ b/indra/newview/skins/default/xui/en/panel_preferences_interface.xml
@@ -112,9 +112,42 @@
     layout="topleft"
     left="45"
     name="HideHoverTextInCinematicMode"
-    top_delta="20"
+    top_pad="7"
     width="256">
     <check_box.commit_callback
       function="Pref.RenderOptionUpdate" />
   </check_box>
+  <text
+     type="string"
+     length="1"
+     follows="left|top"
+     height="10"
+     layout="topleft"
+     left="30"
+     name="InventoryText"
+     mouse_opaque="false"
+     top_pad="7"
+     width="300">
+    Inventory:
+  </text>
+  <check_box
+    control_name="DoubleClickAttachmentAdd"
+    height="16"
+    initial_value="true"
+    label="Double-click to add Attachments"
+    layout="topleft"
+    left="45"
+    name="DoubleClickAttachmentAddCheck"
+    top_pad="7"
+    width="256"/>
+  <check_box
+    control_name="DoubleClickWearableAdd"
+    height="16"
+    initial_value="true"
+    label="Double-click to add Wearables"
+    layout="topleft"
+    left="45"
+    name="DoubleClickWearableAddCheck"
+    top_pad="5"
+    width="256"/>
 </panel>
-- 
GitLab