-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopentabledialog.lua
More file actions
131 lines (101 loc) · 2.93 KB
/
Copy pathopentabledialog.lua
File metadata and controls
131 lines (101 loc) · 2.93 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
local currentPath
local function populateView(listbox)
print("populateView for "..currentPath)
local dirlist=getDirectoryList(currentPath)
local filelist=getFileList(currentPath,'*.CT')
table.sort(dirlist)
table.sort(filelist)
listbox.Items.beginUpdate()
listbox.Items.clear()
if dirlist and filelist and currentPath~='/' then
listbox.Items.add('..')
end
for i=1,#dirlist do
listbox.Items.add(extractFileName(dirlist[i]),1)
end
for i=1,#filelist do
listbox.Items.add(extractFileName(filelist[i]),2)
end
if listbox.items.Count>0 then
listbox.ItemIndex=0
end
listbox.Items.endUpdate()
end
function createOpenTableDialog()
local frmFilePicker=createForm(false)
frmFilePicker.Name='frmFilePicker'
frmFilePicker.Caption='Open Cheat Table'
frmFilePicker.Width=getScreenWidth() / 2
frmFilePicker.Height=getScreenHeight() / 2
frmFilePicker.Font.Size=22
currentPath=MainForm.OpenDialog1.InitialDir
if dirExists(currentPath)==false then
currentPath=os.getenv('HOME')
if dirExists(currentPath) then
if dirExists(currentPath..'Documents') then
currentPath=currentPath..'Documents'
elseif dirExists(currentPath..'/Documents') then
currentPath=currentPath..'/Documents'
end
else
currentPath='./'
end
end
if currentPath:endsWith('/')==false then
currentPath=currentPath..'/'
end
frmFilePicker.BorderStyle=bsSizeable
frmFilePicker.Position=poScreenCenter
local pathlabel=createLabel(frmFilePicker)
pathlabel.align=alTop
pathlabel.Caption=currentPath
local lbFiles=createListBox(frmFilePicker)
lbFiles.align=alClient
populateView(lbFiles)
lbFiles.OnDblClick=function(l)
local i=l.ItemIndex
print(i)
if i~=-1 then
local t=l.Items.Data[i]
print("t="..t)
if t==0 then
local s=currentPath
if s:endsWith('/') then
print("it ends with /")
if #s>1 then
s=s:sub(1,#s-1)
end
end
local newpath=extractFilePath(s)
if newpath=='' then
print('newpath==nil. doing the .. thing')
newpath=currentPath..'/../'
print("newpath="..newpath)
else
print("extracted newpath="..newpath)
end
currentPath=newpath
pathlabel.Caption=currentPath
populateView(l)
elseif t==1 then
--dir
currentPath=currentPath..l.Items[i]..'/'
pathlabel.Caption=currentPath
populateView(l)
elseif t==2 then
print("setting modalresult")
frmFilePicker.ModalResult=mrOK
print("frmFilePicker="..frmFilePicker.Name..':'..frmFilePicker.ClassName)
--frmFilePicker.close()
end
end
end
--end
if frmFilePicker.showModal()==mrOK then
print("returned with mrOK")
if lbFiles.ItemIndex~=-1 then
return currentPath..lbFiles.Items[lbFiles.ItemIndex]
end
end
end
--return createOpenTableDialog()