Можно указать шаблон для фильтрации ярлыков.
Макрос не поддерживает переход на "рабочий каталог" ярлыка.
При вызове выводится меню со списком ярлыков, и через разделитель - список вложенных папок. При выборе вложенной папки выводится следующее меню, отражающее ярлыки и папки выбранной папки.
- --[[
- Работа с элементами StartMenu
- Версия 2
- --]]
- local F=far.Flags
- local GUIDLnkView = "53415453-E31E-4D4C-8FE5-D6B0C6853E7C"
- local MenuID=win.Uuid"72D149F0-C652-45CA-BC78-B9C661DE0515"
- local HelpFile='<' .. mf.fsplit(..., 7) .. (Far.GetConfig('Language.Help') or win.GetEnv('FARLANG') or 'English'):sub(1,3) .. '.hlf' .. '>'
- local InitPrivDir= win.GetEnv"APPDATA"..[[\Microsoft\Windows\Start Menu\Programs]]
- local InitPubDir= win.GetEnv"ALLUSERSPROFILE"..[[\Microsoft\Windows\Start Menu]]
- local function ShortcutList(InitDirs, Masks)
- local Result=true
- local tt = {}
- local bWasFile, bWasDir=false,false
- local function FillMenu(InitDir, AMask)
- -- Список всех подкаталогов первого уровня, внутри которых (на любом уровне) имеется ярлык, соответствующий маске
- local _Mask=AMask
- if _Mask:match('^%s*$') then
- _Mask = '*.lnk'
- elseif mf.fsplit(_Mask,8):lower() ~= '.lnk' then
- _Mask = _Mask .. '.lnk'
- end
- far.RecursiveSearch(InitDir, _Mask,
- function(FI, FName)
- if not FI.FileAttributes:match"d" then
- -- Не каталог, файл найден. Надо занести либо имя файла (если он в текущей папке), либо имя подкаталога
- if mf.fsplit(FName, 3):sub(1,-2):upper() == InitDir:upper() then
- -- Файл в текущем каталоге. Заношу имя файла
- table.insert(tt, {text=mf.fsplit(FName, 12); FullName=FName; sub=1})
- bWasFile = true
- else
- -- Файл во вложенной папке. Заношу имя вложенной папки следующего уровня
- local SubDir=mf.fsplit(FName,3)
- --table.insert(tt, {text=SubDir:sub(InitDir:len()+2):match('^(.-)\\'); SubDir=SubDir:sub(1,-2); sub=3})
- table.insert(tt, {text=SubDir:sub(InitDir:len()+2):sub(1,-2); SubDir=SubDir:sub(1,-2); sub=3})
- bWasDir = true
- end
- end
- end,
- 'FRS_RECUR')
- -- Добавяю папки, соответствующие маске
- _Mask = AMask
- far.RecursiveSearch(InitDir, _Mask,
- function(FI, FName)
- if FI.FileAttributes:match"d" then
- table.insert(tt,{text=FName:sub(InitDir:len()+2); SubDir=FName; sub=3})
- bWasDir = true
- end
- end,
- F.FRS_NONE
- )
- end -- function FillMenu
- for _,v in ipairs(InitDirs) do
- for _,m in ipairs(Masks) do
- FillMenu(v, m)
- end
- end
- --if Mask ~= '' then
- -- for _,v in ipairs(InitDirs) do FillMenu(v, '') end
- --end
- if bWasFile then
- table.insert(tt, {separator=true, text="Ярлыки"; sub=0})
- end
- if bWasDir then
- table.insert(tt, {separator=true, text="Каталоги"; sub=2})
- end
- table.sort(tt, function(Item1, Item2) return Item1.sub < Item2.sub or (Item1.sub == Item2.sub and Item1.text:upper() < Item2.text:upper()) end)
- -- Удаление дублей
- for i=#tt, 2,-1 do
- if tt[i].sub == tt[i-1].sub then
- if ( tt[i].sub == 3 and
- tt[i].SubDir == tt[i-1].SubDir ) or
- ( tt[i].sub == 1 and
- tt[i].FullName == tt[i-1].FullName ) then
- table.remove(tt, i)
- end
- end
- end
- local pos, res = 1
- while Result do
- Result = false
- if Plugin.Exist(GUIDLnkView) then
- res, pos=far.Menu( { Title="Список ярлыков меню Start";
- Bottom="Enter, Ctrl[Shift]PgDn, Ctrl[Shift] ←/→, F3, F4, BS";
- Id=MenuID;
- HelpTopic=HelpFile .. 'Work';
- SelectIndex=pos;
- },
- tt,
- { {BreakKey="CtrlPgDn"}; {BreakKey="CtrlShiftPgDn"}; {BreakKey="CtrlPgUp"}; {BreakKey="CtrlShiftPgUp"};
- {BreakKey="CtrlLeft"}; {BreakKey="CtrlRight"}; {BreakKey="CtrlShiftLeft"}; {BreakKey="CtrlShiftRight"}; -- Почему-то CtrlAlt ←/→ не виден
- {BreakKey="F3"}; {BreakKey="F4"}; {BreakKey="BS"};
- })
- else
- res, pos=far.Menu( { Title="Список ярлыков меню Start";
- Bottom="Enter, BS";
- Id=MenuID;
- HelpTopic=HelpFile .. 'Work';
- SelectIndex=pos;
- },
- tt,
- {{BreakKey="BS"}})
- end -- if Plugin.Exist(<...>)
- if res then
- if res.BreakKey == 'BS' then
- return false
- elseif res.BreakKey and
- (' CtrlPgDn CtrlShiftPgDn CtrlPgUp CtrlShiftPgUp CtrlRight CtrlLeft CtrlShiftRight CtrlShiftLeft '):match('%s('..res.BreakKey..')%s') then
- -- Переход на объект (PgDn) или в рабочий каталог (PgUp)
- local Pan
- if res.BreakKey:match('Pg') then
- Pan = res.BreakKey == 'CtrlPgDn' and 0 or 1 -- CtrlPgDn - переход на активной панели; с Shift-ом - на пассивной
- else
- Pan = (res.BreakKey:match"Left" and APanel.Left) and 0 or 1 -- Ctrl+[←/→] - левая или правая панели
- end
- local _, Link, WorkDir=Plugin.SyncCall(GUIDLnkView, 'extract "'..tt[pos].FullName..'"', '@Target', '@WorkDir' )
- if (WorkDir or '') == '' then WorkDir = Link end
- if Link then
- if res.BreakKey:match('PgUp$') or res.BreakKey:match('^CtrlShift[RL]') then -- Переход в рабочий каталог
- Panel.SetPath(Pan, WorkDir)
- else
- local FI=win.GetFileInfo(Link)
- if FI then
- if FI.FileAttributes:match('d') then
- Panel.SetPath(Pan, Link)
- else
- Panel.SetPath(Pan, mf.fsplit(Link, 3), mf.fsplit(Link, 12))
- end
- end
- end
- end
- elseif res.BreakKey and
- (' F3 F4 '):match('%s('..res.BreakKey..')%s') then
- if tt[pos].FullName then
- local _,Link=Plugin.SyncCall(GUIDLnkView, 'extract "'.. tt[pos].FullName ..'"', '@Target' )
- if Link then
- local FI=win.GetFileInfo(Link)
- if FI and not FI.FileAttributes:match"d" then
- if res.BreakKey == 'F3' then
- viewer.Viewer(Link, "Просмотр файла из меню Start", nil,nil,nil,nil,
- {VF_ENABLE_F6=1; VF_IMMEDIATERETURN=1; VF_NONMODAL=1} )
- else -- res.BreakKey == 'F4'
- editor.Editor(Link, "Редактрование файла из меню Start", nil,nil,nil,nil,
- {EF_NONMODAL=1; EF_IMMEDIATERETURN=1; EF_ENABLE_F6=1; EF_LOCKED=1; EF_OPENMODE_USEEXISTING=1}
- )
- end
- end
- end -- if Link
- end
- elseif res.SubDir then
- Result = not ShortcutList({res.SubDir}, {Masks[1], ''})
- elseif res.FullName and win.GetFileInfo(res.FullName) then
- local Link, Pan
- if Plugin.Exist(GUIDLnkView) then
- Link = ({Plugin.SyncCall(GUIDLnkView, 'extract "'.. tt[pos].FullName ..'"', '@Target' )})[2]
- end
- if Link then
- local FI=win.GetFileInfo(Link)
- if FI and FI.FileAttributes:match"d" then
- local sw = far.Message( 'Выбранный ярлык указывает на папку.\nХотите открыть его в ФАР-е?',
- 'Работа с элементами StartMenu',
- 'На активной панели;На пассивной панели;В проводнике;Отмена')
- if sw==3 then
- Link = nil
- elseif sw==1 then
- Pan=0
- elseif sw==2 then
- Pan=1
- else
- return
- end
- else
- Link = nil
- end
- end
- if Link then
- Panel.SetPath(Pan, Link)
- else
- win.ShellExecute(nil, 'open', res.FullName)
- end
- end
- end -- if res
- end -- while Result
- return true
- end -- function ShortcutList
- Macro{
- -- id="";
- area="Shell Info Tree QView"; -- Menu Dialog Disks Editor Grabber FindFolder Desktop UserMenu DialogAutoCompletion Search ShellAutoCompletion MainMenu Other Help Viewer
- key="CtrlSpace";
- description="BAX: Работа с элементами StartMenu";
- -- filemask="";
- flags="EmptyCommandLine"; -- DisableOutput RunAfterFARStart NotEmptyCommandLine NoFilePanels NoFilePPanels NoPluginPanels NoPluginPPanels NoFolders NoPFolders NoFiles NoPFiles Selection PSelection NoSelection NoPSelection EVSelection NoEVSelection NoSendKeysToPlugins
- -- priority=50;
- -- sortpriority=50;
- condition=function(key)
- if not Plugin.Exist(GUIDLnkView) then far.Message('Plugin not exists\nOnly run item enabled', nil, nil, 'w') end
- return true --Plugin.Exist(GUIDLnkView)
- end;
- action=function()
- --local Mask=BaxUtils.far_InputBox({Title="Работа с элементами StartMenu"; Prompt="Маска:"; History='StartMenu'})
- local Mask=far.InputBox(nil, "Работа с элементами StartMenu", "Маска:", "StartMenu", nil, nil, HelpFile..'Contents', {FIB_BUTTONS=1;FIB_ENABLEEMPTY=1})
- if Mask then
- if Mask:match('%S') and not Mask:match('%*') then Mask = Mask .. '*' end
- ShortcutList({InitPrivDir, InitPubDir}, {Mask})
- end
- end
- }
GeSHi © Codebox Plus Extension
- StartMenu.002.7z
- Версия 2
- (3.96 KiB) Downloaded 65 times