-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdlgproc.lua.1
More file actions
144 lines (141 loc) · 4.53 KB
/
dlgproc.lua.1
File metadata and controls
144 lines (141 loc) · 4.53 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
local Common = ... --O
local F = far.Flags
local HISTORY, DATA = 7,10
local function prepActions (Items)
local Keys,Exec = {},{}
for _,item in ipairs(Items) do
if item.keys then
for key, action in pairs(item.keys) do
if type(assert(action))=="string" then
item.keys[key] = assert(item[action])
end
Keys[#Keys+1] = item
end
end
if item.onexec then Exec[#Exec+1] = item end
end
return {
processKey=function(curitem,hDlg,idx,key)
for _,item in ipairs(Keys) do
local action = item.keys[key]
if action then
local ret = action(curitem,hDlg,idx,key)
if ret~=nil then
return ret
end
end
end
end
}
end
local function getEnvValues (list)
local t = {}
for var in pairs(list) do
local v = win.GetEnv(var)
if v then table.insert(t,v) end
end
return t
end
return function (dialog) --main
local II,opts = dialog.II, dialog.opts -- .populateHistory
local cfg = opts.cfg
local acts = prepActions(II)
return function (hDlg,msg,idx,Param2)
local function run (name, ...)
local self = ...
if self[name] then
return self[name](...)
end
end
local item = II[idx]
if msg==F.DN_INITDIALOG then
for param,list in pairs(cfg.info.predefined or {}) do
dialog.populateHistory(II[param], hDlg, list, "init")
end
for param,list in pairs(Common.O.stdEnvs) do
dialog.populateHistory(II[param], hDlg, getEnvValues(list))
end
for idx,item in ipairs(II) do --luacheck: ignore 421/ idx item
if item.History then
hDlg:SetEditPosition(idx,{CurPos=1})
end
run("oninit",item,hDlg,idx)
end
if opts.nodialog then
hDlg:Close(II.btnGo.idx)
return
end
elseif msg==F.DN_BTNCLICK then
return run("onclick",item,hDlg,idx)
elseif msg==F.DN_CTLCOLORDLGITEM then
return run("oncolor",item,hDlg,idx,Param2)
elseif msg==F.DN_EDITCHANGE then
return run("onedit", item, hDlg, idx, Param2[DATA])
elseif msg==F.DN_GOTFOCUS or msg==F.DN_KILLFOCUS then
return run("onfocus", item, hDlg, idx, msg==F.DN_GOTFOCUS)
elseif msg==F.DN_HELP then
return run("onhelp", item, hDlg, idx, Param2)
elseif msg==F.DN_CLOSE then
II.prompt[DATA] = hDlg:GetText(II.prompt.idx)
for pos,self in ipairs(II) do
if self.onclose then
if self:onclose(hDlg,pos,item)==false then
return false
end
end
end
if item~=II.btnGo then return end
for pos,self in ipairs(II) do
if self.History then
hDlg:AddHistory(pos, hDlg:GetText(pos))
end
end
elseif msg==(F.DN_CONTROLINPUT or F.DN_KEY) then
local KeyToName = far.KeyToName or far.InputRecordToName --luacheck: globals far.KeyToName --far2m
local key = KeyToName(Param2)
local ret = acts.processKey(item,hDlg,idx,key)
if ret~=nil then return ret end
if item then
ret = run("onkey",item,hDlg,idx,key)
if ret~=nil then return ret end
end
if key==Common.O.key then
hDlg:Close(II.btnSwitch.idx)
elseif key=="AltSubtract" then
hDlg:send(F.DN_BTNCLICK, II.btnClrSession.idx)
elseif key=="ShiftF4" then
if II.headers then
local d_item = hDlg:GetDlgItem(II.headers.idx)
local id = win.Uuid"6EDB0A6C-2D65-4F1B-80B9-A8C88B08701B"
local headers = far.InputBox(id, cfg.info.name, "Enter headers (moonscript- or lua-table):",
d_item[HISTORY], d_item[DATA])
if headers then
hDlg:SetText(II.headers.idx, headers)
end
end
elseif key=="F5" then
hDlg:send(F.DN_BTNCLICK, II.btnPreset.idx)
elseif key=="ShiftF5" then
local apibase = II.apibase or II.api_base or II.api or II.provider
if apibase then
hDlg:SetDropdownOpened(apibase.idx, 1)
end
elseif key=="F6" then
hDlg:send(F.DN_BTNCLICK, II.btnModels.idx)
elseif key=="ShiftF6" then
if F.ACTL_GETFARMANAGERVERSION then --far3
hDlg:send(F.DN_BTNCLICK, II.btnModels.idx)
elseif II.model then
hDlg:SetDropdownOpened(II.model.idx, 1)
end
elseif key=="PgUp" or key=="CtrlHome" then
hDlg:SetFocus(II.prompt.idx)
elseif key=="CtrlH" then
opts.compact = not opts._hidden
hDlg:Close(II.profile.idx)
elseif key=="AltU" then
hDlg:ShowItem(II.chkDebug.idx,1)
end
end
end
end