Skip to content

Commit

Permalink
Рефакторинг, уточнения.
Browse files Browse the repository at this point in the history
  • Loading branch information
shmuz committed Jan 13, 2015
1 parent 78e8317 commit b7a006e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion plugins/luamacro/_globalinfo.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function export.GetGlobalInfo()
return {
Version = { 1, 0, 0, 470 },
Version = { 1, 0, 0, 471 },
MinFarVersion = { 3, 0, 0, 4214 },
Guid = win.Uuid("4EBBEFC8-2084-4B7F-94C0-692CE136894D"),
Title = "LuaMacro",
Expand Down
6 changes: 5 additions & 1 deletion plugins/luamacro/changelog
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
shmuel 12.01.2015 20:52:17 +0200 - build 470
shmuel 13.01.2015 19:29:57 +0200 - build 471

1. Рефакторинг, уточнения.

shmuel 12.01.2015 20:52:17 +0200 - build 470

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

Expand Down
30 changes: 21 additions & 9 deletions plugins/luamacro/keymacro.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ local NewMacroState do
IntKey = 0, -- "описание реально нажатой клавиши"
HistoryDisableMask = 0,
UseInternalClipboard = false,
Executing = MACROSTATE_NOMACRO,
MacroQueue = nil
}
local meta = { __index=MacroState }
Expand Down Expand Up @@ -185,7 +184,6 @@ end
function KeyMacro.InitInternalVars (InitedRAM)
if InitedRAM then
CurState.MacroQueue = NewQueue()
CurState.Executing = MACROSTATE_NOMACRO
end
CurState.HistoryDisableMask = 0
end
Expand Down Expand Up @@ -238,6 +236,7 @@ local function GetInputFromMacro()
if StateStack[1] then
PopState(true)
else
CurState = NewMacroState()
return MPRT_HASNOMACRO
end
end
Expand Down Expand Up @@ -297,7 +296,7 @@ local function GetInputFromMacro()
elseif r1 == "eval" then
local m = r2[1]
PushState(true)
KeyMacro.PostNewMacro(m.id, m.flags, r2[2], true)
KeyMacro.PostNewMacro(m.id, m.flags, r2[2], false)
return GetInputFromMacro() -- tail recursion
end

Expand Down Expand Up @@ -335,6 +334,16 @@ function KeyMacro.DisableHistory (Mask)
return oldHistoryDisable
end

local function GetLastPressedKey()
for level=#StateStack,1,-1 do
local state = StateStack[level]
local m = state:GetCurMacro()
if m and 0~=band(m:GetFlags(),MFLAGS_POSTFROMPLUGIN) then return m.m_key end
if state.IntKey > 0 then return state.IntKey end
end
return 0
end

--Mode = 0 - возвращается код клавиши, Mode = 1 - возвращается наименование клавиши.
--Type = 0 - возвращает реально нажатое сочетание, которым вызывался макрос,
-- Type = 1 - возвращает клавишу, на которую назначен макрос.
Expand All @@ -343,9 +352,12 @@ function KeyMacro.akey (Mode, Type)
if TopMacro then
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)
if IsPressedKey then
local key = GetLastPressedKey()
return IsCodeOutput and key or (key>0 and Import.KeyToText(key)) or ""
else
return IsCodeOutput and TopMacro.m_key or TopMacro.m_textkey or Import.KeyToText(TopMacro.m_key)
end
end
return false
end
Expand All @@ -357,9 +369,9 @@ function KeyMacro.TransformKey (key)
elseif lkey == "xlat" then
return 2
elseif lkey == "akey" then
local macro = GetTopMacro()
if not macro then return nil end
return 3, (0==band(macro:GetFlags(),MFLAGS_POSTFROMPLUGIN)) and StateStack:top().IntKey or macro.m_key
if StateStack:empty() then return nil end
local k = GetLastPressedKey()
return 3, k > 0 and k or 0
else
local iKey = Import.KeyNameToKey(key)
return 3, iKey==-1 and KEY_NONE or iKey
Expand Down
2 changes: 1 addition & 1 deletion plugins/luamacro/luamacro.rc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <farversion.hpp>

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

0 comments on commit b7a006e

Please sign in to comment.