Также исправлены некоторые предупреждения и внесены косметические правки.
Code: Select all
-- See https://forum.farmanager.com/viewtopic.php?p=170841#p170841
local F = far.Flags
Macro {
description = "Press F12 twice to go to panels (if any)";
area = 'Menu'; key = 'F12';
condition = function()
return Menu.Id == far.Guids.ScreensSwitchId;
end;
code = [[Keys'Alt1']]
}
local function switchTitles(hDlg)
local cType
local aTitles = {}
local n = far.AdvControl(F.ACTL_GETWINDOWCOUNT)
for i=1,n do
local wi = far.AdvControl(F.ACTL_GETWINDOWINFO, i)
if wi.Type == F.WTYPE_EDITOR then
cType = cType or wi.TypeName -- так не будет зависеть от языка интерфейса
local edid = wi.Id
local f1,f2 = editor.GetFileName(edid), editor.GetTitle(edid)
if f1 ~= f2 then
aTitles[f1] = f2
aTitles[f2] = f1
end
end
end
local ret, r = false, hDlg:send(F.DM_GETDLGRECT)
local wF, w, w0, h0 = Far.Width, 0, r.Right-r.Left+1, r.Bottom-r.Top+1
local lr = hDlg:send(F.DM_GETITEMPOSITION, 1)
n = hDlg:send(F.DM_LISTINFO, 1).ItemsNumber
for i=1, n do
local it = hDlg:send(F.DM_LISTGETITEM, 1, i)
-- как выяснилось, при количестве окон более 9 нумерация становится буквенной A-Z
local tp, pos, fn = it.Text:match'^&?[%d%u ]%s+(%a+)[%s*]+()(.*)$'
if tp == cType and aTitles[fn] then
it.Text = it.Text:sub(1,pos-1) .. aTitles[fn]
it.Index = i
hDlg:send(F.DM_LISTUPDATE, 1, it)
ret = true -- заменили хотя бы один элемент
end
w = math.max(w, it.Text:len())
end -- for i
local w1 = math.max(w0, math.min(w, wF)+8)
hDlg:send(F.DM_RESIZEDIALOG, 0, {X=w1; Y=h0})
local center, dx = -1, w+2 > wF and -1 or 0
hDlg:send(F.DM_MOVEDIALOG, 1, {X=center; Y=r.Top})
hDlg:send(F.DM_MOVEDIALOG, 0, {X=dx; Y=0})
hDlg:send(F.DM_SETITEMPOSITION, 1, {Left=lr.Left,Top=lr.Top,Bottom=lr.Bottom,Right=w1-3})
return ret
end; -- function switchTitles
Event {
description = "Замена (изначально) временного имени редактируемого файла на исходное из NetBox'а, FarCmds'а и т.п.";
id = '86784CDC-465B-47A5-961E-D0CA75372172';
group = 'DialogEvent';
condition = function(Event, Param)
if Event == F.DE_DLGPROCEND and Param.Msg == F.DN_INITDIALOG then
local Id = (Param.hDlg:send(F.DM_GETDIALOGINFO) or {}).Id
return Id == win.Uuid( far.Guids.ScreensSwitchId )
end
end;
action = function(Event, Param)
local _ = Event;
if switchTitles(Param.hDlg) then
-- See https://forum.farmanager.com/viewtopic.php?p=166727#p166727
local Titles = Param.hDlg:send(F.DM_LISTGETTITLES, 1)
Titles.Bottom = 'F2'
Param.hDlg:send(F.DM_LISTSETTITLES, 1, Titles)
end
end;
}
Macro {
description = "Замена (по F2) временного имени редактируемого файла на исходное из NetBox'а, FarCmds'а и т.п.";
id = 'B5254B15-C58F-49A6-87FF-BD1EAE79A0BE';
area = 'Menu'; key = 'F2';
condition = function() --key, data)
return Menu.Id == far.Guids.ScreensSwitchId
end;
action = function() --data)
local hDlg = far.AdvControl( F.ACTL_GETWINDOWINFO ).Id
switchTitles( hDlg )
end;
}