Saving sort order for several directories

You want to talk about Far Manager, but don't know where to turn?
Post Reply
Atys
Posts: 5
Joined: Wed 01 Mar, 2023 09:47

Saving sort order for several directories

Post by Atys »

Hi,

It would be nice if I could save sort order per folder, like the download folder would automatically sorted by "write time" if I enter.
Or is it already possible?

thx
User avatar
buniak_a_h
Posts: 4266
Joined: Sat 20 Apr, 2013 00:17
Location: Санкт-Петробад
Has thanked: 222 times
Been thanked: 644 times
Contact:

Saving sort order for several directories

Post by buniak_a_h »

See viewtopic.php?t=10521&start=60 :
lordmuzer wrote: Thu 23 Feb, 2023 00:23

Code: Select all

Event { description = "PanelChangeDir";
	group = "FolderChanged";
	action = function()
		far.Message("changed!", nil, "w")
	end;
}
Работает на актуальной ночной сборке (Works on the latest nightly build)
Replace far.Message("changed!", nil, "w") with script as you need
Atys
Posts: 5
Joined: Wed 01 Mar, 2023 09:47

Saving sort order for several directories

Post by Atys »

Thank you, this looks really interesting, can you give me a hint where these scripts are processed? Is it far itslef or a plugin?
Is it only in the newest nightly builds?
I can't really understand russian.
Shmuel
Posts: 6836
Joined: Thu 23 Mar, 2006 21:36
Location: Israel
Has thanked: 41 times
Been thanked: 530 times

Saving sort order for several directories

Post by Shmuel »

Atys wrote: Wed 01 Mar, 2023 13:38 where these scripts are processed? Is it far itslef or a plugin?
Far itself + plugin LuaMacro
Atys wrote: Wed 01 Mar, 2023 13:38 Is it only in the newest nightly builds?
This feature ("emitting events on folder change") - yes.

I wouldn't recommend to go that way unless you are willing to spent many many hours studying FAR plugins' API and FAR macrosystem.
On the other hand I'm not aware of any ready solution of what you want to get.
User avatar
HaRT
Moderator
Posts: 10865
Joined: Tue 30 Aug, 2005 17:21
Has thanked: 221 times
Been thanked: 358 times

Saving sort order for several directories

Post by HaRT »

Atys wrote: Wed 01 Mar, 2023 13:38 I can't really understand russian.
In most cases browsers' built-in translation (e.g. in Chrome, Edge) is good enough to understand the discussions and make use of the tips, tricks, and scripts. As you can see, most of this forum is in Russian, so most useful and advanced stuff is in Russian (among much “noise” though).
Фар есть инструмент, а не нянька. © 2009 DrKnS
Atys
Posts: 5
Joined: Wed 01 Mar, 2023 09:47

Saving sort order for several directories

Post by Atys »

well, I'm stuck.

Code: Select all

local F = far.Flags
local savesortmode
Event { description = "PanelChangeDir";
	group = "FolderChanged";
	action = function()	
		if panel.GetPanelDirectory(1).Name == "C:\\Program Files\\Far Manager\\Plugins\\LuaMacro" then
			pinfo = panel.GetPanelInfo(nil, 1)
			if pinfo.PanelType == F.PTYPE_FILEPANEL then
				if not (pinfo.SortMode == F.SM_MTIME) then
					savesortmode = pinfo.SortMode
	        	        	panel.SetSortMode(nil, 1, F.SM_MTIME)
				end
			end
		else
			if savesortmode then
	       	        	panel.SetSortMode(nil, 0, savesortmode)   <-------- 0 is okay on TAB, not okey on leaving the directory on in the same panel
				savesortmode=nil
			end
		end
	end;
}
As pretty much everything is stateless and I can't add custom data to the panel and a CTRL-U also swaps the sides without any notification
I have no idea how could I restore the original sorting in the same panel.

Any ideas?
User avatar
buniak_a_h
Posts: 4266
Joined: Sat 20 Apr, 2013 00:17
Location: Санкт-Петробад
Has thanked: 222 times
Been thanked: 644 times
Contact:

Saving sort order for several directories

Post by buniak_a_h »

Atys wrote: Thu 02 Mar, 2023 13:58 I have no idea how could I restore the original sorting in the same panel.
You can restore sorting "by default":

Code: Select all

panel.SetSortMode(nil, 1, Far.GetConfig("Panel." .. (APanel.Left and "Left" or "Right") .. ".SortMode")
panel.SetSortMode(nil, 0, Far.GetConfig("Panel." .. (PPanel.Left and "Left" or "Right") .. ".SortMode")
Atys
Posts: 5
Joined: Wed 01 Mar, 2023 09:47

Saving sort order for several directories

Post by Atys »

Thank you buniak_a_h, thank you all,

this APanel, PPanel and its properties gave me some ideas, here is what I'm came up with, let's see how it performs:

Code: Select all

local targetdir = "C:\\Program Files\\Far Manager\\Plugins\\LuaMacro"
local F = far.Flags
local SaveSortMode
Event { description = "PanelChangeDir";
  group = "FolderChanged";
  action = function()
    if SaveSortMode then
      if PPanel.Path == targetdir then
        panel.SetSortMode(nil, 0, SaveSortMode)
      else
        panel.SetSortMode(nil, 1, SaveSortMode)
      end
      SaveSortMode = nil
    else
      if APanel.Path == targetdir then
        pinfo = panel.GetPanelInfo(nil, 1)
        if pinfo.PanelType == F.PTYPE_FILEPANEL then
          if not (pinfo.SortMode == F.SM_MTIME) then
            SaveSortMode = pinfo.SortMode
            panel.SetSortMode(nil, 1, F.SM_MTIME)
          end
        end
      end
    end
  end;
}
Next step is to store the dirs and sort modes somewhere with an editor. Some day....
Last edited by HaRT on Fri 03 Mar, 2023 13:00, edited 1 time in total.
Reason: Fix indentation, enable syntax highlighting.
User avatar
HaRT
Moderator
Posts: 10865
Joined: Tue 30 Aug, 2005 17:21
Has thanked: 221 times
Been thanked: 358 times

Saving sort order for several directories

Post by HaRT »

Atys, you likely want local pinfo = … rather than having it global.
Фар есть инструмент, а не нянька. © 2009 DrKnS
Atys
Posts: 5
Joined: Wed 01 Mar, 2023 09:47

Saving sort order for several directories

Post by Atys »

@HaRT I see, thanks, I'm completely lua analphabet.
Post Reply

Return to “General Discussions”