local l = 43 -- ширина участка поля description в меню выбора (при применении key2Process) local BackSlashIn, BackSlashOut, NoBackSlash = 1, 2, 3 local shell_pref = BackSlashOut -- EDIT mode! local ctrl_enter_pref = NoBackSlash -- ... local editor_pref = BackSlashOut -- ... local dialog_pref = BackSlashOut -- ... -- Ctrl + [] -- Left/Right path -- Ctrl + Alt + [] -- Left/Right unc path -- Ctrl + Shift + [] -- Active/Passive path -- Alt + Shift + [] -- Active/Passive unc path local AllKeys = "Ctrl[ Ctrl] CtrlAlt[ CtrlAlt] CtrlShift[ CtrlShift] AltShift[ AltShift]" local function is_rootpath_key(key) local apanel_key; if (key:len() >= 10 or key:sub(1.1) == "A") then -- CtrlShift[ ] or AltShift[ ] apanel_key = key:sub(-1) == "[" else apanel_key = (key:sub(-1) == "[") == APanel.Left end local path0 = apanel_key and APanel.Path0 or PPanel.Path0 return path0:sub(-1) == "\\" -- root path ends with "\" end local function correction_keys(last2, pref) local last = last2:sub(-1) if pref == NoBackSlash then if last == '\\' then return 'BS', 1, nil -- Path\ or "Path"\ --> Path or "Path" elseif last2 == '\\"' then return 'BS BS "', 2, '"' -- "Path\" --> "Path" end elseif pref == BackSlashOut then if last ~= '\\' then if last2 ~= '\\"' then return 'BackSlash', 0, '\\' -- Path or "Path" --> Path\ or "Path"\ else return 'BS BS " BackSlash', 2, '"\\' -- "Path\" --> "Path"\ end end else -- BackSlashIn if last == '"' then if last2 ~= '\\"' then return 'BS BackSlash "', 1, '\\"' -- "Path" --> "Path\" end elseif last == '\\' then if last2 == '"\\' then return 'BS BS BackSlash "', 2, '\\"' -- "Path"\ --> "Path\" end else return 'BackSlash', 0, '\\' -- Path --> Path\ end end return nil end -- -- NOTE: new lua string library required for non-ascii text -- local function modify_redraw(val, nbs, adds, space, pos) Keys("CtrlY") local v = val:sub(1,pos-1-nbs-space) .. adds .. val:sub(pos-space) far.Show(val, nbs, adds, space, pos, v) print(v) for i = pos - nbs + adds:len(), v:len() do Keys("CtrlS") end end --Shell\AllKeys local function correction_keyss(last2, pref, ver) Keys("AKey") if is_rootpath_key(mf.key(akey(1))) then return end -- rootpath is always correct local pos, val = CmdLine.CurPos, CmdLine.Value if pos < 3 then return end -- unexpected result local modify, nbs, adds = correction_keys(val:sub(pos-2,pos-1), ver) --shell_pref if modify then if CmdLine.Eof or not adds then Keys(modify) else modify_redraw(val, nbs, adds, 0, pos) end end end; Macro { --(2useven10) area="Shell"; key=AllKeys; key2='CtrlEnter'; bdsize=l; sortpriority=70; description="путь с замыкающим бэкслешем ВНУТРИ кавычек"; --description="Backslash with Ctrl+[]"; action = function() correction_keyss(last2, pref, BackSlashIn) end; } Macro { --(2useven10) area="Shell"; key=AllKeys; key2='CtrlAlt'; bdsize=l; sortpriority=65; description="путь с замыкающим бэкслешем ЗА кавычками"; --description="Backslash with Ctrl+[]"; action = function() correction_keyss(last2, pref, BackSlashOut) end; } Macro { --(2useven10) area="Shell"; key=AllKeys; key2='CtrlShift'; bdsize=l; sortpriority=61; description="путь БЕЗ замыкающего бэкслеша"; --description="Backslash with Ctrl+[]"; action = function() correction_keyss(last2, pref, NoBackSlash) end; } --Shell\CtrlEnter-CtrlF local function correction_keysen(last2, pref, ver) Keys "CtrlEnter" if APanel.Path0:sub(-1) == "\\" then return end -- rootpath local pos, val = CmdLine.CurPos, CmdLine.Value if pos < 4 or CmdLine.Value:sub(pos-1,pos-1) ~= " " then return end -- unexpected result local modify, nbs, adds = correction_keys(val:sub(pos-3,pos-2), ver) --ctrl_enter_pref if modify then if CmdLine.Eof or not adds then Keys("BS") Keys(modify) Keys("Space") else modify_redraw(val, nbs, adds, 1, pos) end end end; Macro { --(2useven10) area="Shell"; key="CtrlEnter CtrlF"; key2='CtrlEnter'; bdsize=l; sortpriority=70; description="путь с замыкающим бэкслешем ВНУТРИ кавычек"; --description="Ctrl+Enter on .."; condition=function() return APanel.Current==".." end; action = function() correction_keysen(last2, pref, BackSlashIn) end; } Macro { --(2useven10) area="Shell"; key="CtrlEnter CtrlF"; key2='CtrlAlt'; bdsize=l; sortpriority=65; description="путь с замыкающим бэкслешем ЗА кавычками"; --description="Ctrl+Enter on .."; condition=function() return APanel.Current==".." end; action = function() correction_keysen(last2, pref, BackSlashOut) end; } Macro { --(2useven10) area="Shell"; key="CtrlEnter CtrlF"; key2='CtrlShift'; bdsize=l; sortpriority=61; description="путь БЕЗ замыкающего бэкслеша"; --description="Ctrl+Enter on .."; condition=function() return APanel.Current==".." end; action = function() correction_keysen(last2, pref, NoBackSlash) end; } --Editor\AllKeys local function correction_keysed(last2, pref, ver) Keys("AKey") if is_rootpath_key(mf.key(akey(1))) then return end -- rootpath is always correct local pos = Editor.RealPos if pos < 3 then return end -- unexpected result local modify = correction_keys(Editor.Value:sub(pos-2,pos-1), ver) --editor_pref if modify then if editor.GetInfo().Overtype ~= 0 then modify = "Ins "..modify.." Ins" end Keys(modify) end end; Macro { --(2useven10) area="Editor"; key=AllKeys; key2='CtrlEnter'; bdsize=l; sortpriority=70; description="путь с замыкающим бэкслешем ВНУТРИ кавычек"; --description="Backslash with Ctrl+[]"; action = function() correction_keysed(last2, pref, BackSlashIn) end; } Macro { --(2useven10) area="Editor"; key=AllKeys; key2='CtrlAlt'; bdsize=l; sortpriority=65; description="путь с замыкающим бэкслешем ЗА кавычками"; --description="Backslash with Ctrl+[]"; action = function() correction_keysed(last2, pref, BackSlashOut) end; } Macro { --(2useven10) area="Editor"; key=AllKeys; key2='CtrlShift'; bdsize=l; sortpriority=61; description="путь БЕЗ замыкающего бэкслеша"; --description="Backslash with Ctrl+[]"; action = function() correction_keysed(last2, pref, NoBackSlash) end; } --Dialog\AllKeys local function correction_keysdi(last2, pref, ver) Keys("AKey") if is_rootpath_key(mf.key(akey(1))) then return end -- rootpath is always correct local pos, val = Object.CurPos, Dlg.GetValue() if pos < 3 then return end -- unexpected result local modify, nbs, adds = correction_keys(val:sub(pos-2,pos-1), ver) --dialog_pref if modify then if Object.Eof or not adds then Keys(modify) else modify_redraw(val, nbs, adds, 0, pos) end end end; Macro { --(2useven10) area="Dialog"; key=AllKeys; key2='CtrlEnter'; bdsize=l; sortpriority=70; description="путь с замыкающим бэкслешем ВНУТРИ кавычек"; --description="Backslash with Ctrl+[]"; condition = function() return Dlg.ItemType == far.Flags.DI_EDIT end; action = function() correction_keysdi(last2, pref, BackSlashIn) end; } Macro { --(2useven10) area="Dialog"; key=AllKeys; key2='CtrlAlt'; bdsize=l; sortpriority=65; description="путь с замыкающим бэкслешем ЗА кавычками"; --description="Backslash with Ctrl+[]"; condition = function() return Dlg.ItemType == far.Flags.DI_EDIT end; action = function() correction_keysdi(last2, pref, BackSlashOut) end; } Macro { --(2useven10) area="Dialog"; key=AllKeys; key2='CtrlShift'; bdsize=l; sortpriority=61; description="путь БЕЗ замыкающего бэкслеша"; --description="Backslash with Ctrl+[]"; condition = function() return Dlg.ItemType == far.Flags.DI_EDIT end; action = function() correction_keysdi(last2, pref, NoBackSlash) end; } --[=[ 2useven10 Mon 14 Oct 2019 12:18 https://forum.farmanager.com/viewtopic.php?p=155787&sid=1c924111bdeed988fc1dc84e9977942f#p155787 Скрипт позволяет настроить по своим предпочтениям вставку обратного слеша в комстроку по клавишам Ctrl+[], Ctrl+Shift+[], Ctrl+Alt+[], Alt+Shift+[] и Ctrl+Enter на ".." Возможные режимы: без слеша, слеш внутри кавычек и слеш после кавычек. Если кавычек нет, последние 2 режима не отличаются. Скрипт должен работать на всех версиях фар3 где это поведение менялось: "Path\" 4521 "Path"\ 5472 "Path" 5486 "Path\" 2useven10 Mon 14 Oct 2019 12:20 https://forum.farmanager.com/viewtopic.php?p=155819#p155819 Ещё обновление - ошибки и Overtype в Dialog/CmdLine. ]=]-- |