Skip to content

Commit

Permalink
1. Уточнения revision 12801 и revision 12820.
Browse files Browse the repository at this point in the history
2. Рефакторинг.
  • Loading branch information
shmuz committed Jan 12, 2015
1 parent ce39782 commit 78e8317
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 32 deletions.
2 changes: 1 addition & 1 deletion plugins/luamacro/_globalinfo.lua
@@ -1,6 +1,6 @@
function export.GetGlobalInfo()
return {
Version = { 1, 0, 0, 469 },
Version = { 1, 0, 0, 470 },
MinFarVersion = { 3, 0, 0, 4214 },
Guid = win.Uuid("4EBBEFC8-2084-4B7F-94C0-692CE136894D"),
Title = "LuaMacro",
Expand Down
10 changes: 9 additions & 1 deletion plugins/luamacro/changelog
@@ -1,4 +1,12 @@
shmuel 11.01.2015 19:58:26 +0200 - build 469
shmuel 12.01.2015 20:52:17 +0200 - build 470

1. Уточнение 465.1.

2. Уточнение 469.

3. Рефакторинг.

shmuel 11.01.2015 19:58:26 +0200 - build 469

1. Рефакторинг.

Expand Down
49 changes: 21 additions & 28 deletions plugins/luamacro/keymacro.lua
Expand Up @@ -51,6 +51,7 @@ local NewMacroRecord do
m_id = 0, -- идентификатор загруженного макроса в плагине LuaMacro; 0 для макроса, запускаемого посредством MSSC_POST.
m_flags = 0, -- флаги макропоследовательности
m_key = -1, -- назначенная клавиша
m_textkey= nil, -- текстовое представление назначенной клавиши
m_value = nil, -- значение, хранимое исполняющимся макросом
m_handle = nil -- хэндл исполняющегося макроса
}
Expand All @@ -63,8 +64,8 @@ local NewMacroRecord do
function MacroRecord:GetValue() return self.m_value end
function MacroRecord:SetValue(val) self.m_value=val end

NewMacroRecord = function (MacroId, Flags, Key)
return setmetatable({m_id=MacroId, m_flags=Flags, m_key=Key}, meta)
NewMacroRecord = function (MacroId, Flags, Key, TextKey)
return setmetatable({m_id=MacroId, m_flags=Flags, m_key=Key, m_textkey=TextKey }, meta)
end
end
--------------------------------------------------------------------------------
Expand Down Expand Up @@ -303,18 +304,15 @@ local function GetInputFromMacro()
return r1,r2
end

function KeyMacro.PostNewMacro (macroId, flags, key, postFromPlugin)
-- (1) mf.eval (2) keypress macro (3) mf.postmacro
-- (4) command line (5) macro browser (6) autostarting macros
function KeyMacro.PostNewMacro (macroId, flags, textKey, postFromPlugin)
flags = flags or 0
flags = postFromPlugin and bor(flags,MFLAGS_POSTFROMPLUGIN) or flags
local AKey = 0
if key then
local dKey = Import.KeyNameToKey(key)
if dKey ~= -1 then
AKey = dKey
end
if postFromPlugin then
flags = bor(flags, MFLAGS_POSTFROMPLUGIN)
end
CurState.MacroQueue:add(NewMacroRecord(macroId,flags,AKey))
return true
local aKey = textKey and Import.KeyNameToKey(textKey) or 0
CurState.MacroQueue:add(NewMacroRecord(macroId, flags, aKey, textKey))
end

local function TryToPostMacro (Mode, TextKey, IntKey)
Expand All @@ -337,22 +335,17 @@ function KeyMacro.DisableHistory (Mask)
return oldHistoryDisable
end

--Mode = 0 - возвращается код клавиши, Mode = 1 - возвращается наименование клавиши.
--Type = 0 - возвращает реально нажатое сочетание, которым вызывался макрос,
-- Type = 1 - возвращает клавишу, на которую назначен макрос.
function KeyMacro.akey (Mode, Type)
local TopMacro = GetTopMacro()
if TopMacro then
Mode = tonumber(Mode) or 0
Type = tonumber(Type) or 0

local aKey = TopMacro.m_key
if Type == 0 then
if 0 == band(TopMacro:GetFlags(),MFLAGS_POSTFROMPLUGIN) then
aKey = StateStack:top().IntKey
elseif aKey == 0 then
aKey = KEY_NONE
end
end

return Mode == 0 and aKey or Import.KeyToText(aKey)
local IsCodeOutput = (tonumber(Mode) or 0) == 0
local IsPressedKey = (tonumber(Type) or 0) == 0
local key = IsPressedKey and 0==band(TopMacro:GetFlags(),MFLAGS_POSTFROMPLUGIN) and
StateStack:top().IntKey or TopMacro.m_key
return IsCodeOutput and key or TopMacro.m_textkey or Import.KeyToText(key)
end
return false
end
Expand All @@ -364,9 +357,9 @@ function KeyMacro.TransformKey (key)
elseif lkey == "xlat" then
return 2
elseif lkey == "akey" then
local macro = GetCurMacro()
local macro = GetTopMacro()
if not macro then return nil end
return 3, (0==band(macro:GetFlags(),MFLAGS_POSTFROMPLUGIN)) and CurState.IntKey or macro.m_key
return 3, (0==band(macro:GetFlags(),MFLAGS_POSTFROMPLUGIN)) and StateStack:top().IntKey or macro.m_key
else
local iKey = Import.KeyNameToKey(key)
return 3, iKey==-1 and KEY_NONE or iKey
Expand Down Expand Up @@ -412,7 +405,7 @@ function KeyMacro.Dispatch (opcode, ...)
return GetCurMacro() and 0 or 1
elseif opcode == OP_GETSTATESTACKSIZE then
return #StateStack
elseif opcode == OP_POSTNEWMACRO then
elseif opcode == OP_POSTNEWMACRO then -- from API MacroControl(MSSC_POST)
local Lang,Code,Flags,AKey = ...
local f1,f2 = loadmacro(Lang,Code)
if f1 then
Expand Down
3 changes: 2 additions & 1 deletion plugins/luamacro/luamacro.lua
Expand Up @@ -196,7 +196,8 @@ end
local function postmacro (f, ...)
if type(f) == "function" then
return keymacro.PostNewMacro(pack(f, ...), 0, nil, true)
keymacro.PostNewMacro(pack(f, ...), 0, nil, true)
return true
end
return false
end
Expand Down
2 changes: 1 addition & 1 deletion plugins/luamacro/luamacro.rc
@@ -1,6 +1,6 @@
#include <farversion.hpp>

#define PLUGIN_BUILD 469
#define PLUGIN_BUILD 470
#define PLUGIN_DESC "Lua Macros for Far Manager"
#define PLUGIN_NAME "LuaMacro"
#define PLUGIN_FILENAME "luamacro.dll"
Expand Down

0 comments on commit 78e8317

Please sign in to comment.