diff --git a/Core.lua b/Core.lua index 59dbee7..94ecf8a 100644 --- a/Core.lua +++ b/Core.lua @@ -269,9 +269,9 @@ end ]] local function SourceLocation(parent) - local parentName = parent:GetName() - local parentParentName = nil - local parentParentParentName = nil + local parentName = parent:GetName() + local parentParentName = nil + local parentParentParentName = nil if parent:GetParent() and parent:GetParent():GetName() then parentParentName = parent:GetParent():GetName() @@ -285,11 +285,13 @@ local function SourceLocation(parent) local bagIndex = parent:GetParent():GetID() local slotIndex = parent:GetID() local forceBankScope = false - - local locationBagIndex, locationSlotIndex = nil, nil - if parent and parent:GetItemLocation() and parent:GetItemLocation():GetBagAndSlot() then - locationBagIndex, locationSlotIndex = parent:GetItemLocation():GetBagAndSlot() - end + local hasItemLocation = false + + local locationBagIndex, locationSlotIndex = nil, nil + if parent and parent:GetItemLocation() and parent:GetItemLocation():GetBagAndSlot() then + locationBagIndex, locationSlotIndex = parent:GetItemLocation():GetBagAndSlot() + hasItemLocation = locationBagIndex ~= nil and locationSlotIndex ~= nil + end ns.printParentNames(parent) @@ -357,31 +359,48 @@ local function SourceLocation(parent) slotIndex = parent:GetContainerSlotID() end - return isGuildBank, bagIndex, slotIndex, forceBankScope + return isGuildBank, bagIndex, slotIndex, forceBankScope, hasItemLocation end -- Overrides standard function for split dialog -local function OpenFrame(self, maxStack, parent, anchor, anchorTo, stackCount) - - ClearDialog() - dialog = CreateItemSplitterDialog(maxStack) - dialog:ClearAllPoints() - dialog:SetPoint(anchor, parent, anchorTo, 0, 0) +local function OpenFrame(self, maxStack, parent, anchor, anchorTo, stackCount) + + ClearDialog() + dialog = CreateItemSplitterDialog(maxStack) + dialog:ClearAllPoints() + dialog:SetPoint(anchor, parent, anchorTo, 0, 0) dialog.editBox:SetScript("OnEditFocusGained", function(self) C_Timer.After(0.1, function() self:HighlightText() end) end) - dialog.editBox:SetFocus() - - local isGuildBank, bagIndex, slotIndex, forceBankScope = SourceLocation(parent) - - dialog.splitButton:SetScript("OnClick", function() - parent.SplitStack(parent, dialog:GetValue()) -- original behaviour - ClearDialog() - end) - + dialog.editBox:SetFocus() + + local isGuildBank, bagIndex, slotIndex, forceBankScope, hasItemLocation = SourceLocation(parent) + local isMerchant = MerchantFrame and MerchantFrame:IsVisible() + + if isMerchant then + dialog.autoSplitButton:Hide() + dialog.splitButton:ClearAllPoints() + dialog.splitButton:SetPoint("BOTTOM", dialog, "BOTTOM", 0, 10) + if hasItemLocation then + dialog.splitButton:SetText("Sell") + else + dialog.splitButton:SetText("Buy") + end + end + + dialog.splitButton:SetScript("OnClick", function() + local splitValue = dialog:GetValue() + if self and type(self.split) == "function" then + self.split(splitValue) + else + parent.SplitStack(parent, splitValue) -- original behaviour + end + ClearDialog() + end) + dialog.autoSplitButton:SetScript("OnClick", function () DisableDialog() StartAutomaticSplitSession(isGuildBank, bagIndex, slotIndex, dialog:GetValue(), forceBankScope)