-- Timer poll interval in milliseconds. local POLL_INTERVAL = 5000 -- Timer boost on input event interval in milliseconds. local BOOST_INTERVAL = 500 local SQLITE = 'C:\\cygwin\\bin\\setsid.exe C:\\cygwin\\bin\\sqlite3.exe' -- Run sqlite3 in background (returns immediately, best performance). --local SQLITE = 'C:\\cygwin\\bin\\sqlite3.exe' -- Run sqlite3 directly (blocks execution until transaction has finished). local LOCALCONFIG_DB = win.GetEnv('FARPROFILE') .. '\\localconfig.db' --local dbg = require "dbgprint".filter("FAR:"," ") --local inspect = require "inspect" local function CommitPanelState() -- dbg.print('commit') local leftPanel = APanel.Left and APanel or PPanel local rightPanel = APanel.Left and PPanel or APanel local sql = "BEGIN TRANSACTION; DELETE FROM 'general_config'; " .. "INSERT INTO 'general_config' VALUES('Panel.Left','CurFile','" .. leftPanel.Current:gsub("'", "''") .. "'); " .. "INSERT INTO 'general_config' VALUES('Panel.Left','Folder','" .. leftPanel.Path0:gsub("'", "''") .. "'); " .. "INSERT INTO 'general_config' VALUES('Panel.Right','CurFile','" .. rightPanel.Current:gsub("'", "''") .. "'); " .. "INSERT INTO 'general_config' VALUES('Panel.Right','Folder','" .. rightPanel.Path0:gsub("'", "''") .. "'); " .. "INSERT INTO 'general_config' VALUES('Panel','LeftFocus'," .. (APanel.Left and 1 or 0) .. "); " .. "COMMIT;" -- os.execute(SQLITE .. ' "' .. LOCALCONFIG_DB .. '" "' .. sql .. '"') end local lastActiveLeft = APanel.Left local lastLeftPath = APanel.Left and APanel.Path0 or PPanel.Path0 local lastLeftCurrent = APanel.Left and APanel.Current or PPanel.Current local lastRightPath = APanel.Left and PPanel.Path0 or APanel.Path0 local lastRightCurrent = APanel.Left and PPanel.Current or APanel.Current local function UpdatePanelState() local leftPanel = APanel.Left and APanel or PPanel local rightPanel = APanel.Left and PPanel or APanel local modified = false if APanel.Left ~= lastActiveLeft then lastActiveLeft = APanel.Left modified = true end if (leftPanel.Type == 0) and ((leftPanel.Path0 ~= lastLeftPath) or (leftPanel.Current ~= lastLeftCurrent)) then lastLeftPath = leftPanel.Path0 lastLeftCurrent = leftPanel.Current modified = true end if (rightPanel.Type == 0) and ((rightPanel.Path0 ~= lastRightPath) or (rightPanel.Current ~= lastRightCurrent)) then lastRightPath = rightPanel.Path0 lastRightCurrent = rightPanel.Current modified = true end if modified then CommitPanelState() end end local timer = far.Timer(POLL_INTERVAL, function(timer) timer.Enabled = false UpdatePanelState() timer.Interval = POLL_INTERVAL timer.Enabled = true end) Event { description="PanelChangeDir: Clean up timer on exit"; group="ExitFAR"; uid="351F4780-2799-47BF-984A-EB429E8B431E"; action=function() timer:Close() end; } Event { description="PanelChangeDir: Listen to input events"; group="ConsoleInput"; action=function(Rec) if ((Rec.EventType == far.Flags.KEY_EVENT) and (Rec.VirtualKeyCode ~= 0)) or ((Rec.EventType == far.Flags.MOUSE_EVENT) and (Rec.EventFlags ~= far.Flags.MOUSE_MOVED)) then timer.Interval = BOOST_INTERVAL end end; } local function InitPanelState() -- Make sure both panels are visible. if (not APanel.Visible) and (not PPanel.Visible) then Keys('CtrlO') elseif not PPanel.Visible then Keys('CtrlP') end -- If one or both panels have the user's home directory open, go to last history item or two last history items respectively. local home = win.GetEnv('HOMEDRIVE') .. win.GetEnv('HOMEPATH') if (APanel.Path == home) or (PPanel.Path == home) then Keys('AltF12') local itemPos = Menu.Select(home) if itemPos > 0 then Keys('ShiftDel End') end if APanel.Path == home then panel.SetPanelDirectory(nil, 1, Menu.Value or 'C:\\') Keys('Up') end if PPanel.Path == home then panel.SetPanelDirectory(nil, 0, Menu.Value or 'C:\\') end Keys('Esc') end end Macro { description="PanelChangeDir: Init panels on start"; area="Shell"; key="auto"; flags="RunAfterFARStart"; action = InitPanelState; }