Correct 'swap panels' with LUA (solved)

Here you can discuss any topic concerning Far macro commands.
galaxy_far_FAR_away
Posts: 21
Joined: Mon 12 Aug, 2013 14:03
Has thanked: 6 times

Correct 'swap panels' with LUA (solved)

Postby galaxy_far_FAR_away » Wed 14 Oct, 2015 19:08

[Update: working snippet is at a few post below]

1.) Ctrl-U swaps panels well even if they contains plugin content. But it swaps whole panels with their _dimensions_ too (width, height) which is not good for me (I using asymmetric panels because of good reasons)
2.) I made a script which swaps panel _paths_, but of course it can't handle plugin contents.

I like to swap any (even plugin) panel's _content_ without change of layout. My theory is that I call Ctrl-U then You smart LUA-gods drop a few lines of LUA script to me to restore panel's dimension to the original :)

Maybe the solution will be something different, I don't know. Notice that even the built-in 'Same folder' not handles plugin-panels - it's a shame :(

Sidenote: I using ConEmu - it can display picture thumbnails but Ctrl-U leaves thumbnails view on the original side - I feel I need to consult with ConEmu's author right?

I much appreciate any technical details - thank You!
Last edited by galaxy_far_FAR_away on Thu 15 Oct, 2015 05:35, edited 2 times in total.

User avatar
HaRT
Moderator
Posts: 7880
Joined: Tue 30 Aug, 2005 17:21
Location: Санкт-Петербург
Has thanked: 62 times
Been thanked: 93 times

Correct swap panels with LUA

Postby HaRT » Wed 14 Oct, 2015 19:14

galaxy_far_FAR_away, I suggest that you write a simple Lua script that memorizes the panel widths, then swaps panels (CtrlU), then adjusts the widths (CtrlLeft/CtrlRight).
Фар есть инструмент, а не нянька. © 2009 DrKnS

galaxy_far_FAR_away
Posts: 21
Joined: Mon 12 Aug, 2013 14:03
Has thanked: 6 times

Correct swap panels with LUA

Postby galaxy_far_FAR_away » Wed 14 Oct, 2015 19:23

Thanks HaRT, I wrote the same idea just with other words :)

So, I not as experimented as You may think - I dug in the documentations of LUA/FAR plugins (quite) some time ago and I not really found where I can figure out panel's dimensions (?)

User avatar
HaRT
Moderator
Posts: 7880
Joined: Tue 30 Aug, 2005 17:21
Location: Санкт-Петербург
Has thanked: 62 times
Been thanked: 93 times

Correct swap panels with LUA

Postby HaRT » Wed 14 Oct, 2015 19:32

galaxy_far_FAR_away wrote:Source of the post figure out panel's dimensions
See APanel.Width etc in %FARHOME%\Encyclopedia\macroapi_manual.en.chm.
Фар есть инструмент, а не нянька. © 2009 DrKnS

Shmuel
Posts: 4906
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 10 times
Been thanked: 118 times

Correct swap panels with LUA

Postby Shmuel » Wed 14 Oct, 2015 19:39

It is slow but seems to work.

Code: Select all

Macro {
  area="Shell"; key="F1";
  action=function()
    local F = far.Flags
    local apanel = panel.GetPanelInfo(nil,1)
    local ppanel = panel.GetPanelInfo(nil,0)
    local aleft = bit64.band(apanel.Flags, F.PFLAGS_PANELLEFT) ~= 0
    local awidth = apanel.PanelRect.right - apanel.PanelRect.left + 1
    local pwidth = ppanel.PanelRect.right - ppanel.PanelRect.left + 1
    local key1 = aleft and (awidth > pwidth) and "CtrlRight" or
             not aleft and (pwidth > awidth) and "CtrlRight" or "CtrlLeft"
    Keys("CtrlU")
    for k=1, math.abs(awidth-pwidth) do Keys(key1) end
  end;
}

galaxy_far_FAR_away
Posts: 21
Joined: Mon 12 Aug, 2013 14:03
Has thanked: 6 times

Correct swap panels with LUA

Postby galaxy_far_FAR_away » Wed 14 Oct, 2015 19:51

Nice - Shmuel You done Your answer before I could send mine (a short one) :D

OK, I did tested this key-emulation technique and it is not flashing, it is real-time. I will implement height adjustment too (and fix a minor bug because 'divider' moves a bit at every swap if total width is odd).

Many thanks for your super great LUA support!

Shmuel
Posts: 4906
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 10 times
Been thanked: 118 times

Correct swap panels with LUA

Postby Shmuel » Wed 14 Oct, 2015 21:10

The fix for a minor bug you mentioned.

Code: Select all

Macro {
  area="Shell"; key="F1";
  action=function()
    local awidth, aleft = APanel.Width, APanel.Left
    Keys("CtrlU")
    local pwidth = PPanel.Width
    local key1 = aleft == (awidth > pwidth) and "CtrlRight" or "CtrlLeft"
    for k=1, math.abs(awidth-pwidth) do Keys(key1) end
  end;
}

galaxy_far_FAR_away
Posts: 21
Joined: Mon 12 Aug, 2013 14:03
Has thanked: 6 times

Correct swap panels with LUA

Postby galaxy_far_FAR_away » Thu 15 Oct, 2015 05:30

Ahh, the fixed code also much cleaner ;) Thanks to you guys, here is the final snippet for everybody (I using Shift-Tab to swap panels):

Code: Select all

Macro
{
  key        = 'ShiftTab';
  area       = 'Shell';
  flags      = '';
  description= 'Panel: Swap panels';
  action     = function()

  local awidth, aleft = APanel.Width, APanel.Left
  Keys("CtrlU")
  local pwidth = PPanel.Width
  local key1 = aleft == (awidth > pwidth) and "CtrlRight" or "CtrlLeft"
  for k=1, math.abs(awidth-pwidth) do Keys(key1) end


  local dif = APanel.Height - PPanel.Height;
        key1 = (dif>0) and "CtrlShiftUp" or "CtrlShiftDown"
  local key0 = (dif<0) and "CtrlShiftUp" or "CtrlShiftDown"

  dif = math.abs(dif);

  for k=1, dif do Keys(key1) end

  Keys ("Tab");
  for k=1, dif do Keys(key0) end
  Keys ("Tab");

  end;
}


Return to “Macro Commands Discussions”

Who is online

Users browsing this forum: No registered users and 1 guest