[Script] WhiteSpaceCtxMenu

Discuss and share scripts and script files...
Post Reply
klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

[Script] WhiteSpaceCtxMenu

Post by klownboy »

The purpose of this script is to call out specific menus when the user right clicks on the list panel white space. The menu which comes up is dependent on the file type of the current file. So you could set it up such that if you had a jpg or png file selected (i.e <curitem>), a menu with 4 or 5 different programs to select from would display, you'd choose one and the file would be opened in that program. So it similar to a right clicking on the file itself to bring up a context menu, but in this case the user is clicking the white space. I mentioned coming up with something similar to this here http://www.xyplorer.com/xyfc/viewtopic. ... 15#p122111 If no file is selected, the script brings up a default menu which can be anything the user wants (i.e, it could be as simple as bringing up the Favorite Files, Favorite Folders, call your own menu, or something more elaborate). Remember if a file is currently selected, but you'd rather just bring up the default menu rather than the specific file-type menu of a highlighted file, you can simply normal left click on white and then right click. You can also easily set the menu up such that some file types programs would immediately be run in a program of choice. For example, you could have it set such that if you have a single GIF file selected, it would bring up all the folder's GIFs in TheQwerty's 'HTMLImagePreview.xys' viewer. You could even set it up such that the script does something special if a folder is selected.

3 examples of the menus which surface if you right clicked with a certain file types selected along with an example default menu:
WhiteSpace_cap.jpg
WhiteSpace_cap.jpg (67.69 KiB) Viewed 6355 times
No, it's nothing new as far as scripting goes, but setting up a script to run when you right click on white space is quite easy and can be very handy. So, why not improve it, make it a bit smarter by expanding its capabilities. I call the script "WhiteSpaceCtxMenu.xys". To use, the 2 lines in the XYplorer.ini file which have to change are:

Code: Select all

CEA_ListRightClickOnWhite=6
CEA_ListRightClickOnWhite_Script=load "<xyscripts>\WhiteSpaceCtxMenu.xys"
Obviously this is not the type of script a user can simply plop into his script folder and use. This is more of an idea and skeleton script you can use to arrive at your own. You have to take a few minutes an substitute your own programs to run based on the file types and any new files types as you wish. What I show here are just examples and certainly not my final script. I'm finding it easier than using the 'real' context menu or even PFAs since it it seems to be less clicking in many cases. If the file you'd like to run a program on is currently selected simply right click on white to bring up the the specific file type menu. If the file isn't currently selected you simply select with the left click and then move the mouse slightly and right click. If you'd rather bring up the default menu when there's a file currently hi-lighted, just left click on white (to un-select) and then follow with a right click.

Code: Select all

/*** image file menu ***/
  $image = <<<IMAGE
"Thumbnails in new Instance|:conf";
  $jpgPath = getpathcomponent("<curitem>", "path");
  run """<xy>"" /new ""$jpgPath"" /win=normal,10,10,1900,1050 /script=""::if(get('View') != '6') {#308};loadlayout('thumbs');open 'D:\Tools\AutoHotkey\AHK scripts\TB_XY_hide.ahk';"""; end(1); }
"ImageEye|D:\Graphics\Image Eye\Image Eye.exe";
  Openwith "D:\Graphics\Image Eye\Image Eye.exe"; end(1);
"Irfanview|D:\Graphics\IrfanView\i_view32.exe";
  openwith "D:\Graphics\IrfanView\i_view32.exe";end(1);
"Greenfish Icon Editor|D:\Graphics\Greenfish Icon Editor Pro\gfie64.exe" openwith "D:\Graphics\Greenfish Icon Editor Pro\gfie64.exe";
IMAGE;

/*** video file menu ***/
   $vid = <<<VID
"BD Rebuilder|D:\DVD\BD Rebuilder\BDRB.exe" open "D:\DVD\BD Rebuilder\BDRB.exe";
"ConvertXtoDvd|D:\DVD\ConvertX\ConvertXtoDvd.exe" open "D:\DVD\ConvertX\ConvertXtoDvd.exe";
"EMDB|D:\DVD\EMDB\EMDB.exe" open "D:\DVD\EMDB\EMDB.exe";
"ImgBurn|D:\DVD\ImgBurn\ImgBurn.exe" open "D:\DVD\ImgBurn\ImgBurn.exe";
"MPC-HC|D:\DVD\MPC HomeCinema (x64)\mpc-hc64.exe" openwith "D:\DVD\MPC HomeCinema (x64)\mpc-hc64.exe";
"TMPGEnc|C:\Program Files (x86)\Pegasys Inc\TMPGEnc Authoring Works 4\TMPGEncAuthoringWorks4.exe" open "C:\Program Files (x86)\Pegasys Inc\TMPGEnc Authoring Works 4\TMPGEncAuthoringWorks4.exe";
"Video Joiner|D:\DVD\Boilsoft Video Joiner\EZMerge.exe" open "D:\DVD\Boilsoft Video Joiner\EZMerge.exe";
"VLC|D:\DVD\VLC\vlc.exe" openwith "D:\DVD\VLC\vlc.exe";
VID;

/*** text file menu ***/
   $txt = <<<DOC
"NotePad++|D:\Tools\NotePad++\notepad++.exe" openwith "D:\Tools\NotePad++\notepad++.exe";
"PSPad|D:\Tools\PSPad\PSPad.exe" openwith "D:\Tools\PSPad\PSPad.exe";
"Notepad|C:\Windows\notepad.exe" openwith "C:\Windows\notepad.exe";
DOC;

/*** Folder menu ***/
   $dir = <<<FOLDER
"Open Folder in new instance Thumbnail view|:viewthumbs"
   run """<xy>"" /new ""$folder"" /win=normal,10,10,1900,1060 /script=""::if(get('View') != '6') {#308};loadlayout('thumbs');""", , 0, 0;
"Favorite Folders|:favs";
  #550; end(1);
"Favorite Files|:favfiles";
  #564; end(1);
FOLDER;

/*** Copy/Move menu ***/
   $CopyMove = <<<COMO
"Copy|:copyto" #5;
"Move|:moveto" #4;
"Move to &Tools|:moveto";
  moveto "H:\Misc\tools";
"-"
"Sort...|:sort" #320;
"Columns...|D:\Graphics\Icons\table-select-column-fatcow.ico" #360;
"View...|:viewthumbs" #301;
"-"
"New|:newfolder" #230;
COMO;

//***note: if you're not going to use Favorite Folders in conjunction with another menu you don't need this section
//***you can simply use #550
      $FavFolderCount = getkey("Count", "Favorites");
      if($FavFolderCount == "0") {$FFs = "No favorite folders";}
      else {
          $FFs = "";
          $i = 1;
        while ($i <= $FavFolderCount) {
           $a = getkey("Fav$i", "Favorites");
           $FFs = $FFs . $a . "<crlf>";
           $i++;
        }
      }
     $FavFolders = trim($FFs, "<crlf>", 'R');

     if(exists("<selitem>") == 1) {
	     $selext = getpathcomponent("<selitem>", "ext");
		  if(gettokenindex($selext, "jpg|gif|png|ico", '|', 'i')) {load "$image;<crlf>-<crlf>$CopyMove", ,s; end(1);} //load image and CopyMove menus together
		  elseif(gettokenindex($selext, "avi|mp4|wmv|wma", '|', 'i')) {load "$vid", , s; end(1);}    //load video menu
		  elseif(gettokenindex($selext, "ini|txt|nfo|inf|reg|ps1|vbs", '|', 'i')) {load "$txt", , s; end(1);}   //load textfile menu
        elseif("$selext" == "xys") {load("<selitem>"); end(1);}  //no menu - example showing how you can automatically run an XY script on a right click on white
        elseif("$selext" == "ahk") {openwith "D:\Tools\NotePad++\notepad++.exe"; end(1);}   //no menu - example to open an AHK file for editing
        else {load "$FavFolders;<crlf>-<crlf>$CopyMove", ,s; end(1);}
     }
	  elseif(exists("<selitem>") == 2) {
	     perm $folder = "<curitem>";
        load "$dir", , s; end(1);
     }
	  else {
             // when none of the other listed conditions or comparisons are met
	     load "$FavFolders;<crlf>-<crlf>$CopyMove", ,s; end(1)   //this takes care of the "nothing selected" condition
             //you can simply use #550 to load Favorite Folders (or Files #564) alone here or whatever script you 
	  }
	   
"_Terminate";
  unset $folder;  //you don't need this line or "_Terminate"; if you don't use variable $folder above
I hope you can get some use out of it or maybe some new, additional or better ideas will spawn from it. Once set-up, I'm finding easier to use than the normal context menu.
Thanks,
Ken
WhiteSpaceCtxMenu.zip
(2.03 KiB) Downloaded 284 times
Edit1: Modified the script to use SC gettokenindex rather than LikeI comparisons as per PeterH suggestion.
Edit2: Modified the "load" statement that uses the variable '$image' to show how to display 2 menus together (i.e., the Image menu and Copy move menu) as one menu with a separator between them
Edit3: Incorporated the use of new XY variable <selitem> and cleaned up the "if" , "elseif", and "else" structure. Also included obtaining "Favorite Folders" if you want to combine them with another menu. Otherwise you can leave that section out.
Edit4: Uploaded a zip version of script on 07/07/2015 in case there were issues due to copy and paste.
Edit5: Updated the run program with no menu examples to use "LikeI" in lieu of "==".
Last edited by klownboy on 10 Jul 2015 13:58, edited 9 times in total.
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

Stef123

Re: [Script] WhiteSpaceCtxMenu

Post by Stef123 »

klownboy wrote:I hope you can get some use out of it or maybe some new, additional or better ideas will spawn from it. Once set-up, I'm finding easier to use than the normal context menu.
Thanks, Ken. I do find it useful, very much so.
What surprises me most, it comes up instantly. Contrary to what I expected, it doesn't take even a second to make the decision what to pop up.

What I find hard to get used to, is the very unusual handling in terms of haptic mouse operations. Instead of simply right-clicking - a one-click habit reinforced daily by countless other apps - XY now requires me to first left click, then move my hand out of the way, then right-click into white space.

Matter of habit, granted, but I am not so sure yet I really want to train myself into that habit, it will make me lose my selection in other explorers, in Office applications etc.

That's why I still favor an addtional tweak or option, to allow triggering such scripts from the regular list context menu:
http://www.xyplorer.com/xyfc/viewtopic. ... 28#p122228

bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: [Script] WhiteSpaceCtxMenu

Post by bdeshi »

Stef123 wrote:Instead of simply right-clicking [...] now requires me to first left click, then move my hand out of the way, then right-click into white space.
you can do it with just one right-click: right-click on empty space, and drag a bit to create a selection rectangle (however small), and release. You can get to the desired menu based on whether any files are in the selection rect or not.

But when you already have items selected then that's another matter...
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Stef123

Re: [Script] WhiteSpaceCtxMenu

Post by Stef123 »

SammaySarkar wrote:
Stef123 wrote:Instead of simply right-clicking [...] now requires me to first left click, then move my hand out of the way, then right-click into white space.
you can do it with just one right-click: right-click on empty space, and drag a bit to create a selection rectangle (however small), and release.
Hmm - yes, I see what you mean. Getting a little bit of selection mileage out of it. But that requires I always call the new command "sort to top" up front - to group selected items into one heap. There cannot be any gaps in the selection block - unless I am still missing something?

PeterH
Posts: 2776
Joined: 21 Nov 2005 20:39
Location: Germany

Re: [Script] WhiteSpaceCtxMenu

Post by PeterH »

Hi Ken, I had a short look - seems rather configurable. Really fine. :appl:

But I noticed a problem: the test for file extensions might find wrong results. Imagine test for .xlsx: .xls will be found, too. So I'd suggest a change - for example:

Code: Select all

// if("txt|nfo|inf|reg|ps1|vbs" LikeI "*<curext>*") {load "$txt", , s; end(1)}     //load textfile menu
   if(gettokenindex("<curext>", "txt|nfo|inf|reg|ps1|vbs", '|', 'i')) {load "$txt", , s; end(1)}   //load textfile menu
(GetTokenIndex() returns 0 if not found - that's FALSE and the Load will not be executed.)

Yes: you could also modify the LikeI - but I don't Like it, don't know why :-)

Code: Select all

   if("|txt|nfo|inf|reg|ps1|vbs|" LikeI "*|<curext>|*") {load "$txt", , s; end(1)}     //load textfile menu
Notice 4 additional "|". (Not tested :whistle: )
W7(x64) SP1 German
( +WXP SP3 )

Stef123

Re: [Script] WhiteSpaceCtxMenu

Post by Stef123 »

I have a "general section" on top, that applies to all selections, no matter what file type or folder:

Code: Select all

"&COPY across|:syncbrowse" \;*>#804;
"&MOVE across|:syncbrowse" \;*>#803;
"&Dumpster|:moveto" \;*> ::moveto "V:\Repository\Misc\Dumpster";
-
I pasted this as duplicates into all sections. But I wonder if there's a smarter way?
To avoid identical copies, but rather maintain one instance only, from where it gets pulled in, like includes in a wiki-system. So I can reuse the same instance. The recent addition of functions come to mind. :roll: Trying to learn - also on behalf of my other CTB-menus.

nerdweed
Posts: 648
Joined: 25 Feb 2012 07:47

Re: [Script] WhiteSpaceCtxMenu

Post by nerdweed »

This is how I do it. I define the context menus in a variable and pop it through the SC popupmenu (*may not be the exact SC name). The same method is followed for generic items and in sections where I need the generic + contextual, I concatenate them and pop up the menu.

I will post the script (which I worked off from TheQwerty's script), later in the evening today. I haven't done all the work I wanted to do on it but it should be good to base your work on.

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

Re: [Script] WhiteSpaceCtxMenu

Post by klownboy »

PeterH wrote:But I noticed a problem: the test for file extensions might find wrong results
Thanks PeterH for the comments. I should have dug a little deeper on the file extension comparisons before posting especially since I've used SC gettokenindex to do similar comparisons checking for a '0' return. I have both the of your suggestions booked marked from earlier posts like these. http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=12314 and this one here http://www.xyplorer.com/xyfc/viewtopic. ... dex#p92190 Once the user takes the time to setup the script to his/her liking it's quite easy to modify it. I'll fix the post.

Stef123, I'll have to take a further look to see if there's a way to include a section of a menu in all menus while only listing that menu once. I don't think I've ever seen that technique or a scripter do something similar in the past. Maybe one of the more experienced scripters can think of a way.

It would be a well used feature if we could have a menu like these here display immediately when you right-click on a file via PFAs / openwith. As discussed in the other threads, maybe some type of option that would signal XY to display the openwith menu directly when right click a file type in lieu of going thru the normal context menu. 99% of the time that what I want to do - select from a quick list of programs to open the file. Another possibility, is using a modifier like CTRL key held down while right clicking the file instead of the normal context menu display the openwith menu would display or it would run a script like the one in this thread. I could do that using AHK I suppose but it would be much better not to rely on AHK.

Thanks,
Ken
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

Stef123

Re: [Script] WhiteSpaceCtxMenu

Post by Stef123 »

Thank you Ken and nerdweed,
yes, please keep me posted about any advances how to include lines from elsewhere into the menu-sections.
klownboy wrote:It would be a well used feature if we could have a menu like these here display immediately when you right-click on a file via PFAs / openwith. As discussed in the other threads, maybe some type of option that would signal XY to display the openwith menu directly when right click a file type in lieu of going thru the normal context menu. 99% of the time that what I want to do - select from a quick list of programs to open the file.
Same here. Most of the actions I perform on selections are not found in the default entries. And the very few items I do pick on very rare occasions, those could be integrated into my own menu with #123; IDs.

Your script paves the way to a new kind of super-charged context menu. User-scripted decisions that bestow context menus with a smartness I've never seen anywhere else.

Ctrl right-clicking sounds good, too, in fact, any kind of mouse trigger to get to our stuff faster than by traveling to the outer fringes of the screen estate.

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

Re: [Script] WhiteSpaceCtxMenu

Post by klownboy »

Sorry Stef123, I wasn't thinking...there are a number of ways you can combine the sections. I'd make your copy/move menu items a separate heredoc variable like the others and then combine them either directly in the load command or combine them first into a variable and then load the combo variable. Anyway, yes it would be quite easy to layout those copy command in its own section - something like this (tested and works):

Code: Select all

/*** Copy/Move menu ***/
   $CopyMove = <<<COMO
"&COPY across|:syncbrowse" \;*>#804;
"&MOVE across|:syncbrowse" \;*>#803;
"&Dumpster|:moveto" \;*> ::moveto "V:\Repository\Misc\Dumpster";
COMO;
Combine the $CopyMove variable with the other viariables:

Code: Select all

  $videoMenu = $video . <crlf>"-"<crlf> . $CopyMove;
  $imageMenu = $image . <crlf>"-"<crlf> . $CopyMove;
Then you can change your load line similar to this.

Code: Select all

if(gettokenindex("<curext>", "jpg|gif|png|ico", '|', 'i')) {load "$imageMenu", , s; end(1)}   //load image menu
I wanted to accomplish this directly using the load command without combing them first, but was having issues getting the separator properly. I defined the separator with a variable like this and used load with the multiple variables.

Code: Select all

perm $sep = <crlf><crlf>"-"<crlf><crlf>;
if(gettokenindex("<curext>", "jpg|gif|png|ico", '|', 'i')) {load $image; $sep; $CopyMove, , s; end(1)}  
The other method works fine 'til I figure out the issue with the load directly method.
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

Stef123

Re: [Script] WhiteSpaceCtxMenu

Post by Stef123 »

Thank you Ken,
I remember having read about Heredoc in SC help, as an alternate syntax dialect - or so my interpretation, what I made of it. Anyway, to avoid information overload I decided to keep my beginners mind from overheating with confusing mix-ups.

I need more peace and quiet to try it out - also want to understand the workings behind it. Too distracted for that ATM, doing phone support, continual interruptions. Will tackle it tomorrow.

Many thanks
Stef

nerdweed
Posts: 648
Joined: 25 Feb 2012 07:47

Re: [Script] WhiteSpaceCtxMenu

Post by nerdweed »

This is how I do.

P.S. This was work in progress. I deleted some stuff which is not relevant here, so there may be some formatting issues

Code: Select all

"CEA"
	$main = "Fav Folders;550 | Fav Files;564 | Favorites;_favsFull | - | Drives;526 | Drives+Special;_drivesSpecial | - | All Tabs;690 | Pane Tabs;538" ;
	
	if (get("FocusedControl") == "T") {
		#690;
	} else {
		$choice = popupmenu($main, -1, -1, 1, -1, 0, " | ", ";", "Esc") ;
		end ($choice == "Esc") ;
		if ($choice Like "_*") {
			sub "$choice";
		} else { #$choice; }
	}
"_favsFull"
	popupmainmenu 'favorites';
"_drivesSpecial"
	$sub=get("Drives", ," | ") . " | " . %computer% . " | " . %personal% . " | " . %net% . " | " . %recycler% ;
	$choice = popupmenu($sub, -1, -1, 1, -1, 0, " | ", ";", "Esc") ;
	end ($choice == "Esc") ;
	goto "$choice";

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

Re: [Script] WhiteSpaceCtxMenu

Post by klownboy »

Hi Stef123, I was able to get the menus to combine properly with the separator between them without having to combine them first into another variable as I did above. This way is cleaner and you don't have to make combo variables as I did. First, add the $CopyMove variable made with heredoc along with the other ones (same as above).

Code: Select all

/*** Copy/Move menu ***/
   $CopyMove = <<<COMO
"&COPY across|:syncbrowse" \;*>#804;
"&MOVE across|:syncbrowse" \;*>#803;
"&Dumpster|:moveto" \;*> moveto "V:\Repository\Misc\Dumpster";
COMO;
Then all you have to do is change the load lines that you wish to combine with the CopyMove menu like this:

Code: Select all

 if(gettokenindex("<curext>", "jpg|gif|png|ico", '|', 'i')) {load "$image;<crlf>-<crlf>$CopyMove", ,s; end(1)}   //load image and CopyMove menus together
Of course you can flip the order in the load statement if you'd rather have the CopyMove menu items on the top. Tested, works fine. By the way, you can delete the first line making that perm variable I didn't end up using it in the script. :)
Image and CopyMove menus.PNG
Image and CopyMove menus.PNG (7.47 KiB) Viewed 6217 times
Thanks nerdweed. I'll give that one a try too.

By the way Stef123, do those commands in your menu as written actually work for you? Did you pull those from a PFA? "&COPY across|:syncbrowse" \;*>#804;
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

Stef123

Re: [Script] WhiteSpaceCtxMenu

Post by Stef123 »

OK, I am getting ready to tackle it.
@nerdweed - thanks for posting your version. Glancing through it I feel totally overwhelmed. I bookmarked it to come back to it later. This is not to say it's overly complicated - I can't really judge anyway. Just saying it SEEMS way above my present scripting level. I might be wrong, of course, and it just takes well-chosen help topics I need to read. Will see.

@Ken
Those recent changes leave me somewhat disoriented about what to alter in your original script to bring it up to par with the issues discussed between you and PeterH. Will try and see ....

Before I dive into it ... yes, #803 and #804 pull it off nicely for me ... but I pasted the wrong lines here into the forum - that's probably why you ask. I don't yet have much of an eye for those minute scripting details and differences. Just like you assumed, those lines still carry the "\;*" folder/file wildcards from PFA with them, which of course are no longer needed thanks to your much smarter approach.

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

Re: [Script] WhiteSpaceCtxMenu

Post by klownboy »

Hi Stef123, I've incorpoarated peterH's comments into the first post but it boils down simply to the 'load' statements (99% of the time it will work as I originally had it - it will fail if you had extensions like .xlsx and were looking for xls). So it may look overwhelming or confusing, but all you really have to do is place the Copy / Move menu heredoc (it has the variable $CopyMove) from my last post (the first code block in the post) - copy and paste it up in front, or in-between the other heredoc sections or after the last heredoc - anywhere before the "if (exists("<curitem>") == 1) { " line. Then change your load statement(s) to look similar to the this:

Code: Select all

	if(gettokenindex("<curext>", "jpg|gif|png|ico", '|', 'i')) {load "$image;<crlf>-<crlf>$CopyMove", ,s; end(1)} 
substituting your variable if different from $image for each of your menus. Let me know if you have any problems.

Edit: I updated the first post code to show the CopyMove menu melded with the Image menu thought the picture doesn't reflect that (i.e., it would look like the picture in my previous post).
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

Post Reply