Skip to content

Commit

Permalink
Highlight 0.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
shmuz committed Oct 20, 2023
1 parent 8e46a6d commit 95c235e
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 59 deletions.
14 changes: 2 additions & 12 deletions lua_share/far2/custommenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1055,8 +1055,7 @@ local function Menu (props, list)
local ret, ret_item, ret_pos
local Rect
local Items = { -- a hidden element for setting console title
osWindows and { F.DI_TEXT, 1,1,8,1, 0,0,0,F.DIF_HIDDEN, "" }
or { F.DI_TEXT, 1,1,8,1, 0,0,F.DIF_HIDDEN,0, "" },
{ F.DI_TEXT, 1,1,8,1, 0,0,0,F.DIF_HIDDEN, "" },
list:CreateDialogItems(2, 1),
}
local pos_title, pos_usercontrol = 1, 2
Expand All @@ -1068,10 +1067,6 @@ local function Menu (props, list)
DlgSend(hDlg, F.DM_SETINPUTNOTIFY or F.DM_SETMOUSEEVENTNOTIFY, 1) -- keep flag backward compatibility
list:OnInitDialog (hDlg)

elseif not osWindows and msg == F.DN_GETDIALOGINFO then
list.Log("DN_GETDIALOGINFO")
return props.DialogId

elseif osWindows and msg == F.DN_GETVALUE then
if param1 == pos_usercontrol then
local tp = param2.GetType
Expand Down Expand Up @@ -1190,12 +1185,7 @@ local function Menu (props, list)
X2, Y2 = X1+X2-1, Y1+Y2-1
end

if osWindows then
local id = props.DialogId or ("\0"):rep(16)
ret = far.Dialog(id, X1, Y1, X2, Y2, props.HelpTopic, Items, 0, DlgProc)
else
ret = far.Dialog(X1, Y1, X2, Y2, props.HelpTopic, Items, 0, DlgProc)
end
ret = far.Dialog(props.DialogId, X1, Y1, X2, Y2, props.HelpTopic, Items, 0, DlgProc)
if ret == pos_usercontrol then
return ret_item, ret_pos
end
Expand Down
11 changes: 11 additions & 0 deletions lua_share/far2/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,19 @@ local function mload (key, name, location)
return val, err
end

local function field (t, seq)
checkarg(t, 1, "table")
checkarg(seq, 2, "string")
for key in seq:gmatch("[^.]+") do
t[key] = t[key] or {}
t = t[key]
end
return t
end

return {
deserialize = deserialize;
field = field;
mdelete = mdelete;
mload = mload;
msave = msave;
Expand Down
45 changes: 12 additions & 33 deletions lua_share/far2/simpledialog.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ local Send = far.SendDlgMessage
local Colors = far.Colors or F

local IND_TYPE, IND_X1, IND_Y1, IND_X2, IND_Y2, IND_HISTORY, IND_DATA = 1,2,3,4,5,7,10
local IND_FOCUS = (FarVer==2) and 6 or nil
local IND_SELECTED = (FarVer==2) and 7 or 6
local IND_MASK = (FarVer==2) and 7 or 8
local IND_LIST = (FarVer==2) and 7 or 6
local IND_VBUF = (FarVer==2) and 7 or 6
local IND_FLAGS = (FarVer==2) and 8 or 9
local IND_DFLT = (FarVer==2) and 9 or nil
local IND_SELECTED = 6
local IND_MASK = 8
local IND_LIST = 6
local IND_VBUF = 6
local IND_FLAGS = 9

local mod = {} -- this module
local mod_meta = { __index=mod; }
Expand Down Expand Up @@ -207,11 +205,13 @@ local FlagsMap = {
btnnoclose = F.DIF_BTNNOCLOSE;
centergroup = F.DIF_CENTERGROUP;
centertext = F.DIF_CENTERTEXT;
default = F.DIF_DEFAULTBUTTON;
disable = F.DIF_DISABLE;
dropdown = F.DIF_DROPDOWNLIST;
editexpand = F.DIF_EDITEXPAND;
editor = F.DIF_EDITOR;
editpath = F.DIF_EDITPATH;
focus = F.DIF_FOCUS;
group = F.DIF_GROUP;
hidden = F.DIF_HIDDEN;
lefttext = F.DIF_LEFTTEXT;
Expand All @@ -236,9 +236,7 @@ if (FarVer == 2) then
FlagsMap.colormask = F.DIF_COLORMASK
FlagsMap.setcolor = F.DIF_SETCOLOR
else
FlagsMap.default = F.DIF_DEFAULTBUTTON
FlagsMap.editpathexec = F.DIF_EDITPATHEXEC
FlagsMap.focus = F.DIF_FOCUS
FlagsMap.listtrackmouse = F.DIF_LISTTRACKMOUSE
FlagsMap.listtrackmouseinfocus = F.DIF_LISTTRACKMOUSEINFOCUS
FlagsMap.righttext = F.DIF_RIGHTTEXT
Expand Down Expand Up @@ -345,8 +343,6 @@ function mod:Run()
if inp.hist then t [IND_HISTORY ] = inp.hist; end
if inp.val then t [IND_SELECTED] = inp.val; end
if inp.vbuf then t [IND_VBUF ] = inp.vbuf; end
if v.focus and FarVer==2 then t [IND_FOCUS ] = 1; end
if v.default and FarVer==2 then t [IND_DFLT ] = 1; end
if inp.text then t [IND_DATA ] = inp.text; end
return t
end
Expand Down Expand Up @@ -460,9 +456,6 @@ function mod:Run()
if Msg == F.DN_INITDIALOG then
if inData.initaction then inData.initaction(hDlg); end

elseif (FarVer == 2) and Msg == F.DN_GETDIALOGINFO then
return guid

elseif Msg == F.DN_CLOSE then
if inData.closeaction and inData[Par1] and not inData[Par1].cancel then
return inData.closeaction(hDlg, Par1, self:GetDialogState(hDlg))
Expand Down Expand Up @@ -513,17 +506,7 @@ function mod:Run()

elseif Msg == F.DN_CTLCOLORDLGITEM then
local colors = outData[Par1].colors
if colors then
if FarVer == 3 then -- TODO for Far 2
return colors
else
local col = 0
for i,v in ipairs(colors) do
col = bor(col, lshift(v,8*(i-1)))
end
return col
end
end
if colors then return colors end

end

Expand All @@ -533,16 +516,12 @@ function mod:Run()
local x1, y1 = inData.x1 or -1, inData.y1 or -1
local x2 = x1==-1 and W or x1+W-1
local y2 = y1==-1 and H or y1+H-1
local hDlg
if FarVer == 2 then
hDlg = far.DialogInit(x1,y1,x2,y2, help, outData, inData.flags, DlgProc)
else
hDlg = far.DialogInit(guid, x1,y1,x2,y2, help, outData, inData.flags, DlgProc)
if hDlg and F.FDLG_NONMODAL and 0 ~= band(inData.flags, F.FDLG_NONMODAL) then
local hDlg = far.DialogInit(guid, x1,y1,x2,y2, help, outData, inData.flags, DlgProc, inData.data)
if hDlg then
if F.FDLG_NONMODAL and 0 ~= band(inData.flags, F.FDLG_NONMODAL) then
return hDlg -- non-modal dialogs were introduced in build 3.0.5047
end
end
if not hDlg then
else
far.Message("Error occured in far.DialogInit()", "module 'simpledialog'", nil, "w")
return nil
end
Expand Down
3 changes: 1 addition & 2 deletions plugins/highlight/build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ scripts = \
$(path_plugin)\_globalinfo.lua

modules = \
$(path_share)*shmuz\serial.lua \
$(path_share)*far2\history.lua \
$(path_share)*far2\settings.lua \
$(path_share)*far2\simpledialog.lua

# Do not include PROCESSEDITOREVENT - it is in "highlight.c".
Expand Down
4 changes: 2 additions & 2 deletions plugins/highlight/build/define.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
-- Definitions
VER_MAJOR = "0"
VER_MINOR = "6"
VER_MICRO = "0"
VER_MICRO = "1"

MINFARVERSION = "{ 3, 0, 0, 4164 }"

COPYRIGHT = "Shmuel Zeigerman, 2014-2021"
COPYRIGHT = "Shmuel Zeigerman, 2014-2023"

-- Derivative values --
VER_STRING = VER_MAJOR.."."..VER_MINOR.."."..VER_MICRO
3 changes: 3 additions & 0 deletions plugins/highlight/doc/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
Legend: [+] added; [-] deleted; [*] changed; [!] fixed;
------------------------------------------------------------------

2023-10-20, v0.6.1
[*] Refactoring: use far2.settings instead of far2.history

2023-10-19, v0.6.0
[*] Refactoring: use far2.simpledialog instead of far2.dialog

Expand Down
22 changes: 12 additions & 10 deletions plugins/highlight/highlight.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,30 @@ local function NormalizeColorPriority (p)
return p
end

local Sett = require "far2.settings"
local sd = require "far2.simpledialog"
local SETTINGS_KEY = "shmuz"
local SETTINGS_NAME = "plugin_highlight"
local Field = Sett.field

local F = far.Flags
local band, bor, bxor, lshift = bit64.band, bit64.bor, bit64.bxor, bit64.lshift

local acFlags = bor(F.ECF_TABMARKCURRENT, F.ECF_AUTODELETE)
local AppTitle
local Hist_Config, Config
local Hist_Extra, Extra
local Hist, Config, Extra
local Owner
local PatEndLine = rex.new("$")
local Classes = {}
local sd = require "far2.simpledialog"
local libHistory = require "far2.history"

-- initialize AppTitle, Owner, Hist_Config, Config.
do
local info = export.GetGlobalInfo()
AppTitle, Owner = info.Title, info.Guid

Hist_Config = libHistory.newsettings(nil, "Config")
Config = Hist_Config.Data
Hist_Extra = libHistory.newsettings(nil, "ExtraData")
Extra = Hist_Extra.Data
Hist = Sett.mload(SETTINGS_KEY, SETTINGS_NAME) or {}
Config = Field(Hist, "Config")
Extra = Field(Hist, "ExtraData")

far.ReloadDefaultScript = Config.bDebugMode
Config.nColorPriority = NormalizeColorPriority(Config.nColorPriority)
Expand Down Expand Up @@ -516,7 +518,7 @@ local function ShowSettings()
end

far.ReloadDefaultScript = Config.bDebugMode
Hist_Config:save()
Sett.msave(SETTINGS_KEY, SETTINGS_NAME, Hist)
editor.Redraw()
end
end
Expand Down Expand Up @@ -655,7 +657,7 @@ local function HighlightExtra()
for k,v in pairs(data) do Extra[k]=v end
state.extracolor = extracolor
Extra.Color = extracolor
Hist_Extra:save()
Sett.msave(SETTINGS_KEY, SETTINGS_NAME, Hist)
else
ErrMsg(r)
return 0
Expand Down

0 comments on commit 95c235e

Please sign in to comment.