-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmlc_panel.lua
189 lines (161 loc) · 4.96 KB
/
xmlc_panel.lua
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
-- far.Message("load xmlc_panel.lua")
local F = far.Flags
local VK = win.GetVirtualKeys()
local band, bor = bit64.band, bit64.bor
require 'common'
local xmlc_reader = require 'xmlc_reader'
local xmlc_filter = require 'xmlc_filter'
-- =========================== PANEL ============================
local xmlc_panel = {}
local xmlc_panel_mt = {__index=xmlc_panel}
function xmlc_panel.open(file_name)
local self = {
file_name = file_name,
curr_object = nil,
panel_mode = nil, -- valid values are: "root",
panel_info = {
title = '',
modes = {};
},
reader = xmlc_reader.new(),
}
setmetatable(self, xmlc_panel_mt)
if self.reader:open(file_name) then
self.filter = xmlc_filter.init(self.reader)
self:open_root()
return self
end
end
function xmlc_panel:open_root()
self.panel_mode = "root"
self.curr_object = ""
self:prepare_panel_info()
return true
end
local function add_keybar_label(panel_info, label, vkc, cks)
local kbl = {
Text = label;
LongText = label;
VirtualKeyCode = vkc;
ControlKeyState = cks or 0;
}
for _, item in pairs(panel_info.key_bar) do
if item.VirtualKeyCode == kbl.VirtualKeyCode and item.ControlKeyState == kbl.ControlKeyState then
item.Text = kbl.Text
item.LongText = kbl.LongText
return
end
end
table.insert(panel_info.key_bar, kbl)
end
function xmlc_panel:prepare_panel_info()
local info = self.panel_info
info.title = "XMLC: " .. self.file_name:match("[^\\/]*$")
if self._curr_object == "" or self._curr_object == nil then
-- pass
else
info.title = info.title .. " [" .. self._curr_object .. "]"
end
local pm = {
ColumnTypes = 'C0,N,C1,C2,C3,C4',
ColumnWidths = '6,0,6,6,13,10',
ColumnTitles = {'N', 'Type', 'Rail', 'Chnl', 'Coordinate', 'Value'},
}
pm.StatusColumnTypes = pm.ColumnTypes
pm.StatusColumnWidths = pm.ColumnWidths;
info.modes = {pm,}
info.key_bar = {}
for i = VK.F1, VK.F12 do
add_keybar_label(info, "", i, F.LEFT_CTRL_PRESSED + F.RIGHT_CTRL_PRESSED)
add_keybar_label(info, "", i, F.LEFT_ALT_PRESSED + F.LEFT_ALT_PRESSED)
add_keybar_label(info, "", i)
end
add_keybar_label(info, self.filter.enable and "OFF FLTR" or "ON FLTR", VK.F5)
add_keybar_label(info, "TUNE FLTR", VK.F6)
-- add_keybar_label(info, "CHANNEL", VK.F7)
-- add_keybar_label(info, "SYS_COORD", VK.F8)
end
function xmlc_panel:get_panel_info()
return {
CurDir = self.curr_object;
Flags = bor(F.OPIF_DISABLESORTGROUPS, F.OPIF_DISABLEFILTER),
HostFile = self.file_name,
KeyBar = self.panel_info.key_bar;
PanelTitle = self.panel_info.title,
PanelModesArray = self.panel_info.modes;
PanelModesNumber = #self.panel_info.modes;
StartPanelMode = ("0"):byte();
StartSortMode = F.SM_UNSORTED;
}
end
function xmlc_panel:get_panel_list()
local rc = false
if self.panel_mode == "root" then
rc = self:get_panel_list_root()
-- elseif self._panel_mode=="table" or self._panel_mode=="view" then
-- rc = self:get_panel_list_obj()
-- elseif self._panel_mode == "query" then
-- rc = self:get_panel_list_query()
end
return rc
end
local function format_sys_coord(coord)
local mm = coord % 1000
local km_m = (coord - mm) /1000
local m = km_m % 1000
local km = (km_m-m) / 1000
return sprintf(' %03d.%03d.%03d', km, m, mm)
end
function xmlc_panel:get_panel_list_root()
--far.Message('get_panel_list_root')
local result = { { FileName=".."; FileAttributes="d"; } }
for i, item in ipairs(self.reader.values) do
local file_item = {}
file_item.UserData = i
file_item.FileName = item.name
file_item.CustomColumnData = {
sprintf('%5d', i),
sprintf('%5d', item.rail),
sprintf('%5d', item.channel),
format_sys_coord(item.coord),
sprintf('%9d', item.value),
}
result[#result+1]= file_item
end
return result
end
function xmlc_panel:handle_keyboard(handle, key_event)
local vcode = key_event.VirtualKeyCode
local cstate = key_event.ControlKeyState
local ctrl = cstate == F.LEFT_CTRL_PRESSED or cstate == F.RIGHT_CTRL_PRESSED
local shift = cstate == F.SHIFT_PRESSED
if vcode == VK.F3 or vcode == VK.F4 then
self:view_data(vcode == VK.F4)
return true
elseif vcode == VK.F5 then
self.filter.enable = not self.filter.enable
self:prepare_panel_info()
panel.RedrawPanel (handle, 1)
panel.UpdatePanel (handle, 1)
--far.Message('F5')
return true
elseif vcode == VK.F6 then
self.filter:show()
panel.UpdatePanel (handle, 1)
return true
end
end
function xmlc_panel:view_data(edit)
far.Message('not implemented yet')
-- local item = panel.GetCurrentPanelItem(nil, 1)
-- if not item then return end
-- local tmp_file_name = self.reader:Export(item.UserData)
-- if tmp_file_name then
-- if edit then
-- editor.Editor(tmp_file_name, "", nil, nil, nil, nil, F.EF_DISABLESAVEPOS + F.EF_DISABLEHISTORY, nil, nil, 65001)
-- else
-- viewer.Viewer(tmp_file_name, nil, 0, 0, -1, -1, bor(F.VF_DISABLEHISTORY, F.VF_DELETEONLYFILEONCLOSE), 65001) -- , F.VF_IMMEDIATERETURN, F.VF_NONMODAL
-- end
-- end
end
return xmlc_panel