style = 512 for inputselect()

Features wanted...
highend
Posts: 13311
Joined: 06 Feb 2011 00:33

style = 512 for inputselect()

Post by highend »

512 = Return all items in their current order (only useful when combined with 16, otherwise the order is always the one from the original listdata)

For example:

Code: Select all

a
b
c
d
and inside the window you reorder them to

Code: Select all

a
c
b
d
then inputselect(..., 2:=<crlf>, 3:=512)

would return exactly the items (with <crlf> as the separator) from the second code block

Why is this useful?
I'd write a script that makes it easier for the user to reorder his custom column entries...
And this would possibly apply to a few other things that are hard to do / tedious when done manually

I know that something like this can be achieved by using prechecked checkboxes for all entries combined with style=16 but if the user accidentally
clicks one off, the whole ship sinks...
One of my scripts helped you out? Please donate via Paypal

admin
Site Admin
Posts: 60538
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: style = 512 for inputselect()

Post by admin »

Okay. :)

highend
Posts: 13311
Joined: 06 Feb 2011 00:33

Re: style = 512 for inputselect()

Post by highend »

Thanks!
One of my scripts helped you out? Please donate via Paypal

zakhar
Posts: 150
Joined: 08 Sep 2010 21:13

Re: style = 512 for inputselect()

Post by zakhar »

1024 = Show file system icons for the items without paths
(1024 as example)

Why is this useful?
I let XYplorer build and open a menu to start programs - only program shortcuts
represented by lnk files names must be shown.
If I choose style=1 then XYplorer shows not only lnk files itself,
but the paths of this lnk files too - that is not convenient, as the paths are too long
and the distance betwenn program icons and their corresponded program names shown in the inputselect() menu are too long too.
To eliminate paths I detach paths from their names building a second data list,
that is then represented in the inputselect() menu and choose style 4 - the obvious disadvantage is
that the icons of the programs (represented by lnk files) are then not visible.

admin
Site Admin
Posts: 60538
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: style = 512 for inputselect()

Post by admin »

And the returned item should also be without path?

zakhar
Posts: 150
Joined: 08 Sep 2010 21:13

Re: style = 512 for inputselect()

Post by zakhar »

No,
the returned item should be with path
so that the returned content can be passed directly to the open() command to start the desired program.
The path should not be shown in the inputselect() menu - that is all.

zakhar
Posts: 150
Joined: 08 Sep 2010 21:13

Re: style = 512 for inputselect()

Post by zakhar »

Here is my script:

Code: Select all

 $qs1 = quicksearch(".lnk","C:\Users\User\Desktop\1");
 $qs2 = quicksearch(".lnk","C:\Users\User\Desktop\2");
 $qs3 = quicksearch(".lnk","C:\Users\User\Desktop\3");
 $qs4 = quicksearch(".lnk /n","C:\Users\User\Desktop");
  
 $d = "--------------------------------------------x";
 $qs1 = "$qs1<crlf>$d<crlf>$qs2<crlf>$d<crlf>$qs3<crlf>$d<crlf>$qs4";
 
// extracting of shortcuts without paths
// beginn
 
 $i1 = 1;
 while($i1 <= 3){
  
 $a1 = gettoken($qs1,"count",<crlf>);

 $m1 = "";
 $m2 = "";
 $i = 1;
 while($i <= $a1){
 $a2 = gettoken($qs1,$i,<crlf>);
 $a3 = gettoken($a2,-1,"\");

// shown menu
// beginn
 if($m1 == ""){
 $m1 = "$a3-delim";
 } else {
 $m1 = "$m1$a3-delim";
 }
// shown menu
// end

// hidden list with numbers
// beginn
 $a4 = "$a3|$i-delim";
 if($m2 == ""){
 $m2 = $a4;
 } else {
 $m2 = "$m2$a4";
 }
// hidden list with numbers
// end 
 
 $i++;
 }
   
// extracting of shortcuts without paths
// end

 $a = inputselect("","$m1","-delim",4,0,400,700,"",);
 if($a == "" || $a == $d){
 $a = 0;
 }
 end $a == 0;
 
// connecting the choosen link to its path
// beginn

 $i = 1;
 while($i <= $a1 && $t != 1){
 $b1 = gettoken($m2,$i,"-delim");
 $b2 = gettoken($b1,1,"|");
 if($b2 == "$a"){
 $t = 1;
 $b3 = gettoken($b1,-1,"|");
 $b4 = gettoken($qs1,$b3,<crlf>);
 }
 
 $i++;
 }
 
// connecting the choosen link to its path
// end

 open "$b4";



admin
Site Admin
Posts: 60538
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: style = 512 for inputselect()

Post by admin »

Well, I first thought this would be quick and easy to add, but it's not. I don't want to open this can now. Sorry, maybe later.

jupe
Posts: 2790
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: style = 512 for inputselect()

Post by jupe »

@zakhar: I think where you have used inputselect() style 4, I think you meant to use 8, I could be wrong though, also instead of building 2 lists you could use the token index to run the command, this won't solve your icons problem but it is a bit less scripting, here is a quick+rough example of what I mean, that is if you are interested:

Code: Select all

  $qs1 = quicksearch(".lnk", "C:\Users\User\Desktop");
  $qs2 = regexreplace($qs1, "^(.+\\)(.*)$", "$2");
  $sel = inputselect(,$qs2, <crlf>, 128+8+1, 0, 400, 700);

  if ($sel) { open gettoken($qs1, $a, <crlf>); }

zakhar
Posts: 150
Joined: 08 Sep 2010 21:13

Re: style = 512 for inputselect()

Post by zakhar »

admin wrote:Well, I first thought this would be quick and easy to add, but it's not. I don't want to open this can now. Sorry, maybe later.
No problem at all. :?

highend
Posts: 13311
Joined: 06 Feb 2011 00:33

Re: style = 512 for inputselect()

Post by highend »

A (imho) better way for your script (and ofc it doesn't solve the icon problem as well, at least not if you want a way to filter your items on demand and not use a popupmenu()...):

More readable, easier to expand, less error prone (non-existing paths e.g.):

Code: Select all

    $subSearchLocations = <<<>>>
%USERPROFILE%\Desktop\1
%USERPROFILE%\Desktop\2
%USERPROFILE%\Desktop\3
>>>;
    $sep = "--------------------------------------------x";

    $listOfLinks = "";
    foreach($subLocation, $subSearchLocations, <crlf>, "e") {
        if (exists($subLocation) == 2) {
            $links = quicksearch(".lnk", $subLocation);
            if ($links) { $listOfLinks .= $links . <crlf> . $sep . <crlf>; }
        }
    }
    $listOfLinks .= quicksearch(".lnk /n", "%USERPROFILE%\Desktop");

    // List of links with paths truncated
    $listOfLinksNoPaths = regexreplace($listOfLinks, "^(.+\\)(.+$)", "$2");

    // Sel + execute item
    $index = inputselect("", $listOfLinksNoPaths, <crlf>, 4+128, , 400, 700);

    if ($index && (gettoken($listOfLinksNoPaths, $index, <crlf>) != $sep)) { open gettoken($listOfLinks, $index, <crlf>); }
One of my scripts helped you out? Please donate via Paypal

zakhar
Posts: 150
Joined: 08 Sep 2010 21:13

Re: style = 512 for inputselect()

Post by zakhar »

jupe wrote:...I think you meant to use 8...
Thank you, jupe!
I avoid to use regexreplace() for complexity of the sentences like "^(.+\\)(.*)$",
that I do not understand now and that take too long to learn deep enough.
Therefore I prefer to write a little bit more but simpler.

zakhar
Posts: 150
Joined: 08 Sep 2010 21:13

Re: style = 512 for inputselect()

Post by zakhar »

highend wrote:A (imho) better way for your script ... More readable, easier to expand, less error prone (non-existing paths e.g.):
Thank you, highend!
Interesting combination for me is the following
(although I avoid to use foreach() - in older versions I had often hangups of unknown reasons, may be of my own miscoding)... and prefer while() )
:

Code: Select all

    $subSearchLocations = <<<>>>
%USERPROFILE%\Desktop\1
%USERPROFILE%\Desktop\2
%USERPROFILE%\Desktop\3
>>>;
 ...
    foreach($subLocation, $subSearchLocations, <crlf>, "e")
and using "." and newly introduced ".=" .

highend
Posts: 13311
Joined: 06 Feb 2011 00:33

Re: style = 512 for inputselect()

Post by highend »

@Don
Why not do it this way (style = 1024):

This style would allow user defined icons (but the path isn't autotruncated by XY, the user has to take care of this),
with the following logic
- Separator must have been set to something _different_ than "|"

This would switch the behavior of to what popupmenu() / popupnested() already provide:
listdata can be used as "Caption|Data|Icon|State" where the separator is bound to "|".
If you want to add the full logic, "State" could be supported (e.g. if state contains "1", items are preselected when style = 2 is used in conjunction)
But because prefixing each line with a "+" leads to the same result, this could be left out.

If only "Caption" is used ("|" is NOT present at all), it's still the same old behavior, "Caption" would be treated as
the full path to a file and the icon is taken from it (if style = 1 or style = 8 is set), otherwise if "|" is present
the icon is taken from the "Icon" field and if "Icon" is not used, but "Data" is, it is taken from that one).

This wouldn't break existing scripts (style = 1024 is necessary), requires not too much additional programming
for the logic (no can of worms here), doesn't require any additional params ("sep_itemlist" would not be necessary
and not in an unexpected position (at the end of the parameter list)) and opens inputselect() a whole new world
by supporting user defined icons.
The only minor drawback: The separator for "Caption|Data|Icon|State" is bound to "|"...

Code: Select all

    $list = <<<>>>
%USERPROFILE%\Desktop\7-Zip|R:\7-Zip.lnk|D:\Tools\7-Zip\7zFM.exe
%USERPROFILE%\Desktop\AIMP|R:\AIMP.lnk|D:\Tools\AIMP\some_icon.ico
%USERPROFILE%\Desktop\HxD|D:\Tools\HxD\HxDPortable.exe
D:\Tools\IcoFx\icofx3.exe
>>>;

    $sel = inputselect("Start app...", $list, <crlf>, 1024);

    // 1st entry: Caption|Data|Icon -> Get icon from "Icon"    | Shows: 7-Zip
    // 2nd entry: Caption|Data|Icon -> Get icon from "Icon"    | Shows: AIMP
    // 3rd entry: Caption|Data      -> Get icon from "Data"    | Shows: HxD
    // 4th entry: Caption           -> Get icon from "Caption" | Shows: D:\Tools\IcoFx\icofx3.exe
One of my scripts helped you out? Please donate via Paypal

admin
Site Admin
Posts: 60538
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: style = 512 for inputselect()

Post by admin »

Good design, but there is another drawback: This would be a LOT of work. :)

Post Reply