Insert button Close On Tablist

Features wanted...
Post Reply
tramy12062017
Posts: 5
Joined: 08 Dec 2019 12:04

Insert button Close On Tablist

Post by tramy12062017 »

Dear Xyplorer team,
Thanks for awesome file manager!
I think you should developing a button close (x) on tablist
It's easy for close a unuse tab
Thanks!
Attachments
close x button.jpg
close x button.jpg (393.53 KiB) Viewed 1643 times

highend
Posts: 13313
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Insert button Close On Tablist

Post by highend »

This could be easily done with a simple script:

Code: Select all

$menu = "";
    while ($i++ < tab("get", "count")) {
        $info = tab("get", "name", $i);
        $icon = gettoken($info, 2, "|");
        if (!$icon) { $icon = ":showfolders"; }
        $caption = tab("get", "path", $i);
        $menu   .= $caption . "|" . $caption . "|" . $icon . <crlf>;
    }
    $id = popupmenu($menu, 5:=1, 6:=<crlf>, 7:="|");
    if ($id) { tab("close", 1, $id); }
Put it on a button, a catalog entry, a user defined command, whatever you like.
The entry clicked will be the tab that gets closed (and XY will ask before doing this, if it is e.g. a locked tab)...
One of my scripts helped you out? Please donate via Paypal

tramy12062017
Posts: 5
Joined: 08 Dec 2019 12:04

Re: Insert button Close On Tablist

Post by tramy12062017 »

Thanks highend!
It's worked. But each click only close a tab. If you want to close multiple tab, you must click button, catalog entry, user defined command multiple times!

highend
Posts: 13313
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Insert button Close On Tablist

Post by highend »

Then do it this way... But you won't get asked if a tab gets closed, even when it is e.g. locked^^

Code: Select all

$ids = inputselect("Check tab(s) to close...", get("tabs", <crlf>), <crlf>, 1+2+32+128+1024+8192, , 800, 600);
    $cntClosed   = 1;
    $firstClosed = false;
    foreach($id, $ids, <crlf>, "e") {
        if ($firstClosed) {
            $id -= $cntClosed;
            $cntClosed++;
        }
        tab("close", 0, $id);
        $firstClosed = true;
    }
One of my scripts helped you out? Please donate via Paypal

tramy12062017
Posts: 5
Joined: 08 Dec 2019 12:04

Re: Insert button Close On Tablist

Post by tramy12062017 »

Thanks Again!
If have a button close (x), you can do both select a tab or close a tab (by click x button) on tablist.
With your solution, select tab and close tab separate. But it's good solution. Thanks!

tramy12062017
Posts: 5
Joined: 08 Dec 2019 12:04

Re: Insert button Close On Tablist

Post by tramy12062017 »

I am newber in Xyplorer, please help me edit your second script to:
- Insert number 01,02,03,.. to begin tab path as above tab list: 01 - Q:\DEMO, 02 - D:\TEST, 03 - F:\MUSIC,...
- When double click or shortcut as Shift + Click on tab => Open Tab
It is seem better solution because it can close tab and open tab in a window.
However, I think a simple and best solution is close button on tab list as I mentioned above. It working like Tree Style Tab addon in Firefox, so easy close tab or open tab.
Thanks!

highend
Posts: 13313
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Insert button Close On Tablist

Post by highend »

Shift + OK button = open (the first selected) tab
OK button without shift = close all selected tab(s)

Code: Select all

$tabs = "";
    while ($i++ < tab("get", "count")) {
        $info = tab("get", "name", $i);
        $icon = gettoken($info, 2, "|");
        if (!$icon) { $icon = ":showfolders"; }
        $caption = tab("get", "path", $i);
        $tabs   .= format($i, "00") . " - " . $caption . "|" . $caption . "|" . $icon . <crlf>;
    }
    $ids = inputselect("Check tab(s) to close...", $tabs, <crlf>, 1+2+32+128+1024+8192, , 800, 600);
    if (!$ids) { status "No entry checked, aborted!", "8B4513", "stop"; end true; }

    if (get("shift")) {
        $id = gettoken($ids, 1, <crlf>);
        seltab $id;
    } else {
        $cntClosed   = 1;
        $firstClosed = false;
        foreach($id, $ids, <crlf>, "e") {
            if ($firstClosed) {
                $id -= $cntClosed;
                $cntClosed++;
            }
            tab("close", 0, $id);
            $firstClosed = true;
        }
    }
One of my scripts helped you out? Please donate via Paypal

tramy12062017
Posts: 5
Joined: 08 Dec 2019 12:04

Re: Insert button Close On Tablist

Post by tramy12062017 »

Thanks good man!
Your Script works great!
But open a tab must through two steps (click checkbox, Shift + OK)
I think the solution to create a close button like on Tree Style Tab of firefox would be better as image:
Attachments
select_close_tab.jpg
select_close_tab.jpg (311.87 KiB) Viewed 1601 times

klownboy
Posts: 4139
Joined: 28 Feb 2012 19:27

Re: Insert button Close On Tablist

Post by klownboy »

I noticed that when I placed a header on top of the popupmenu listing the resulting list value (popupmenu using index,5:=1) is thrown off by 1 (higher). Adding the header line is adding an increment to the resulting index. Should popupmenu be ignoring that header line? Is there some other way to properly incorporate a header into a SC popupmenu. Obviously the script works fine without the header.

I achieved the correct result (and with a header) using another method (heredoc) but I was curious about this situation. I was actually using a left click/right click menu (via AutoHotKey) and that's why I figured I'd add a header to clarify the action, but to demonstrate on the forum I reverted back to shift-click.

Code: Select all

	$tabs = "";
	while ($i++ < tab("get", "count")) {
        $info = tab("get", "name", $i);
        $icon = gettoken($info, 2, "|");
        if (!$icon) { $icon = ":showfolders"; }
        $caption = tab("get", "path", $i);
        $tabs .= format($i, "00") . " - " . $caption . "|" . $caption . "|" . $icon . <crlf>;
	}

	$heading = "   [Normal]click - Close tabs        [Shift]click - Selects tabs" . <crlf>;
	$tabs = $heading . $tabs;

	$id = popupmenu($tabs, 5:=1, 6:=<crlf>, 7:="|");
	if ($id) {
		 if (get("shift")) {
			seltab $id;
		} else {
			tab("close", 1, $id);
		}
	}

	e $id;
Thanks.
Edit: I forgot to mention that I did try changing the SC popupmenu "start" value (e.g., 2),but of course for this situation (using index) it throws of the tab index value.
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

highend
Posts: 13313
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Insert button Close On Tablist

Post by highend »

Should popupmenu be ignoring that header line?
Nope, how should popupmenu() (by itself) know what a header is and what not...
Is there some other way to properly incorporate a header into a SC popupmenu
Sure, but (although this is possible as well) not by using an index.
I'm already using the caption|data|icon syntax, so this is an easy task...

Code: Select all

    $tabs = "";
    while ($i++ < tab("get", "count")) {
        $info = tab("get", "name", $i);
        $icon = gettoken($info, 2, "|");
        if (!$icon) { $icon = ":showfolders"; }
        $caption = tab("get", "path", $i);
        $tabs .= format($i, "00") . " - " . $caption . "|" . "$i<:>$caption" . "|" . $icon . <crlf>;
    }

    $heading = "   [Normal]click - Close tabs        [Shift]click - Selects tabs|<heading>|:tsf" . <crlf>;
    $tabs = $heading . $tabs;

    $entry = popupmenu($tabs, 6:=<crlf>, 7:="|");
    if ($entry && $entry != "<heading>") {
        $id = gettoken($entry, 1, "<:>");
        if (get("shift")) {
            seltab $id;
        } else {
            tab("close", 1, $id);
        }
    }
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4139
Joined: 28 Feb 2012 19:27

Re: Insert button Close On Tablist

Post by klownboy »

highend wrote: 10 Dec 2019 21:33 Nope, how should popupmenu() (by itself) know what a header is and what not...
I realized that wasn't possible at least as written and shouldn't have asked.
highend wrote: 10 Dec 2019 21:33 Sure, but (although this is possible as well) not by using an index.
I'm already using the caption|data|icon syntax, so this is an easy task...
I had noticed the day you posted it that you had "data" even though you were using "index".

Question though, in your line if ($entry && $entry != "<heading>") { I know what $entry is but what is <heading>? I see you use it in the header variable $header, but I'm not sure what it defines or how it's used. I din't see its use in the help file and I haven't run across its use. So effectively what you are doing with that statement is ensuring that first line (which we don't want to be included) is not included and the index starts with the actual first tab. I suppose that could be accomplished numerous ways.

Thanks highend.
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

highend
Posts: 13313
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Insert button Close On Tablist

Post by highend »

I suppose that could be accomplished numerous ways.
Yeah, but this is imho the easiest way to do it. Why? Imagine you have more than one
caption line inside the menu and not only a single header and some of them may exists
and some not...

Code: Select all

Scripts in root
1.xys
2.xys
...
Scripts for user name "Ugly kid joe" but that user does not exist on this computer
<no scripts to list here>

Scripts for your own user name
a.xys
b.xys
...
etc.
<heading> may look confusing because it uses XY's internal variable syntax.
As long as you don't have name clash(es) everything's fine. Ofc you could use a different
syntax like: :heading:.

For possible multiple headings (which I have in my personal: 'Do everything I need' script)
I use a regexmatches() check instead like

if (!regexmatches($entry, "<(caption_a|...|caption_z)>") to make sure that not a header line was clicked...
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4139
Joined: 28 Feb 2012 19:27

Re: Insert button Close On Tablist

Post by klownboy »

Hey highend, thanks for the explanations. I'm still unsure about the use of "XY's internal variable syntax". Is "<header>" or :header: an internal variable for the header or caption? I know XYplorer has internal variables but I didn't know that "header" or in your other regex example, "caption" were one of them. Is that discussed anywhere? I tried your example multiple times stepping through the script but it doesn't explain to me what those values are when I click on the header in the menu. What does XY equate <header> or <(caption_a|...|caption_z) to be?

So for the regexmatches example if (!regexmatches($entry, "<(caption_a|...|caption_z)>") for use when you potentially have multiple headers, does the $header variable suppose to be:
$heading = " [Normal]click - Close tabs [Shift]click - Selects tabs|<(caption_a|...|caption_z)>|:tsf" . <crlf>; or can you still use:
$heading = " [Normal]click - Close tabs [Shift]click - Selects tabs|<heading>|:tsf" . <crlf>;

Is the syntax for this <header>to use a "|" separator before <header> all within the "Caption" portion of "Caption|Icon|State|Level : Label" Script ?

If I clean up my $header variable so it's simply:

Code: Select all

    $heading = "   [Normal]click - Close tabs        [Shift]click - Selects tabs";
    $tabs = $heading<crlf>$tabs;
In that case (for this specific case only) if ($entry != $heading) { works. But the beauty of your code examples is that they can be used in any header situation.

Lastly, I'm a little confused on the line, if ($entry && $entry != "<heading>") { why did you use $entry && $entry?

Thanks.
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

highend
Posts: 13313
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Insert button Close On Tablist

Post by highend »

<header> isn't a variable. It just looks like one because I've used the same syntax as XY does.
You can use whatever you want to identify an entry (in this case a caption inside a popupmenu) as long as you use the caption|data|icon format
It's really only a (hopefully unique) identifier for an entry (in the |data| part)...
why did you use $entry && $entry?
Click outside of the menu. $entry is empty in that case.
So I make sure that it is not empty (a menu item was clicked) and that it is a valid entry, not some header...
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4139
Joined: 28 Feb 2012 19:27

Re: Insert button Close On Tablist

Post by klownboy »

Duh, it finally dawned on me that you were simply putting the $header variable into the popupmenu format of caption|data|icon. I hadn't done that originally and most of my questions were because I didn't realize that's what you were doing. After testing I understand now what you mean about the if ($entry && $entry != "<heading>") { and taking care of both clicking on the header and outside the menu.

I tested theif (!regexmatches($entry, "<(caption_a|...|caption_z)>") { you suggested for multiple headers situations and I added an additional header for testing and more importantly learning.

Code: Select all

    $heading = "   [Normal]click - Close tabs        [Shift]click - Selects tabs|<caption_a>|:tsf" . <crlf>;
    $heading2 = "   [Normal]click - My tabs        [Shift]click - My Selects tabs|<caption_b>|:tsf" . <crlf>;
    $tabs = $heading . $tabs . $heading2;
It wasn't working through numerous runs and I finally realized that there was no second closing ")" causing it to yield a positive "if" result and continue in the script. Working great now!

Thanks again highend.
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

Post Reply