Back to Home

ESO Lua File v101041

libraries/utility/zo_editcontrolgroup.lua

[◄ back to folders ]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
--[[
This combines a set of edit controls into a group that can be navigated using the TAB key. Shift+TAB can be used to navigate the group in reverse.
--]]
ZO_EditControlGroup = ZO_Object:Subclass()
function ZO_EditControlGroup:New()
    local group = ZO_Object.New(self)
    group:Initialize()
    return group
end
function ZO_EditControlGroup:Initialize()
    self.editControls = {}
end
function ZO_EditControlGroup:OnTabPressed(control)
    local index = control.editControlGroupIndex
    local newIndex = index + (IsShiftKeyDown() and -1 or 1)
    if newIndex < 1 then
        newIndex = #self.editControls
    elseif newIndex > #self.editControls then
        newIndex = 1
    end
    self.editControls[newIndex]:TakeFocus()
end
function ZO_EditControlGroup:AddEditControl(control, autoCompleteObject)
    self.editControls[#self.editControls + 1] = control
    control.editControlGroupIndex = #self.editControls
    if autoCompleteObject then
        local autoCompleteTabHandler = control:GetHandler("OnTab")
        control:SetHandler("OnTab", function (control, ...)
            if autoCompleteObject:IsOpen() then
                autoCompleteTabHandler(control, ...)
            else
                self:OnTabPressed(control)
            end
        end)
    else
        control:SetHandler("OnTab", function(control)
            self:OnTabPressed(control)
        end)
    end
end