Hide Layout Buttons

I normally use two Layouts for which I have made 2 Buttons to switch between them using the following Commands:

Prefs LAYOUT="Default Layout"
Prefs LAYOUT="Small Layout"

I now want to hide the "Default Layout" button when I am in Default Layout and the "Small Layout" button when I am in Small Layout. How to do that? Thanks in advance.

Use these buttons...

@hideif:=Val("$lst:myLayout")=="Default Layout"
Prefs LAYOUT="Default Layout"
@hideif:=Val("$lst:myLayout")=="Small Layout"
Prefs LAYOUT="Small Layout"

... with this script in the background that will make the current layout available to buttons:

function OnInit(initData) {
    initData.name = 'SaveLayoutAsVar';
    initData.version = '2024-06-10';
    initData.url = 'https://resource.dopus.com/t/hide-layout-buttons/51212';
    initData.default_enable = true;
    initData.min_version = '12.0';
}

function OnActivateLister(activateListerData) {
    activateListerData.lister.vars.set('myLayout', activateListerData.lister.layout);
}

Save EventSaveLayoutAsVar.js.txt to   ↓

%appdata%\GPSoftware\Directory Opus\Script AddIns

How to use buttons and scripts from this forum


Up for a challenge? Use a single button with a dynamic label.

2 Likes

It worked like a charm. Thanks a lot. Your solution turned out to be more complex than I initially thought (it needed script to accomplish what I wanted).

This is great Ixp and very useful!

Got me wondering if it would also be possible to have a single button with a similar purpose but one that cycles though all saved layouts. Switching to the next saved layout on each subsequent click, with a dynamic label displaying the current active layout and displaying the next in line on mouse hover.

I wish I could accept your suggested challenge but that would be just silly due to my brains computing limitations regarding to coding :sweat_smile:

We could set the variables locally in the button but would run into problems if layouts opened new listers.

Have a look here.

You could also use a button like

Prefs LAYOUTLIST

lxp... Can you elaborate on that?

Before requesting here I tried the following command in button:

@hideif: Prefs LAYOUT="Default Layout"
Prefs LAYOUT="Default Layout"

But it didn't work. Can you explain why it didn't work? Why we needed script in this case? Forgive me if my question looks silly, I am a new user without any coding background.

Command modifiers can test many settings but not all. So there is nothing that could tell us the current layout. We need to take notes ourselves and store that info in a variable.

Every lister needs its own variable so it needs to be scoped to the lister level. If calling a layout only changes the current lister we are fine.

But do we do when the layout opens one or more listers?

What if there is a second button that opens listers?

All these cases are covered by a short script that updates the info about the layout whenever a lister gets activated.

1 Like

I didn't noticed earlier but I am getting the following error:

11-06-2024 07:28 SaveLayoutAsVar: Error at line 10, position 5
11-06-2024 07:28 SaveLayoutAsVar: 'lister.vars' is null or not an object (0x800a138f)

What this error means? What changes I need to make?

That's a bit odd, not sure why this is happening.

Please disable the old script and use this instead:

function OnInit(initData) {
    initData.name = 'SaveLayoutAsVar';
    initData.version = '2024-06-11';
    initData.url = 'https://resource.dopus.com/t/hide-layout-buttons/51212';
    initData.default_enable = true;
    initData.min_version = '12.0';
}

function OnActivateLister(activateListerData) {
    if (!activateListerData) {
        DOpus.Output('!activateListerData');
        return;
    }

    if (!activateListerData.active) {
        DOpus.Output('!activateListerData.active');
        return;
    }
    if (!activateListerData.lister) {
        DOpus.Output('!activateListerData.lister');
        return;
    }

    if (!activateListerData.lister.vars) {
        DOpus.Output('!activateListerData.lister.vars');
        return;
    }

    activateListerData.lister.vars.set('myLayout', activateListerData.lister.layout);
}

EventSaveLayoutAsVar.js.txt

The only message you should see is

!activateListerData.active

Please post if you see any other message and what you did to trigger it.

1 Like

BTW: If you also use the big version you can skip this script altogether and use currLayout instead of myLayout in all your buttons.

This version of script runs without any error message. Thanks for your efforts.

Where I am supposed to see this message?

In the script log.

Yes... Its there.

A little late to the party and perhaps a tangent but...

Here are commands for a button that toggles between two listers:

@if:$glob:lay
@set glob:lay
@sync:/home\dopusrt.exe /cmd Close
Prefs LAYOUT="Your first lister"
@if:else
@sync:/home\dopusrt.exe /cmd Close
Prefs LAYOUT="Your second lister"
@set glob:lay=on
1 Like

Thanks @jinsight . It works fine. The only thing lacking in your code is that the Button Label doesn't change dynamically when I change the Layout. In my case detailed above when I am in "Small Layout", it should show "Default Layout" and vice versa.