package.nounload.ljsqlite3 = true
local sql = require "ljsqlite3"
-- Проверка, один ли столбец
local function OneColumn()
local fname = win.GetEnv("farprofile").."\\panelmodes.db"
local conn = assert(sql.open(fname, "ro"))
local wm = panel.GetPanelInfo(nil, 1).ViewMode
local iCurr = wm
if iCurr == 10 then iCurr = 0 end
if iCurr <= 9 then iCurr = iCurr + 1 end -- Одна из стандартных панелей. >9 - свои добавленные
local SQL = [[SELECT name, value FROM table_values WHERE key_id=]]..iCurr
local t = conn:exec(SQL)
conn:close()
if t then
for i, v in ipairs(t.name) do
if v == 'ColumnTitles' then
return (','..t.value[i]):find(",N.*,N") == nil
end
end
else
-- Почему-то база пустая. видимо, после установки не настраивали панели. Тогда по умолчанию
-- режимы 1 и 2 - многостолбцовые; остальные - по одному.
return not (wm == 1 or wm == 2)
end
end
local function CheckFileAssociates(FName)
local fname = win.GetEnv("farprofile").."\\associations.db"
local conn = assert(sql.open(fname, "ro"))
local SQL = [[SELECT id,mask FROM filetypes ]]
local ft = conn:exec(SQL)
if ft then
SQL = [[SELECT * FROM commands ]]
local cm = conn:exec(SQL)
for i,v in ipairs(ft.mask) do
if mf.fmatch(FName, v) == 1 then
local id = ft.id[i]
for j, ft_id in ipairs(cm.ft_id) do
if ft_id == id and tonumber(cm.type[j]) == 1 and
tonumber(cm.enabled[j]) == 1 and
cm.command[j]:match"%S" then
return cm.command[j]
end
end
end
end
end -- if ft
conn:close()
end -- CheckFileAssociates
local function PanRowCount()
local res=APanel.Height - 5
if not Far.GetConfig('Panel.Layout.ColumnTitles') then res = res + 1 end
if not Far.GetConfig('Panel.Layout.StatusLine') then res = res + 2 end
return res
end -- PanRowCount
Macro {
area="Shell";
key="Left"; flags="EmptyCommandLine"; description="LYNX-style motion";
condition=function()
return APanel.Visible and ( APanel.CurPos <= PanRowCount() or APanel.CurPos == APanel.ItemCount or OneColumn() )
end;
action = function()
Keys('CtrlPgUp')
end;
}
Macro {
area="Shell"; key="Right"; flags="EmptyCommandLine"; description="LYNX-style motion";
condition=function()
if APanel.Folder and APanel.Current == '..' then return end
-- Проверка количества столбцов на панели
if APanel.Visible and (APanel.CurPos > APanel.ItemCount - PanRowCount() or OneColumn() ) then
if APanel.Folder then
return APanel.Current ~= '..'
else
return true
end
end
end;
action = function()
if APanel.Folder then
local Dest=APanel.Path .. (APanel.Path:sub(-1)=='\\' and '' or '\\') .. APanel.Current
if APanel.Plugin then
local pd=panel.GetPanelDirectory(nil, 1)
pd.Name = Dest
if not panel.SetPanelDirectory(nil, 1, pd) then -- некоторые плагины не поддерживают...
Keys('CtrlPgDn')
end
else
Panel.SetPath(0, Dest)
end;
elseif CheckFileAssociates(APanel.Current) then
Keys('PgDn')
else
Keys('CtrlPgDn')
end
end
}