Toggle floating preview script help

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
fogg
Posts: 32
Joined: 15 Jul 2014 16:13
Location: Going around the World

Toggle floating preview script help

Post by fogg »

Hello! I am running the floating preview in my script but floating preview closes after each one time!

My script is select one file and floating preview and open this file in notepad. And again select the next file when I exit the notepad.
s404:signature not found.

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: scripting floating preview bug

Post by bdeshi »

How are you running floating preview in your script?
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

fogg
Posts: 32
Joined: 15 Jul 2014 16:13
Location: Going around the World

Re: scripting floating preview bug

Post by fogg »

It is my script

Code: Select all

$NUMBER = 56;
 $LOOP = 0;
 while($LOOP < $NUMBER){
  $LOOP++;
  sel  $LOOP;
  #178; // it is floating preview code at help | list all commands
  run "notepad <curitem>",,1,1;
 }
I run script with Menu >Script >Run Script
s404:signature not found.

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

Re: scripting floating preview bug

Post by highend »

This is no bug. It toggles fp on / off.

Regarding your script and to handle it correctly:
You can get the state of fp with

Code: Select all

$state = get("#178");
0 = FP not active
1 = FP active
So you only need to execute it on the first item
and execute it again after the loop is done

I've moved the topic...
One of my scripts helped you out? Please donate via Paypal

fogg
Posts: 32
Joined: 15 Jul 2014 16:13
Location: Going around the World

Re: Toggle floating preview script help

Post by fogg »

Thankyou!!! :biggrin: :biggrin:
Now it is my script. All ok!

Code: Select all

$state = get("#178");
 if($state==1){  #178; // it is floating preview code at help | list all commands}
 $NUMBER = 56;
 $LOOP = 0;
 while($LOOP < $NUMBER){
  $LOOP++;
  sel  $LOOP;
  run "notepad <curitem>",,1,1;
 }
 $state = get("#178");
 if($state==1){  #178; // it is floating preview code at help | list all commands}
s404:signature not found.

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Toggle floating preview script help

Post by bdeshi »

:eh: @fogg: It's wokring yes, but accidentally. You're missing two pieces of the puzzle

1.) You've commented out an important bit: the } at the end of the if clause.

Code: Select all

$state = get("#178");
 if($state==1){  #178; // it is floating preview code at help | list all commands}
2.) Also, you have to check if the FP is NOT open and open it in this case. $state==1 means the FP is already open - #178 will now toggle it off. So your code when corrected will never show the FP!


So, all in all, use this instead:

Code: Select all

  $state = get("#178"); // get FP status. 1 is open, 0 is closed
  if ($state==0) {      // $state==0 means floating preview is NOT active. 
    #178;               // #178 opens it in that case.
  }
  $NUMBER = 56;
  $LOOP = 0;
  while ($LOOP < $NUMBER) {
    $LOOP++;
    sel $LOOP;
    run "notepad <curitem>",,1,1;
   }
   #178; // since FP is sure to be open at this point, this will toggle it off.
fogg wrote:I've moved the topic...
got me mildly panicking a bit there! I was typing a response and submitted only to get ~"the topic does not exist".
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

fogg
Posts: 32
Joined: 15 Jul 2014 16:13
Location: Going around the World

Re: Toggle floating preview script help

Post by fogg »

Thank you too!!! :kidding: :kidding: :kidding: This script also work. I use your script now.
SammaySarkar wrote: I've moved the topic...

got me mildly panicking a bit there! I was typing a response and submitted only to get ~"the topic does not exist".
BUt i didnot move the topic!
s404:signature not found.

fogg
Posts: 32
Joined: 15 Jul 2014 16:13
Location: Going around the World

Re: Toggle floating preview script help

Post by fogg »

Also i want help to automactic count number of files? Now I write $NUMBER=56 when 56 files and other number for other files. I wish like this:

Code: Select all

$NUMBER=count("files");
???
s404:signature not found.

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

Re: Toggle floating preview script help

Post by highend »

Count which files, all existing

Code: Select all

$NUMBER = listfolder(, , 1+32);
or e.g. only txt files?

Code: Select all

$NUMBER = listfolder(, "*.txt", 1+32);
One of my scripts helped you out? Please donate via Paypal

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Toggle floating preview script help

Post by bdeshi »

counting items: I believe you are looking for item count to run the while loop on them to select and run in notepad. You'd better use the items' full paths instead of blind list indexes (in case list might have other items besides your to-preview files). Try something like this:

Code: Select all

  $ITEMS = listpane(, "*.txt", 1); // |-separated list of only pdf files in list.
  foreach ($ITEM, $ITEMS) {        // walk thru each item on the $ITEMS list
    selectitems($ITEM, 2);         // select $ITEM.  unlike sel, selectitems can select by full path
    if (get("#178")==0) { #178; }  // open FP.       get("#178")==0 means floating preview is NOT active. #178 opens it.
    run "notepad ""$ITEM""",,1,1;  // open notepad.  note the doublequotes around $ITEM. the fullpath can have spaces
   }
   #178;                           // since FP is sure to be open at this point, this will toggle it off

This will get a list of all txt files in current list (adjust pattern in listpane() to fit your needs), and loop thru only these files, selecting and opening in notepad.
(Also, I moved the floating preview opening logic after the selection statement, because I discovered the FP won't open if there happens to be no valid selection before the script starts.)

HTH.

--- ---
fogg wrote:
SammaySarkar wrote: I've moved the topic...

got me mildly panicking a bit there! I was typing a response and submitted only to get ~"the topic does not exist".
BUt i didnot move the topic!
Sorry I meant to say that to highend.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

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

Re: Toggle floating preview script help

Post by highend »

@Sammay

Do you really think he wants to open .pdf files in standard Windows notepad? :P
One of my scripts helped you out? Please donate via Paypal

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Toggle floating preview script help

Post by bdeshi »

heh! :ninja: Ii think I was just copying your post.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

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

Re: Toggle floating preview script help

Post by highend »

It occurred to me that he was probably not attempting to open those files so I changed it a minute later :mrgreen:
One of my scripts helped you out? Please donate via Paypal

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Toggle floating preview script help

Post by bdeshi »

Well,
fogg wrote:select one file and floating preview and open this file in notepad.
I'm not exactly sure what's the purpose of the script: opening the same file in the FP and notepad? What does this accomplish? :eh:
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

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

Re: Toggle floating preview script help

Post by highend »

No clue but hey, it's his script...
One of my scripts helped you out? Please donate via Paypal

Post Reply