Panel.JumpToSelectedFile.lua — прыжки по выделенным файлам

Здесь обсуждается всё, что касается макросов.
User avatar
John Doe
Бюрократ
Posts: 13807
Joined: Wed 27 Apr, 2005 20:42
Has thanked: 73 times
Been thanked: 426 times
Contact:

Re: Panel.JumpToSelectedFile.lua

Post by John Doe »

Latest post of the previous page:

Всё что после if not selected_cycle then return end можно заменить на вызов Home/End
User avatar
Smitis
Posts: 1709
Joined: Fri 18 Mar, 2005 12:51
Location: Питер
Has thanked: 23 times
Been thanked: 55 times

Re: Panel.JumpToSelectedFile.lua

Post by Smitis »

John Doe wrote:Всё что после if not selected_cycle then return end можно заменить на вызов Home/End
Да! Сейчас поправлю (у меня циклического перебора вообще не было, поторопился добавить :oops: )
Разум когда-нибудь победит.
User avatar
John Doe
Бюрократ
Posts: 13807
Joined: Wed 27 Apr, 2005 20:42
Has thanked: 73 times
Been thanked: 426 times
Contact:

Re: Panel.JumpToSelectedFile.lua

Post by John Doe »

Другое дело.
Теперь я сам буду выступать за то, чтобы заменить штатный вариант вашим.
За лаконичность.
User avatar
John Doe
Бюрократ
Posts: 13807
Joined: Wed 27 Apr, 2005 20:42
Has thanked: 73 times
Been thanked: 426 times
Contact:

Re: Panel.JumpToSelectedFile.lua

Post by John Doe »

Хотя всё-таки вариант, где за все 4 действия отвечает одна функция, мне кажется более концептуальным.
Вот, разгрузил функцию, вынес наружу инициализацию параметров, теперь она принимает (from,to)
  1. local cyclic = true -- set false to disable cyclic jump
  2.  
  3. local is_selected = 8
  4.  
  5. local function JumpToSelected (from, to)
  6.  
  7.   for pos=from,to,from<to and 1 or -1 do
  8.  
  9.     if Panel.Item(0,pos,is_selected) then return Panel.SetPosIdx(0,pos) end
  10.  
  11.   end            
  12.  
  13.   if cyclic then JumpToSelected(APanel.ItemCount-to,to) end
  14.  
  15. end
  16.  
  17.  
  18.  
  19. Macro {description="Jump to the next selected file";
  20.  
  21.   area="Shell Search"; key="CtrlShiftDown"; flags="Selection"; 
  22.  
  23.   action = function() JumpToSelected(APanel.CurPos+1,APanel.ItemCount) end;
  24.  
  25. }
  26.  
  27.  
  28.  
  29. Macro {description="Jump to the previous selected file";
  30.  
  31.   area="Shell Search"; key="CtrlShiftUp"; flags="Selection"; 
  32.  
  33.   action = function() JumpToSelected(APanel.CurPos-1,1) end;
  34.  
  35. }
  36.  
  37.  
  38.  
  39. Macro {description="Jump to the first selected file"; 
  40.  
  41.   area="Shell Search"; key="CtrlShiftHome CtrlShiftNum7"; flags="Selection";
  42.  
  43.   action = function() JumpToSelected(1,APanel.ItemCount) end;
  44.  
  45. }
  46.  
  47.  
  48.  
  49. Macro {description="Jump to the last selected file"; 
  50.  
  51.   area="Shell Search"; key="CtrlShiftEnd CtrlShiftNum1"; flags="Selection"; 
  52.  
  53.   action = function() JumpToSelected(APanel.ItemCount,1) end;
  54.  
  55. }
Получилось так же лаконично.
User avatar
Smitis
Posts: 1709
Joined: Fri 18 Mar, 2005 12:51
Location: Питер
Has thanked: 23 times
Been thanked: 55 times

Re: Panel.JumpToSelectedFile.lua

Post by Smitis »

Попробовал с отметкой текущего файла. Если без цикличности, тоже лаконичный вариант.

Code: Select all

local function selected_jump3( dir )
	local current = Panel.SetPosIdx(0,0)
	local nosel = not Panel.Item(0,0,8)
	if nosel then Panel.Select(0,1,1) end
	Panel.SetPosIdx(0,Panel.SetPosIdx(0,0,1)+dir,1)
	if nosel then Panel.Select(0,0,1,current) end
	if selected_cycle and Panel.SetPosIdx(0,0)==current then -- если не переместились, зацикливаем
		Panel.SetPosIdx(0,(dir>0 and 1 or APanel.SelCount),1)
	end
end
С цикличностью менее красиво будет, из-за дополнительных проверок. И что-то лень делать :)
Добавил цикличность
Разум когда-нибудь победит.
Post Reply

Return to “Обсуждение макросов”