Toggle button to maximize source pane

I've used a toggle command for maximizing the current source pane (see code below). Today I tried to make it a toggle button in my main toolbar. Unfortunately it doesn't detect the toggle state automatically. Are there any further modifiers to control the toggle state of a button manually?

To be honest currently I'm thinking about adapting this command to a script because I , do not like that Set LAYOUT=restore even restores all tabs in the source pane (I just want to restore the panel states but keep the tabs).

Thus if I switch over to a scripted version of this command would it be possible to achieve the toggle state of a toolbar button even if the button refers to a JScript?

@ifset:TREE=toggle
Set LAYOUT=remember
Set TREE=off DUAL=off METAPANE=off  UTILITY=off VIEWPANE=off
@ifset:else
Set LAYOUT=restore

Finally I want to let you know two problems I've observed with the script:

  1. When executing Set LAYOUT=remember each time the layout is restored there will be created an additional tab in the destination panel.
  2. Initially I tried @ifset:TREE=off but this didn't work at all (on the other hand the same condition works well for the viewpane).

Add @toggle:If TREE=toggle to the first line to make the button appear pushed in when the tree is on and flat when the tree is off.

This also works if the button runs a script, as long as it's on the first line, before the @script line.

Great, now I'm so close to my maximize/minimize button but unfortunately loading the style always replaces the tabs as well. I just need to remember and restore the state of the view elements without affecting the source tabs. Even if I disable the appropriate buttons ("Close existing folder tabs") in the preferences for the recently created style it will be overriden on the next STYLESAVE operation. I initally hoped that the actual state of the opened tabs is part of a layout and not of a style.

BTW: Prefs STYLE SourceMaximizedStyle always asks for a name if it is called the first time (style does not yet exists).

@toggle:if $glob:SourceMaximized
@ifset:$glob:SourceMaximized
@set glob:SourceMaximized
Prefs STYLE SourceMaximizedStyle
@ifset:else
@set glob:SourceMaximized=on
Prefs STYLESAVE SourceMaximizedStyle
Set TREE=off DUAL=off METAPANE=off UTILITY=off VIEWPANE=off

Certainly it would be even better if also the destination tabs will be remembered but I'm not sure whether the "remember" option can be used for the "off" argument:

...
Set TREE=off DUAL=off,remember METAPANE=off UTILITY=off VIEWPANE=off
...

Works OK here. I'm not sure it makes sense when you are not turning dual back on in the same way, though.

To be honest, if you were thinking of using scripting before, you might as well just skip to that, since you want to do something quite complex and particular. Trying to do it without scripting seems like a waste of time when it's more straightforward with it and you're already considering it.

Basically, you're right, but when you're so close to the solution, then you will naturally seek desperately for the last step.

And today it's woth the time because finally I got it! The "remember" has to be on the "on" argument instead of the "off" and then everything works as expected!!! :thumbsup:

This button command toggles the source pane to maximum and back ...

It's easy if you always want particular panels to be turned on. From what the initial buttons were doing, I assumed you wanted it to remember whether everything except the tree was on or off.

Yes, that is exactly what I actually want. But for the moment I can live with this workaround. Maybe in the future there will be any option to control whether styles should be restored with or without tabs. Then I will update the command and it will be finally perfect.

Personally I would prefer if saving a style that already exists won't override the additional options (like tab handling) with default values each time. Thus a user can create a new style and set some of the additional options allowing him to simply update the lister element states by a command (but keeping the additional options).

PS: Thanks for help, allowing me to quickly get this nice button in out configuration.

Scripts exist to let you do esoteric things.

Well, the naming you were using seemed a bit of reverse logic to me - so my answer will be written in a way that makes more sense to me... :slight_smile:

I see you had switched to Styles from Layouts, but then abandoned both - and I see why based on your follow-up comments. Among the many things that both systems share - is a predisposition to wanting to save all folder tabs you've got open when you save the lister programatically using RAW commands, as well as then wanting to load those stored folder tabs when you then load the saved lister using the RAW commands. There are very few RAW command controls to affect this layout and style save/load behavior (and moreso for Layouts than Styles - where I think with some extensions to the controls for layouts and we would never have even seen styles make an appearance). But in this case, I think you WANT that behavior for the purposes of restoring your lister state back to what it was before you enabled 'max source display' mode...

And even though you had switched to Styles - you still seemed bent on manually doing some of the things they provide :slight_smile:. Since your current solution now has you manually turning on ALL the extra lister elements - even if they had not already been on before you went 'max source display' mode, maybe you might try this:

Manually pre-create a Style called SourceMaximizedStyle and configure it to turn OFF all the things you're turning off manually:


The naming is just semantics - use whatever makes you happy of course, but I'm using the name SourceMaximizedStyle to represent the lister config you want to use when you actually want the source display 'maximmized'.

Then, let the button save another / second _restore style to do what you were doing before == saving the current lister state before you max the source display so you can restore it after you're done operating in maximized mode:

[code]@toggle:if $glob:SourceMaximized

@ifset:$glob:SourceMaximized
@set glob:SourceMaximized
Prefs STYLE SourceMaximizedStyle_restore

@ifset:else
@set glob:SourceMaximized=true
Prefs STYLESAVE SourceMaximizedStyle_restore
Prefs STYLE SourceMaximizedStyle[/code]

The drawback here - is that while saving the folder paths in both displays (if you had two open) is desirable - if you turn this on, then change folder paths while maximized - "restoring" the _restore style will send the source file display BACK to the folder that was opened when you saved the _restore style. This might not be what you want... and among the sort of layout/style enhancements that could help here would be some more granular controls like:

Prefs STYLE SourceMaximizedStyle_restore STYLEIGNORESOURCEFOLDERS
and/or
Prefs STYLESAVE SourceMaximizedStyle_restore STYLEIGNORESOURCEFOLDERS

Yes, and this predisposition is wrong because I want to keep the tabs (or even better keep the tabs including their selection and focus state).

[quote="steje"]
Prefs STYLE SourceMaximizedStyle_restore STYLEIGNORESOURCEFOLDERS
and/or
Prefs STYLESAVE SourceMaximizedStyle_restore STYLEIGNORESOURCEFOLDERS[/quote]

This would definitely allow more flexible (Leo would say "esoteric") commands allowing to handle the lister style ignoring the tab state. :thumbsup:

I translated the command to a script to allow conditional restoring of the separate lister view elements as Leo recommended ...

@toggle:if $lst:SourceMaximized
@script jscript


function toggleSourceMaximize(tab, cmd) {
	var lister = tab.lister;
	var vars = lister.vars;
	if (!vars.Exists("SourceMaximized")) {
		// remember lister view elements
		vars.Set("SourceMaximized", "on");
		vars.Set("SourceMaximized.TREE", lister.tree != 0);
		vars.Set("SourceMaximized.DUAL", lister.dual != 0);
		vars.Set("SourceMaximized.UTILPANE", lister.utilpane != 0);
		vars.Set("SourceMaximized.METAPANE", lister.metapane != 0);
		vars.Set("SourceMaximized.VIEWPANE", lister.viewpane != 0);
		vars.Set("SourceMaximized.TABRIGHT", tab.right);
		// hide lister view elements
		cmd.AddLine("Set TREE=off DUAL=off VIEWPANE=off METAPANE=off UTILITY=off");
	} else {
		// restore lister view elements
		if (vars.Get("SourceMaximized.TREE")) {
			cmd.AddLine("Set TREE=on");
		}
		if (vars.Get("SourceMaximized.DUAL")) {
			cmd.AddLine("Set DUAL=on,remember");
		}
		if (vars.Get("SourceMaximized.UTILPANE")) {
			cmd.AddLine("Set UTILITY=on");
		}
		if (vars.Get("SourceMaximized.METAPANE")) {
			cmd.AddLine("Set METAPANE=on");
		}
		if (vars.Get("SourceMaximized.VIEWPANE")) {
			cmd.AddLine("Set VIEWPANE=on");
		}
		// swap displays if needed
		if (vars.Get("SourceMaximized.TABRIGHT") && lister.dual == 0) {
			cmd.addLine("Go SWAP");
			cmd.addLine("Set SOURCE=right");
			cmd.addLine("Set FOCUS=right");
		}
		// delete lister variables
		vars.Delete("SourceMaximized");
		vars.Delete("SourceMaximized.TREE");
		vars.Delete("SourceMaximized.DUAL");
		vars.Delete("SourceMaximized.UTILPANE");
		vars.Delete("SourceMaximized.VIEWPANE");
		vars.Delete("SourceMaximized.METAPANE");
		vars.Delete("SourceMaximized.TABRIGHT");
	}
	cmd.Run();
}

function OnClick(clickData) {
	toggleSourceMaximize(clickData.func.sourcetab, clickData.func.command);
}

That looks good, nicely done!

Indeed! That knob is good! Thanks AKA! o)

This is a slighty shaped version. It also restores vertical/horizontal state of DUAL, META- and VIEWPane correctly and takes Double-TREE layout into account. The SourceMaximized status is remembered on restart of DO and in case you try to use that button on a "thin-single lister", it won't error. o)

Some issues arize when de-maximizing after DO restart (set RememberMaximizedOnRestart=false to disable):

  • Dual destination tabs are lost
  • Utility pane height and horizontal viewer/meta pane height is not restored correctly (default lister dependent?)
    The dest-tabs issue can probably be fixed by scripting, the rest is out of reach for the scripting party I guess.

[code]@toggle:if $lst:SourceMaximized
@script jscript

var RememberMaximizedOnRestart = true;

function ToggleSourceMaximize(tab, cmd) {
var lister = tab.lister;
var vars = lister.vars;
var ind = {"TREE":0,"DUAL":1,"UTILPANE":2,"METAPANE":3,"VIEWPANE":4,"TABRIGHT":5};
cmd.Addline("//prevent exception if no line was added");
if (!vars.Exists("SourceMaximized")) {
// remember lister view elements
var v = DOpus.Create.Vector();
v(ind.TREE) = lister.tree;
v(ind.DUAL) = lister.dual;
v(ind.UTILPANE) = lister.utilpane;
v(ind.METAPANE) = lister.metapane;
v(ind.VIEWPANE) = lister.viewpane;
v(ind.TABRIGHT) = tab.right*1;
vars.Set("SourceMaximized") = v;
vars("SourceMaximized").persist = RememberMaximizedOnRestart;
// hide lister view elements
cmd.AddLine("Set TREE=off,left,right DUAL=off VIEWPANE=off METAPANE=off UTILITY=off");
} else {
// restore lister view elements
var v = vars.Get("SourceMaximized");
if (v(ind.TREE)==1) cmd.AddLine("Set TREE=on,left");
if (v(ind.TREE)==2) cmd.AddLine("Set TREE=on,right");
if (v(ind.TREE)==3) cmd.AddLine("Set TREE=on,left,right");
if (v(ind.DUAL)==1) cmd.AddLine("Set DUAL=on,vert,remember");
if (v(ind.DUAL)==2) cmd.AddLine("Set DUAL=on,horiz,remember");
if (v(ind.UTILPANE)) cmd.AddLine("Set UTILITY=on");
if (v(ind.METAPANE)==1) cmd.AddLine("Set METAPANE=on,vert");
if (v(ind.METAPANE)==2) cmd.AddLine("Set METAPANE=on,horiz");
if (v(ind.VIEWPANE)==1) cmd.AddLine("Set VIEWPANE=on,vert");
if (v(ind.VIEWPANE)==2) cmd.AddLine("Set VIEWPANE=on,horiz");
// swap displays if needed
if (v(ind.TABRIGHT) && lister.dual == 0) {
cmd.addLine("Go SWAP");
cmd.addLine("Set SOURCE=right");
cmd.addLine("Set FOCUS=right");
}
// delete lister variables
vars.Delete("SourceMaximized");
}
cmd.Run();
}

function OnClick(clickData) {
ToggleSourceMaximize(clickData.func.sourcetab, clickData.func.command);
}
[/code]

Fantastic, that looks much more flexible than mine! Thanks for sharing that.