-- started: 2014-03-09 local ThisScriptId = "A84D789F-C101-4055-BFDA-E1594CB489DE" local F = far.Flags local plugmenuId = win.Uuid("937F0B1C-7690-4F85-8469-AA935517F202") local cfgmenuId = win.Uuid("B4C242E7-AA8E-4449-B0C3-BD8D9FA11AED") local farconfigId = win.Uuid("A204FF09-07FA-478C-98C9-E56F61377BDE") local Positions = mf.mload(ThisScriptId, "FarMenuPositions") or {} local LastArea = "Shell" -- Since Plugins menu can be called from various areas and it has the same GUID -- but different contents depending on the area it called from, in order to -- distinguish between those menus, this macro stores the area name prior to -- calling Plugins menu. Macro { description="Call Plugins menu"; area="Common"; key="F11 ShiftF11"; action=function() local a = Area.Current LastArea = (a=="Search" or a=="Tree" or a=="Info") and "Shell" or a Keys("F11") -- Execute the menu item if akey(1,1)=="ShiftF11" then Keys("Enter") end end; } -- Get the key for accessing the Positions table. -- NOTE: when adding new keys, their values must differ from any name of Far -- macro areas (numeric values are OK). local function GetKey (hDlg) local info = hDlg:send("DM_GETDIALOGINFO") if info then return info.Id == plugmenuId and LastArea or info.Id == cfgmenuId and 1 or info.Id == farconfigId and 2 end end local function EvHandler (Event, FarDialogEvent) --if Event == F.DE_DLGPROCINIT then --> crashes when opening RESearch plugin's search or replace dialogs. if Event == F.DE_DLGPROCEND then local hDlg, Msg = FarDialogEvent.hDlg, FarDialogEvent.Msg if Msg == F.DN_INITDIALOG then -- Set position in the menu local key = GetKey(hDlg) if key and Positions[key] then hDlg:send("DM_LISTSETCURPOS", 1, { SelectPos=Positions[key] }) end elseif Msg == F.DN_CLOSE then -- Get menu position local key = GetKey(hDlg) if key then local t = hDlg:send("DM_LISTGETCURPOS", 1) if t then Positions[key] = t.SelectPos end LastArea = "Shell" end end end end Event { description="Store and restore menu positions"; group="DialogEvent"; action=EvHandler; } Event { description="Save menu positions"; group="ExitFAR"; action=function() mf.msave(ThisScriptId, "FarMenuPositions", Positions) end; } |