Возможности:
* при показе истории сразу включен режим фильтра (для фильтрации элементов истории);
* нажатие Alt+F8 / Alt+F11 / Alt+F12 во время показа истории переключает её тип (например, из истории папок нажатием Alt+F11 можно перейти в историю просмотра/редактирования);
* нажатие Del очищает фильтр;
* нажатие Ctrl+PgUp переходит в указанную папку (из истории папок или просмотра/редактирования) и позиционирует на имя файла из истории просмотра/редактирования;
* нажатие Ctrl+PgDn переходит в указанную папку (из истории папок или просмотра/редактирования), позиционирует на имя файла из истории просмотра/редактирования и открывает этот файл в просмотрщике/редакторе;
* нажатие Shift+Enter в истории папок переходит в указанную папку на пассивной панели.
- local HistoryMenuType = {
- ViewEdit = 1,
- Folders = 2,
- Commands = 3
- }
- local HistoryMenuId = {
- ViewEdit = "E770E044-23A8-4F4D-B268-0E602B98CCF9",
- Folders = "FC3384A8-6608-4C9B-8D6B-EE105F4C5A54",
- Commands = "880968A6-6258-43E0-9BDC-F2B8678EC278"
- }
- local ItemAction = {
- SetFile = 0,
- OpenFile = 1,
- SetDir = 2
- }
- local MenuInvokeAreaIsShell = true
- local SavedMenuId = ""
- local function GetHistoryMenuId(menuType)
- if menuType == HistoryMenuType.ViewEdit then
- return HistoryMenuId.ViewEdit
- elseif menuType == HistoryMenuType.Folders then
- return HistoryMenuId.Folders
- elseif menuType == HistoryMenuType.Commands then
- return HistoryMenuId.Commands
- else
- return nil
- end
- end
- local function GetLocalizedStrings()
- local lang = far.lang or win.GetEnv("farlang")
- if lang == "Russian" then
- return {
- CmdView = "просмотр";
- CmdEdit = "редактор";
- }
- else
- return {
- CmdView = "view";
- CmdEdit = "edit";
- }
- end
- end
- local function GetShowMenuKeys(s)
- return string.format("%s AltEnd CtrlAltF", s)
- end
- local function IsAnyHistoryMenu()
- local menuId = Menu.Id
- return menuId == HistoryMenuId.ViewEdit or menuId == HistoryMenuId.Folders or menuId == HistoryMenuId.Commands
- end
- local function IsDirectory(path)
- return bit.band(mf.fattr(path), 0x00000010) ~= 0
- end
- local function StripPath(path)
- if path:len() >= 2 and path:sub(1, 1) == '"' and path:sub(path:len()) == '"' then
- path = path:sub(2, path:len() - 1)
- end
- if path:len() > 0 and (path:sub(path:len()) == '\\' or path:sub(path:len()) == '/') then
- path = path:sub(1, path:len() - 1)
- end
- -- mf.msgbox(path)
- return path
- end
- local function Panel_GoToFolderAndOpen(path, panelType, itemAction)
- local dir = ""
- local name = ""
- local cmdViewEdit = 0
- local i = mf.index(path, ":")
- if i > 0 then
- local prefix = mf.lcase(mf.substr(path, 0, i))
- local localizedStrings = GetLocalizedStrings()
- if prefix == localizedStrings.CmdView then
- cmdViewEdit = 1
- elseif prefix == localizedStrings.CmdEdit then
- cmdViewEdit = 2
- end
- if cmdViewEdit ~= 0 then
- path = mf.trim(mf.substr(path, i + 1))
- end
- end
- dir = path
- if itemAction == ItemAction.SetDir then
- i = mf.rindex(path, "\\")
- if i <= 0 then
- i = mf.rindex(path, "/")
- end
- if i > 0 then
- name = mf.substr(path, i + 1)
- dir = mf.substr(path, 0, i)
- end
- elseif not IsDirectory(path) then
- name = mf.fsplit(path, 0x0000000C)
- dir = mf.fsplit(path, 0x00000003)
- end
- Panel.SetPath(panelType, dir, name)
- if itemAction == ItemAction.OpenFile and mf.fexist(path) then
- if cmdViewEdit == 1 then
- viewer.Viewer(path, nil, nil, nil, nil, nil, far.Flags.VF_IMMEDIATERETURN + far.Flags.VF_NONMODAL)
- elseif cmdViewEdit == 2 then
- editor.Editor(path, nil, nil, nil, nil, nil, far.Flags.EF_IMMEDIATERETURN + far.Flags.EF_NONMODAL)
- end
- end
- end
- local function Menu_ReTitle()
- local windowInfo = far.AdvControl(far.Flags.ACTL_GETWINDOWINFO)
- local oldTitles = far.SendDlgMessage(windowInfo.Id, far.Flags.DM_LISTGETTITLES) or { Title = "", Bottom = "" }
- local newTitles = { Title = oldTitles.Title .. " []", Bottom = oldTitles.Bottom }
- msgbox(newTitles.Title)
- far.SendDlgMessage(windowInfo.Id, far.Flags.DM_LISTSETTITLES, 0, newTitles)
- end
- Macro {
- area="Shell";
- description="View/Edit history (filtered)";
- key="AltF11";
- action = function()
- MenuInvokeAreaIsShell = true
- Keys( GetShowMenuKeys("AltF11") )
- -- Menu_ReTitle()
- end;
- }
- Macro {
- area="Shell";
- description="Folders history (filtered)";
- key="AltF12";
- action = function()
- MenuInvokeAreaIsShell = true
- Keys( GetShowMenuKeys("AltF12") )
- end;
- }
- Macro {
- area="Shell";
- description="Commands history (filtered)";
- key="AltF8";
- action = function()
- MenuInvokeAreaIsShell = true
- local filter = CmdLine.Value
- Keys( GetShowMenuKeys("AltF8") )
- if filter ~= "" then
- Menu.FilterStr(1, filter)
- end
- end;
- }
- Macro {
- area="Editor";
- description="View/Edit history (filtered)";
- key="AltF11";
- condition = function()
- return bit.band(Editor.State, 0x00000800) == 0
- end;
- action = function()
- MenuInvokeAreaIsShell = false
- Keys( GetShowMenuKeys("AltF11") )
- end;
- }
- Macro {
- area="Viewer";
- description="View/Edit history (filtered)";
- key="AltF11";
- condition = function()
- return bit.band(Viewer.State, 0x00000800) == 0
- end;
- action = function()
- MenuInvokeAreaIsShell = false
- Keys( GetShowMenuKeys("AltF11") )
- end;
- }
- Macro {
- area="Menu";
- description="View/Edit history (from other history)";
- key="AltF11";
- condition = function()
- return Menu.Id == HistoryMenuId.Commands or Menu.Id == HistoryMenuId.Folders
- end;
- action = function()
- local filter = Menu.FilterStr(0)
- Keys( "Esc " .. GetShowMenuKeys("AltF11") )
- Menu.FilterStr(1, filter)
- end;
- }
- Macro {
- area="Menu";
- description="Commands history (from other history)";
- key="AltF8";
- condition = function()
- return (Menu.Id == HistoryMenuId.ViewEdit or Menu.Id == HistoryMenuId.Folders) and MenuInvokeAreaIsShell
- end;
- action = function()
- local filter = Menu.FilterStr(0)
- Keys( "Esc " .. GetShowMenuKeys("AltF8") )
- Menu.FilterStr(1, filter)
- end;
- }
- Macro {
- area="Menu";
- description="Folders history (from other history)";
- key="AltF12";
- condition = function()
- return (Menu.Id == HistoryMenuId.ViewEdit or Menu.Id == HistoryMenuId.Commands) and MenuInvokeAreaIsShell
- end;
- action = function()
- local filter = Menu.FilterStr(0)
- Keys( "Esc " .. GetShowMenuKeys("AltF12") )
- Menu.FilterStr(1, filter)
- end;
- }
- Macro {
- area="Menu";
- description="History: clear the filter";
- key="Del";
- condition = function()
- return IsAnyHistoryMenu() and Menu.Filter(0, -1) ~= 0
- end;
- action = function()
- Menu.FilterStr(1, "")
- end;
- }
- Macro {
- area="Menu";
- description="History: go to folder and file";
- key="CtrlPgUp";
- condition = function()
- SavedMenuId = Menu.Id
- return IsAnyHistoryMenu()
- end;
- action = function()
- local path = StripPath(Menu.Value)
- Keys("Esc")
- if not MenuInvokeAreaIsShell then
- Keys("F12 0")
- end
- if SavedMenuId == HistoryMenuId.Commands then
- if mf.fexist(path) then
- local itemAction = ItemAction.SetFile
- if IsDirectory(path) then
- itemAction = ItemAction.SetDir
- end
- Panel_GoToFolderAndOpen(path, 0, itemAction)
- end
- elseif SavedMenuId == HistoryMenuId.Folders then
- Panel_GoToFolderAndOpen(path, 0, ItemAction.SetDir)
- else
- Panel_GoToFolderAndOpen(path, 0, ItemAction.SetFile)
- end
- end;
- }
- Macro {
- area="Menu";
- description="History: go to folder and file plus view/edit";
- key="CtrlPgDn";
- condition = function()
- return Menu.Id == HistoryMenuId.ViewEdit or Menu.Id == HistoryMenuId.Folders
- end;
- action = function()
- local path = StripPath(Menu.Value)
- Keys("Esc")
- if not MenuInvokeAreaIsShell then
- Keys("F12 0")
- end
- Panel_GoToFolderAndOpen(path, 0, ItemAction.OpenFile)
- end;
- }
- Macro {
- area="Menu";
- description="History: go to folder on the passive panel";
- key="ShiftEnter";
- condition = function()
- return Menu.Id == HistoryMenuId.Folders
- end;
- action = function()
- local path = StripPath(Menu.Value)
- Keys("Esc")
- Panel_GoToFolderAndOpen(path, 1, ItemAction.SetFile)
- end;
- }
GeSHi © Codebox Plus Extension