Skip to content

Commit

Permalink
LuaMacro: в таблицы определений Macro и Event добавлено опциональное …
Browse files Browse the repository at this point in the history
…поле "id" типа string.
  • Loading branch information
shmuz committed Jul 18, 2016
1 parent d44cb4d commit 0b01648
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 39 deletions.
18 changes: 10 additions & 8 deletions enc/enc_lua/macroapi_manual.en.tsi
Expand Up @@ -101,7 +101,7 @@ lv=2
dt=Text
nm=Regular macros
ctime=3580139016
mtime=3666203724
mtime=3678015120
<article>
#_<markdown>
#_
Expand All @@ -118,6 +118,7 @@ mtime=3666203724
#_ sortpriority = 50; -- number (optional field)
#_ condition = function(key) return Far.Height>30 end; -- function (optional field)
#_ action = function() msgbox("","Macro example") end; -- function
#_ id = "F0109446-AA63-4873-AEC3-17AEE993AA53"; -- string (optional field)
#_ }
#_```
#_
Expand Down Expand Up @@ -225,7 +226,7 @@ lv=2
dt=Text
nm=Event handlers
ctime=3580139337
mtime=3655200145
mtime=3678018954
<article>
#_<markdown>
#_
Expand All @@ -235,12 +236,13 @@ mtime=3655200145
#_
#_```
#_Event {
#_ group = "EditorEvent"; -- string
#_ description = "Event example"; -- string (optional field)
#_ filemask = "*.txt,*.cpp"; -- string (optional field)
#_ priority = 50; -- number (optional field)
#_ condition = function() ...... end; -- function (optional field)
#_ action = function() ...... end; -- function
#_ group = "EditorEvent"; -- string
#_ description = "Event example"; -- string (optional field)
#_ filemask = "*.txt,*.cpp"; -- string (optional field)
#_ priority = 50; -- number (optional field)
#_ condition = function() ...... end; -- function (optional field)
#_ action = function() ...... end; -- function
#_ id = "F0109446-AA63-4873-AEC3-17AEE993AA53"; -- string (optional field)
#_}
#_```
#_
Expand Down
18 changes: 10 additions & 8 deletions enc/enc_lua/macroapi_manual.ru.tsi
Expand Up @@ -101,7 +101,7 @@ lv=2
dt=Text
nm=������������ �������
ctime=3580139016
mtime=3666203478
mtime=3678014959
<article>
#_<markdown>
#_
Expand All @@ -118,6 +118,7 @@ mtime=3666203478
#_ sortpriority = 50; -- number (������������ ����)
#_ condition = function(key) return Far.Height>30 end; -- function (������������ ����)
#_ action = function() msgbox("","Macro example") end; -- function
#_ id = "F0109446-AA63-4873-AEC3-17AEE993AA53"; -- string (������������ ����)
#_ }
#_```
#_
Expand Down Expand Up @@ -226,7 +227,7 @@ lv=2
dt=Text
nm=����������� �������
ctime=3580139337
mtime=3655200078
mtime=3678018855
<article>
#_<markdown>
#_
Expand All @@ -236,12 +237,13 @@ mtime=3655200078
#_
#_```
#_Event {
#_ group = "EditorEvent"; -- string
#_ description = "Event example"; -- string (������������ ����)
#_ filemask = "*.txt,*.cpp"; -- string (������������ ����)
#_ priority = 50; -- number (������������ ����)
#_ condition = function() ...... end; -- function (������������ ����)
#_ action = function() ...... end; -- function
#_ group = "EditorEvent"; -- string
#_ description = "Event example"; -- string (������������ ����)
#_ filemask = "*.txt,*.cpp"; -- string (������������ ����)
#_ priority = 50; -- number (������������ ����)
#_ condition = function() ...... end; -- function (������������ ����)
#_ action = function() ...... end; -- function
#_ id = "F0109446-AA63-4873-AEC3-17AEE993AA53"; -- string (������������ ����)
#_}
#_```
#_
Expand Down
2 changes: 1 addition & 1 deletion plugins/luamacro/_globalinfo.lua
@@ -1,6 +1,6 @@
function export.GetGlobalInfo()
return {
Version = { 1, 0, 0, 578 },
Version = { 1, 0, 0, 579 },
MinFarVersion = { 3, 0, 0, 4582 },
Guid = win.Uuid("4EBBEFC8-2084-4B7F-94C0-692CE136894D"),
Title = "LuaMacro",
Expand Down
2 changes: 1 addition & 1 deletion plugins/luamacro/api.lua
Expand Up @@ -411,7 +411,7 @@ function mf.eval (str, mode, lang)

local macro = utils.GetMacro(area,key,usecommon,false)
if not macro then return -2 end
if not macro.id then return -3 end
if not macro.index then return -3 end

return Eval_FixReturn(yieldcall("eval", macro, key))
end
Expand Down
6 changes: 5 additions & 1 deletion plugins/luamacro/changelog
@@ -1,4 +1,8 @@
shmuel 04.07.2016 17:35:59 +0200 - build 578
shmuel 18.07.2016 15:59:19 +0200 - build 579

1. В таблицы определений Macro и Event добавлено опциональное поле "id" типа string.

shmuel 04.07.2016 17:35:59 +0200 - build 578

1. LuaFAR: добавлена функция win.GetKeyState.

Expand Down
2 changes: 1 addition & 1 deletion plugins/luamacro/keymacro.lua
Expand Up @@ -310,7 +310,7 @@ end
local function TryToPostMacro (Mode, TextKey, IntKey)
local m = utils.GetMacro(Mode, TextKey, true, false)
if m then
if m.id then
if m.index then
KeyMacro.PostNewMacro(m, m.flags, TextKey, false)
CurState.HistoryDisableMask = 0
CurState.IntKey = IntKey
Expand Down
2 changes: 1 addition & 1 deletion plugins/luamacro/luamacro.rc
@@ -1,6 +1,6 @@
#include <farversion.hpp>

#define PLUGIN_BUILD 578
#define PLUGIN_BUILD 579
#define PLUGIN_DESC "Lua Macros for Far Manager"
#define PLUGIN_NAME "LuaMacro"
#define PLUGIN_FILENAME "luamacro.dll"
Expand Down
4 changes: 2 additions & 2 deletions plugins/luamacro/mbrowser.lua
Expand Up @@ -53,7 +53,7 @@ local function GetItems (fcomp, sortmark, onlyactive)
s=s..(ars[v] and areaCodes[v] or ".")
end
m.codedArea=s
m.description=m.description and norm_utf8(m.description) or "id="..m.id
m.description=m.description and norm_utf8(m.description) or "index="..m.index
m.key=norm_utf8(m.key)
macros[#macros+1]=m
local keylen = m.key:len()
Expand All @@ -62,7 +62,7 @@ local function GetItems (fcomp, sortmark, onlyactive)
end
end
else
m.description=m.description and norm_utf8(m.description) or "id="..m.id
m.description=m.description and norm_utf8(m.description) or "index="..m.index
events[#events+1]=m
end
end
Expand Down
47 changes: 31 additions & 16 deletions plugins/luamacro/utils.lua
Expand Up @@ -60,6 +60,7 @@ local Events
local EventGroups = {"dialogevent","editorevent","editorinput","exitfar","viewerevent", "consoleinput"}
local AddedMenuItems
local AddedPrefixes
local IdSet

package.nounload = {lpeg=true}
local initial_modules = {}
Expand Down Expand Up @@ -162,6 +163,17 @@ local function ReadIniFile (filename)
return t
end

local function AddId (trg, src)
trg.id = "<no id>"
if type(src.id)=="string" then
local lstr = src.id:lower()
if not IdSet[lstr] then
IdSet[lstr] = true
trg.id = src.id
end
end
end

local function EV_Handler (macros, filename, ...)
-- Get current priorities.
local indexes,priorities = {},{}
Expand Down Expand Up @@ -379,6 +391,7 @@ local function AddRegularMacro (srctable, FileName)
if type(priority)=="number" then
macro.sortpriority = priority>100 and 100 or priority<0 and 0 or priority
end
AddId(macro, srctable)

if FileName then
macro.FileName = FileName
Expand All @@ -389,8 +402,8 @@ local function AddRegularMacro (srctable, FileName)
macro.language = srctable.language
end

macro.id = #LoadedMacros+1
LoadedMacros[macro.id] = macro
macro.index = #LoadedMacros+1
LoadedMacros[macro.index] = macro
return macro
end
end
Expand Down Expand Up @@ -427,8 +440,8 @@ local function AddRecordedMacro (srctable, filename)
macro.flags = StringToFlags(srctable.flags, filename)
if type(macro.description)~="string" then macro.description=nil end

macro.id = #LoadedMacros+1
LoadedMacros[macro.id] = macro
macro.index = #LoadedMacros+1
LoadedMacros[macro.index] = macro
end

local AddEvent_fields = {"group","action","description","priority","condition","filemask"}
Expand All @@ -451,9 +464,10 @@ local function AddEvent (srctable, FileName)
if type(macro.priority)~="number" then macro.priority=50
elseif macro.priority>100 then macro.priority=100 elseif macro.priority<0 then macro.priority=0
end
AddId(macro, srctable)

macro.id = #LoadedMacros+1
LoadedMacros[macro.id] = macro
macro.index = #LoadedMacros+1
LoadedMacros[macro.index] = macro
return macro
end

Expand Down Expand Up @@ -486,8 +500,8 @@ local function AddMenuItem (srctable, FileName)
item.action = srctable.action
item.description = type(srctable.description)=="string" and srctable.description or ""
item.FileName = FileName
item.id = #AddedMenuItems + 1
AddedMenuItems[item.id] = item
item.index = #AddedMenuItems + 1
AddedMenuItems[item.index] = item
AddedMenuItems[item.guid] = item
return true
end
Expand Down Expand Up @@ -628,6 +642,7 @@ local function LoadMacros (unload, paths)
LoadedMacros = {}
AddedMenuItems = {}
AddedPrefixes = { [1]="" }
IdSet = {}
if Shared.panelsort then Shared.panelsort.DeleteSortModes() end

local AreaNames = allAreas and AllAreaNames or SomeAreaNames
Expand All @@ -650,8 +665,8 @@ local function LoadMacros (unload, paths)
table.insert(newAreas[a][k], m)
if not IdUpdated[m] then
IdUpdated[m] = true
m.id = #LoadedMacros+1
LoadedMacros[m.id] = m
m.index = #LoadedMacros+1
LoadedMacros[m.index] = m
end
end
end
Expand Down Expand Up @@ -832,7 +847,7 @@ local function GetFromMenu (macrolist)
for i,macro in ipairs(macrolist) do
local descr = macro.description
if not descr or descr=="" then
descr = ("< No description: Id=%d >"):format(macro.id)
descr = ("< No description: Index=%d >"):format(macro.index)
end
menuitems[i] = { text=descr, macro=macro }
end
Expand Down Expand Up @@ -1023,8 +1038,8 @@ local function ProcessRecordedMacro (Mode, Key, code, flags, description)
needsave=true
}
local existing = Areas[area][keys[1]] and Areas[area][keys[1]].recorded
macro.id = existing and existing.id or #LoadedMacros+1
LoadedMacros[macro.id] = macro
macro.index = existing and existing.index or #LoadedMacros+1
LoadedMacros[macro.index] = macro

for i=1,numkeys do
local k = keys[i]
Expand Down Expand Up @@ -1090,10 +1105,10 @@ local function RunStartMacro()
return true
end

local function GetMacroCopy (id)
if LoadedMacros[id] then
local function GetMacroCopy (index)
if LoadedMacros[index] then
local t={}
for k,v in pairs(LoadedMacros[id]) do t[k]=v end
for k,v in pairs(LoadedMacros[index]) do t[k]=v end
return t
end
return nil
Expand Down

0 comments on commit 0b01648

Please sign in to comment.