Page 1 of 1

Multi-selecting items from a given selection

Posted: 05 Jun 2022 15:11
by Norn
Multi-selecting items from a given selection:
Selecting the next to all selected items.
Selecting the odd row items of all selected items.
Selecting the even row items of all selected items.

The last popup menu script combines the previous three scripts.
How to use and execute a script: viewtopic.php?f=7&t=6560

Code: Select all

//Function : Selecting the next to all selected items
//Created  : 2022-06-05
//Modified : 2022-06-05
//Version  : 1.0

//Get selectedItems
 $selectedItems = "<get SelectedItemsPathNames>";

//First item of selectedItems
 $start = gettoken($selectedItems, 1, <crlf>);

//Last item of selectedItems
 $end = gettoken($selectedItems, -1, <crlf>);

//Get row number of $start
 $start = row($start);

// Get row number of $end, then +1
 $end = row($end)+1;

//Select all items from row $start to row $end
 sel $start, $end;

//Get selectedItems, then deselect all
 $list = "<get SelectedItemsPathNames>"; sel;



//Foreach $selectedItems [View the Help file "Foreach Loops"]
 foreach($item, $selectedItems, "<crlf>") {
    //Foreach $list
    foreach($item2, $list, "<crlf>") {
	   The $case variable is a switch, enable to selecting every $item2 in foreach loop. if $item == $item2 {$case = "1";} next $item2 will be selected, $item2 is next to $item
	   if $case == "1" {selectitems $item2, , , a; $case = "0";}    //selectitems $item, , , a;   ->   Add $item to the current selections
	   if $item == $item2 {$case = "1";}
	   }
	 }

Code: Select all

//Function: Multi-selecting items from a given selection (1, 3, 5 . . . 15 . . . 999 . . .)
//Created : 2022-06-05
//Modified: 2022-06-05
//Version : 1.0

//Get selectedItems
 $selectedItems = "<get SelectedItemsPathNames>";

//Deselect all
 sel;

//First item of selectedItems
 $start = gettoken($selectedItems, 1, <crlf>);

//Last item of selectedItems
 $end = gettoken($selectedItems, -1, <crlf>);



//The $case variable is a switch
 $case = "1";

//Foreach $selectedItems [View the Help file "Foreach Loops"]
 foreach($item, $selectedItems, "<crlf>") {
	   //The $case variable is a switch, enable to selecting every $item in foreach odd loop (or every $item in foreach even loop). For example: row 1, row 3, row 5 or row 2, row 4, row 6 of the selected list
	   if $case == "2" {$case = "0";}
	   if $case == "1" {selectitems $item, , , a; $case = "2";}    //selectitems $item, , , a;   ->   Add $item to the current selections
	   if $case == "0" {$case = "1";}
	   }

Code: Select all

//Function: Multi-selecting items from a given selection (2, 4, 6 . . . 16 . . . 1000 . . .)
//Created : 2022-06-05
//Modified: 2022-06-05
//Version : 1.0

//Get selectedItems
 $selectedItems = "<get SelectedItemsPathNames>";

//Deselect all
 sel;

//First item of selectedItems
 $start = gettoken($selectedItems, 1, <crlf>);

//Last item of selectedItems
 $end = gettoken($selectedItems, -1, <crlf>);



//The $case variable is a switch
 $case = "1";

//Foreach $selectedItems [View the Help file "Foreach Loops"]
 foreach($item, $selectedItems, "<crlf>") {
	   //The $case variable is a switch, enable to selecting every $item in foreach odd loop (or every $item in foreach even loop). For example: row 1, row 3, row 5 or row 2, row 4, row 6 of the selected list
	   if $case == "1" {$case = "0";}
	   if $case == "2" {selectitems $item, , , a; $case = "1";}    //selectitems $item, , , a;   ->   Add $item to the current selections
	   if $case == "0" {$case = "2";}
	   }
Popup menu:

Code: Select all

//Function: Multi-selecting items from a given selection
//Created : 2022-06-05
//Modified: 2022-06-05
//Version : 1.0

"Multi-selecting items from a given selection (1, 3, 5 . . . 15 . . .)";
//Get selectedItems
 $selectedItems = "<get SelectedItemsPathNames>";

//Deselect all
 sel;

//First item of selectedItems
 $start = gettoken($selectedItems, 1, <crlf>);

//Last item of selectedItems
 $end = gettoken($selectedItems, -1, <crlf>);



//The $case variable is a switch
 $case = "1";

//Foreach $selectedItems [View the Help file "Foreach Loops"]
 foreach($item, $selectedItems, "<crlf>") {
	   //The $case variable is a switch, enable to selecting every $item in foreach odd loop (or every $item in foreach even loop). For example: row 1, row 3, row 5 or row 2, row 4, row 6 of the selected list
	   if $case == "2" {$case = "0";}
	   if $case == "1" {selectitems $item, , , a; $case = "2";}    //selectitems $item, , , a;   ->   Add $item to the current selections
	   if $case == "0" {$case = "1";}
	   }






"Multi-selecting items from a given selection (2, 4, 6 . . . 16 . . .)";
//Get selectedItems
 $selectedItems = "<get SelectedItemsPathNames>";

//Deselect all
 sel;

//First item of selectedItems
 $start = gettoken($selectedItems, 1, <crlf>);

//Last item of selectedItems
 $end = gettoken($selectedItems, -1, <crlf>);



//The $case variable is a switch
 $case = "1";

//Foreach $selectedItems [View the Help file "Foreach Loops"]
 foreach($item, $selectedItems, "<crlf>") {
	   //The $case variable is a switch, enable to selecting every $item in foreach odd loop (or every $item in foreach even loop). For example: row 1, row 3, row 5 or row 2, row 4, row 6 of the selected list
	   if $case == "1" {$case = "0";}
	   if $case == "2" {selectitems $item, , , a; $case = "1";}    //selectitems $item, , , a;   ->   Add $item to the current selections
	   if $case == "0" {$case = "2";}
	   }






"Selecting the next to all selected items";
//Get selectedItems
 $selectedItems = "<get SelectedItemsPathNames>";

//First item of selectedItems
 $start = gettoken($selectedItems, 1, <crlf>);

//Last item of selectedItems
 $end = gettoken($selectedItems, -1, <crlf>);

//Get row number of $start
 $start = row($start);

//Get row number of $end, then +1
 $end = row($end)+1;

//Select all items from row $start to row $end
 sel $start, $end;

//Get selectedItems, then deselect all
 $list = "<get SelectedItemsPathNames>"; sel;



//Foreach $selectedItems [View the Help file "Foreach Loops"]
 foreach($item, $selectedItems, "<crlf>") {
    //Foreach $list
    foreach($item2, $list, "<crlf>") {
	   //The $case variable is a switch, enable to selecting every $item2 in foreach loop. if $item == $item2 {$case = "1";} next $item2 will be selected, $item2 is next to $item
	   if $case == "1" {selectitems $item2, , , a; $case = "0";}    //selectitems $item, , , a;   ->   Add $item to the current selections
	   if $item == $item2 {$case = "1";}
	   }
	 }

Re: Multi-selecting items from a given selection

Posted: 05 Jun 2022 21:07
by Filehero
I appreciate your engagement, but I think some introducing words would be of some help especially to XY script novices. ;)

Anyway, @Don:

Regarding if $case == "1" {selectitems $item2, , , a; $case = "0";}

Shouldn't this or if 1 == 1 { msg "Yes" }; pop a "Dubios Syntax" message with "Syntax Checking" on?

From the manual's corresponding section:
if (expression) {
 statement;
}


Remarks
· Parentheses around the expression are mandatory.
· Curly braces around the statement block are mandatory (even if there is only one statement).

Re: Multi-selecting items from a given selection

Posted: 06 Jun 2022 11:51
by admin
Filehero wrote: 05 Jun 2022 21:07 Shouldn't this or if 1 == 1 { msg "Yes" }; pop a "Dubios Syntax" message with "Syntax Checking" on?
Yes, I would have expected that too, but it is tolerated. I don't really see any reason to be stricter here.

Re: Multi-selecting items from a given selection

Posted: 06 Jun 2022 18:53
by Filehero
admin wrote: 06 Jun 2022 11:51 Yes, I would have expected that too, but it is tolerated. I don't really see any reason to be stricter here.
Me too, I was just curious.

Re: Multi-selecting items from a given selection

Posted: 06 Jun 2022 19:25
by Norn
Ok, I edited. :ninja:

Re: Multi-selecting items from a given selection

Posted: 06 Jun 2022 19:39
by Filehero
Norn wrote: 06 Jun 2022 19:25 Ok, I edited. :ninja:
Good move! :)