List Items in a List in Search Tab

Discuss and share scripts and script files...
Enternal
Posts: 1174
Joined: 10 Jan 2012 18:26

Re: List Items in a List in Search Tab

Post by Enternal »

@ FluxTorpedo
Ooh your script is very interesting! I like that ability to drag and drop the most! And haha yes, can't wait for Virtual Folders. For the longest time, I have been setting the "Label" button and the "Find Label" button and using these two extensively as a "container" for so long. Just got a bit tired of that hehe. Now we have multiple cooler ways of doing it!

Have you also tried my script? One of the things I like about mine is that I thought it was quite straightforward and that you can easily edit the stuff in the containers.

EDIT: Oh yeah. I renamed certain things hoping that it's a bit clearer. No other changes.

Code: Select all

"_Initialize"
	Perm $Selections;
	Perm $Selections2;
	Perm $SelectionStore;
	If $SelectionStore == "" {
		$SelectionStore = 1; }

"Add Selected Item(s)"
	End ("<selitems>"==""),"Nothing Is Selected!";
	$CountItems = Get("CountSelected");
	If $SelectionStore == 2 {
		$Selections2 = "$Selections2"."|".Get("SelectedItemsPathNames","|");
		$Selections2 = FormatList("$Selections2","ned"); }
	Else {
		$Selections = "$Selections"."|".Get("SelectedItemsPathNames","|");
		$Selections = FormatList("$Selections","ned"); }
	Status "$CountItems Item(s) Added to Selection Store #$SelectionStore.",,"ready";

"Remove Selected Item(s)"
	End ("<selitems>"==""),"Nothing Is Selected!";
	$CountItems = Get("CountSelected");
	Global $SelectionsRemove = Get("SelectedItemsPathNames","|");
	If $SelectionStore == 2 {
		ForEach($Item,$SelectionsRemove,"|") {
			$Selections2 = Replace($Selections2,$Item,,1); }
		$Selections2 = FormatList("$Selections2","ned"); }
	Else {
		ForEach($Item,$SelectionsRemove,"|") {
			$Selections = Replace($Selections,$Item,,1); }
		$Selections = FormatList("$Selections","ned"); }
	Status "$CountItems Item(s) Removed from Selection Store #$SelectionStore.",,"alert";

""
"Edit Store"
	If $SelectionStore == 2 {
		If $Selections2 > 0 {
			$Contents2 = Replace($Selections2,"|","<crlf>");
			$Selections2 = Input("Edit Selection Store #2",,$Contents2,m);
			$Selections2 = Replace($Selections2,"<crlf>","|");
			$Selections2 = FormatList("$Selections2","ned"); }
		Else {
			Status "No Item(s) in Selection Store #$SelectionStore.",,"alert"; } }
	Else {
		If $Selections > 0 {
			$Contents = Replace($Selections,"|","<crlf>");
			$Selections = Input("Edit Selection Store #1",,$Contents,m);
			$Selections = Replace($Selections,"<crlf>","|");
			$Selections = FormatList("$Selections","ned"); }
		Else {
			Status "No Item(s) in Selection Store #$SelectionStore.",,"alert"; } }
	
"Show Store"
	If $SelectionStore == 2 {
		If $Selections2 > 0 {
			Tag SelectionStoreItems,$Selections2,1;
			Goto "*?Tags:SelectionStoreItems /r";
			Tag SelectionStoreItems,$Selections2,1,2;
			Tab(Rename, "Selection Store #$SelectionStore"); }
		Else {
			Status "No Item(s) in Selection Store #$SelectionStore.",,"alert"; } }
	Else {
		If $Selections > 0 {
			Tag SelectionStoreItems,$Selections,1;
			Goto "*?Tags:SelectionStoreItems /r";
			Tag SelectionStoreItems,$Selections,1,2;
			Tab(Rename, "Selection Store #$SelectionStore"); }
		Else {
			Status "No Item(s) in Selection Store #$SelectionStore.",,"alert"; } }

"Copy Store Item(s) to Clipboard"
	If $SelectionStore == 2 {
		If $Selections2 > 0 {
			Copy $Selections2; }
		Else {
			Status "No Item(s) in Selection Store #$SelectionStore.",,"alert"; } }
	Else {
		If $Selections > 0 {
			Copy $Selections; }
		Else {
			Status "No Item(s) in Selection Store #$SelectionStore.",,"alert"; } }

""
"Copy Store Item(s) to Here"
	If $SelectionStore == 2 {
		If $Selections2 > 0 == 1 {
			CopyTo <curtab>,$Selections2; }
		Else {
			Status "No Item(s) in Selection Store #$SelectionStore.",,"alert"; } }
	Else {
		If $Selections > 0 == 1 {
			CopyTo <curtab>,$Selections; }
		Else {
			Status "No Item(s) in Selection Store #$SelectionStore.",,"alert"; } }

"Move Store Item(s) to Here"
	If $SelectionStore == 2 {
		If $Selections2 > 0 == 1 {
			MoveTo <curtab>,$Selections2; }
		Else {
			Status "No Item(s) in Selection Store #$SelectionStore.",,"alert"; } }
	Else {
		If $Selections > 0 == 1 {
			MoveTo <curtab>,$Selections; }
		Else {
			Status "No Item(s) in Selection Store #$SelectionStore.",,"alert"; } }

""
"Clear Selection Store #1"
	$Clear = Confirm("Are You Sure You Want To Clear Selection Store #1?");
	End ($Clear == 0);
	Unset $Selections;
	Status "Selection Store #1 Cleared!",,"alert";

"Clear Selection Store #2"
	$Clear = Confirm("Are You Sure You Want To Clear Selection Store #2?");
	End ($Clear == 0);
	Unset $Selections2;
	Status "Selection Store #2 Cleared!",,"alert";

"Clear All Selection Store"
	$Clear = Confirm("Are You Sure You Want To Clear All Selection Store?");
	End ($Clear == 0);
	Unset $Selections, $Selections2, $SelectionStore;
	Msg "All Cleared! Selection Store #1 Will Activate at Next Start.";

""
"Activate Selection Store #1"
	$SelectionStore = 1;
	Msg "Selection Store #1 Activated.";

"Activate Selection Store #2"
	$SelectionStore = 2;
	Msg "Selection Store #2 Activated.";
[/size]
Last edited by Enternal on 03 Apr 2013 09:56, edited 1 time in total.

Enternal
Posts: 1174
Joined: 10 Jan 2012 18:26

Re: List Items in a List in Search Tab

Post by Enternal »

So I attempted to add the drag and drop feature but it did not work as well as I hoped. The main problem was I got really annoyed with the pop up menu showing up after dropping. So in the end I had to split the script into 2. SelectionStore.xys has the drop function. SelectionStoreM.xys has the menu function with all the other stuff.

SelectionStore.xys

Code: Select all

"_Initialize"
	Perm $Selections;
	Perm $Selections2;
	Perm $SelectionStore;
	If $SelectionStore == "" {$SelectionStore = 1;}

"Selection Store"
	If <get drop |> != "" {
		$CountItems = GetToken(<get drop |>, "count", "|");
		If $SelectionStore == 2 {
			$Selections2 = "$Selections2"."|".<get drop |>;
			$Selections2 = FormatList("$Selections2","ned"); }
		Else {
			$Selections = "$Selections"."|".<get drop |>;
			$Selections = FormatList("$Selections","ned"); }
		Status "$CountItems Item(s) Added to Selection Store #$SelectionStore.",,"ready"; }
	Else {
		Load SelectionStoreM; }
[/size]

SelectionStoreM.xys

Code: Select all

"Add to Store #$SelectionStore|:newtab"
	End ("<selitems>"==""),"Nothing Is Selected!";
	$CountItems = Get("CountSelected");
	If $SelectionStore == 2 {
		$Selections2 = "$Selections2"."|".Get("SelectedItemsPathNames","|");
		$Selections2 = FormatList("$Selections2","ned"); }
	Else {
		$Selections = "$Selections"."|".Get("SelectedItemsPathNames","|");
		$Selections = FormatList("$Selections","ned"); }
	Status "$CountItems Item(s) Added to Selection Store #$SelectionStore.",,"ready";

"Remove from Store #$SelectionStore|:closetab"
	End ("<selitems>"==""),"Nothing Is Selected!";
	$CountItems = Get("CountSelected");
	Global $SelectionsRemove = Get("SelectedItemsPathNames","|");
	If $SelectionStore == 2 {
		ForEach($Item,$SelectionsRemove,"|") {
			$Selections2 = Replace($Selections2,$Item,,1); }
		$Selections2 = FormatList("$Selections2","ned"); }
	Else {
		ForEach($Item,$SelectionsRemove,"|") {
			$Selections = Replace($Selections,$Item,,1); }
		$Selections = FormatList("$Selections","ned"); }
	Status "$CountItems Item(s) Removed from Selection Store #$SelectionStore.",,"alert";

""
"Edit Store #$SelectionStore|:rename"
	If $SelectionStore == 2 {
		If $Selections2 > 0 {
			$Contents2 = Replace($Selections2,"|","<crlf>");
			$Selections2 = Input("Edit Selection Store #2",,$Contents2,m,,750,500);
			$Selections2 = Replace($Selections2,"<crlf>","|");
			$Selections2 = FormatList("$Selections2","ned"); } }
	Else {
		If $Selections > 0 {
			$Contents = Replace($Selections,"|","<crlf>");
			$Selections = Input("Edit Selection Store #1",,$Contents,m,,750,500);
			$Selections = Replace($Selections,"<crlf>","|");
			$Selections = FormatList("$Selections","ned"); } }
	If $Selections == "" {Status "No Item(s) in Selection Store #$SelectionStore.",,"alert";}
	
"Show Store #$SelectionStore|:grid"
	If $SelectionStore == 2 {
		If $Selections2 > 0 {
			Tag SelectionStoreItems2,$Selections2,1;
			Goto "*?Tags:SelectionStoreItems2 /r";
			Tab(Rename, "Selection Store #$SelectionStore"); } }
	Else {
		If $Selections > 0 {
			Tag SelectionStoreItems1,$Selections,1;
			Goto "*?Tags:SelectionStoreItems1 /r";
			Tab(Rename, "Selection Store #$SelectionStore"); } }
	If $Selections == "" {Status "No Item(s) in Selection Store #$SelectionStore.",,"alert";}

"Copy Store #$SelectionStore to Clip|:clip"
	If $SelectionStore == 2 {
		If $Selections2 > 0 {
			Copy $Selections2;
			Status "Copied Selection Store #$SelectionStore Item(s) to Windows Clipboard.",,"alert"; } }
	Else {
		If $Selections > 0 {
			Copy $Selections;
			Status "Copied Selection Store #$SelectionStore Item(s) to Windows Clipboard.",,"alert"; } }
	If $Selections == "" {Status "No Item(s) in Selection Store #$SelectionStore.",,"alert";}

""
"Copy Store #$SelectionStore to Here|:copyto"
	If $SelectionStore == 2 {
		If $Selections2 > 0 {
			CopyTo <curtab>,$Selections2; } }
	Else {
		If $Selections > 0 {
			CopyTo <curtab>,$Selections; } }
	If $Selections == "" {Status "No Item(s) in Selection Store #$SelectionStore.",,"alert";}

"Move Store #$SelectionStore to Here|:moveto"
	If $SelectionStore == 2 {
		If $Selections2 > 0 {
			MoveTo <curtab>,$Selections2;
			Tag SelectionStoreItems,$Selections2,1,2;
			Unset $Selections2; } }
	Else {
		If $Selections > 0 {
			MoveTo <curtab>,$Selections;
			Tag SelectionStoreItems,$Selections,1,2;
			Unset $Selections; } }
	If $Selections == "" {Status "No Item(s) in Selection Store #$SelectionStore.",,"alert";}

""
"Clear Store #1|:stop"
	Tag SelectionStoreItems1,$Selections,1,2;
	Unset $Selections;
	Status "Selection Store #1 Cleared!",,"ready";

"Clear Store #2|:stop"
	Tag SelectionStoreItems2,$Selections2,1,2;
	Unset $Selections2;
	Status "Selection Store #2 Cleared!",,"ready";

"Clear All Store|:del"
	$Clear = Confirm("Are You Sure You Want To Clear All Selection Store?");
	End ($Clear == 0);
	Tag SelectionStoreItems1,$Selections,1,2;
	Tag SelectionStoreItems2,$Selections2,1,2;
	Unset $Selections, $Selections2, $SelectionStore;
	Status "All Selection Store Cleared!",,"ready";
	Msg "All Cleared! Selection Store #1 Will Activate at Next Start.";

""
"Activate Store #1|:dp1"
	$SelectionStore = 1;
	Status "Selection Store #1 Activated.",,"ready";
	Msg "Selection Store #1 Activated.";

"Activate Store #2|:dp2"
	$SelectionStore = 2;
	Status "Selection Store #2 Activated.",,"ready";
	Msg "Selection Store #2 Activated.";
[/size]
Currently there's in an issue with referencing icon dp1 or dp2. It works in button but not in scripts.

FluxTorpedo, you don't mind if I continue to try to incorporate some of your feature in my script? One thing I won't be able to incorporate is the different caption -> different container. The reason is I want to maintain the ability to edit the container and other stuff but if I do it your way, I won't be able to keep those features.
Last edited by Enternal on 04 Apr 2013 04:32, edited 1 time in total.

FluxTorpedoe
Posts: 904
Joined: 05 Oct 2011 13:15

Re: List Items in a List in Search Tab

Post by FluxTorpedoe »

Well, Virtual Folders are gonna have competition when they arrive! :kidding:
BTW, of course, take/change whatever you want from my script. It needed some cleaning and rewrite anyway. ;)
I guess your script would be probably more useful for complex transactions. As a matter of fact, I don't even use mine very often because most of the time, "flagging" (labeling with green/orange/red) is enough for me. ;)

Regarding the last version of your script, you could keep it in one file, but that would mean using a dynamic menu, which is much harder to maintain... (though a bit clearer with HEREDOC). It has a lot of advantages, but that would mean a big rewrite!

Enternal
Posts: 1174
Joined: 10 Jan 2012 18:26

Re: List Items in a List in Search Tab

Post by Enternal »

FluxTorpedoe wrote:Well, Virtual Folders are gonna have competition when they arrive! :kidding:
BTW, of course, take/change whatever you want from my script. It needed some cleaning and rewrite anyway. ;)
I guess your script would be probably more useful for complex transactions. As a matter of fact, I don't even use mine very often because most of the time, "flagging" (labeling with green/orange/red) is enough for me. ;)

Regarding the last version of your script, you could keep it in one file, but that would mean using a dynamic menu, which is much harder to maintain... (though a bit clearer with HEREDOC). It has a lot of advantages, but that would mean a big rewrite!
Lol! After working on this script for several days, I'm starting to wonder why did I even start writing this script when I could just have continued to use the labels like you and I have always been using... it's a lot of work so far with this script lol.

I don't know if I'm doing what you're suggesting since I don't quite understand dynamic menu since the only thing I know close to dynamic is adding variables to the captions but:

Code: Select all

"_Initialize"
	Perm $Selections;
	Perm $Selections2;
	Perm $SelectionStore;
	Perm $SelectionStoreName = Self("base");
	If $SelectionStore == "" {$SelectionStore = 1;}


/* -------- Menu -------- */
	Perm $SelectionStoreMenu =<<<Menu
"_Terminate"
	Load "$SelectionStoreName", "_Done";
"Add to Store #$SelectionStore|:newtab"
	Load "$SelectionStoreName", "_Add";
"Remove from Store #$SelectionStore|:closetab"
	Load "$SelectionStoreName", "_Remove";
""
"Edit Store #$SelectionStore|:rename"
	Load "$SelectionStoreName", "_Edit";
"Show Store #$SelectionStore|:grid"
	Load "$SelectionStoreName", "_Show";
"Copy Store #$SelectionStore to Clip|:clip"
	Load "$SelectionStoreName", "_Copy";
""
"Copy Store #$SelectionStore to Here|:copyto"
	Load "$SelectionStoreName", "_CopyTo";
"Move Store #$SelectionStore to Here|:moveto"
	Load "$SelectionStoreName", "_MoveTo";
""
"Clear Store #1|:stop"
	Load "$SelectionStoreName", "_Clear1";
"Clear Store #2|:stop"
	Load "$SelectionStoreName", "_Clear2";
"Clear All Store|:del"
	Load "$SelectionStoreName", "_ClearAll";
""
"Activate Store #1|:dp1"
	Load "$SelectionStoreName", "_Act1";
"Activate Store #2|:dp2"
	Load "$SelectionStoreName", "_Act2";
Menu;




/* -------- Drag n' Drop -------- */
"Selection Store"
	If <get drop |> != "" {
		$CountItems = GetToken(<get drop |>, "count", "|");
		If $SelectionStore == 2 {
			$Selections2 = "$Selections2"."|".<get drop |>;
			$Selections2 = FormatList("$Selections2","ned"); }
		Else {
			$Selections = "$Selections"."|".<get drop |>;
			$Selections = FormatList("$Selections","ned"); }
		Status "$CountItems Item(s) Added to Selection Store #$SelectionStore.",,"ready"; }
	Else {
		Load $SelectionStoreMenu,*,s; }




/* -------- Body -------- */
"_Add"
	End ("<selitems>"==""),"Nothing Is Selected!";
	$CountItems = Get("CountSelected");
	If $SelectionStore == 2 {
		$Selections2 = "$Selections2"."|".Get("SelectedItemsPathNames","|");
		$Selections2 = FormatList("$Selections2","ned"); }
	Else {
		$Selections = "$Selections"."|".Get("SelectedItemsPathNames","|");
		$Selections = FormatList("$Selections","ned"); }
	Status "$CountItems Item(s) Added to Selection Store #$SelectionStore.",,"ready";

"_Remove"
	End ("<selitems>"==""),"Nothing Is Selected!";
	$CountItems = Get("CountSelected");
	Global $SelectionsRemove = Get("SelectedItemsPathNames","|");
	If $SelectionStore == 2 {
		ForEach($Item,$SelectionsRemove,"|") {
			$Selections2 = Replace($Selections2,$Item,,1); }
		$Selections2 = FormatList("$Selections2","ned"); }
	Else {
		ForEach($Item,$SelectionsRemove,"|") {
			$Selections = Replace($Selections,$Item,,1); }
		$Selections = FormatList("$Selections","ned"); }
	Status "$CountItems Item(s) Removed from Selection Store #$SelectionStore.",,"alert";

"_Edit"
	If $SelectionStore == 2 {
		If $Selections2 > 0 {
			$Contents2 = Replace($Selections2,"|","<crlf>");
			$Selections2 = Input("Edit Selection Store #2",,$Contents2,m,,750,500);
			$Selections2 = Replace($Selections2,"<crlf>","|");
			$Selections2 = FormatList("$Selections2","ned"); } }
	Else {
		If $Selections > 0 {
			$Contents = Replace($Selections,"|","<crlf>");
			$Selections = Input("Edit Selection Store #1",,$Contents,m,,750,500);
			$Selections = Replace($Selections,"<crlf>","|");
			$Selections = FormatList("$Selections","ned"); } }
	If $Selections == "" {Status "No Item(s) in Selection Store #$SelectionStore.",,"alert";}

"_Show"
	If $SelectionStore == 2 {
		If $Selections2 > 0 {
			Tag SelectionStoreItems2,$Selections2,1;
			Goto "*?Tags:SelectionStoreItems2 /r";
			Tab(Rename, "Selection Store #$SelectionStore"); } }
	Else {
		If $Selections > 0 {
			Tag SelectionStoreItems1,$Selections,1;
			Goto "*?Tags:SelectionStoreItems1 /r";
			Tab(Rename, "Selection Store #$SelectionStore"); } }
	If $Selections == "" {Status "No Item(s) in Selection Store #$SelectionStore.",,"alert";}

"_Copy"
	If $SelectionStore == 2 {
		If $Selections2 > 0 {
			Copy $Selections2;
			Status "Copied Selection Store #$SelectionStore Item(s) to Windows Clipboard.",,"alert"; } }
	Else {
		If $Selections > 0 {
			Copy $Selections;
			Status "Copied Selection Store #$SelectionStore Item(s) to Windows Clipboard.",,"alert"; } }
	If $Selections == "" {Status "No Item(s) in Selection Store #$SelectionStore.",,"alert";}

"_CopyTo"
	If $SelectionStore == 2 {
		If $Selections2 > 0 {
			CopyTo <curtab>,$Selections2; } }
	Else {
		If $Selections > 0 {
			CopyTo <curtab>,$Selections; } }
	If $Selections == "" {Status "No Item(s) in Selection Store #$SelectionStore.",,"alert";}

"_MoveTo"
	If $SelectionStore == 2 {
		If $Selections2 > 0 {
			MoveTo <curtab>,$Selections2;
			Tag SelectionStoreItems,$Selections2,1,2;
			Unset $Selections2; } }
	Else {
		If $Selections > 0 {
			MoveTo <curtab>,$Selections;
			Tag SelectionStoreItems,$Selections,1,2;
			Unset $Selections; } }
	If $Selections == "" {Status "No Item(s) in Selection Store #$SelectionStore.",,"alert";}

"_Clear1"
	Tag SelectionStoreItems1,$Selections,1,2;
	Unset $Selections;
	Status "Selection Store #1 Cleared!",,"ready";

"_Clear2"
	Tag SelectionStoreItems2,$Selections2,1,2;
	Unset $Selections2;
	Status "Selection Store #2 Cleared!",,"ready";

"_ClearAll"
	$Clear = Confirm("Are You Sure You Want To Clear All Selection Store?");
	End ($Clear == 0);
	Tag SelectionStoreItems1,$Selections,1,2;
	Tag SelectionStoreItems2,$Selections2,1,2;
	Unset $Selections, $Selections2, $SelectionStore;
	Status "All Selection Store Cleared!",,"ready";
	Msg "All Cleared! Selection Store #1 Will Activate at Next Start.";

"_Act1"
	$SelectionStore = 1;
	Status "Selection Store #1 Activated.",,"ready";
	Msg "Selection Store #1 Activated.";

"_Act2"
	$SelectionStore = 2;
	Status "Selection Store #2 Activated.",,"ready";
	Msg "Selection Store #2 Activated.";

"_Done"
	Unset $SelectionStoreMenu, $SelectionStoreName;
[/size]
It just seems... messy. At least it's all in one script now but I highly doubt it's efficient...or pretty lol.
Last edited by Enternal on 05 Apr 2013 01:55, edited 1 time in total.

Filehero
Posts: 2713
Joined: 27 Feb 2012 18:50
Location: Windows 11@100%

Re: List Items in a List in Search Tab

Post by Filehero »

Enternal wrote:I don't know if I'm doing what you're suggesting since I don't quite understand dynamic menu since the only thing I know close to dynamic is adding variables to the captions but:
I think Flux meant something like that, where the entire menu and scipt can be generated on the fly dpending on the contextual state(s):

Code: Select all

	$label = "Menu Entry Label";
	$icon_1 = ":dp1";
	$icon_2 = ":conf";
	$idx = rand(1, 10);
	
	// preparing the menu script code
	$mscript = "";
	$mscript = $mscript . "$label|$icon_1 "<crlf>;
	$mscript = $mscript . "  msg(""Hi Enternal :-)"");<crlf><crlf>";
	$i = 1;
	while ($i <= $idx) {
		$mscript = $mscript . "$i. Label|$icon_2 "<crlf>;
		$mscript = $mscript . "  msg(""Bye Enternal ;-)"");<crlf><crlf>";
		$i++;
	}
	
	// copytext($mscript);
	// running the menu script
	load($mscript, , s);
The HEREDOC way might be a more elegant, it's just a matter of personal taste.

":dp1" might not be working because it's simply unknown/unresolvable?


Cheers,
Filehero

Enternal
Posts: 1174
Joined: 10 Jan 2012 18:26

Re: List Items in a List in Search Tab

Post by Enternal »

Ah I see what FluxTorpedo means now. Wow that looks a bit too complicated for me but I'm going to try and play with it and see if I can use it although as of right now, the heredoc seems simple enough.

Just out of curiosity, is it possible to generate variables on the fly? I'm assuming now from what I see so far. Also do you think it would be nice if the heredoc has a feature that allows you to have it completely as-is? What I mean is that the variables remain unresolved. So basically:

Code: Select all

    $Test =<<<Test
This is a $Variable
Test;
Msg "$Test";
Output:
"This is a $Variable"

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

Re: List Items in a List in Search Tab

Post by highend »

What I mean is that the variables remain unresolved
Because you didn't set $Variable before?^^

Code: Select all

 $Variable = "test";
 $Test =<<<Test
This is a $Variable
Test;
 Msg "$Test";
One of my scripts helped you out? Please donate via Paypal

FluxTorpedoe
Posts: 904
Joined: 05 Oct 2011 13:15

Re: List Items in a List in Search Tab

Post by FluxTorpedoe »

I'm not sure if enternal wanted the var resolved or not...
If yes, then highend answered, if no, that raises a question I have too:

@all
• How do you keep variables unresolved when nested?
The problem occurs when (re)defining existing variables inside a variable (dynamic menu/script, etc.). e.g. to keep the same example (Menu 2 is the problem):

Code: Select all

 $Variable = "test";

 $Test =<<<Test
"Menu 1"
  msg "This is a $Variable";
"Menu 2"
  $Variable = "yet another test";
  msg "This is a $Variable";
Test;

 load($Test, , s);
The $Variable in "Menu 2" is resolved beforehand so it's considered to be the string "test", not a var. Logical per se, but how do you force it as a real unresolved variable?
I've tried all combinations of single and double-quotes, but can't figure how to do it. So I always had to resort to defining new vars... not practical when juggling with globals.

• Bonus (tricky) question :twisted:
Who knows how to, or would dream of "dynamic" definition of variables? i.e. $foo$bar = toto;
e.g. (not working)

Code: Select all

  $var = "Menu";
  while ($i < 3) {
    $i++;
    $var_$i = $i;
    echo $i;
  }
:arrow:
msg $Menu_1; // returns 1
msg $Menu_2; // returns 2...

Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Re: List Items in a List in Search Tab

Post by Marco »

Ahah, I know the bonus, I know the bonus :D
You should use eval(), like here http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=7423 (while loop towards the end and second post)

Re the first question, not possible afaik. :(
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: List Items in a List in Search Tab

Post by TheQwerty »

FluxTorpedoe wrote:The $Variable in "Menu 2" is resolved beforehand so it's considered to be the string "test", not a var. Logical per se, but how do you force it as a real unresolved variable?
I've tried all combinations of single and double-quotes, but can't figure how to do it. So I always had to resort to defining new vars... not practical when juggling with globals.
Erm... you can't, and I'm not sure I understand why using unique variables within the heredoc is problematic here. :?


I haven't run into this particular "issue" but I've been thinking about coding guidelines and would suggest following a naming convention. I'm trying to adopt:

Code: Select all

$P_PERMANENT_VARIABLE
$G_GLOABL_VARIABLE
$localVariable
$_embeddedVariable
Then since permanent variables in shared scripts may be retained I make them ridiculously long by including my username and a script identifier, such as "$P_THEQWERTY_PREVIEW_CODE__OPTIONS". This way they are more likely to be unique and give other users an idea of the source of the variable. Thankfully Sublime Text can auto-complete this for me. :)

Filehero
Posts: 2713
Joined: 27 Feb 2012 18:50
Location: Windows 11@100%

Re: List Items in a List in Search Tab

Post by Filehero »

FluxTorpedoe wrote: • How do you keep variables unresolved when nested?
The problem occurs when (re)defining existing variables inside a variable (dynamic menu/script, etc.).
.....
Logical per se, but how do you force it as a real unresolved variable?
I've tried all combinations of single and double-quotes, but can't figure how to do it. So I always had to resort to defining new vars... not practical when juggling with globals.
Skip HEREDOC. :mrgreen:

In my "dynamic" scenarios so far I initialize variables inside a dynamic script block which I only reference in scripts being called from there. Such as

Code: Select all

	// preparing the menu script code
	$mscript = "";
	$mscript = $mscript . "Menu 1"<crlf>;	
	$mscript = $mscript . "  global $g_variable;<crlf>";
	$mscript = $mscript . "  msg(""This is a $g_variable"");<crlf><crlf>";
	$mscript = $mscript . "Menu 2 "<crlf>;
	$mscript = $mscript . "  global $g_variable;<crlf>";
	$mscript = $mscript . "  $" . "g_variable = ""different test, hmm?"";<crlf>";
	$mscript = $mscript . "  load(""<xyscripts>\TestDynamicVariables.xys"", ""_doRun"", f);<crlf><crlf>";
  
	copytext($mscript);
	load($mscript, , s);
	 
	 
"doRun : _doRun"
	global $g_variable;
	msg($g_variable);
Here, HEREDOC would indeed work, but because....>>>>
Note: since load() asks for an explicit reference you need to run this script from a file (at least, I haven't found a way to "pass" the caller to the dynamic script). For ease of use, I have attached it (see below).

>>>>...I never know where all my scripting sessions will end up, I skip HEREDOC most of the time.

The other way (where variables that already have been initialized have to be accessed/changed) goes like this:

Code: Select all

	global $g_variable;
	 
	// preparing the menu script code
	$mscript = "";
	$mscript = $mscript . "Menu 1"<crlf>;	
	$mscript = $mscript . "  global $" . "g_variable;<crlf>";
	$mscript = $mscript . "  msg(""This is a $" . "g_variable"");<crlf><crlf>";
	$mscript = $mscript . "Menu 2 "<crlf>;
	$mscript = $mscript . "  global $" . "g_variable;<crlf>";
	$mscript = $mscript . "  $" . "g_variable = ""different test, hmm?"";<crlf>";
	$mscript = $mscript . "  msg(""This is a $" . "g_variable"");<crlf><crlf>";
  
	copytext($mscript);
	load($mscript, , s);
	 
	 
"_Initialize"
	global $g_variable;
	$g_variable = "test";
	msg($g_variable);
	 
"_Terminate"
	global $g_variable;
	msg($g_variable);
Here the key is avoiding variables being resolved at the "first" interpreter pass before the dynamic script is generated by concatenating the variable identifier. Thereby, the script interpreter gets tricked because during the first pass there's no variable identifier yet to be resolved. And that's the reason why HEREDOC can't work - it's treated as a block and there's only "one pass".
But even I haven't found a real situation requiring to go that quirky route - but you never know where it ends. :wink:


Cheers,
Filehero

Edit: some lots of refinements
Attachments
TestDynamicVariables.xys
(617 Bytes) Downloaded 151 times

Filehero
Posts: 2713
Joined: 27 Feb 2012 18:50
Location: Windows 11@100%

Re: List Items in a List in Search Tab

Post by Filehero »

TheQwerty wrote:I haven't run into this particular "issue" but I've been thinking about coding guidelines and would suggest following a naming convention. I'm trying to adopt:

Code: Select all

$P_PERMANENT_VARIABLE
$G_GLOBAL_VARIABLE
$localVariable
$_embeddedVariable
Then since permanent variables in shared scripts may be retained I make them ridiculously long by including my username and a script identifier, such as "$P_THEQWERTY_PREVIEW_CODE__OPTIONS". This way they are more likely to be unique and give other users an idea of the source of the variable. Thankfully Sublime Text can auto-complete this for me. :)
From now on I will generally go with the prefixes. I use upper/lower cases to further semantically discriminate variables from constants. Especially for longer "scripts" in interpreted and untyped languages this helps me lot to re-get my code long after it has been "released". :biggrin:

Code: Select all

$p_permanent_variable
$G_PERMANENT_CONSTANT
$g_global_variable
$G_GLOBAL_CONSTANT
etc.
Good one. :appl:


Cheers,
Filehero

Enternal
Posts: 1174
Joined: 10 Jan 2012 18:26

Re: List Items in a List in Search Tab

Post by Enternal »

Yes, as FluxTorpedo said, I don't want the variables to be resolved. Using heredoc, I wanted $Variable to stay as $Variable and not changed to whatever it may be. Completely as-is.

@ TheQWERTY
Oooh, nice naming convention. This will at least keep things looking clean and consistent!

@ Marco
That's exactly what I was looking when I asked about dynamic variables. Very interesting ways of doing it heh. Thanks!

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

Re: List Items in a List in Search Tab

Post by highend »

Ok, this is still resolved but at least you display what you want *g*

Code: Select all

 $Variable = "$Variable";
 $Test =<<<Test
This is a $Variable
Test;
 Msg "$Test";
One of my scripts helped you out? Please donate via Paypal

Enternal
Posts: 1174
Joined: 10 Jan 2012 18:26

Re: List Items in a List in Search Tab

Post by Enternal »

highend wrote:Ok, this is still resolved but at least you display what you want *g*

Code: Select all

 $Variable = "$Variable";
 $Test =<<<Test
This is a $Variable
Test;
 Msg "$Test";
Hehe that's true but it won't be useful anymore if you intend to load the heredoc as a script with
that variable remain as a variable until it's resolved inside of that heredoc script. However it definitely
has its use so thank you. There were a few times I wanted to display a variable as a string and now
I know of a method.

On another note with the eval command while looking at the dynamic variable link, I was playing with
it:

$Test = "Test";
$Test2 = "Test2";
$Combine = Eval($Test1$Test2);
Text $Combine;

but the output turns out to be $Test1$Test2. Is that what supposed to happen? I'm expecting Test1Test2 as the output.

Post Reply