Toggle column width: Automatic / Maximum

I was looking for a way to toggle column widths between Automatic and Maximum modes, and found the following script written by @Leo here

function OnClick(clickData)
{
	var anyColumns = false;
	var cmdLine = "Set COLUMNSADD=";
	for(var e = new Enumerator(clickData.func.sourcetab.format.columns); !e.atEnd(); e.moveNext())
	{
		var col = e.item();
		if (!col.Autosize || col.Max != 0)
		{
			if (anyColumns) cmdLine += ",";
			cmdLine += col.Name;
			cmdLine += "(!,a,0)"; // Keep position. Auto-size. No maximum.
			anyColumns = true;
		}
	}
	if (!anyColumns) cmdLine = "Set FORMAT=!folder";
	clickData.func.command.RunCommand(cmdLine);
}

The script works perfectly well, but I have noticed that in the folders that contain images, when I press the button, the width of the columns is not modified but rather it goes from Details mode to Thumbnails mode.

Could you help me so that the script only alternates between the Automatic and Maximum column widths without changing the Details mode?

What is the view mode when you enter a folder with images?
I guess it's thumbnails mode as well.

The script simply resets the folder format to "toggle back" the column width, but if the folder format is "thumbnails" for your folder, you get what you describe.

You can force details mode by adding this line right before the last curly bracket.
clickData.func.command.RunCommand("Set VIEW=Details");

Not the best solution, but to get something more smart, the whole scripts needs to be changed I guess.

2 Likes

Thank you very much @tbone for your answer, now I understood the behavior of the script. When I enter folders with images, Thumbnail mode is automatically applied; If I change to Details, and apply the script twice, the format of the folder is completely restored, in this case Thumbnails, I thought that the script only modified the width of the columns, that's why I didn't understand why if I left the folder in Details ended up showing in Thumbnails.

Your suggestion clickData.func.command.RunCommand("Set VIEW=Details"); It works very well, now I get the exact result I wanted, always maintaining the Details mode, since I only use the script in Details mode (@hideif:!Set VIEW=Details).

Thank you very! :grinning: