Quantcast

- Further updates to Repair

urnati [12-01-22 - 13:21]
- Further updates to Repair
- Config - added notes and change log to About; added notes to Plugins > <each plugin>
Filename
Titan/TitanConfig.lua
Titan/TitanUtils.lua
TitanRepair/TitanRepair.lua
diff --git a/Titan/TitanConfig.lua b/Titan/TitanConfig.lua
index 3e709d5..3ce5664 100644
--- a/Titan/TitanConfig.lua
+++ b/Titan/TitanConfig.lua
@@ -18,6 +18,40 @@ local TitanSkinToRemove = "None";
 local TitanSkinName, TitanSkinPath = "", "";
 local TitanGlobalProfile = ""

+--[[
+Use for notes and change log in game.
+New Release Format
+Gold - version & date
+Green - 'header'
+Highlight - notes. tips. and details
+
+--]]
+local notes = ""
+	..TitanUtils_GetRedText("NOTE : ")
+	..TitanUtils_GetNormalText(""
+		.." There have been many comments about errors including tool tips. The short answer is Blizzard tainted the path used by TitanRepair and bags. They both use tool tips - don't ask, I have no answer!\n"
+		.."My thought is TitanRepair and Blizzard using similar routines doing their normal processing can cause the errors being seen.\n"
+		.."I have seen odd tool tip behavior with a pet in a cage - and Titan NOT enabled. The pet tool tip forces itself onto the screen at odd times... Even when one has not moused over the cage.\n"
+		.."If someone more knowledgeable has tips to work around this - feel free to contact us!\n"
+		)
+	.."\n"
+	..TitanUtils_GetRedText("NOTE : ")
+	..TitanUtils_GetNormalText(""
+		.."Due to the UI changes in DragonFlight (API 100000), Titan Panel no longer auto adjusts the UI elements / frames. Please use the WoW UI edit mode to adjust frames away from Titan Panel bar(s).\n"
+		.."Currently the menu & bag frame and the status / xp frame are NOT adjustable via edit mode. In the Titan Configuration for Bottom Bars you may adjust the menu & bag frame and the status / xp frame *vertically only*.\n"
+		)
+local changes = ""
+	..TitanUtils_GetGoldText("6.00.08.100002  : 2020/12/01\n")
+	..TitanUtils_GetGreenText("TitanRepair rewritten - Notable changes: \n")
+	..TitanUtils_GetHighlightText(""
+		.."- See plugin notes.\n"
+		)
+	..TitanUtils_GetGreenText("TitanPanel\n")
+	..TitanUtils_GetHighlightText(""
+		.."- Added change log / notes in About config.\n"
+		.."- Added notes section to each plugin - Configuration > Plugins > <each plugin>.\n"
+		)
+
 TITAN_PANEL_CONFIG = {
 	topic = {
 		About			= L["TITAN_PANEL"],
@@ -105,7 +139,7 @@ local function TitanPanel_TicketReload()
 end

 -------------
--- skins config section
+-- about config section
 --[[ local
 NAME: optionsControl
 DESC: Local table to hold the 'about' Titan info in the options.
@@ -123,6 +157,7 @@ local optionsControl = {
 		},
 		confinfodesc = {
 			name = "About",
+			order = 5,
 			type = "group", inline = true,
 			args = {
 				confversiondesc = {
@@ -175,7 +210,35 @@ local optionsControl = {
 					cmdHidden = true
 				},
 			}
-		}
+		},
+		confnotes = {
+			name = "Notes",
+			order = 3,
+			type = "group", inline = true,
+			args = {
+				confversiondesc = {
+				order = 1,
+				type = "description",
+				name = ""
+					..notes,
+				cmdHidden = true
+				},
+			}
+		},
+		confchanges = {
+			order = 7,
+			name = CHANGES_COLON,
+			type = "group", inline = true,
+			args = {
+				confversiondesc = {
+				order = 1,
+				type = "description",
+				name = ""
+					..changes,
+				cmdHidden = true
+				},
+			}
+		},
 	}
 }
 -------------
@@ -1761,6 +1824,30 @@ local function TitanUpdateConfigAddons()
 					TitanPanelButton_UpdateButton(info[1])
 					end,
 			}
+			-- Notes, if available
+			args[plug_in.id].args.custom_notes = {
+				order = 70,
+				type = "header",
+				name = "Notes",
+			}
+			if plug_in.notes then
+				args[plug_in.id].args.notes = {
+					type = "description",
+					name = "Notes",
+					order = 71,
+				name = ""
+					.._G["GREEN_FONT_COLOR_CODE"]..plug_in.notes.."|r",
+				cmdHidden = true,
+				}
+			else
+				args[plug_in.id].args.notes = {
+					type = "description",
+					name = "Notes",
+					order = 71,
+				name = _G["GREEN_FONT_COLOR_CODE"]..NONE.."|r",
+				cmdHidden = true,
+				}
+			end
 		end
 	end

diff --git a/Titan/TitanUtils.lua b/Titan/TitanUtils.lua
index 70a4a5f..4525759 100644
--- a/Titan/TitanUtils.lua
+++ b/Titan/TitanUtils.lua
@@ -18,6 +18,7 @@ TITAN_PANEL_VARS.debug = {}
 TITAN_PANEL_VARS.debug.movable = false
 TITAN_PANEL_VARS.debug.events = false
 TITAN_PANEL_VARS.debug.ldb_setup = false
+TITAN_PANEL_VARS.debug.tool_tips = false

 local _G = getfenv(0);
 local L = LibStub("AceLocale-3.0"):GetLocale(TITAN_ID, true)
@@ -1039,7 +1040,7 @@ function TitanPanelRightClickMenu_AddControlVars(id, hide_text)
 	TitanPanelRightClickMenu_AddToggleRightSide(id, level)

 	TitanPanelRightClickMenu_AddSpacer();
-	TitanPanelRightClickMenu_AddCommand(L["TITAN_PANEL_MENU_HIDE"], TITAN_VOLUME_ID, TITAN_PANEL_MENU_FUNC_HIDE);
+	TitanPanelRightClickMenu_AddCommand(L["TITAN_PANEL_MENU_HIDE"], id, TITAN_PANEL_MENU_FUNC_HIDE);
 end


@@ -1721,10 +1722,12 @@ local function TitanRightClickMenu_OnLoad(self)
 			UIDropDownMenu_Initialize(self, prepareFunction, "MENU");
 		end
 	else
-		-- TitanDebug("Could not display tooltip. "
-		-- .."Could not determine Titan ID for "
-		-- .."'"..(self:GetName() or "?").."'. "
-		-- ,"error")
+		if TITAN_PANEL_VARS.debug.tool_tips then
+			TitanDebug("Could not display tooltip. "
+			.."Could not determine Titan ID for "
+			.."'"..(self:GetName() or "?").."'. "
+			,"error")
+		end
 	end
 end

@@ -2183,6 +2186,23 @@ function TitanArgConvert (event, a1, a2, a3, a4, a4, a5, a6)
 	)
 end

+function TitanDumpTable(tb, level)
+  level = level or 1
+  local spaces = string.rep(' ', level*2)
+  for k,v in pairs(tb) do
+    if type(v) ~= "table" then
+      print("["..level.."]v'"..spaces.."["..tostring(k).."]='"..tostring(v).."'")
+    else
+      print("["..level.."]t'"..spaces.."["..tostring(k).."]")
+     level = level + 1
+	 if level <= 8 then
+     TitanDumpTable(v, level)
+	 end
+    end
+  end
+end
+
+
 --------------------------------------------------------------
 --
 -- Deprecated routines
diff --git a/TitanRepair/TitanRepair.lua b/TitanRepair/TitanRepair.lua
index 5273c0c..34bfde9 100644
--- a/TitanRepair/TitanRepair.lua
+++ b/TitanRepair/TitanRepair.lua
@@ -1,58 +1,43 @@
+--[[
 -- **************************************************************************
 -- * TitanRepair.lua
 -- *
 -- * By: The Titan Panel Development Team
 -- **************************************************************************
+--]]

 -- ******************************** Constants *******************************
 local TITAN_REPAIR_ID = "Repair";
 local TITAN_BUTTON = "TitanPanel"..TITAN_REPAIR_ID.."Button"
+local TITAN_TOOLTIP = "Titan"..TITAN_REPAIR_ID.."Tooltip"
+local NYL = "nyl"

 local L = LibStub("AceLocale-3.0"):GetLocale("Titan", true)
-local TitanRepairModule = LibStub("AceAddon-3.0"):NewAddon("TitanRepair", "AceHook-3.0", "AceTimer-3.0")
+local TitanRepair = LibStub("AceAddon-3.0"):NewAddon(TITAN_REPAIR_ID, "AceHook-3.0", "AceTimer-3.0")
 local _G = getfenv(0);
-local TPR = TitanRepairModule
-TPR.ITEM_STATUS = {};
-TPR.ITEM_BAG = {};
-
--- this index (0) will never be set, just accessed to this state,
--- it simplifies code for TitanRepair_GetMostDamagedItem() when Tit_R_EquipedMinIndex == 0
-TPR.END=11
-TPR.ITEM_STATUS[0] = { values = {}, name = INVTYPE_HEAD, slot = "VIRTUAL" };
-TPR.ITEM_STATUS[1] = { values = {}, name = INVTYPE_HEAD, slot = "Head" };
-TPR.ITEM_STATUS[2] = { values = {}, name = INVTYPE_SHOULDER, slot = "Shoulder" };
-TPR.ITEM_STATUS[3] = { values = {}, name = INVTYPE_CHEST, slot = "Chest" };
-TPR.ITEM_STATUS[4] = { values = {}, name = INVTYPE_WAIST, slot = "Waist" };
-TPR.ITEM_STATUS[5] = { values = {}, name = INVTYPE_LEGS, slot = "Legs" };
-TPR.ITEM_STATUS[6] = { values = {}, name = INVTYPE_FEET, slot = "Feet" };
-TPR.ITEM_STATUS[7] = { values = {}, name = INVTYPE_WRIST, slot = "Wrist" };
-TPR.ITEM_STATUS[8] = { values = {}, name = INVTYPE_HAND, slot = "Hands" };
-TPR.ITEM_STATUS[9] = { values = {}, name = INVTYPE_WEAPONMAINHAND, slot = "MainHand" };
-TPR.ITEM_STATUS[10] = { values = {}, name = INVTYPE_WEAPONOFFHAND, slot = "SecondaryHand" };
---TPR.ITEM_STATUS[11] = { values = {}, name = INVTYPE_RANGED, slot = "Ranged" }; -- Ranged weapons are no longer available in WoW
-TPR.ITEM_STATUS[TPR.END] = { values = {}, name = INVENTORY_TOOLTIP };
-TPR.INVENTORY_STATUS = {}
-TPR.INVENTORY_STATUS[0] = { values = {}, name = INVENTORY_TOOLTIP };
-TPR.INVENTORY_STATUS[1] = { values = {}, name = INVENTORY_TOOLTIP };
-TPR.INVENTORY_STATUS[2] = { values = {}, name = INVENTORY_TOOLTIP };
-TPR.INVENTORY_STATUS[3] = { values = {}, name = INVENTORY_TOOLTIP };
-TPR.INVENTORY_STATUS[4] = { values = {}, name = INVENTORY_TOOLTIP };
-
--- ******************************** Variables *******************************
-TPR.INDEX = 0;
-TPR.MONEY = 0;
-TPR.WholeScanInProgress = false;
-TPR.EquipedMinIndex = 0; -- keep a record of the most damaged equiped item (used when removing the most damaged item placed in the inventory to switch on an equiped index)
-TPR.PleaseCheckBag = { };
-TPR.CouldRepair = false;
-TPR.MerchantisOpen = false;
-TPR.PleaseCheckBag[0] = 0; -- TPR.PleaseCheckBag element values meaning:
-TPR.PleaseCheckBag[1] = 0; --  0 means "This bag did not changed, no need to scan it"
-TPR.PleaseCheckBag[2] = 0; --  1 means "Please Check This Bag"
-TPR.PleaseCheckBag[3] = 0; --  2 means "Yes I'm checking, don't disturb me"
-TPR.PleaseCheckBag[4] = 0;
-TPR.PleaseCheckBag[5] = 0; -- this will be used for equiped items, not very good but simplify the code...
-TPR.show_debug = false; -- will tell you a lot about what's happening
+local TR = TitanRepair
+TR.ITEM_STATUS = {};
+TR.ITEM_BAG = {};
+
+-- locals
+local tool_tip = nil
+TR.repair_total = 0
+TR.dur_total = 0
+
+TR.repair_bags = {}
+TR.repair_equip = {}
+
+TR.money_total = 0
+TR.bag_list = {}
+TR.equip_list = {}
+TR.equip_most = nil
+TR.last_scan = GetTime() -- seconds with milliseconds - sec.milli
+TR.scan_time = 0
+TR.scan_running = false
+
+--debug
+TR.show_debug = false -- will tell you a lot about what's happening
+TR.show_debug_scan = false -- shows items processed during scan

 StaticPopupDialogs["REPAIR_CONFIRMATION"] = {
 	text = L["REPAIR_LOCALE"]["confirmation"],
@@ -63,10 +48,9 @@ StaticPopupDialogs["REPAIR_CONFIRMATION"] = {
 		TitanPanelRepairButton_ScanAllItems();
 		TitanRepairModule:CancelAllTimers()
 		TitanRepairModule:ScheduleTimer(TitanPanelRepairButton_OnUpdate, 2)
-		TPR.CouldRepair = false;
 	end,
 	OnShow = function(self)
-		MoneyFrame_Update(self.moneyFrame, TPR.MONEY);
+		MoneyFrame_Update(self.moneyFrame, TR.repair_total);
 	end,
 	hasMoneyFrame = 1,
 	timeout = 0,
@@ -75,738 +59,400 @@ StaticPopupDialogs["REPAIR_CONFIRMATION"] = {

 -- ******************************** Functions *******************************

+--[[ local
 -- **************************************************************************
--- NAME : TitanPanelRepairButton_OnLoad(self)
--- DESC : Registers the plugin upon it loading
+-- NAME : debug_msg(Message)
+-- DESC : Debug function to print message to chat frame
+-- VARS : Message = message to print to chat frame
 -- **************************************************************************
-function TitanPanelRepairButton_OnLoad(self)
-	self.registry = {
-		id = TITAN_REPAIR_ID,
-		category = "Built-ins",
-		version = TITAN_VERSION,
-		menuText = L["REPAIR_LOCALE"]["menu"],
-		buttonTextFunction = "TitanPanelRepairButton_GetButtonText",
-		tooltipTitle = L["REPAIR_LOCALE"]["tooltip"],
-		tooltipTextFunction = "TitanPanelRepairButton_GetTooltipText",
-		icon = "Interface\\AddOns\\TitanRepair\\TitanRepair",
-		iconWidth = 16,
-		controlVariables = {
-			ShowIcon = true,
-			ShowLabelText = true,
-			ShowColoredText = true,
-			DisplayOnRightSide = true,
-		},
-		savedVariables = {
-			ShowIcon = 1,
-			ShowLabelText = 1,
-			ShowMostDamaged = false,
-			ShowUndamaged = false,
-			ShowPopup = false,
-			ShowDurabilityFrame = 1,
-			AutoRepair = false,
-			DiscountFriendly = false,
-			DiscountHonored = false,
-			DiscountRevered = false,
-			DiscountExalted = false,
-			ShowPercentage = false,
-			ShowColoredText = false,
-			ShowInventory = false,
-			ShowRepairCost = 1,
-			ShowMostDmgPer = 1,
-			IgnoreThrown = false,
-			UseGuildBank = false,
-			AutoRepairReport = false,
-			ShowItems = true,
-			ShowDiscounts = true,
-			ShowCosts = true,
-			DisplayOnRightSide = false,
-		}
-	};
-
-	self:RegisterEvent("PLAYER_LEAVING_WORLD");
-	self:RegisterEvent("PLAYER_ENTERING_WORLD");
-
-	-- (re)set the status structures we need to change & store
-	for i = 0, table.getn(TPR.ITEM_STATUS) do
-		TitanPanelRepairButton_ResetStatus(TPR.ITEM_STATUS[i].values)
-	end
-	for i = 0, table.getn(TPR.INVENTORY_STATUS) do
-		TitanPanelRepairButton_ResetStatus(TPR.INVENTORY_STATUS[i].values)
+--]]
+local function debug_msg(Message)
+	if (TR.show_debug) then
+		local msg = ""
+		local stamp = date("%H:%M:%S") -- date("%m/%d/%y %H:%M:%S")
+		local milli = GetTime() -- seconds with millisecond precision (float)
+		milli = string.format("%0.2F", milli - math.modf(milli))
+		msg = msg..TitanUtils_GetGoldText(stamp..milli.." "..TITAN_REPAIR_ID..": ")
+		msg = msg..TitanUtils_GetGreenText(Message)
+		DEFAULT_CHAT_FRAME:AddMessage(msg)
+--		DEFAULT_CHAT_FRAME:AddMessage(TITAN_REPAIR_ID..": " .. Message, 1.00, 0.49, 0.04)
 	end
 end

+--[[ local
 -- **************************************************************************
--- NAME : TitanPanelRepairButton_ResetStatus(status)
--- DESC : Reset the record to default values
--- VARS : status = the record to (re)set values for
+-- NAME : RepairInit()
+-- DESC : Reset the tables and variables to default values
+-- VARS : None
 -- **************************************************************************
-function TitanPanelRepairButton_ResetStatus(status)
-	status.max = 0
-	status.val = 0
-	status.cost = 0
-	status.item_name = ""
-	status.item_type = ""
-	status.item_subtype = ""
-	status.item_quality = ""
-	status.item_color = ""
-	status.item_frac = 1.0
+--]]
+local function RepairInit()
+	TR.repair_total = 0
+	TR.repair_bags = { cur = 0, max = 0, dur = 0, total = 0 }
+	TR.repair_equip = { cur = 0, max = 0, dur = 0, total = 0 }
+
+	TR.money_total = 0
+	TR.bag_list = {}
+	TR.equip_list = {}
+	TR.equip_most = nil
 end

+--[[ local
 -- **************************************************************************
--- NAME : TitanPanelRepairButton_ScanAllItems()
--- DESC : Set all bags and equipment to be scanned
---        and set the 'scan in progress'
+-- NAME : Scan(reason, force)
+-- DESC : Scan all bags and equipment and set the 'scan in progress'
+-- VARS :
+-- reason : string : for debug only - why was the scan requested?
+-- force : boolean : whether to force a scan such as on player entering world or user request
 -- **************************************************************************
-function TitanPanelRepairButton_ScanAllItems()
--- if (TitanGetVar(TITAN_REPAIR_ID,"ShowInventory") == 1) then
-	TPR.PleaseCheckBag[0] = 1;
-	TPR.PleaseCheckBag[1] = 1;
-	TPR.PleaseCheckBag[2] = 1;
-	TPR.PleaseCheckBag[3] = 1;
-	TPR.PleaseCheckBag[4] = 1;
--- end
-	TPR.PleaseCheckBag[5] = 1;
-	TPR.WholeScanInProgress = true;
-	TitanPanelButton_UpdateButton(TITAN_REPAIR_ID);
-end
-
--- **************************************************************************
--- NAME : TitanPanelRepairButton_OnEvent(self, event, a1, ...)
--- DESC : This section will grab the events registered to the add on and act on them
--- **************************************************************************
-function TitanPanelRepairButton_OnEvent(self, event, a1, ...)
-
--- NOTE that events test are done in probability order:
--- The events that fires the most are tested first
-	if (TPR.show_debug) then -- this is not necessary but is here to optimize this part the most possible
-		tit_debug_bis("Event " .. event .. "...");
-	end
-
-	if event == "UNIT_INVENTORY_CHANGED" and a1 == "player" then
-		TPR.PleaseCheckBag[5] = 1
-		TitanRepairModule:CancelAllTimers()
-		TitanRepairModule:ScheduleTimer(TitanPanelRepairButton_OnUpdate, 1)
-		return
-	end
-
-	if event == "PLAYER_MONEY" and TPR.MerchantisOpen == true and CanMerchantRepair() then
-		TitanPanelRepairButton_ScanAllItems()
-		TitanRepairModule:CancelAllTimers()
-		TitanRepairModule:ScheduleTimer(TitanPanelRepairButton_OnUpdate, 1)
-		return
-	end
-
-	if event == "PLAYER_REGEN_ENABLED" then
-		TitanPanelRepairButton_ScanAllItems()
-		TitanPanelRepairButton_OnUpdate()
-		return
-	end
-
-	if event == "PLAYER_DEAD" then
-		TitanPanelRepairButton_ScanAllItems()
-		TitanPanelRepairButton_OnUpdate()
-		return
-	end
-
-	if event == "PLAYER_UNGHOST" then
-		TitanPanelRepairButton_ScanAllItems()
-		TitanPanelRepairButton_OnUpdate()
-		return
-	end
-
-	if (event == "UPDATE_INVENTORY_ALERTS") then
-		-- register to check the equiped items on next appropriate OnUpdate call
-		if (TPR.show_debug) then -- this is not necessary but is here to optimize this part the most possible
-			tit_debug_bis("Event " .. event .. " TREATED!");
-		end
-		TPR.PleaseCheckBag[5] = 1;
-		TitanPanelRepairButton_OnUpdate()
-		return;
-	end
-
-	-- when a1 is > 4 it means that a bank's bag has been updated
-	if ( (event == "BAG_UPDATE")
-		and (a1 < 5)
-		--and (TitanGetVar(TITAN_REPAIR_ID,"ShowInventory") == 1)
-		)
-	then
-		-- register to check this bag's items on next appropriate OnUpdate call
-		if (TPR.show_debug) then -- this if is not necessary but is here to optimize this part the most possible
-			tit_debug_bis("Event " .. event .. " TREATED!");
-		end
-
-		TPR.PleaseCheckBag[5] = 1;
-		TPR.PleaseCheckBag[a1] = 1;
-		TitanRepairModule:CancelAllTimers()
-		TitanRepairModule:ScheduleTimer(TitanPanelRepairButton_OnUpdate, 3)
-		return;
-	end
+--]]
+local function Scan(reason, force)
+	local must_do = force or false
+	local milli = GetTime() -- seconds with millisecond precision (float)
+	local dmsg = ""
+	local msg = "Scan "
+		.." '"..tostring(reason).."'"
+--		.." "..tostring(force)
+		.." "..string.format("%0.2F",(milli - TR.last_scan)).." sec"
+
+	if must_do or (milli > TR.last_scan + 1) then -- no more than a scan per sec
+		msg = msg.." : running "
+		debug_msg(msg)
+
+		-- Init the repair tables
+		RepairInit()
+
+		local itemName, _, itemQuality
+
+		TR.repair_total = 0
+		TR.dur_total = 0
+
+		TR.repair_equip = { cur = 0, max = 0, dur = 0, total = 0 }
+		TR.scan_running = true
+
+		-- scan equipped
+		dmsg = "Start equip scan"
+			.." - "..(TitanGetVar(TITAN_REPAIR_ID,"ShowUndamaged") and "Include Undamaged" or "Only Damaged")
+		debug_msg(dmsg)
+
+		for slotName, slotID in pairs(Enum.InventoryType) do
+			local hasItem = {}
+			local repairCost = 0
+			local dbg_str_01 = ""
+
+			local minimum, maximum = GetInventoryItemDurability(slotID)
+
+			if minimum and maximum then
+				-- 	Only when item has durability
+
+				--Blizz changed SetInventoryItem for DragonFlight - use C_TooltipInfo namespace for everything
+				hasItem = C_TooltipInfo.GetInventoryItem("player", slotID)
+				if hasItem then
+					TooltipUtil.SurfaceArgs(hasItem) -- readable format
+					repairCost = (hasItem.repairCost or 0) -- possibly not 'damaged' or no durability
+				end
+				if hasItem then
+					local itemLink = GetInventoryItemLink("player", slotID)
+
+					if itemLink then
+						itemName, _, itemQuality = GetItemInfo(itemLink)
+						local r, g, b, hex = GetItemQualityColor(itemQuality or 1)
+						-- save item for tooltip and debug
+						if ((repairCost and repairCost > 0) or TitanGetVar(TITAN_REPAIR_ID,"ShowUndamaged")) then
+							TR.equip_list[slotName] = {
+												name = (itemName or UNKNOWN),
+												quality = (itemQuality or UNKNOWN),
+												color = (hex or UNKNOWN),
+												dur_max = (maximum or UNKNOWN),
+												dur_cur = (minimum or UNKNOWN),
+												dur_per = ((maximum > 0 and floor(minimum / maximum * 100)) or 100),
+												cost = (repairCost or 0),
+												}
+							-- debug
+							if show_debug_scan then
+								dbg_str_01 = tostring(slotName)..":"..tostring(slotId)
+												.." '"..tostring(TR.equip_list[slotName].name).."'"
+												.." "..tostring(TR.equip_list[slotName].quality)
+												.." "..tostring(TR.equip_list[slotName].cost)
+												.." "..tostring(TR.equip_list[slotName].dur_per).."%"
+												.." "..tostring(TR.equip_list[slotName].dur_cur)
+												.."/"..tostring(TR.equip_list[slotName].dur_max)
+								debug_msg(dbg_str_01)
+							else
+								-- not requested
+							end
+						end
+					else
+						-- nothing
+					end

-	if (event == "MERCHANT_SHOW") then
-		TPR.MerchantisOpen = true;
-		local canRepair = CanMerchantRepair();
-		if not canRepair then
-			return;
-		end
-		--if (TitanGetVar(TITAN_REPAIR_ID,"ShowInventory") == 1) then
-		TPR.PleaseCheckBag[0] = 1;
-		TPR.PleaseCheckBag[1] = 1;
-		TPR.PleaseCheckBag[2] = 1;
-		TPR.PleaseCheckBag[3] = 1;
-		TPR.PleaseCheckBag[4] = 1;
-		--end
-		TPR.PleaseCheckBag[5] = 1;
-		TitanPanelRepairButton_OnUpdate()
-		if TitanGetVar(TITAN_REPAIR_ID,"ShowPopup") == 1 then
-			local repairCost, canRepair = GetRepairAllCost();
-			if (canRepair) then
-				TPR.CouldRepair = true;
-				if (repairCost > 0) then
-					TPR.MONEY = repairCost;
-					StaticPopup_Show("REPAIR_CONFIRMATION");
+					TR.repair_total = TR.repair_total + repairCost
+					TR.repair_equip.total = TR.repair_equip.total + repairCost
 				end
+
+				TR.repair_equip.cur = TR.repair_equip.cur + minimum
+				TR.repair_equip.max = TR.repair_equip.max + maximum
+
+			else
+				-- some equipped items do not have durability
 			end
-		end
-		-- handle auto-repair
-		if (TitanGetVar(TITAN_REPAIR_ID,"AutoRepair") == 1) then
-			local repairCost, canRepair = GetRepairAllCost();
-			if (canRepair) then
-				TPR.CouldRepair = true;
-				if (repairCost > 0) then
-					TitanRepair_RepairItems();
-					TitanPanelRepairButton_ScanAllItems();
-					TitanRepairModule:CancelAllTimers()
-					TitanRepairModule:ScheduleTimer(TitanPanelRepairButton_OnUpdate, 2)
-					TPR.CouldRepair = false;
+		end -- InventoryType
+		TR.repair_equip.dur = (TR.repair_equip.max > 0 and floor(TR.repair_equip.cur / TR.repair_equip.max * 100)) or 100
+		dmsg = "End equip scan "
+			.." $"..tostring(TR.repair_equip.total)
+			.." "..tostring(TR.repair_equip.dur).."%"
+			.." = "..tostring(TR.repair_equip.cur)
+			.." / "..tostring(TR.repair_equip.max)
+		debug_msg(dmsg)
+
+		TR.repair_bags = { cur = 0, max = 0, dur = 0, total = 0 }
+		if (TitanGetVar(TITAN_REPAIR_ID,"ShowInventory") == 1) then
+			-- scan bags for 'damaged' items
+			debug_msg("Bags scan Start - ShowInventory")
+
+			tool_tip:SetOwner(UIParent, "ANCHOR_NONE")
+			for bag = 0, 4 do
+				for slot = 1, C_Container.GetContainerNumSlots(bag) do
+					local repairCost = 0
+
+					local minimum, maximum = C_Container.GetContainerItemDurability(bag, slot)
+					if minimum and maximum then
+						local data = C_TooltipInfo.GetBagItem(bag, slot)
+						if data then
+							TooltipUtil.SurfaceArgs(data) -- readable format
+							repairCost = (data.repairCost or 0)
+						end
+						if (repairCost and (repairCost > 0)) then
+							TR.repair_total = TR.repair_total + repairCost
+							TR.repair_bags.total = TR.repair_bags.total + repairCost
+						end
+						TR.repair_bags.cur = TR.repair_bags.cur + minimum
+						TR.repair_bags.max = TR.repair_bags.max + maximum
+					end
 				end
 			end
-		end
-		return;
-	end
-
-	if ( event == "MERCHANT_CLOSED" ) then
-		TitanRepairModule:CancelAllTimers()
-		TPR.MerchantisOpen = false;
-		StaticPopup_Hide("REPAIR_CONFIRMATION");
-		-- When an object is repaired in a bag,
-		-- the BAG_UPDATE event is not sent
-		-- so we rescan all
-		if (TPR.CouldRepair) then
-			TitanPanelRepairButton_ScanAllItems();
-			TitanRepairModule:ScheduleTimer(TitanPanelRepairButton_OnUpdate, 1)
-			TPR.CouldRepair = false;
+			tool_tip:Hide();
+			TR.repair_bags.dur = (TR.repair_bags.max > 0 and floor(TR.repair_bags.cur / TR.repair_bags.max * 100)) or 100
+			dmsg = "Bags scan End "
+				.." "..tostring(TR.repair_bags.dur)
+				.." $ "..tostring(TR.repair_bags.total)
+			debug_msg(dmsg)
 		else
-			--if (TitanGetVar(TITAN_REPAIR_ID,"ShowInventory") == 1) then
-			TPR.PleaseCheckBag[0]  = 1;
-			TPR.PleaseCheckBag[1]  = 1;
-			TPR.PleaseCheckBag[2]  = 1;
-			TPR.PleaseCheckBag[3]  = 1;
-			TPR.PleaseCheckBag[4]  = 1;
-			--end
-			TPR.PleaseCheckBag[5] = 1;
-			TitanRepairModule:ScheduleTimer(TitanPanelRepairButton_OnUpdate, 1)
+			debug_msg("Bags scan None - User did not request")
 		end
-		return;
-	end
-
-	if (event == "PLAYER_ENTERING_WORLD") then
-		self:RegisterEvent("BAG_UPDATE");
-		self:RegisterEvent("UPDATE_INVENTORY_ALERTS");
-		self:RegisterEvent("MERCHANT_SHOW");
-		self:RegisterEvent("MERCHANT_CLOSED");
-		self:RegisterEvent("PLAYER_REGEN_ENABLED")
-		self:RegisterEvent("PLAYER_DEAD")
-		self:RegisterEvent("PLAYER_UNGHOST")
-		self:RegisterEvent("PLAYER_MONEY");
-		self:RegisterEvent("UNIT_INVENTORY_CHANGED");
-		-- Check everything on world enter (at init and after zoning)
-		TitanPanelRepairButton_ScanAllItems();
-		TitanPanelRepairButton_OnUpdate()
-		TitanRepair_DurabilityFrame();
-		return;
-	end

-	if (event == "PLAYER_LEAVING_WORLD") then
-		self:UnregisterEvent("BAG_UPDATE");
-		self:UnregisterEvent("UPDATE_INVENTORY_ALERTS");
-		self:UnregisterEvent("MERCHANT_SHOW");
-		self:UnregisterEvent("MERCHANT_CLOSED");
-		self:UnregisterEvent("PLAYER_REGEN_ENABLED")
-		self:UnregisterEvent("PLAYER_DEAD")
-		self:UnregisterEvent("PLAYER_UNGHOST")
-		self:UnregisterEvent("PLAYER_MONEY");
-		self:UnregisterEvent("UNIT_INVENTORY_CHANGED");
-		return;
-	end
-end
-
--- **************************************************************************
--- NAME : tit_debug_bis(Message)
--- DESC : Debug function to print message to chat frame
--- VARS : Message = message to print to chat frame
--- **************************************************************************
-function tit_debug_bis(Message)
-	if (TPR.show_debug) then
-		DEFAULT_CHAT_FRAME:AddMessage("TiT_Rep: " .. Message, 1.00, 0.49, 0.04);
+		-- Calc total durability %
+		TR.dur_total = ((TR.repair_bags.max + TR.repair_equip.max) > 0
+			and floor( (TR.repair_bags.cur + TR.repair_equip.cur) / (TR.repair_bags.max + TR.repair_equip.max) * 100))
+			or 100
+		dmsg = "Calc total durability"
+			.." '"..tostring(TR.dur_total).."'"
+			.." "..tostring(TR.repair_equip.max)
+			.." "..tostring(TR.repair_equip.cur)
+			.." "..tostring(TR.repair_bags.max)
+			.." "..tostring(TR.repair_bags.cur)
+		debug_msg(dmsg)
+
+		-- cleanup
+		TR.scan_time = GetTime() - milli
+		TR.last_scan = GetTime()
+		TR.scan_running = false
+
+		-- update button text
+		TitanPanelButton_UpdateButton(TITAN_REPAIR_ID)
+
+		dmsg = "...Scan complete"
+		debug_msg(dmsg)
+	else
+		msg = msg.." : NOT running - too soon "
+		debug_msg(msg)
 	end
 end

-
+--[[ local
 -- **************************************************************************
--- NAME : TitanPanelRepairButton_OnUpdate(self, Elapsed)
--- DESC : <research>
--- VARS : elapsed = <research>
+-- NAME : RepairShow()
+-- DESC : Prepare to activate Repair - events, init, etc.
+-- VARS : None
 -- **************************************************************************
-function TitanPanelRepairButton_OnUpdate()
-	-- test if a "bag" needs to be scanned
-	for tocheck = 0, 5 do
-		-- if there is one
-		if TPR.PleaseCheckBag[tocheck] == 1 then
-			-- we are checking...
-			TPR.PleaseCheckBag[tocheck] = 2
-			if (tocheck ~= 5) then  -- call update inventory function (I've put this test first because there is 5 chances on 6 that it returns true)
-				tit_debug_bis("Update: Checking bag " .. tocheck .. " as requested");
-				TitanRepair_GetInventoryInformation(tocheck);
-			else -- call update equiped items function
-				tit_debug_bis("Update: Checking equiped items as requested");
-				TitanRepair_GetEquipedInformation();
-			end
-			-- test if another check was requested during this update
-			-- (avoid to missing something... rare but still)
-			if TPR.PleaseCheckBag[tocheck] ~= 1 then
-				-- Check completed
-				TPR.PleaseCheckBag[tocheck] = 0;
-			end
-		end
-	end
-end;
-
--- **************************************************************************
--- NAME : TitanRepair_GetStatusPercent(val, max)
--- DESC : <research>
--- VARS : val = <research>, max = <research>
--- **************************************************************************
-function TitanRepair_GetStatusPercent(val, max)
-
-	-- if max or val are nil then there are other issues but at least return something
-	if (max and val) then
-		if (max and max > 0) then
-			return (val / max);
-		end
-	end
-	return 1.0;
-end;
-
--- **************************************************************************
--- NAME : TitanRepair_GetMostDamagedItem()
--- DESC : <research>
--- **************************************************************************
-function TitanRepair_GetMostDamagedItem()
-	-- Get repair status for Equiped items and inventory
-	-- NOTE: TitanRepair_GetStatusPercent() will return 1.0 if max value <= 0
-	local equip_status = TPR.ITEM_STATUS[TPR.EquipedMinIndex].values
-	local inv_status = TPR.ITEM_STATUS[TPR.END].values
-	local EquipedItemsStatus   = equip_status.item_frac;
-	local InventoryItemsStatus = inv_status.item_frac;
-
-	-- if everything is repaired
-	if (EquipedItemsStatus == 1.0 and InventoryItemsStatus == 1.0) then
-		tit_debug_bis("Everything is repaired");
-		return 0;
-	end
-
-	-- If something is more or equally damaged than the current most damaged equiped item
-	--
-	-- NOTE: The <= is important because InventoryItemsStatus is updated BEFORE EquipedItemsStatus
-	-- The typical case is when you move the most damaged equiped item to your iventory,
-	-- when this function will be called by TitanRepair_GetInventoryInformation(), TPR.EquipedMinIndex will point to an empty slot:
-	-- since TitanRepair_GetEquipedInformation() won't have been called yet (bag update events are treated before equiped item event),
-	-- EquipedItemsStatus will be egual to InventoryItemsStatus...
-	-- So the <= is to avoid that TPR.EquipedMinIndex points to nothing
-	-- (even if it has no concequence right now, it may save hours of debugging some day...)
-
-	if ( (InventoryItemsStatus <= EquipedItemsStatus)
-	and (TitanGetVar(TITAN_REPAIR_ID,"ShowInventory") == 1) ) then
-		tit_debug_bis("Inventory is more damaged than equiped items");
-		return TPR.END;
-	else -- if EquipedItemsStatus < InventoryItemsStatus
-		tit_debug_bis("Equiped items are more damaged than inventory");
-		return TPR.EquipedMinIndex;
-	end
+--]]
+local function RepairShow(self)
+	debug_msg("RepairShow - starting")
+	RepairInit()
+
+	self:RegisterEvent("MERCHANT_SHOW");
+	self:RegisterEvent("MERCHANT_CLOSED");
+	self:RegisterEvent("PLAYER_REGEN_ENABLED")
+	self:RegisterEvent("UNIT_INVENTORY_CHANGED")
+	self:RegisterEvent("UPDATE_INVENTORY_DURABILITY")

-	-- Typical 6 possibilities:
-	-- - InventoryItemsStatus == 1 and EquipedItemsStatus == 1 ==> returns 0
-	-- - InventoryItemsStatus < 1 and EquipedItemsStatus == 1 ==> returns TPR.END
-	-- - InventoryItemsStatus == 1 and EquipedItemsStatus < 1 ==> ! (InventoryItemsStatus <= EquipedItemsStatus) ==> returns TPR.EquipedMinIndex
-	-- - InventoryItemsStatus < 1 and EquipedItemsStatus < 1 :
-	-- - InventoryItemsStatus <= EquipedItemsStatus ==> returns TPR.END
-	-- - InventoryItemsStatus > EquipedItemsStatus ==> ! (InventoryItemsStatus <= EquipedItemsStatus) ==> returns TPR.EquipedMinIndex
+	-- Check everything on world enter (at init and after zoning)
+	Scan("OnShow", true)

-end;
+	debug_msg("...RepairShow - complete")
+end

+--[[ local
 -- **************************************************************************
--- NAME : TitanRepair_GetInventoryInformation(bag)
--- DESC : <research>
--- VARS : bag = <research>
+-- NAME : RepairHide()
+-- DESC : Prepare to deactivate Repair - events, etc.
+-- VARS : None
 -- **************************************************************************
-function TitanRepair_GetInventoryInformation(bag)
-
- -- check to see if a merchant that can repair is open
-	if TPR.MerchantisOpen then
-		local canRepair = CanMerchantRepair();
-		if not canRepair then
-			return;
-		end
-	end
-
-	local min_status = 1.0;
-	local min_val = 0;
-	local min_max = 0;
-
-	TitanRepairTooltip:SetOwner(UIParent, "ANCHOR_NONE");
-
-	if (bag > 4) then -- should never get true though, bag > 4 are for the bank's bags
-		return;
-	end
-
-	-- we re-scan the whole bag so we reset its status
-	TPR.INVENTORY_STATUS[bag].values.val = 0
-	TPR.INVENTORY_STATUS[bag].values.max = 0
-	TPR.INVENTORY_STATUS[bag].values.cost = 0
-
--- DF
---	for slot = 1, GetContainerNumSlots(bag) do
-	local get_slots = nil
-	if C_Container.GetContainerNumSlots then
-		get_slots = C_Container.GetContainerNumSlots
-	elseif GetContainerNumSlots then
-		get_slots = GetContainerNumSlots
-	end
-
-	for slot = 1, get_slots(bag) do
-		-- retrieve item repair status of this slot in the bag
-		local act_status, act_val, act_max, act_cost = TitanRepair_GetStatus(slot, bag);
-		if act_max ~= 0 then
-			TPR.INVENTORY_STATUS[bag].values.val = TPR.INVENTORY_STATUS[bag].values.val + act_val;
-			TPR.INVENTORY_STATUS[bag].values.max = TPR.INVENTORY_STATUS[bag].values.max + act_max;
-		end
-		-- add this item cost to this bag global repair cost
-		TPR.INVENTORY_STATUS[bag].values.cost = TPR.INVENTORY_STATUS[bag].values.cost + act_cost;
-	end
-
-	-- Recalc the total repair of all bags
-	TPR.ITEM_STATUS[TPR.END].values.val = 0
-	TPR.ITEM_STATUS[TPR.END].values.max = 0
-	TPR.ITEM_STATUS[TPR.END].values.cost = 0
-	for bag = 0, 4 do
-		local act_val		= TPR.INVENTORY_STATUS[bag].values.val ;
-		local act_max		= TPR.INVENTORY_STATUS[bag].values.max ;
-		local act_cost		= TPR.INVENTORY_STATUS[bag].values.cost ;
-		local act_status	= TPR.INVENTORY_STATUS[bag].values.item_frac;
-
-		TPR.ITEM_STATUS[TPR.END].values.val = TPR.ITEM_STATUS[TPR.END].values.val + act_val;
-		TPR.ITEM_STATUS[TPR.END].values.max = TPR.ITEM_STATUS[TPR.END].values.max + act_max;
-		-- add each bag global repair cost to inventory global repair cost
-		TPR.ITEM_STATUS[TPR.END].values.cost = TPR.ITEM_STATUS[TPR.END].values.cost + act_cost;
-	end
-	TPR.ITEM_STATUS[TPR.END].values.item_frac =
-	TitanRepair_GetStatusPercent(TPR.ITEM_STATUS[TPR.END].values.val, TPR.ITEM_STATUS[TPR.END].values.max)
-
-	TPR.INDEX = TitanRepair_GetMostDamagedItem();
-
-	tit_debug_bis("(inv) REPAIR_INDEX=" ..TPR.INDEX );
-
-	-- Update the button text only if we are not waiting for TitanRepair_GetEquipedInformation()
-	-- else an incorrect value may be displayed till TitanRepair_GetEquipedInformation() is called
-	-- if a whole scan is in progress we update the button ("Updating..." is displayed in that case, so incorrect values are acceptable)
-	if ( (TPR.PleaseCheckBag[5] == 0) or TPR.WholeScanInProgress ) then
-		TitanPanelButton_UpdateButton(TITAN_REPAIR_ID);
-	else
-		tit_debug_bis("Waiting for updating button text");
-	end
-	local frame = _G["TitanPanelRepairButton"]
-	TitanPanelButton_UpdateTooltip(frame);
-	TitanRepairTooltip:Hide();
+--]]
+local function RepairHide(self)
+	debug_msg("RepairHide - shutting down")
+	RepairInit() -- cleanup footprint
+
+	self:UnregisterEvent("MERCHANT_SHOW");
+	self:UnregisterEvent("MERCHANT_CLOSED");
+	self:UnregisterEvent("PLAYER_REGEN_ENABLED")
+	self:UnregisterEvent("UNIT_INVENTORY_CHANGED");
+	self:UnregisterEvent("UPDATE_INVENTORY_DURABILITY");
+
+	debug_msg("...RepairHide - complete")
 end

+--[[ local
 -- **************************************************************************
--- NAME : TitanRepair_GetEquipedInformation()
--- DESC : <research>
+-- NAME : GetGSC(money)
+-- DESC : Scan all bags and equipment and set the 'scan in progress'
+-- VARS :
+-- money : int : money in copper
+-- OUT :
+-- int : gold component
+-- int : silver component
+-- int : copper component
+-- boolean : whether value is negative or not
 -- **************************************************************************
-function TitanRepair_GetEquipedInformation()
-
-	tit_debug_bis("_GetEquipedInfo Merchant=" ..(TPR.MerchantisOpen and "T" or "F") );
-	-- check to see if a merchant that can repair is open
-	if TPR.MerchantisOpen then
-		local canRepair = CanMerchantRepair();
-		if not canRepair then
-			return;
-		end
-	end
-
-	local min_status = 1.0;
-	local min_val = 0;
-	local min_max = 0;
-	local min_index = 0;
-	TPR.EquipedMinIndex = 0;
-
-	TitanRepairTooltip:SetOwner(UIParent, "ANCHOR_NONE");
-
-	tit_debug_bis("_GetEquipedInfo loop" );
-	for index, value in pairs(INVENTORY_ALERT_STATUS_SLOTS) do -- index begins from 1
-		if index==11 then
-			--do nothing
-		else
-			local act_status, act_val, act_max, act_cost,
-			itemName, itemType, itemSubType, itemRarity, itemColor = TitanRepair_GetStatus(index);
-			if TitanGetVar(TITAN_REPAIR_ID,"IgnoreThrown")
-				and itemSubType == INVTYPE_THROWN then
-				-- do not use it per user request
-				act_status = 1.0 -- act as if repaired
-				act_val = act_max -- no durability hit
-			else
-				if ( act_status < min_status ) then
-					min_status = act_status;
-					min_val = act_val;
-					min_max = act_max;
-					min_index = index;
-				end
-			end
-
-			-- this stores some extra information but it makes a quick
-			-- lookup in the display parts of the code
-			TPR.ITEM_STATUS[index].values.val = act_val;
-			TPR.ITEM_STATUS[index].values.max = act_max;
-			TPR.ITEM_STATUS[index].values.cost = act_cost;
-			TPR.ITEM_STATUS[index].values.item_name = itemName;
-			TPR.ITEM_STATUS[index].values.item_type = itemType;
-			TPR.ITEM_STATUS[index].values.item_subtype = itemSubType;
-			TPR.ITEM_STATUS[index].values.item_quality = itemRarity;
-			TPR.ITEM_STATUS[index].values.item_color = itemColor;
-			TPR.ITEM_STATUS[index].values.item_frac = act_status;
-		end
-	end
-	tit_debug_bis("_GetEquipedInfo loop end " .. (min_status or 0).. " | " ..(min_index or 0));
-	TPR.EquipedMinIndex = min_index;
-
-	TPR.INDEX = TitanRepair_GetMostDamagedItem();
-
-	-- if a whole update is in progress, and we are here, then we have finished this whole update :)
-	-- it has to be here because it changes the text of the button.
-	if (TPR.WholeScanInProgress) then
-		TPR.WholeScanInProgress = false;
+--]]
+local function GetGSC(money)
+	local neg = false;
+	if (money == nil) then money = 0; end
+	if (money < 0) then
+		neg = true;
+		money = money * -1;
 	end
-
-	tit_debug_bis("(equip) REPAIR_INDEX=" ..TPR.INDEX  .. "  min_index=" .. min_index);
-
-	TitanPanelButton_UpdateButton(TITAN_REPAIR_ID);
-	local frame = _G["TitanPanelRepairButton"]
-	TitanPanelButton_UpdateTooltip(frame);
-	TitanRepairTooltip:Hide();
+	local g = math.floor(money / 10000);
+	local s = math.floor((money - (g * 10000)) / 100);
+	local c = math.floor(money - (g * 10000) - (s * 100));
+	return g, s, c, neg;
 end

+--[[ local
 -- **************************************************************************
--- NAME : TitanRepair_GetStatus(index, bag)
--- DESC : <research>
--- VARS : index = <research>, bag = <research>
+-- NAME : GetGSC(money)
+-- DESC : Scan all bags and equipment and set the 'scan in progress'
+-- VARS :
+-- money : int : money in copper
+-- OUT :
+-- gsc : string : formatted and colored of given money
 -- **************************************************************************
-function TitanRepair_GetStatus(index, bag)
-	local _, curDurability, maxDurability, repairCost
-	local hasItem, itemName, itemRarity, itemType, itemSubType, itemColor
-
-	--tit_debug_bis("_GetStatus index="..(index or "NIL").." bag="..(bag or "NIL"))
-	TitanRepairTooltip:ClearLines()
-
-	-- DF difference in Beta versus PTR??
-	local get_dur = nil
-	if C_Container.GetContainerItemDurability then
-		get_dur = C_Container.GetContainerItemDurability
-	elseif GetContainerItemDurability then
-		get_dur = GetContainerItemDurability
-	end
-
-	if (bag) then
-		_, repairCost = TitanRepairTooltip:SetBagItem(bag, index)
---		curDurability, maxDurability = C_Container.GetContainerItemDurability(bag, index)
-		curDurability, maxDurability = get_dur(bag, index)
+--]]
+local function GetTextGSC(money)
+	local GSC_GOLD = "ffd100";
+	local GSC_SILVER = "e6e6e6";
+	local GSC_COPPER = "c8602c";
+	local GSC_START = "|cff%s%d|r";
+	local GSC_PART = ".|cff%s%02d|r";
+	local GSC_NONE = "|cffa0a0a0" .. NONE .. "|r";
+	local g, s, c, neg = GetGSC(money);
+	local gsc = "";
+	if (g > 0) then
+		gsc = format(GSC_START, GSC_GOLD, g);
+		gsc = gsc .. format(GSC_PART, GSC_SILVER, s);
+		gsc = gsc .. format(GSC_PART, GSC_COPPER, c);
+	elseif (s > 0) then
+		gsc = format(GSC_START, GSC_SILVER, s);
+		gsc = gsc .. format(GSC_PART, GSC_COPPER, c);
+	elseif (c > 0) then
+		gsc = gsc .. format(GSC_START, GSC_COPPER, c);
 	else
-		local slotName = TPR.ITEM_STATUS[index].slot.."Slot"
-		--tit_debug_bis("_GetStatus index="..index..", slotName="..(slotName or "NIL"))
-		local slotId = GetInventorySlotInfo(slotName) or -1
-		hasItem, _, repairCost = TitanRepairTooltip:SetInventoryItem("player", slotId)
-		--tit_debug_bis("_GetStatus slotName="..slotName..", slotId="..slotId..", hasItem="..(hasItem or 0))
-		if hasItem then
-			curDurability, maxDurability = GetInventoryItemDurability(slotId)
-			itemName, _, itemRarity, _,	_, itemType, itemSubType = GetItemInfo(GetInventoryItemLink("player", slotId) or "")
-			local r, g, b, hex = GetItemQualityColor(itemRarity or 1)
-			itemColor = "|c"..hex
-		end
+		gsc = GSC_NONE;
 	end
-
-	-- Turn any NIL results into 0's
-	repairCost = repairCost or 0
-	curDurability = curDurability or 0
-	maxDurability = maxDurability or 0
-
-	--[[
-	tit_debug_bis("_GetStatus: "
-		.." curDur="..curDurability
-		.." maxDur="..maxDurability
-		.." rCost="..repairCost
-		.." iName="..(itemName or 0)
-		.." iType="..(itemType or 0)
-		.." iSubType="..(itemSubType or 0)
-		.." iRarity="..(itemRarity or 0)
-		.." iColor="..(itemColor or 0)
-	)
-	--]]
-
-	return
-		TitanRepair_GetStatusPercent(curDurability, maxDurability),
-		curDurability,
-		maxDurability,
-		repairCost,
-		itemName,
-		itemType,
-		itemSubType,
-		itemRarity,
-		itemColor
+	if (neg) then gsc = "(" .. gsc .. ")"; end
+	return gsc;
 end

+--[[ local
 -- **************************************************************************
--- NAME : TitanRepair_GetStatusStr(index, short)
+-- NAME : TitanRepair_RepairItems()
 -- DESC : <research>
--- VARS : index = <research>, short = <research>
 -- **************************************************************************
-TPR.LastKnownText = "";
-TPR.LastKnownItemFrac = 1.0;
-function TitanRepair_GetStatusStr(index, short)
-	-- skip if fully repaired
-	if (index == 0) then
-		return TitanRepair_AutoHighlight(1.0, "100%");
-	end
-
-	local valueText = "";
-
-	-- if used for button text
-	if (short) then
-		valueText = TPR.LastKnownText;
-	end
-
-	local item_status = TPR.ITEM_STATUS[index];
-	local item_frac = item_status.values.item_frac;
+--]]
+local function TitanRepair_RepairItems()
+	-- New RepairAll function
+	local cost = GetRepairAllCost();
+	local money = GetMoney();
+	local withdrawLimit = GetGuildBankWithdrawMoney();
+	local guildBankMoney = GetGuildBankMoney();

-	-- skip if empty slot
-	if (item_status.max == 0) then
-		if (short) then
-			if (not TPR.WholeScanInProgress) then
-				valueText =  TitanRepair_AutoHighlight(TPR.LastKnownItemFrac, valueText
-					.. " (" .. L["REPAIR_LOCALE"]["WholeScanInProgress"] .. ")");
+	-- Use Guild Bank funds
+	if TitanGetVar(TITAN_REPAIR_ID,"UseGuildBank") then
+		debug_msg("UseGuildBank"
+			.." $"..tostring(cost)..""
+			.." limit: "..tostring(withdrawLimit)
+			.." guild $: "..tostring(guildBankMoney)
+			)
+---[[
+--]]
+		if IsInGuild() and CanGuildBankRepair() then
+			if withdrawLimit >= cost then
+				RepairAllItems(true)
+				if TitanGetVar(TITAN_REPAIR_ID,"AutoRepairReport") then
+					DEFAULT_CHAT_FRAME:AddMessage(_G["GREEN_FONT_COLOR_CODE"]..L["TITAN_REPAIR"]..": ".."|r"..L["TITAN_REPAIR_REPORT_COST_CHAT"]..GetTextGSC(cost).."|r.")
+				end
+				-- disable repair all icon in merchant
+				SetDesaturation(MerchantRepairAllIcon, 1);
+				MerchantRepairAllButton:Disable();
+				-- disable guild bank repair all icon in merchant
+				SetDesaturation(MerchantGuildBankRepairButtonIcon, 1);
+				MerchantGuildBankRepairButton:Disable();
+				-- report repair cost to chat (optional)
 			else
-				valueText =  TitanRepair_AutoHighlight(TPR.LastKnownItemFrac, valueText);
+				DEFAULT_CHAT_FRAME:AddMessage(_G["GREEN_FONT_COLOR_CODE"]..L["TITAN_REPAIR"]..": ".."|r"..L["TITAN_REPAIR_GBANK_NOMONEY"])
 			end
-
-			return valueText;
 		else
-			return nil;
+			DEFAULT_CHAT_FRAME:AddMessage(_G["GREEN_FONT_COLOR_CODE"]..L["TITAN_REPAIR"]..": ".."|r"..L["TITAN_REPAIR_GBANK_NORIGHTS"])
 		end
-	end
-
-	-- determine the percent or value per user request
-	if (TitanGetVar(TITAN_REPAIR_ID,"ShowPercentage") or short) then
-		valueText = string.format("%d%%", item_frac * 100);
-	else
-		valueText = string.format("%d / %d", item_status.values.val, item_status.values.max);
-	end
-
-	-- determine color
-	valueText = TitanRepair_AutoHighlight(item_frac, valueText);
-
-	-- determine the name
-	local SlotID, itemColor, itemRarity;
-	local itemName = "";
-	local itemLabel = "";
-
-	if (not short or TitanGetVar(TITAN_REPAIR_ID, "ShowMostDamaged")) then
-		if item_status.slot ~=nil then
-			if item_status.values.item_name==nil
-			or item_status.values.item_name == "" then
-				valueText = valueText .. " " .. LIGHTYELLOW_FONT_COLOR_CODE..item_status.name.._G["FONT_COLOR_CODE_CLOSE"];
-				itemLabel = LIGHTYELLOW_FONT_COLOR_CODE..item_status.name.._G["FONT_COLOR_CODE_CLOSE"];
-			else
-				valueText = valueText .. " "
-					..item_status.values.item_color
-					..item_status.values.item_name;
-				itemLabel = item_status.values.item_color..item_status.values.item_name;
+	else -- Use own funds
+		debug_msg("Use own gold "
+			.." $"..tostring(cost)..""
+			.." gold: "..tostring(money)
+			)
+		if money > cost then
+			RepairAllItems()
+			-- report repair cost to chat (optional)
+			if TitanGetVar(TITAN_REPAIR_ID,"AutoRepairReport") then
+				DEFAULT_CHAT_FRAME:AddMessage(_G["GREEN_FONT_COLOR_CODE"]..L["TITAN_REPAIR"]..": ".."|r"..L["TITAN_REPAIR_REPORT_COST_CHAT"]..GetTextGSC(cost))
 			end
+			-- disable repair all icon in merchant
+			SetDesaturation(MerchantRepairAllIcon, 1);
+			MerchantRepairAllButton:Disable();
+			-- disable guild bank repair all icon in merchant
+			SetDesaturation(MerchantGuildBankRepairButtonIcon, 1);
+			MerchantGuildBankRepairButton:Disable();
 		else
-			valueText = valueText .. " " .. LIGHTYELLOW_FONT_COLOR_CODE..item_status.name.._G["FONT_COLOR_CODE_CLOSE"];
-			itemLabel = LIGHTYELLOW_FONT_COLOR_CODE..item_status.name.._G["FONT_COLOR_CODE_CLOSE"];
-		end
-	end
-
-	-- add repair cost
-	-- local item_cost = TitanRepair_GetCostStr(item_status.cost);
-	local item_cost = TitanPanelRepair_GetTextGSC(item_status.values.cost);
-	if (not TPR.MerchantisOpen) and (not TPR.WholeScanInProgress) then
-		if TitanGetVar(TITAN_REPAIR_ID, "DiscountFriendly") then
-			item_cost = TitanPanelRepair_GetTextGSC(item_status.values.cost * 0.95);
-		elseif TitanGetVar(TITAN_REPAIR_ID, "DiscountHonored") then
-			item_cost = TitanPanelRepair_GetTextGSC(item_status.values.cost * 0.90);
-		elseif TitanGetVar(TITAN_REPAIR_ID, "DiscountRevered") then
-			item_cost = TitanPanelRepair_GetTextGSC(item_status.values.cost * 0.85);
-		elseif TitanGetVar(TITAN_REPAIR_ID, "DiscountExalted") then
-			item_cost = TitanPanelRepair_GetTextGSC(item_status.values.cost * 0.80);
-		end
-	end
-
-	if ((not short) and item_cost and TitanGetVar(TITAN_REPAIR_ID,"ShowRepairCost")) then
-		if (not TPR.MerchantisOpen) and (not TPR.WholeScanInProgress) then
-			if TitanGetVar(TITAN_REPAIR_ID, "DiscountFriendly") then
-				valueText = valueText .. "\t" .. item_cost..TitanUtils_GetGreenText(" ("..FACTION_STANDING_LABEL5..")");
-			elseif TitanGetVar(TITAN_REPAIR_ID, "DiscountHonored") then
-				valueText = valueText .. "\t" .. item_cost..TitanUtils_GetGreenText(" ("..FACTION_STANDING_LABEL6..")");
-			elseif TitanGetVar(TITAN_REPAIR_ID, "DiscountRevered") then
-				valueText = valueText .. "\t" .. item_cost..TitanUtils_GetGreenText(" ("..FACTION_STANDING_LABEL7..")");
-			elseif TitanGetVar(TITAN_REPAIR_ID, "DiscountExalted") then
-				valueText = valueText .. "\t" .. item_cost..TitanUtils_GetGreenText(" ("..FACTION_STANDING_LABEL8..")");
-			else
-				valueText = valueText .. "\t" .. item_cost;
-			end
-		end
-	end
-
-	if (short) then
-		local pos;
-		pos = string.find(valueText, itemLabel, 1, true);
-		if (pos) and itemLabel~= "" then
-			valueText = string.sub(valueText,1,pos-1);
+			DEFAULT_CHAT_FRAME:AddMessage(_G["GREEN_FONT_COLOR_CODE"]..L["TITAN_REPAIR"]..": ".."|r"..L["TITAN_REPAIR_CANNOT_AFFORD"])
 		end
-		--valueText = string.gsub(valueText, itemLabel, "" );
-		TPR.LastKnownText = valueText;
-		TPR.LastKnownItemFrac = item_frac;
 	end
-
-	return valueText, itemLabel;
-
 end

+--[[ local
 -- **************************************************************************
--- NAME : TitanRepair_AutoHighlight (item_frac, valueText)
--- DESC : <research>
--- VARS : item_frac = <research>, valueText = <research>
+-- NAME : AutoHighlight (item_frac, valueText)
+-- DESC : Color (green / white / red) the given string (durability as % or x / y) based on the given percentage
+-- VARS :
+-- item_frac : float : the percentage of durability
+-- valueText : string : durability in color
 -- **************************************************************************
-function TitanRepair_AutoHighlight (item_frac, valueText)
-	-- I've changed this so when the ratio is 1, the text is green (green means OK for FPS, Latency, etc...)
-	-- beneath 0.91 (so it can be true for 0.90) the text is white
-	-- and red if the ratio reach 0.20
-	-- I didn't check for <= 0.90 or <= 0.20 because fractional eguality test is not acurate...
+--]]
+local function AutoHighlight (item_frac, valueText)
+	-- Basic threshold coloring
+	-- Do not check for <= 0.90 or <= 0.20 because fractional eguality test is not acurate...
 	if (TitanGetVar(TITAN_REPAIR_ID, "ShowColoredText")) then
-		if (item_frac == 0.0) then
+		if (item_frac < 21) then
 			valueText = TitanUtils_GetRedText(valueText);
-		elseif (item_frac < 0.21) then
-			valueText = TitanUtils_GetNormalText(valueText);
-		elseif (item_frac < 0.91) then
+		elseif (item_frac < 91) then
 			valueText = TitanUtils_GetHighlightText(valueText);
 		else
 			valueText = TitanUtils_GetGreenText(valueText);
@@ -818,147 +464,174 @@ function TitanRepair_AutoHighlight (item_frac, valueText)
 	return valueText;
 end

-function TitanRepair_GetCostStr(cost)
-	if (cost > 0) then
-		return TitanUtils_GetHighlightText(string.format("%.2fg" , cost / 10000));
-	end
-
-	return nil;
+--[[ Titan
+-- **************************************************************************
+-- NAME : TitanPanelRepairButton_OnLoad(self)
+-- DESC : Registers the plugin upon loading; OnShow to start; OnHide to stop
+-- **************************************************************************
+--]]
+function TitanPanelRepairButton_OnLoad(self)
+	local notes = "Rewritten Nov 2022 - Notable changes:\n"
+		.."- Uses less events; faster.\n"
+		.."- OnShow / OnHide now start / stop processing. Hopefully stopping 'protected' errors for those not running Repair.\n"
+		.."- Gated to once per sec except at Merchant and OnShow.\n"
+		.."- Left - Click added to force a scan - just in case.\n"
+		.."- Removed 'most damaged' item to save a few cycles.\n"
+	self.registry = {
+		id = TITAN_REPAIR_ID,
+		category = "Built-ins",
+		version = TITAN_VERSION,
+		menuText = L["REPAIR_LOCALE"]["menu"],
+		buttonTextFunction = "TitanPanelRepairButton_GetButtonText",
+		tooltipTitle = L["REPAIR_LOCALE"]["tooltip"],
+		tooltipTextFunction = "TitanPanelRepairButton_GetTooltipText",
+		icon = "Interface\\AddOns\\TitanRepair\\TitanRepair",
+		iconWidth = 16,
+		notes = notes,
+		controlVariables = {
+			ShowIcon = true,
+			ShowLabelText = true,
+			ShowColoredText = true,
+			DisplayOnRightSide = true,
+		},
+		savedVariables = {
+			ShowIcon = 1,
+			ShowLabelText = 1,
+			ShowUndamaged = false,
+			ShowPopup = false,
+			AutoRepair = false,
+			DiscountFriendly = false,
+			DiscountHonored = false,
+			DiscountRevered = false,
+			DiscountExalted = false,
+			ShowPercentage = false,
+			ShowColoredText = false,
+			ShowInventory = false,
+			ShowRepairCost = 1,
+			ShowMostDmgPer = 1,
+			UseGuildBank = false,
+			AutoRepairReport = false,
+			ShowItems = true,
+			ShowDiscounts = true,
+			ShowCosts = true,
+			DisplayOnRightSide = false,
+		}
+	};
 end

-local function RepairSumTotals()
-	local sums = {}
-	if (not TPR.WholeScanInProgress) then
+--[[ Titan
+-- **************************************************************************
+-- NAME : TitanPanelRepairButton_OnEvent(self, event, a1, ...)
+-- DESC : This section will grab the events registered to the add on and act on them
+-- **************************************************************************
+--]]
+function TitanPanelRepairButton_OnEvent(self, event, a1, ...)
+
+	local msg = "Event"
+		.." "..tostring(event)
+		.." "..tostring(a1)
+		.."..."
+	debug_msg(msg)

-		local cost = 0;
-		local sum = 0;
-		local costStr = 0;
-		local item_status = {};
-		local item_frac = 0;
-		local frac_counter = 0;
-		local total_frac = 0;
-		local inv_frac = 1 ;
-		local duraitems = 0;
+	if (event == "PLAYER_REGEN_ENABLED")
+	or (event == "UNIT_INVENTORY_CHANGED" and a1 == "player")
+	or (event == "UPDATE_INVENTORY_DURABILITY")
+	then
+		Scan(event, false)
+	end

-		-- calculate the totals
-		-- traverse through the durability table and get the damage value,
-		-- item_frac = 1 (undamaged), item_frac < 1 (damaged)
-		for i = 1, table.getn(TPR.ITEM_STATUS) do
-			item_status = TPR.ITEM_STATUS[i].values;
-			item_frac = item_status.item_frac;
-			-- set the inventory damage to a seperate variable
-			if TPR.ITEM_STATUS[i].name == INVENTORY_TOOLTIP then
-				inv_frac = item_frac;
-				sums.inven_percent = item_frac ;
-				sums.inven_cost = item_status.cost
-				item_frac = 0;
-			end
+	if (event == "PLAYER_MONEY" and TR.MerchantisOpen == true and CanMerchantRepair())
+	then
+		Scan(event, true)
+	end

-			if (item_status.max ~=0 and TPR.ITEM_STATUS[i].name ~= INVENTORY_TOOLTIP) then
-				frac_counter = frac_counter + item_frac;
-				duraitems = duraitems + 1;
-				sums.equip_cost = (sums.equip_cost or 0) + item_status.cost
+	if (event == "MERCHANT_SHOW") then
+		TR.MerchantisOpen = true;
+		local canRepair = CanMerchantRepair();
+		if not canRepair then
+			return;
+		end
+		self:RegisterEvent("PLAYER_MONEY") -- this prevents scans on looting...
+		if TitanGetVar(TITAN_REPAIR_ID,"ShowPopup") == 1 then
+			if (TR.repair_total > 0) then
+				TR.MONEY = repairCost;
+				StaticPopup_Show("REPAIR_CONFIRMATION");
 			end
+		end
+		-- handle auto-repair
+		if (TitanGetVar(TITAN_REPAIR_ID,"AutoRepair") == 1) then
+			if (TR.repair_total > 0) then
+				TitanRepair_RepairItems();
+				Scan("MERCHANT_SHOW - AutoRepair", true)
+			end
+		end
+
+	end

-			cost = item_status.cost;
-			sum = sum + cost;
-		end  -- for loop
+	if ( event == "MERCHANT_CLOSED" ) then
+		TR.MerchantisOpen = false;

-		-- failsafe if you have no item with a valid durability value
-		if duraitems == 0 then
-			duraitems = 1;
-			frac_counter = 1;
-		end
+		StaticPopup_Hide("REPAIR_CONFIRMATION");
+		-- When an object is repaired in a bag, the BAG_UPDATE event is not sent so we rescan all
+		Scan("MERCHANT_CLOSED",  true)
+		self:UnregisterEvent("PLAYER_MONEY");
+	end

-		--total_frac = frac_counter / 11 ;
-		sums.total_percent = (total_frac + inv_frac) / 2;
-		sums.total_cost = sum
-		sums.equip_percent = frac_counter / duraitems;
+	local msg = "...Event"
+		.." "..tostring(event)
+		.." ".."complete"
+	debug_msg(msg)
+end

-		sums.scan = false
+function TitanPanelRepairButton_OnClick(self, button)
+	if button == "LeftButton" and IsShiftKeyDown() then
+		TitanUtils_CloseAllControlFrames();
+		if (TitanPanelRightClickMenu_IsVisible()) then
+			TitanPanelRightClickMenu_Close();
+		end
+		Scan("User Sh+L click", true)
 	else
-		sums.scan = true
+		TitanPanelButton_OnClick(self, button);
 	end
-
-	return sums
 end
+
+--[[ Titan
 -- **************************************************************************
 -- NAME : TitanPanelRepairButton_GetButtonText(id)
--- DESC : <research>
--- VARS : id = <research>
+-- DESC : Determine the plugin button text based on last scan values and user preferences
+-- VARS : id = plugin id (Repair)
+-- OUT :
+-- string : plugin label
+-- string : plugin text / values
 -- **************************************************************************
+--]]
 function TitanPanelRepairButton_GetButtonText(id)
-	local text, itemLabel = TitanRepair_GetStatusStr(TPR.INDEX, 1);
+	local text, itemLabel = "", "" -- TitanRepair_GetStatusStr(TPR.INDEX, 1);
 	local itemNamesToShow = "";
 	local itemPercent = 0
 	local itemCost = 0
-	if TitanGetVar(TITAN_REPAIR_ID, "ShowMostDamaged") then
-		itemPercent = (text or "")
-		itemNamesToShow = (itemLabel or "")
-	end
-	-- supports turning off labels
-	if (not TPR.WholeScanInProgress) then

-		local cost = 0;
-		local sum = 0;
-		local costStr = 0;
-		local item_status = {};
-		local item_frac = 0;
-		local frac_counter = 0;
-		local total_frac = 0;
-		local inv_frac = 1 ;
-		local duraitems = 0;
-		local discountlabel = "";
-		local canRepair = false;
-
-		if TitanGetVar(TITAN_REPAIR_ID, "ShowMostDamaged") then  -- most damaged
-			--item_status = TPR.ITEM_STATUS[TPR.INDEX].values;
-			total_frac = TPR.ITEM_STATUS[TPR.INDEX].values.item_frac;
-			sum = TPR.ITEM_STATUS[TPR.INDEX].values.cost
-		else -- calculate the totals
-			-- traverse through the durability table and get the damage value,
-			-- item_frac = 1 (undamaged), item_frac < 1 (damaged)
-			for i = 1, table.getn(TPR.ITEM_STATUS) do
-				item_status = TPR.ITEM_STATUS[i].values;
-				item_frac = item_status.item_frac;
-				-- set the inventory damage to a seperate variable
-				if TPR.ITEM_STATUS[i].name == INVENTORY_TOOLTIP then
-					inv_frac = item_frac;
-					item_frac = 0;
-				end
-
-				if (item_status.max ~=0 and TPR.ITEM_STATUS[i].name ~= INVENTORY_TOOLTIP) then
-					frac_counter = frac_counter + item_frac;
-					duraitems = duraitems + 1;
-				end
-
-				cost = item_status.cost;
-				sum = sum + cost;
-			end  -- for loop
-
-			-- failsafe if you have no item with a valid durability value
-			if duraitems == 0 then
-				duraitems = 1;
-				frac_counter = 1;
-			end
-
-			--total_frac = frac_counter / 11 ;
-			total_frac = frac_counter / duraitems ;
-
-			if (TitanGetVar(TITAN_REPAIR_ID,"ShowInventory") == 1) then
-				total_frac = (total_frac + inv_frac) / 2;
-			end
-		end  -- if "ShowMostDamaged"
+	-- supports turning off labels
+	if TR.scan_running then
+		return L["REPAIR_LOCALE"]["button"],
+			text .. " (" .. L["REPAIR_LOCALE"]["WholeScanInProgress"] .. ")";
+	else
+		local costStr = 0;
+		local discountlabel = "";

-		text = string.format("%d%%", total_frac * 100);
-		text = TitanRepair_AutoHighlight (total_frac, text);
+		-- calculate the totals
+		dura_total = TR.dur_total
+		bags_dur = TR.repair_bags.dur
+		equip_dur = TR.repair_equip.dur

-		-- check to see if a merchant that can repair is open
-		if TPR.MerchantisOpen then
-			canRepair = CanMerchantRepair();
-		end
+		text = string.format("%d%%", dura_total);
+		text = AutoHighlight (dura_total, text);
+		text = text.." " -- total %

-		if (not TPR.MerchantisOpen or (TPR.MerchantisOpen and not canRepair)) then
+		-- show cost per the user choice
+		local sum = TR.repair_total
+		if (sum > 0 and TitanGetVar(TITAN_REPAIR_ID,"ShowRepairCost")) then
+			-- if a discount was requested by user
 			if TitanGetVar(TITAN_REPAIR_ID, "DiscountFriendly") then
 				sum = sum * 0.95;
 				discountlabel = FACTION_STANDING_LABEL5;
@@ -971,19 +644,8 @@ function TitanPanelRepairButton_GetButtonText(id)
 			elseif TitanGetVar(TITAN_REPAIR_ID, "DiscountExalted") then
 				sum = sum * 0.80;
 				discountlabel = FACTION_STANDING_LABEL8;
-			end  -- if merchant
-		end  -- if discounts
-
-		-- select which % to show
-		if (TitanGetVar(TITAN_REPAIR_ID,"ShowMostDamaged")) then
-			text = itemPercent.." " -- item %
-		else
-			text = text.." " -- total %
-		end
-
-		-- show cost per the user choice
-		if (sum > 0 and TitanGetVar(TITAN_REPAIR_ID,"ShowRepairCost")) then
-			costStr = "(".. TitanPanelRepair_GetTextGSC(sum)..") ";
+			end
+			costStr = "(".. GetTextGSC(sum)..") ";
 			discountlabel = GREEN_FONT_COLOR_CODE..discountlabel..FONT_COLOR_CODE_CLOSE.." "
 		else
 			-- user does not want to see cost; clear the reputation also
@@ -997,143 +659,152 @@ function TitanPanelRepairButton_GetButtonText(id)
 			..costStr
 			..discountlabel
 			..itemNamesToShow
---			..(TitanGetVar(TITAN_REPAIR_ID,"ShowInventory" and "*" or "^"))
-	else
-		return L["REPAIR_LOCALE"]["button"],
-			text .. " (" .. L["REPAIR_LOCALE"]["WholeScanInProgress"] .. ")";
 	end
 end

-
+--[[ Titan
 -- **************************************************************************
 -- NAME : TitanPanelRepairButton_GetTooltipText()
--- DESC : <research>
+-- DESC : Create the Repair tool tip based on last scan and user preferences
 -- **************************************************************************
+--]]
 function TitanPanelRepairButton_GetTooltipText()
-
 	local out = "";
-	local str = "";
-	local label = "";
 	local cost = 0;
-	local sum = 0;
-
-	-- Checking if the user wants to show items several times looks odd
-	-- but we need to calc 'sum' and we need to format the tooltip
-	if (TitanGetVar(TITAN_REPAIR_ID,"ShowItems")) then
-		out = out..TitanUtils_GetGoldText(L["REPAIR_LOCALE"]["Items"])..TitanUtils_GetHighlightText("\n")
-	end
-	for i = 1, table.getn(TPR.ITEM_STATUS) do
-		cost = TPR.ITEM_STATUS[i].values.cost;
-		str, label = TitanRepair_GetStatusStr(i);
+	local sum = TR.repair_total

-		sum = sum + cost;
+	local msg = "Tooltip Start "
+		.." items:"..tostring(TitanGetVar(TITAN_REPAIR_ID,"ShowItems"))
+		.." discounts:"..tostring(TitanGetVar(TITAN_REPAIR_ID,"ShowDiscounts"))
+		.." costs:"..tostring(TitanGetVar(TITAN_REPAIR_ID,"ShowCosts"))
+		.." guild:"..tostring(TitanGetVar(TITAN_REPAIR_ID,"UseGuildBank"))
+	debug_msg(msg)

-		if (TitanGetVar(TITAN_REPAIR_ID,"ShowItems")) then
-			if ((str) and (TitanGetVar(TITAN_REPAIR_ID,"ShowUndamaged") or (cost > 0))) then
-				if TitanGetVar(TITAN_REPAIR_ID,"IgnoreThrown")
-					and TPR.ITEM_STATUS[i].values.item_subtype == INVTYPE_THROWN then
-					-- do not show it per user request
+	if (TitanGetVar(TITAN_REPAIR_ID,"ShowItems")) then
+		out = out..TitanUtils_GetGoldText(L["REPAIR_LOCALE"]["Items"]).."\n"
+
+		local num_items = 0
+		-- walk items saved from the scan
+		for slotName, slotID in pairs(Enum.InventoryType) do
+			if TR.equip_list[slotName] then
+				-- determine the percent or value per user request
+				local valueText = ""
+--[[
+				msg = ""
+					.." '"..tostring(slotName).."'"
+					.." '"..tostring(TR.equip_list[slotName].name).."'"
+					.." "..tostring(TR.equip_list[slotName].quality)
+					.." "..tostring(TR.equip_list[slotName].cost)
+					.." "..tostring(TR.equip_list[slotName].dur_per).."%"
+					.." "..tostring(TR.equip_list[slotName].dur_cur)
+					.."/"..tostring(TR.equip_list[slotName].dur_max)
+				debug_msg(msg)
+--]]
+				if (TitanGetVar(TITAN_REPAIR_ID,"ShowPercentage")) then
+					valueText = string.format("%d%%", TR.equip_list[slotName].dur_per)
 				else
-					out = out .. str .. "\n";
+					valueText = string.format("%d/%d", TR.equip_list[slotName].dur_cur, TR.equip_list[slotName].dur_max)
 				end
+				-- % color
+				out = out..AutoHighlight(TR.equip_list[slotName].dur_per, valueText).."  "
+				-- name with color
+				out = out.."|c"..TR.equip_list[slotName].color..TR.equip_list[slotName].name.._G["FONT_COLOR_CODE_CLOSE"]
+				-- add column
+				out = out.."\t"
+				-- add cost
+				out = out..GetTextGSC(TR.equip_list[slotName].cost)
+				out = out.."\n"
+
+				num_items = num_items + 1
+			else
+				-- slot is empty or not 'damaged'
 			end
 		end
+
+		if num_items == 0 then
+			-- All items are at 100%
+			out = out..TitanUtils_GetHighlightText("No items damaged").."\n"
+		end
+		debug_msg(tostring("Items shown : "..num_items))
 	end
-	if (TitanGetVar(TITAN_REPAIR_ID,"ShowItems")) then
+
+	out = out.."\n" -- spacer
+	if (TitanGetVar(TITAN_REPAIR_ID,"ShowDiscounts")) then
+		if (sum > 0) then
+			out = out..TitanUtils_GetGoldText(L["REPAIR_LOCALE"]["Discounts"])..TitanUtils_GetHighlightText("").."\n"
+			out = out.. TitanUtils_GetHighlightText(L["REPAIR_LOCALE"]["normal"]) .. "\t" .. GetTextGSC(sum).."\n"
+			out = out.. TitanUtils_GetHighlightText(L["REPAIR_LOCALE"]["friendly"]) .. "\t" .. GetTextGSC(sum * 0.95).."\n"
+			out = out.. TitanUtils_GetHighlightText(L["REPAIR_LOCALE"]["honored"]) .. "\t" .. GetTextGSC(sum * 0.90).."\n"
+			out = out.. TitanUtils_GetHighlightText(L["REPAIR_LOCALE"]["revered"]) .. "\t" .. GetTextGSC(sum * 0.85).."\n"
+			out = out.. TitanUtils_GetHighlightText(L["REPAIR_LOCALE"]["exalted"]) .. "\t" .. GetTextGSC(sum * 0.80).."\n"
+		else
+			out = out..TitanUtils_GetGoldText(L["REPAIR_LOCALE"]["Discounts"]).."\t".."|cffa0a0a0"..NONE.."|r".."\n"
+		end
 		out = out.."\n"
 	end

-	if (TitanGetVar(TITAN_REPAIR_ID,"ShowDiscounts")) then
+	if (TitanGetVar(TITAN_REPAIR_ID,"ShowCosts")) then
 		if (sum > 0) then
-			out = out..TitanUtils_GetGoldText(L["REPAIR_LOCALE"]["Discounts"])..TitanUtils_GetHighlightText("")
-			local costStr = TitanPanelRepair_GetTextGSC(sum);
-			local costfrStr = TitanPanelRepair_GetTextGSC(sum * 0.95);
-			local costhonStr = TitanPanelRepair_GetTextGSC(sum * 0.90);
-			local costrevStr = TitanPanelRepair_GetTextGSC(sum * 0.85);
-			local costexStr = TitanPanelRepair_GetTextGSC(sum * 0.80);
-			if (costStr) then
-				if TPR.MerchantisOpen then
-					out = out .. "\n" .. TitanUtils_GetHighlightText(REPAIR_COST) .. " " .. costStr;
-					local canRepair = CanMerchantRepair();
-					if not canRepair then
-						out = out .. "\n"
-							.. GREEN_FONT_COLOR_CODE..L["REPAIR_LOCALE"]["badmerchant"];
-					end
+			out = out..TitanUtils_GetGoldText(L["REPAIR_LOCALE"]["Costs"]).." ".."\n"
+			out = out.. TitanUtils_GetHighlightText(L["REPAIR_LOCALE"]["CostEquip"]).." : ".. "\t" .. GetTextGSC(TR.repair_equip.total).."\n"
+			out = out.. TitanUtils_GetHighlightText(L["REPAIR_LOCALE"]["CostBag"]).." : ".. "\t" .. GetTextGSC(TR.repair_bags.total).."\n"
+			out = out.. "---".. "\t" .. "---".."\n"
+			out = out.. TitanUtils_GetHighlightText(REPAIR_COST).. "\t" .. GetTextGSC(TR.repair_total).."\n"
+		else
+			out = out..TitanUtils_GetGoldText(L["REPAIR_LOCALE"]["Costs"]).."\t".."|cffa0a0a0"..NONE.."|r".."\n"
+		end
+		out = out .. "\n"
+	end
+
+	-- Show the guild - if player is in one
+	--GUILDBANK_REPAIR
+	if IsInGuild() then
+		out = out..TitanUtils_GetGoldText(GUILD).."\n"
+		local name, rank, index, realm = GetGuildInfo("player")
+		out = out..TitanUtils_GetHighlightText(name).." : ".."\t"..TitanUtils_GetHighlightText(rank).."\n"
+
+		if TitanGetVar(TITAN_REPAIR_ID, "UseGuildBank") then
+			if CanGuildBankRepair() then
+				if IsGuildLeader() then
+					-- Can use the whole bank amount...
+					out = out..TitanUtils_GetHighlightText(WITHDRAW.." "..AVAILABLE).."\t" ..UNLIMITED.."\n"
 				else
-					out = out .. "\n" .. TitanUtils_GetHighlightText(L["REPAIR_LOCALE"]["normal"]) .. "\t" .. costStr;
-				end
-				if (not TPR.MerchantisOpen) and (not TPR.WholeScanInProgress) then
-					out = out .. "\n" .. TitanUtils_GetHighlightText(L["REPAIR_LOCALE"]["friendly"]) .. "\t" .. costfrStr;
-					out = out .. "\n" .. TitanUtils_GetHighlightText(L["REPAIR_LOCALE"]["honored"]) .. "\t" .. costhonStr;
-					out = out .. "\n" .. TitanUtils_GetHighlightText(L["REPAIR_LOCALE"]["revered"]) .. "\t" .. costrevStr;
-					out = out .. "\n" .. TitanUtils_GetHighlightText(L["REPAIR_LOCALE"]["exalted"]) .. "\t" .. costexStr;
+					local withdrawLimit = GetGuildBankWithdrawMoney()
+					out = out..TitanUtils_GetHighlightText(WITHDRAW.." "..AVAILABLE).."\t"..GetTextGSC(withdrawLimit).."\n"
+					if (withdrawLimit >= sum) then
+						-- funds available
+					else
+						out = out.. TitanUtils_GetRedText(GUILDBANK_REPAIR_INSUFFICIENT_FUNDS).."\n"
+					end
 				end
+			else
+				out = out..TitanUtils_GetHighlightText(WITHDRAW.." "..AVAILABLE).."\t".."|cffa0a0a0"..NONE.."|r".."\n"
 			end
-			out = out.."\n\n"
+		else
+			out = out..TitanUtils_GetHighlightText(L["TITAN_REPAIR_GBANK_USEFUNDS"]).." : ".."\t"..TitanUtils_GetHighlightText(tostring(false)).."\n"
 		end
+		out = out .. "\n"
 	end

-	if (TitanGetVar(TITAN_REPAIR_ID,"ShowCosts")) then
-		out = out..TitanUtils_GetGoldText(L["REPAIR_LOCALE"]["Costs"])
-		local sums = RepairSumTotals()
-		out = out .. "\n" .. TitanUtils_GetHighlightText(L["REPAIR_LOCALE"]["CostTotal"]).. "\t" .. TitanPanelRepair_GetTextGSC(sums.total_cost)
-		out = out .. "\n\n" .. TitanUtils_GetHighlightText(L["REPAIR_LOCALE"]["CostEquip"]).. "\t" .. TitanPanelRepair_GetTextGSC(sums.equip_cost)
-		out = out .. "\n" .. TitanUtils_GetHighlightText(L["REPAIR_LOCALE"]["CostBag"]).. "\t" .. TitanPanelRepair_GetTextGSC(sums.inven_cost)
-		out = out .. "\n\n"
-	end
-
-	return out;
-end
+	out = out..L["REPAIR_LOCALE"]["AutoRepitemlabel"].." : ".."\t"
+		..TitanUtils_GetHighlightText(tostring(TitanGetVar(TITAN_REPAIR_ID, "AutoRepair") and true or false)).."\n"
+	out = out..L["REPAIR_LOCALE"]["showinventory"].." : ".."\t"
+		..TitanUtils_GetHighlightText(tostring(TitanGetVar(TITAN_REPAIR_ID, "ShowInventory") and true or false)).."\n"
+	out = out.."\n"

--- **************************************************************************
--- NAME : TitanPanelRepair_GetGSC(money)
--- DESC : <research>
--- VARS : money = <research>
--- **************************************************************************
-function TitanPanelRepair_GetGSC(money)
-	local neg = false;
-	if (money == nil) then money = 0; end
-	if (money < 0) then
-		neg = true;
-		money = money * -1;
-	end
-	local g = math.floor(money / 10000);
-	local s = math.floor((money - (g * 10000)) / 100);
-	local c = math.floor(money - (g * 10000) - (s * 100));
-	return g, s, c, neg;
-end
+	out = out..TitanUtils_GetGreenText("Hint: Shift + Left click to force a scan of repair info.")

-function TitanPanelRepair_GetTextGSC(money)
-	local GSC_GOLD = "ffd100";
-	local GSC_SILVER = "e6e6e6";
-	local GSC_COPPER = "c8602c";
-	local GSC_START = "|cff%s%d|r";
-	local GSC_PART = ".|cff%s%02d|r";
-	local GSC_NONE = "|cffa0a0a0" .. NONE .. "|r";
-	local g, s, c, neg = TitanPanelRepair_GetGSC(money);
-	local gsc = "";
-	if (g > 0) then
-		gsc = format(GSC_START, GSC_GOLD, g);
-		gsc = gsc .. format(GSC_PART, GSC_SILVER, s);
-		gsc = gsc .. format(GSC_PART, GSC_COPPER, c);
-	elseif (s > 0) then
-		gsc = format(GSC_START, GSC_SILVER, s);
-		gsc = gsc .. format(GSC_PART, GSC_COPPER, c);
-	elseif (c > 0) then
-		gsc = gsc .. format(GSC_START, GSC_COPPER, c);
-	else
-		gsc = GSC_NONE;
-	end
-	if (neg) then gsc = "(" .. gsc .. ")"; end
-	return gsc;
+	return out, itemLabel
 end

+--[[ Titan
 -- **************************************************************************
 -- NAME : TitanPanelRightClickMenu_PrepareRepairMenu()
--- DESC : <research>
+-- DESC : Create the Repair right click menu
 -- **************************************************************************
+--]]
 function TitanPanelRightClickMenu_PrepareRepairMenu()
-local info;
+	local info;

 	-- level 2
 	if TitanPanelRightClickMenu_GetDropdownLevel() == 2 then
@@ -1143,7 +814,7 @@ local info;
 			info = {};
 			info.text = L["REPAIR_LOCALE"]["buttonNormal"];
 			info.checked = not TitanGetVar(TITAN_REPAIR_ID,"DiscountFriendly") and not TitanGetVar(TITAN_REPAIR_ID,"DiscountHonored") and not TitanGetVar(TITAN_REPAIR_ID,"DiscountRevered") and not TitanGetVar(TITAN_REPAIR_ID,"DiscountExalted");
-			info.disabled = TPR.MerchantisOpen;
+			info.disabled = TR.MerchantisOpen;
 			info.func = function()
 				TitanSetVar(TITAN_REPAIR_ID,"DiscountFriendly", nil)
 				TitanSetVar(TITAN_REPAIR_ID,"DiscountHonored", nil)
@@ -1156,7 +827,7 @@ local info;
 			info = {};
 			info.text = L["REPAIR_LOCALE"]["buttonFriendly"];
 			info.checked = TitanGetVar(TITAN_REPAIR_ID,"DiscountFriendly");
-			info.disabled = TPR.MerchantisOpen;
+			info.disabled = TR.MerchantisOpen;
 			info.func = function()
 				TitanSetVar(TITAN_REPAIR_ID,"DiscountFriendly", 1)
 				TitanSetVar(TITAN_REPAIR_ID,"DiscountHonored", nil)
@@ -1169,7 +840,7 @@ local info;
 			info = {};
 			info.text = L["REPAIR_LOCALE"]["buttonHonored"];
 			info.checked = TitanGetVar(TITAN_REPAIR_ID,"DiscountHonored");
-			info.disabled = TPR.MerchantisOpen;
+			info.disabled = TR.MerchantisOpen;
 			info.func = function()
 				TitanSetVar(TITAN_REPAIR_ID,"DiscountFriendly", nil)
 				TitanSetVar(TITAN_REPAIR_ID,"DiscountHonored", 1)
@@ -1182,7 +853,7 @@ local info;
 			info = {};
 			info.text = L["REPAIR_LOCALE"]["buttonRevered"];
 			info.checked = TitanGetVar(TITAN_REPAIR_ID,"DiscountRevered");
-			info.disabled = TPR.MerchantisOpen;
+			info.disabled = TR.MerchantisOpen;
 			info.func = function()
 				TitanSetVar(TITAN_REPAIR_ID,"DiscountFriendly", nil)
 				TitanSetVar(TITAN_REPAIR_ID,"DiscountHonored", nil)
@@ -1195,7 +866,7 @@ local info;
 			info = {};
 			info.text = L["REPAIR_LOCALE"]["buttonExalted"];
 			info.checked = TitanGetVar(TITAN_REPAIR_ID,"DiscountExalted");
-			info.disabled = TPR.MerchantisOpen;
+			info.disabled = TR.MerchantisOpen;
 			info.func = function()
 				TitanSetVar(TITAN_REPAIR_ID,"DiscountFriendly", nil)
 				TitanSetVar(TITAN_REPAIR_ID,"DiscountHonored", nil)
@@ -1210,53 +881,22 @@ local info;
 			TitanPanelRightClickMenu_AddTitle(L["TITAN_PANEL_OPTIONS"], TitanPanelRightClickMenu_GetDropdownLevel());

 			info = {};
-			info.text = L["REPAIR_LOCALE"]["percentage"];
---			info.func = TitanRepair_ShowPercentage;
-			info.func = function()
-				TitanToggleVar(TITAN_REPAIR_ID, "ShowPercentage");
-				TitanPanelButton_UpdateButton(TITAN_REPAIR_ID);
-			end
-			info.checked = TitanGetVar(TITAN_REPAIR_ID,"ShowPercentage");
-			TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());
-
-			info = {};
-			info.text = L["REPAIR_LOCALE"]["mostdamaged"];
-			info.func = TitanRepair_ShowMostDamaged;
-			info.checked = TitanGetVar(TITAN_REPAIR_ID,"ShowMostDamaged");
-			TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());
-
-			info = {};
-			info.text = L["REPAIR_LOCALE"]["undamaged"];
-			info.func = TitanRepair_ShowUndamaged;
-			info.checked = TitanGetVar(TITAN_REPAIR_ID,"ShowUndamaged");
-			TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());
-
-			info = {};
 			info.text = L["REPAIR_LOCALE"]["showinventory"];
-			info.func = TitanRepair_ShowInventory;
+			info.func = function()
+				TitanToggleVar(TITAN_REPAIR_ID, "ShowInventory");
+				Scan("Calc inventory durability", true)
+				end
 			info.checked = TitanGetVar(TITAN_REPAIR_ID,"ShowInventory");
 			TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());

 			info = {};
 			info.text = L["REPAIR_LOCALE"]["ShowRepairCost"];  --"Show Repair Cost"
-			info.func = TitanRepair_ShowRepairCost;
+			info.func = function()
+				TitanToggleVar(TITAN_REPAIR_ID, "ShowRepairCost");
+				TitanPanelButton_UpdateButton(TITAN_REPAIR_ID);
+				end
 			info.checked = TitanGetVar(TITAN_REPAIR_ID,"ShowRepairCost");
 			TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());
-
-			info = {};
-			info.text = L["REPAIR_LOCALE"]["showdurabilityframe"];
-			info.func = function()
-			TitanToggleVar(TITAN_REPAIR_ID, "ShowDurabilityFrame");
-			TitanRepair_DurabilityFrame();
-			end
-			info.checked = TitanGetVar(TITAN_REPAIR_ID,"ShowDurabilityFrame");
-			TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());
-
-			info = {};
-			info.text = L["REPAIR_LOCALE"]["ignoreThrown"];
-			info.func = TitanRepair_IgnoreThrown;
-			info.checked = TitanGetVar(TITAN_REPAIR_ID,"IgnoreThrown");
-			TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());
 		end

 		if TitanPanelRightClickMenu_GetDropdMenuValue() == "AutoRepair" then
@@ -1264,13 +904,23 @@ local info;

 			info = {};
 			info.text = L["REPAIR_LOCALE"]["popup"];
-			info.func = TitanRepair_ShowPop;
+			info.func = function()
+				TitanToggleVar(TITAN_REPAIR_ID, "ShowPopup");
+				if TitanGetVar(TITAN_REPAIR_ID,"ShowPopup") and TitanGetVar(TITAN_REPAIR_ID,"AutoRepair") then
+					TitanSetVar(TITAN_REPAIR_ID,"AutoRepair",nil);
+				end
+				end
 			info.checked = TitanGetVar(TITAN_REPAIR_ID,"ShowPopup");
 			TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());

 			info = {};
 			info.text = L["REPAIR_LOCALE"]["AutoRepitemlabel"];
-			info.func = TitanRepair_AutoRep;
+			info.func = function()
+				TitanToggleVar(TITAN_REPAIR_ID, "AutoRepair");
+				if TitanGetVar(TITAN_REPAIR_ID,"AutoRepair") and TitanGetVar(TITAN_REPAIR_ID,"ShowPopup") then
+					TitanSetVar(TITAN_REPAIR_ID,"ShowPopup",nil);
+				end
+				end
 			info.checked = TitanGetVar(TITAN_REPAIR_ID,"AutoRepair");
 			TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());

@@ -1279,20 +929,7 @@ local info;
 			info.func = function() TitanToggleVar(TITAN_REPAIR_ID, "AutoRepairReport"); end
 			info.checked = TitanGetVar(TITAN_REPAIR_ID,"AutoRepairReport");
 			TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());
-		end

-		if TitanPanelRightClickMenu_GetDropdMenuValue() == "GuildBank" then
-			totalGBCP = GetGuildBankMoney();
-			withdrawGBCP = GetGuildBankWithdrawMoney();
-			if IsGuildLeader() ~= true then
-				withdrawGB = TitanPanelRepair_GetTextGSC(withdrawGBCP);
-			end
-			totalGB = TitanPanelRepair_GetTextGSC(GetGuildBankMoney());
-			if (totalGBCP < withdrawGBCP) or IsGuildLeader() == true then
-				withdrawGB = totalGB;
-			end
-			TitanPanelRightClickMenu_AddTitle(L["TITAN_REPAIR_GBANK_TOTAL"].." "..totalGB, TitanPanelRightClickMenu_GetDropdownLevel());
-			TitanPanelRightClickMenu_AddTitle(L["TITAN_REPAIR_GBANK_WITHDRAW"].." "..withdrawGB, TitanPanelRightClickMenu_GetDropdownLevel());
 			info = {}
 			info.text = L["TITAN_REPAIR_GBANK_USEFUNDS"]
 			info.func = function() TitanToggleVar(TITAN_REPAIR_ID, "UseGuildBank"); end
@@ -1311,6 +948,25 @@ local info;
 			TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());

 			info = {};
+			info.text = L["REPAIR_LOCALE"]["undamaged"];
+			info.func = function()
+				TitanToggleVar(TITAN_REPAIR_ID, "ShowUndamaged");
+				end
+			info.checked = TitanGetVar(TITAN_REPAIR_ID,"ShowUndamaged");
+			TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());
+
+			TitanPanelRightClickMenu_AddSeparator(TitanPanelRightClickMenu_GetDropdownLevel());
+
+			info = {};
+			info.text = L["REPAIR_LOCALE"]["percentage"];
+			info.func = function()
+				TitanToggleVar(TITAN_REPAIR_ID, "ShowPercentage");
+				TitanPanelButton_UpdateButton(TITAN_REPAIR_ID);
+			end
+			info.checked = TitanGetVar(TITAN_REPAIR_ID,"ShowPercentage");
+			TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());
+
+			info = {};
 			info.text = L["REPAIR_LOCALE"]["ShowDiscounts"];
 			info.func = function() TitanToggleVar(TITAN_REPAIR_ID, "ShowDiscounts"); end
 			info.checked = TitanGetVar(TITAN_REPAIR_ID,"ShowDiscounts");
@@ -1344,7 +1000,7 @@ local info;
 	info.value = "AutoRepair"
 	info.hasArrow = 1;
 	TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());
-
+--[[
 	local guildName, _, _ = GetGuildInfo("player")
 	info = {};
 	info.notCheckable = true
@@ -1356,7 +1012,7 @@ local info;
 		info.disabled = true
 	end
 	TitanPanelRightClickMenu_AddButton(info, TitanPanelRightClickMenu_GetDropdownLevel());
-
+--]]
 	info = {};
 	info.notCheckable = true
 	info.text = L["REPAIR_LOCALE"]["discount"];
@@ -1374,186 +1030,12 @@ local info;
 	TitanPanelRightClickMenu_AddControlVars(TITAN_REPAIR_ID)
 end

-
--- **************************************************************************
--- NAME : TitanRepair_ShowPercentage()
--- DESC : <research>
--- **************************************************************************
-function TitanRepair_ShowPercentage()
-	TitanToggleVar(TITAN_REPAIR_ID, "ShowPercentage");
-	TitanPanelButton_UpdateButton(TITAN_REPAIR_ID);
-end
-
--- **************************************************************************
--- NAME : TitanRepair_IgnoreThrown()
--- DESC : <research>
--- **************************************************************************
-function TitanRepair_IgnoreThrown()
-	TitanToggleVar(TITAN_REPAIR_ID, "IgnoreThrown");
-	-- Need to recalc the cost at least. May have to change most damaged item.
-	TitanPanelRepairButton_ScanAllItems()
-	TitanPanelRepairButton_OnUpdate()
-	TitanPanelButton_UpdateButton(TITAN_REPAIR_ID);
-end
-
--- **************************************************************************
--- NAME : TitanRepair_ShowRepairCost()
--- DESC : <research>
--- **************************************************************************
-function TitanRepair_ShowRepairCost()
-	TitanToggleVar(TITAN_REPAIR_ID, "ShowRepairCost");
-	TitanPanelButton_UpdateButton(TITAN_REPAIR_ID);
-end
-
--- **************************************************************************
--- NAME : TitanRepair_ShowDurabilityFrame()
--- DESC : <research>
--- **************************************************************************
-function TitanRepair_DurabilityFrame(isOnShow)
-	if TitanGetVar(TITAN_REPAIR_ID,"ShowDurabilityFrame") then
-		-- Prevent a circular reference by checking if function was triggered by our SecureHook into OnShow.
-		-- If OnShow didn't trigger this just do whatever Blizzard wants.
-		if not isOnShow then DurabilityFrameMixin:SetAlerts() end -- DurabilityFrame_SetAlerts() end
-	else
-		-- Always hide this frame since user wants it hidden.
-		DurabilityFrame:Hide()
-	end
-end
-
--- **************************************************************************
--- NAME : TitanRepair_ShowMostDamaged()
--- DESC : <research>
--- **************************************************************************
-function TitanRepair_ShowMostDamaged()
-	TitanToggleVar(TITAN_REPAIR_ID, "ShowMostDamaged");
-	TitanPanelButton_UpdateButton(TITAN_REPAIR_ID);
-end
-
--- **************************************************************************
--- NAME : TitanRepair_ShowUndamaged()
--- DESC : <research>
--- **************************************************************************
-function TitanRepair_ShowUndamaged()
-	TitanToggleVar(TITAN_REPAIR_ID, "ShowUndamaged");
-end
-
--- **************************************************************************
--- NAME : TitanRepair_ShowPop()
--- DESC : <research>
--- **************************************************************************
-function TitanRepair_ShowPop()
-	TitanToggleVar(TITAN_REPAIR_ID, "ShowPopup");
-	if TitanGetVar(TITAN_REPAIR_ID,"ShowPopup") and TitanGetVar(TITAN_REPAIR_ID,"AutoRepair") then
-		TitanSetVar(TITAN_REPAIR_ID,"AutoRepair",nil);
-	end
-end
-
--- **************************************************************************
--- NAME : TitanRepair_AutoRep()
--- DESC : <research>
--- **************************************************************************
-function TitanRepair_AutoRep()
-	TitanToggleVar(TITAN_REPAIR_ID, "AutoRepair");
-	if TitanGetVar(TITAN_REPAIR_ID,"AutoRepair") and TitanGetVar(TITAN_REPAIR_ID,"ShowPopup") then
-		TitanSetVar(TITAN_REPAIR_ID,"ShowPopup",nil);
-	end
-end
-
--- **************************************************************************
--- NAME : TitanRepair_ShowInventory()
--- DESC : <research>
--- **************************************************************************
-function TitanRepair_ShowInventory()
-	tit_debug_bis("TitanRepair_ShowInventory has been called !!");
-	TitanToggleVar(TITAN_REPAIR_ID, "ShowInventory");
-
-	if TitanGetVar(TITAN_REPAIR_ID,"ShowInventory") ~= 1 then
-		TitanPanelRepairButton_ResetStatus(TPR.ITEM_STATUS[TPR.END].values)
-	end
-
-	TitanPanelRepairButton_ScanAllItems();
-	TitanPanelRepairButton_OnUpdate()
-end
-
--- **************************************************************************
--- NAME : TitanRepair_RepairItems()
--- DESC : <research>
--- **************************************************************************
-function TitanRepair_RepairItems()
-	-- New RepairAll function
-	local cost = GetRepairAllCost();
-	local money = GetMoney();
-	local withdrawLimit = GetGuildBankWithdrawMoney();
-	local guildBankMoney = GetGuildBankMoney();
-
-	-- Use Guild Bank funds
-	if TitanGetVar(TITAN_REPAIR_ID,"UseGuildBank") then
-		if IsInGuild() and CanGuildBankRepair() then
-			if withdrawLimit > cost then
-				RepairAllItems(true)
-				-- disable repair all icon in merchant
-				SetDesaturation(MerchantRepairAllIcon, 1);
-				MerchantRepairAllButton:Disable();
-				-- disable guild bank repair all icon in merchant
-				SetDesaturation(MerchantGuildBankRepairButtonIcon, 1);
-				MerchantGuildBankRepairButton:Disable();
-				-- report repair cost to chat (optional)
-				if TitanGetVar(TITAN_REPAIR_ID,"AutoRepairReport") then
-					DEFAULT_CHAT_FRAME:AddMessage(_G["GREEN_FONT_COLOR_CODE"]..L["TITAN_REPAIR"]..": ".."|r"..L["TITAN_REPAIR_REPORT_COST_CHAT"]..TitanPanelRepair_GetTextGSC(cost).."|r.")
-				end
-			else
-				DEFAULT_CHAT_FRAME:AddMessage(_G["GREEN_FONT_COLOR_CODE"]..L["TITAN_REPAIR"]..": ".."|r"..L["TITAN_REPAIR_GBANK_NOMONEY"])
-			end
-		else
-			DEFAULT_CHAT_FRAME:AddMessage(_G["GREEN_FONT_COLOR_CODE"]..L["TITAN_REPAIR"]..": ".."|r"..L["TITAN_REPAIR_GBANK_NORIGHTS"])
-		end
-	end
-
-	-- Use own funds
-	if not TitanGetVar(TITAN_REPAIR_ID,"UseGuildBank") then
-		if money > cost then
-			RepairAllItems()
-			-- disable repair all icon in merchant
-			SetDesaturation(MerchantRepairAllIcon, 1);
-			MerchantRepairAllButton:Disable();
-			-- disable guild bank repair all icon in merchant
-			SetDesaturation(MerchantGuildBankRepairButtonIcon, 1);
-			MerchantGuildBankRepairButton:Disable();
-			-- report repair cost to chat (optional)
-			if TitanGetVar(TITAN_REPAIR_ID,"AutoRepairReport") then
-				DEFAULT_CHAT_FRAME:AddMessage(_G["GREEN_FONT_COLOR_CODE"]..L["TITAN_REPAIR"]..": ".."|r"..L["TITAN_REPAIR_REPORT_COST_CHAT"]..TitanPanelRepair_GetTextGSC(cost))
-			end
-		else
-			DEFAULT_CHAT_FRAME:AddMessage(_G["GREEN_FONT_COLOR_CODE"]..L["TITAN_REPAIR"]..": ".."|r"..L["TITAN_REPAIR_CANNOT_AFFORD"])
-		end
-	end
-end
-
+--[[ local
 -- **************************************************************************
--- NAME : TitanRepair_GetRepairInvCost()
--- DESC : <research>
+-- NAME : Create_Frames()
+-- DESC : Create the required Repair plugin frames
 -- **************************************************************************
-function TitanRepair_GetRepairInvCost()
-	local result = 0;
-	local bag;
-	TitanRepairTooltip:SetOwner(UIParent, "ANCHOR_NONE");
-
-	for bag = 0, 4 do
-
---		for slot = 1, GetContainerNumSlots(bag) do
-		for slot = 1, ContainerFrame_GetContainerNumSlotsWithBase(bag) do
-			local _, repairCost = TitanRepairTooltip:SetBagItem(bag, slot);
-			if (repairCost and (repairCost > 0)) then
-				result = result + repairCost;
-			end
-		end
-	end
-	TitanRepairTooltip:Hide();
-
-	return result;
-end
-
--- ====== Create needed frames
+--]]
 local function Create_Frames()
 	if _G[TITAN_BUTTON] then
 		return -- if already created
@@ -1573,16 +1055,21 @@ local function Create_Frames()
 	window:SetScript("OnEvent", function(self, event, ...)
 		TitanPanelRepairButton_OnEvent(self, event, ...)
 	end)
+	window:SetScript("OnClick", function(self, button)
+		TitanPanelRepairButton_OnClick(self, button)
+		TitanPanelButton_OnClick(self, button)
+	end)
+	window:SetScript("OnShow", function(self, button)
+		RepairShow(self)
+	end)
+	window:SetScript("OnHide", function(self, button)
+		RepairHide(self)
+	end)


 	-- Tooltip frame
-	local tt = CreateFrame("GameTooltip", "TitanRepairTooltip", f, "GameTooltipTemplate")
+	tool_tip = CreateFrame("GameTooltip", TITAN_TOOLTIP, f, "GameTooltipTemplate")
 end

-
-Create_Frames() -- do the work
-
--- Hooks
---TitanRepairModule:SecureHook("DurabilityFrame_SetAlerts", TitanRepair_DurabilityFrame)
-TitanRepairModule:SecureHook(DurabilityFrame, "Show", function() TitanRepair_DurabilityFrame(true) end)
-
+-- Create needed Repair plugin frames here on load rather than in XML.
+Create_Frames()