Текст модуля (версия 1.5) :
- -- Plugins and Scripts Registration v1.5
- -- Tim Sobolev
- local Register
- local function GetLanguage()
- return (Far.Cfg_Get("Language","Main") or win.GetEnv("FARLANG")):lower():sub(1,3);
- end;
- local function RegisterEvent(Event,KeyArea,KeybarLabels)
- local keyArea = KeyArea:lower();
- local DescriptionRegister = "["..KeyArea.."] ".."KeyBar Register";
- local DescriptionUnregister = "["..KeyArea.."] ".."KeyBar Restore";
- if keyArea=="editor"
- then
- if not far.keybarEditor
- then
- _G.far.keybarEditor = {}
- Event
- {
- description=DescriptionRegister; group="EditorEvent";
- condition=function(id,Event) return Event==far.Flags.EE_GOTFOCUS end;
- action=function(id) editor.SetKeyBar(id,far.keybarEditor) end;
- }
- Event
- {
- description=DescriptionUnregister; group="EditorEvent";
- condition=function(id,Event) return Event==far.Flags.EE_KILLFOCUS end;
- action=function(id) editor.SetKeyBar(id,"restore") end;
- }
- end;
- for pairId,KeybarLabel in ipairs(KeybarLabels) do table.insert(far.keybarEditor,KeybarLabels[pairId]); end;
- elseif keyArea=="viewer"
- then
- if not far.keybarViewer
- then
- _G.far.keybarViewer = {};
- Event
- {
- description=DescriptionRegister; group="ViewerEvent";
- condition=function(id,Event) return Event==far.Flags.VE_GOTFOCUS end;
- action=function(id) viewer.SetKeyBar(id,far.keybarViewer) end;
- }
- Event
- {
- description=DescriptionUnregister; group="ViewerEvent";
- condition=function(id,Event) return Event==far.Flags.VE_KILLFOCUS end;
- action=function(id) viewer.SetKeyBar(id,"restore") end;
- }
- end;
- for pairId,KeybarLabel in ipairs(KeybarLabels) do table.insert(far.keybarViewer,KeybarLabels[pairId]); end;
- elseif keyArea=="shell"
- then
- if not far.keybarPanel
- then
- _G.far.keybarPanel = {};
- -- Event
- -- {
- -- description=DescriptionRegister; group="PanelEvent";
- -- condition=function(id,Event) return Event==far.Flags.FE_GOTFOCUS end;
- -- action=function(id) panel.SetKeyBar(id,far.keybarPanel) end;
- -- }
- -- Event
- -- {
- -- description=DescriptionUnregister; group="PanelEvent";
- -- condition=function(id,Event) return Event==far.Flags.FE_KILLFOCUS end;
- -- action=function(id) panel.SetKeyBar(id,"restore") end;
- -- }
- end;
- for pairId,KeybarLabel in ipairs(KeybarLabels) do table.insert(far.keybarPanel,KeybarLabels[pairId]); end;
- end;
- end;
- local function KeyBarInfo(Event,funcInfo)
- if funcInfo.Keybar and #funcInfo.Keybar > 0
- then
- _G.far.lng = far.lng or GetLanguage();
- _G.vk = vk or win.GetVirtualKeys();
- local KeybarLabels = {};
- for KeyValue in funcInfo.Keys:gmatch("%s*(%S+)%s*") do
- local KeyRec = far.NameToInputRecord (KeyValue);
- if KeyRec.VirtualKeyCode>=vk.F1 and KeyRec.VirtualKeyCode<=vk.F12 then
- if funcInfo.Keybar[far.lng]
- then KeyBar = funcInfo.Keybar[far.lng]
- else KeyBar = funcInfo.Keybar[1];
- end;
- table.insert(KeybarLabels,{VirtualKeyCode=KeyRec.VirtualKeyCode;ControlKeyState=KeyRec.ControlKeyState;Text=KeyBar;LongText=KeyBar});
- end;
- end;
- if #KeybarLabels > 0
- then for KeyArea in funcInfo.Area:gmatch("%s*(%S+)%s*") do RegisterEvent(Event,KeyArea,KeybarLabels); end;
- end;
- end;
- end;
- local function ScriptInfo(Event,Macro,scriptInfo)
- for funcIdx,funcInfo in ipairs(scriptInfo.Functions) do
- Macro
- {
- description = "["..scriptInfo.Name.."] "..funcInfo.Name; area = funcInfo.Area; key = funcInfo.Keys; flags = funcInfo.Flags;
- condition = funcInfo.Condition;
- action = function()
- if funcInfo.Action
- then funcInfo.Action()
- end;
- if funcInfo.PostKeys
- then Keys(funcInfo.PostKeys);
- end;
- end;
- }
- KeyBarInfo(Event,funcInfo);
- end;
- end
- local function PluginInfo(Event,Macro,pluginInfo)
- if Plugin.Exist(pluginInfo.ID) then
- for funcIdx,funcInfo in ipairs(pluginInfo.Functions) do
- Macro
- {
- description = pluginInfo.Name..": "..funcInfo.Name; area = funcInfo.Area; key = funcInfo.Keys; flags = funcInfo.Flags;
- condition = funcInfo.Condition;
- action = function()
- if funcInfo.Action
- then funcInfo.Action()
- elseif funcInfo.Menu
- then Plugin.Menu(pluginInfo.ID,funcInfo.Menu);
- elseif funcInfo.ID
- then
- if funcInfo.subID
- then Plugin.SyncCall(pluginInfo.ID,funcInfo.ID,funcInfo.subID);
- else Plugin.SyncCall(pluginInfo.ID,funcInfo.ID);
- end;
- else
- if funcInfo.PostKeys
- then Plugin.Menu(pluginInfo.ID);
- else Plugin.SyncCall(pluginInfo.ID);
- end
- end;
- if funcInfo.PostKeys
- then Keys(funcInfo.PostKeys);
- end;
- end;
- }
- KeyBarInfo(Event,funcInfo);
- end;
- end;
- end
- return
- {
- PluginInfo=PluginInfo,
- ScriptInfo=ScriptInfo,
- }
GeSHi © Codebox Plus Extension
Примеры:
- Регистрация плагинов:
- local allPanels = "Shell Info QView Tree Search Dialog"
- local allScreens = allPanels.." ".."Editor Viewer"
- local function Colorize()
- local guid="D2F36B62-A470-418D-83A3-ED7A3710E5B5"
- Plugin.Call(guid,"Settings","Status",Plugin.Call(guid,"Editor","Status") and 0 or 1)
- end;
- local function IsDialogEditor()
- return (Dlg.ItemType==4) or (Dlg.ItemType==6)
- end;
- local function FastWheel()
- n = mf.iif(akey(1) == "MsWheelUp", 1, 2);
- if not Plugin.SyncCall("4DF17F5F-E79B-46B1-A70C-04B573CECAA4", n) then Keys("AKey") end
- end;
- local function WindowSize(X,Y)
- return Plugin.SyncCall("94624B7B-FFDB-435F-B955-F99DBBC3BFE0", "WindowSize", X, Y);
- end;
- local pluginInfoList =
- {{
- Name = "Ctags";
- ID = "2E34B611-3DF1-463F-8711-74B0F21558A5";
- Functions = {
- {Name="Complete Name" ; Area="Editor"; Menu="A5B1037E-2F54-4609-B6DD-70CD47BD222B"; Keys="CtrlEnter" ; PostKeys="2"; },
- {Name="Open declaration" ; Area="Editor"; Menu="A5B1037E-2F54-4609-B6DD-70CD47BD222B"; Keys="F12" ; PostKeys="1"; Keybar={"Name",rus="Имя"} },
- {Name="Go back" ; Area="Editor"; Menu="A5B1037E-2F54-4609-B6DD-70CD47BD222B"; Keys="AltBS" ; PostKeys="3"; },
- {Name="Go forward" ; Area="Editor"; Menu="A5B1037E-2F54-4609-B6DD-70CD47BD222B"; Keys="AltBackSlash" ; PostKeys="F"; },
- {Name="Class Members" ; Area="Editor"; Menu="A5B1037E-2F54-4609-B6DD-70CD47BD222B"; Keys="AltC" ; PostKeys="4"; },
- {Name="Name in opened file" ; Area="Editor"; Menu="A5B1037E-2F54-4609-B6DD-70CD47BD222B"; Keys="AltL" ; PostKeys="5"; },
- {Name="name in entire repository"; Area="Editor"; Menu="A5B1037E-2F54-4609-B6DD-70CD47BD222B"; Keys="AltG" ; PostKeys="6"; },
- {Name="Search file by name" ; Area="Editor"; Menu="A5B1037E-2F54-4609-B6DD-70CD47BD222B"; Keys="Ctrl'" ; PostKeys="7"; },
- }
- },{
- Name = "TrueTemplate";
- ID = "91804043-507F-4ECA-9A87-5F96A4B24146";
- Functions = {
- {Name="Execute" ; Area="Editor"; Menu="91804043-507F-4ECA-9A87-5F96A4B24146"; Keys="F5" ; PostKeys="E"; Keybar={"Execute",rus="Выполнить"} },
- {Name="Show output" ; Area="Editor Viewer"; Menu="91804043-507F-4ECA-9A87-5F96A4B24146"; Keys="CtrlO" ; PostKeys="*"; },
- }
- },{
- Name = "EditCase";
- ID = "0E92FC81-4888-4297-A85D-31C79E0E0CEE";
- Functions = {{Name="Change case"; Area="Editor"; Keys="Ctrl="}}
- },{
- Name = "FarColorer";
- ID = "D2F36B62-A470-418D-83A3-ED7A3710E5B5";
- Functions = {
- {Name="Colorizing off/on" ; Area="Editor"; Action=Colorize; Keys="ShiftF3"; Keybar={"Color|er",rus="Раскр|аска"} },
- {Name="Syntax" ; Area="Editor"; ID="Types"; subID="Menu"; Keys="AltShiftF3"; Keybar={"Syntax",rus="Синтак|сис"} },
- {Name="Goto matching Bracket" ; Area="Editor"; ID="Brackets"; subID="Match"; Keys="Ctrl] Ctrl[" },
- {Name="Select block with brackets" ; Area="Editor"; ID="Brackets"; subID="SelectAll"; Keys="CtrlShift]" },
- {Name="Select block without brackets"; Area="Editor"; ID="Brackets"; subID="SelectIn"; Keys="CtrlShift[" },
- {Name="Goto Symbol" ; Area="Editor"; ID="Functions"; subID="Show"; Keys="AltR" },
- }
- },{
- Name = "FastWheel";
- ID = "4DF17F5F-E79B-46B1-A70C-04B573CECAA4";
- Functions = {{Name="Fast Wheel"; Area="Editor"; Keys="MsWheelUp MsWheelDown"; Action=FastWheel}}
- },{
- Name = "Filters";
- ID = "C061BF35-247C-48CA-BD77-5885125C5229";
- Functions = {{Name="Execute"; Area="Editor"; ID="execute"; Keys="ShiftF5"; Keybar={"Filter",rus="Фильтр"}}}
- },{
- Name = "MBlockEditor";
- ID = "D82D6847-0C7B-4BF4-9A31-B0B929707854";
- Functions = {
- {Name="Indent selection" ; Area="Editor"; ID=1; Keys="Tab" ; Flags="EVSelection"},
- {Name="Unindent selection" ; Area="Editor"; ID=2; Keys="ShiftTab" ; Flags="EVSelection"},
- {Name="Indent" ; Area="Editor"; ID=1; Keys="Alt]" },
- {Name="Unindent" ; Area="Editor"; ID=2; Keys="Alt[" },
- {Name="Comment" ; Area="Editor"; ID=3; Keys="Ctrl/" },
- {Name="Uncomment" ; Area="Editor"; ID=4; Keys="CtrlShift/" }
- }
- },{
- Name = "RESearch";
- ID = "F250C12A-78E2-4ABC-A784-3FDD3156E415";
- Functions = {
- {Name="Filter" ; Area="Editor"; ID="Filter"; Keys="CtrlAltG"},
- {Name="Grep" ; Area="Shell" ; ID="Grep"; Keys="CtrlAltG"},
- {Name="Find" ; Area="Shell" ; ID="Search"; Keys="CtrlAltF"},
- {Name="Find" ; Area="Editor"; ID="Search"; Keys="CtrlAltF"},
- {Name="Find" ; Area="Viewer"; ID="Search"; Keys="CtrlAltF"},
- {Name="Replace" ; Area="Shell" ; ID="Replace"; Keys="CtrlAltH"},
- {Name="Replace" ; Area="Editor"; ID="Replace"; Keys="CtrlAltH"},
- {Name="Next" ; Area="Editor"; ID="SRAgain"; Keys="CtrlAltN"},
- {Name="Next" ; Area="Viewer"; ID="SRAgain"; Keys="CtrlAltN"},
- {Name="Previous" ; Area="Editor"; ID="SRAgainRev"; Keys="CtrlAltP"},
- {Name="Renumber" ; Area="Shell" ; ID="Renumber"; Keys="CtrlAltB"},
- {Name="Rename" ; Area="Shell" ; ID="Rename"; Keys="CtrlAltN"},
- {Name="Rename" ; Area="Shell" ; ID="RenameSelected"; Keys="CtrlAltR"},
- }
- },{
- Name = "SortString";
- ID = "5FE4D394-2FE5-453F-8DB9-D63C32E01D13";
- Functions = {{Name="Sort block"; Area="Editor"; Menu="8F24402E-6080-4497-84D2-EA60FB360815"; Keys="ShiftF6"; Keybar={"Sort",rus="Сортиров|ка"}}}
- },{
- Name = "WordCompletion";
- ID = "A227A268-5682-4C83-9341-EAE3405D4666";
- Functions = {{Name="Complete word"; Area="Editor"; Menu="A227A268-5682-4C83-9341-EAE3405D4666"; Keys="CtrlSpace"; PostKeys="Enter"}}
- },{
- Name = "AdvancedCompare";
- ID = "ED0C4BD8-D2F0-4B6E-A19F-B0B0137C9B0C";
- Functions = {{Name="Compare files / DIRs"; Area="Shell"; Keys="Ctrl/"}}
- },{
- Name = "ConsoleControl";
- ID = "94624B7B-FFDB-435F-B955-F99DBBC3BFE0";
- Functions = {
- {Name="Window 158x69"; Area="Shell"; Keys="CtrlAltF9"; Action=function() WindowSize(158,69) end;}
- }
- },{
- Name = "FileCase";
- ID = "ADAC3050-56E8-45FE-9CB1-A737623CC4A6";
- Functions = {{Name="Change case of files / DIRs"; Area="Shell"; Keys="Ctrl="}}
- },{
- Name = "TextConv";
- ID = "DD10A9C6-ECAC-4BFA-BB07-4A1E92744162";
- Functions = {{Name="Text file converter"; Area="Shell Editor"; Keys="Ctrl-"}}
- },{
- Name = "Calculator";
- ID = "894EAABB-C57F-4549-95FC-4AC6F3102A36";
- Functions = {
- {Name="Calculator" ; Area="Shell Viewer"; Keys="Alt="},
- {Name="Calculate line" ; Area="Editor"; Menu="DCEFBFC8-9C43-49E5-ABE6-875FED184652"; Keys="Alt=" },
- {Name="Calculate line (hex)" ; Area="Editor"; Menu="DCEFBFC8-9C43-49E5-ABE6-875FED184652"; Keys="Alt-"; PostKeys="h" }
- }
- },{
- Name = "DialogTools";
- ID = "B2EC2264-0F55-4B86-87F7-F1392B8FC5DC";
- Functions = {
- {Name="Undo" ; Area="Dialog"; Menu="1117C0E3-76BA-443D-90E3-89D20C45F364"; Keys="CtrlZ" ; Condition=IsDialogEditor; PostKeys="Enter" },
- {Name="Redo" ; Area="Dialog"; Menu="1117C0E3-76BA-443D-90E3-89D20C45F364"; Keys="CtrlShiftZ" ; Condition=IsDialogEditor; PostKeys="Down Enter" },
- {Name="Select Filename"; Area="Dialog"; Menu="39AE5A2C-A38D-40DE-AA59-207E96E5A17D"; Keys="CtrlF" ; Condition=IsDialogEditor },
- {Name="String Case" ; Area="Dialog"; Menu="37123652-3645-4776-86D6-A94FB2B12FC8"; Keys="Ctrl=" ; Condition=IsDialogEditor },
- {Name="String Edit" ; Area="Dialog"; Menu="D0C5118D-E750-4E00-A4D4-0E0E0063571F"; Keys="F4" ; Condition=IsDialogEditor },
- {Name="String Find" ; Area="Dialog"; Menu="40E53FB1-6291-45A1-9DDF-B4A2048CA6BA"; Keys="CtrlAltF" ; Condition=IsDialogEditor },
- {Name="String Replace" ; Area="Dialog"; Menu="F4C58B97-BA69-4814-9FC9-DAB9307C0E88"; Keys="CtrlAltH" ; Condition=IsDialogEditor }
- }
- }}
- Register = require("Register");
- for pairId,pluginInfo in ipairs(pluginInfoList) do
- Register.PluginInfo(Event,Macro,pluginInfo);
- end;
GeSHi © Codebox Plus Extension- local function SplitBookName(F)
- if mf.substr(F,-1)=="]" or mf.substr(F,-1)==")" or mf.substr(F,-1)=="}"
- then
- N=F; X="";
- else
- N=mf.fsplit(F,4); X=mf.fsplit(F,8);
- end
- -- Find remark(s)
- RIS=mf.rindex(N,"{");
- RIE=mf.rindex(N,"}");
- if RIS~=-1 and RIE~=-1
- then
- R=mf.trim(mf.substr(N,RIS+1,RIE-RIS-1));
- N=mf.trim(mf.substr(N,0,RIS)).." "..mf.trim(mf.substr(N,RIE+1));
- else
- R="";
- end
- -- Find author(s)
- AIS=mf.index(N,"[");
- AIE=mf.index(N,"]");
- if AIS~=-1 and AIE~=-1
- then
- T=mf.trim(mf.substr(N,0,AIS));
- A=mf.trim(mf.substr(N,AIS+1,AIE-AIS-1));
- N=mf.trim(mf.substr(N,AIE+1));
- else
- A="";
- T="";
- end
- -- Find year / edition
- EIS=mf.rindex(N,"(");
- EIE=mf.rindex(N,")");
- if EIS~=-1 and EIE~=-1
- then
- -- Find edition
- E=mf.trim(mf.substr(N,EIS+1,EIE-EIS-1));
- if mf.fmatch(E,"/.*\\D$/")==1
- then
- N=mf.trim(mf.substr(N,0,EIS)).." "..mf.trim(mf.substr(N,EIE+1));
- YIS=mf.rindex(N,"(");
- YIE=mf.rindex(N,")");
- else
- E="";
- YIS=EIS;
- YIE=EIE;
- end
- -- Find year
- Y=mf.trim(mf.substr(N,YIS+1,YIE-YIS-1));
- YL=mf.len(Y);
- if (YL<=4 and mf.fmatch(Y,"/\\d+/")==1) or (YL>=7 and YL<=10 and mf.fmatch(Y,"/\\d{3,4}.\\d{1,2}.\\d{1,2}/")==1)
- then
- N=mf.trim(mf.substr(N,0,YIS)).." "..mf.trim(mf.substr(N,YIE+1));
- else
- Y="";
- end
- else
- Y="";
- E="";
- end
- -- Find title
- T=mf.trim(T.." "..mf.trim(N));
- return T, A, Y, E, R, X
- end
- local function ChangeComplexName()
- if APanel.Bof and not APanel.Root
- then
- Keys("AKey")
- exit()
- end
- F = APanel.Current
- -- Edit book name
- while 1 do
- -- Split book name
- T, A, Y, E, R, X = SplitBookName(F);
- -- Edit selected (space to delete field)
- Idx=Menu.Show("\1Название\n&1. "..T.."\n\1Автор\n&2. "..A.."\n\1Год\n&3. "..Y.."\n\1Издание\n&4. "..E.."\n\1Примечания\n&5. "..R.."\n","Добавить или изменить",0x8);
- Changed=0;
- if Idx==2
- then
- S=prompt("|"..T.."|","Название:",0x30, T, "CCN.Title");
- if S then T=mf.trim(S); end
- elseif Idx==4
- then
- S=prompt("|"..A.."|","Автор:",0x30, A, "CCN.Author");
- if S then A=mf.trim(S); end
- elseif Idx==6
- then
- S=prompt("|"..Y.."|","Год:",0x30, Y, "CCN.Year");
- if S then Y=mf.trim(S); end
- elseif Idx==8
- then
- S=prompt("|"..E.."|","Издание:",0x30, E, "CCN.Edition");
- if S then E=mf.trim(S); end
- elseif Idx==10
- then
- S=prompt("|"..R.."|","Примечания:",0x30, R, "CCN.Remarks");
- if S then R=mf.trim(S); end
- else
- break
- end
- -- Join book name
- F=T;
- if A~="" then F=F.." ["..A.."]"; end
- if Y~="" then F=F.." ("..Y..")"; end
- if E~="" then F=F.." ("..E..")"; end
- if R~="" then F=F.." {"..R.."}"; end
- F=F..X;
- end
- if F~=APanel.Current then Keys("ShiftF6") print(F); Keys("Enter") end
- end;
- local function CopyFileSize()
- mf.clip(1,string.format('%d',Panel.Item(0,0,6)))
- end;
- local scriptInfo =
- {
- Name = "Shell";
- Functions = {
- {Name="Show console" ; Area="Shell"; Keys="Esc" ; PostKeys="CtrlO" },
- {Name="Copy File Name" ; Area="Shell"; Keys="CtrlIns" ; PostKeys="CtrlShiftIns" },
- {Name="Copy File Size" ; Area="Shell"; Keys="CtrlAltS" ; Action=CopyFileSize },
- {Name="Delete File" ; Area="Shell"; Keys="Del" ; PostKeys="F8" ; Flags="EmptyCommandLine"},
- {Name="Select File" ; Area="Shell"; Keys="Space" ; PostKeys="Ins" ; Flags="EmptyCommandLine"},
- {Name="Parent Directory" ; Area="Shell"; Keys="BS" ; PostKeys="CtrlPgUp" ; Flags="EmptyCommandLine"},
- {Name="Previous Directory" ; Area="Shell"; Keys="AltBS" ; PostKeys="AltF12 Up" },
- {Name="Change file name" ; Area="Shell"; Keys="AltShiftF6" ; Action=ChangeComplexName ; Keybar={"ChName",rus="ИзмИмя"}},
- }
- }
- require("Register").ScriptInfo(Event,Macro,scriptInfo);
GeSHi © Codebox Plus Extension
1.2. Уточнение получения языка меню FAR. Поддержка subID.
1.4. Разрешение конфликтов с другими модулями. Поле Conditions.
1.5. Использование Plugin.SyncCall вместо Plugin.Call, Plugin.Menu вместо Plugin.SyncCall при наличии PostKeys
1.4. Разрешение конфликтов с другими модулями. Поле Conditions.
1.5. Использование Plugin.SyncCall вместо Plugin.Call, Plugin.Menu вместо Plugin.SyncCall при наличии PostKeys