While testing a new version of my ChatIt addons multiple windows feature I found one more bug.
It is possible to transfer the main (first) window tab of the primary container to another container. It is also possible to transfer every window out of the primary container which really causes problems.
I do realize this sounds minor & highly unlikely...but it happened to me on accident, that's how I found it so I figure it could happen to someone else. Also since there are code checks to prevent transferring the 1st tab out of the primary container, it is obviously an unwanted feature so I thought I'de post this.
While testing my addon I was attempting to transfer several tab windows to another chat container. To make this easier I moved them very close to each other. When you drag a tab window if the mouse overlaps more than one TabDropArea, both controls get monitored by function
Warning: Spoiler
Lua Code:
SharedChatContainer:MonitorTabMovement()
local monitoredControl = self.monitoredControl
local x, y = GetUIMousePosition()
if Contains(x, y, GetTabDropArea(self.control, self.windows[1].tab)) then
self.insertIndex = FindInsertPosition(self, monitoredControl, x)
--peform a layout with extra space for the potential tab
self:PerformLayout(self.insertIndex, monitoredControl:GetWidth())
elseif self.insertIndex then
--reset the layout
self:PerformLayout()
self.insertIndex = nil
end
end
Since the tab drop areas are overlapping and that function uses GetUIMousePosition() both controls will pass the Contains(...) check and thus both containers get self.insertIndex set.
Then when you actually drop the tab, whichever container it goes into properly gets self.insertIndex set to nil, but the other container will still have self.insertIndex set to some value
(what value is irrelevant).
If it dropped into the primary container and you then drag the 1st tab window from the primary container and drop it on top of the other containers TabDropArea
(the other container still has self.insertIndex set so) it will transfer the tab to that container, even though it was the 1st tab window of the primary container because:
Warning: Spoiler
Lua Code:
-- This function is called "OnMouseUp"
function SharedChatContainer:StopDraggingTab()
-- Which calls:
function SharedChatSystem:StopContainersTabDrop(initiator)
local tabDropContainer
for i, container in ipairs(self.containers) do
if container ~= initiator then
if not tabDropContainer and container:CanTakeTabDrop() then
tabDropContainer = container
end
container:StopTabDrop()
end
end
if tabDropContainer then
--It's always the first window since that's the only draggable tab
initiator:TransferWindow(1, tabDropContainer)
end
end
container ~= initiator AND container:CanTakeTabDrop() will return true
(because container still has self.insertIndex set to some value) then it will set tabDropContainer = container, then the TransferWindow code will run which will transfer the first tab window to the other container.
Lua Code:
function SharedChatSystem:StopContainersTabDrop(initiator)
...
-- It looks like it could use a primary check here:
if not initiator:IsPrimary() then
initiator:TransferWindow(1, tabDropContainer)
end
...
end
and something to ensure all container.insertIndex values get wiped out on a tab drop.