--- John Doe Sun 18 Jan, 2015 20:36 http://forum.farmanager.com/viewtopic.php?p=127449#p127449 --[[ Обновление http://forum.farmanager.com/viewtopic.php?p=127345#p127345 Добавлена защита от ошибок. Скрипт теперь можно вызвать из любого диалога, а также из редактора, и из командой строки. Учтены прочие пожелания (показываются и собственные пути, список сортируется, дубликаты исключаются). ]]-- --http://forum.farmanager.com/viewtopic.php?p=127345#p127345 --- (John Doe Wed 14 Jan, 2015 20:50) --[[ Вызывается так: — комбинацией CtrlUp (в предопредёлённых диалогах) — из меню плагинов (во всех диалогах, а также в редакторе и командной строке) ]]-- local IncludeOwnPaths = true local SortItems = true local NAME = "выберите путь в т.ч. на панелях другого Фара (JD) .. .. .. .. .. .. .. .. .. CtrlUp" --- local NAME = "Pick path from other FAR instances" local FileExist = win.GetFileAttr local workpath = win.GetEnv"TEMP"..[[\FARTasks\]] local err = select(2,win.CreateDir(workpath)) assert(FileExist(workpath),err) local taskname = "getpaths" local taskfile = workpath..taskname..".task" --name for task file local poll_delay = 50 local task_timeout = 200 if panel.CheckPanelsExist() then local resfile = workpath..taskname.."."..Far.PID --name for result file local timer = far.Timer(poll_delay,function(timer) timer.Enabled = false if FileExist(taskfile) and not FileExist(resfile) then --wait for query local f,err = io.open(resfile,"w") if err then timer:Close(); far.Message(err,NAME,nil,"w"); return end for i=1,0,-1 do local pd = panel.GetPanelDirectory(nil,i) if pd then f:write(pd.Name,"\\\n") else mf.beep() end --add BackSlash end f:close() end timer.Enabled = true end) Event { description=NAME..": очистка таймера на выходе"; group="ExitFAR"; --- description=NAME..": Clean up timer on exit"; uid="351F4780-2799-47BF-984A-EB429E8B431E"; action=function() timer:Close() end; } end local function AddPath(Items,path) for i,p in ipairs(Items) do if p.text==path then return end end table.insert(Items,{text=path}) end local function PickPath() --Inquire panel paths of all running FAR instances if not FileExist(taskfile) then assert(io.open(taskfile,"w")):close() else --remove garbage far.RecursiveSearch(workpath, taskname..".*", function(_,filename) win.DeleteFile(filename) end) end win.Sleep(task_timeout) if IncludeOwnPaths then mf.waitkey(1) end --ACTL_SYNCHRO win.DeleteFile(taskfile) local Items = {} far.RecursiveSearch(workpath, taskname..".*", function(_,filename) local f = assert(io.open(filename)) for i=1,2 do AddPath(Items,f:read() or "<error>") end f:close() win.DeleteFile(filename) end) if not Items[1] then mf.beep(); return end if SortItems then table.sort(Items,function(a,b)return a.text<b.text end) end local item = far.Menu ({Title="Выберите путь:"}, Items) --- local item = far.Menu ({Title="Select path to insert:"}, Items) if item then mf.postmacro(print,item.text) end end local F = far.Flags local Defined = { ["FCEF11C4-5490-451D-8B4A-62FA03F52759"] = "CopyFilesId"; ["431A2F37-AC01-4ECD-BB6F-8CDE584E5A03"] = "MoveFilesId"; ["5EB266F4-980D-46AF-B3D2-2C50E64BCA81"] = "HardSymLinkId"; ["FAD00DBE-3FFF-4095-9232-E1CC70C67737"] = "MakeFolderId"; ["DC8D98AC-475C-4F37-AB1D-45765EF06269"] = "FolderShortcutsDlgId"; ["1D07CEE2-8F4F-480A-BE93-069B4FF59A2B"] = "FileOpenCreateId"; ["9162F965-78B8-4476-98AC-D699E5B6AFE7"] = "FileSaveAsId"; --arclite (ShiftF1/F2) ["CD57D7FA-552C-4E31-8FA8-73D9704F0666"] = "c_update_dialog_guid"; ["97877FD0-78E6-4169-B4FB-D76746249F4D"] = "c_extract_dialog_guid"; } Macro { description=NAME; area="Dialog"; key="CtrlShiftN CtrlUp"; uid="351F4780-2799-47BF-984A-EB429E8B431E"; condition=function() return Defined[Dlg.Id] and Dlg.ItemType==F.DI_EDIT end; action=PickPath; } Macro { description=NAME; area="Shell"; key="CtrlShiftN CtrlUp"; uid="6993B560-A06C-4078-B43C-A0E400A64550"; -- condition=function() return Defined[Dlg.Id] and Dlg.ItemType==F.DI_EDIT end; action=function() Keys("F11 p p") end; } local maxDelay = 500 local t = 0 Macro { description="выберите путь в т.ч. на панелях другого Фара (JD) ctrlUp"; -- description=NAME; area="Shell"; key="Shift"; uid="6993B560-A06C-4078-B43C-A0E433A64553"; condition=function() local t1 = Far.UpTime local delay = t1-t t = t1 return delay<maxDelay end; action=function() Keys("F11 p p") -- far.Message"tada!" end; } -- John Doe Wed 13 Jul 2016 19:50 http://forum.farmanager.com/viewtopic.php?p=139385#p139385 MenuItem { description=NAME; menu="Plugins"; area="Dialog Shell Editor"; guid="C182D0F8-8DF8-4AFD-9EFB-4EA143007A04"; text=function() return (not Area.Dialog or Dlg.ItemType==F.DI_EDIT) and NAME end; action=PickPath; } |