Folder Icon Setting [need help]

Discuss and share scripts and script files...
eil
Posts: 1866
Joined: 13 Jan 2011 19:44

Re: Folder Icon Setting [need help]

Post by eil »

klownboy wrote:Might it be better to have the user select the icon to be used by using "inputselect" or similar method and then do the same for the associated file or folder? This assumes the user knows exactly what needs to be done which could be a problem.
that's the point of simplicity: pick an icon source, "mark it", choose a folder, set it.
klownboy wrote:You may want to consider using "exists" to see if the selected item is a folder rather than checking if the <curext> is "". It also looks like you'll have to make $f_ico a perm variable such that it's still around for the next run and delete the perm after it gets assigned.
thanks for tips- will try with <exists>! no need for perm- this button designed exactly for current/on the fly work.
most of don't undestand why

Code: Select all

msg +<curitem>\>$f_ico;
shows just "1"?..
admin wrote:Does everybody agree? Please only vote if you are actually using this function.
i definitely wouldn't want a wipe, so i'm for Add by default.
Win 7 SP1 x64 100% 1366x768|1900x1080

klownboy
Posts: 4459
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8037 at 100% 2560x1440

Re: Folder Icon Setting [need help]

Post by klownboy »

eil wrote:no need for perm- this button designed exactly for current/on the fly work
I can see that you want it to be on the fly, but the script has to run a second time, once to set the icon and then again to pick the folder the icon variable is not going to exist on the second run.

By the way, you have to use the "()" following CTBstate when checking the state, such as...

Code: Select all

elseif(CTBstate() == "1" AND exists("<curitem>") == "2") {... 

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

Re: Folder Icon Setting [need help]

Post by bdeshi »

eil, as Ken (klownboy) said, the $f_ico variable isn't remembered when you click the button the second time. you need some persistent medium to hold the variable.
if you aggree to settle for a slightly different operation, you can use this script.
workflow: select exe or ico files and click the ctb. They are recorded in a file, <xyicons>\seticonlist.txt . Everytime you select exe/ico and click ctb, new icons are recorded if found. You can also select more than one file at once. So you can record all needed icons in one go before applying them.
Then select a folder and click the button to choose and apply the recorded icon. Right click the button to view the list or view CFI dialog. (read the comments in the code, there's a line you can uncomment which will remove used icons from the list)

Type ::snippet; into the addressbar and paste the following code, a new ctb will be created:

Code: Select all

Snip: CTB 1
  XYplorer 14.20.0204, 6/21/2014 7:36:32 PM
Action
  NewUserButton
Name
  IconSetter
Icon
  
ScriptL
  //path to iconlist
  $list = "<xyicons>\seticonlist.txt";
   //create the list file
   if (exists("$list")==0){new("$list", "file");}
  
   //set ctb on if list is not empty, off otherwise
   //list is empty if it doesnt have any periods (.)
   if (gettokenindex('.', readfile("$list"),<crlf>)!=0){ctbstate(1);ctbicon(":tagsrmv");}
   else {ctbstate(0);ctbicon(":tagsadd");}
  
   foreach ($item, <get SelectedItemsPathNames |>, "|"){
    $ext = getpathcomponent("$item",ext);
    //if selected items include files with exe or ico ext then...
    if ($ext=="exe") || ($ext=="ico"){
    //if the files is not listed already then...
     if (gettokenindex("$item", readfile("$list"), <crlf>)==0){
     //add it to the icon list
      writefile("$list", "$item<crlf>", a);
     }
    }
   }
   //if curitem is folder...
   if (exists("<curitem>")==2){
    //popup saved icon list and...
    $icon = popupmenu(readfile("$list"),,,,,,<crlf>,,'');
    //if a menu item is selected, set that as folder icon
    if ($icon != ''){
     seticons("+<curitem>\>$icon",a,0); //definitions for the same folder is not overwritten
    }
    //uncomment following line to remove used icon from list
    //writefile("$list",replacelist(readfile("$list"), "$icon|<crlf><crlf>", "|",'|'), o);
    //^double crlf replacement attempts to remove extra empty lines
   }
  
   //check list and set ctbstate again
   if (gettokenindex('.', readfile("$list"),<crlf>)==0){ctbstate(0);ctbicon(":tagsadd");}
   else{ctbstate(1);ctbicon(":tagsrmv");}
ScriptR
  "View Iconlist"
   open "<xyicons>\seticonlist.txt"; //edit to match LClick script path
  "Custom File Icons"
   #605;
FireClick
  0
[/size]

edit: multiple selections allowed
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

eil
Posts: 1866
Joined: 13 Jan 2011 19:44

Re: Folder Icon Setting [done]

Post by eil »

with the help of variant from SammaySarkar, i made mine real. :kidding: if someone interested:

Code: Select all

if (exists(<curitem>) == 1 && (<curext> == "exe" || <curext> == "ico")) {
  perm $f_ico;  
  $f_ico = <curitem>;
  echo [icon]= $f_ico;
  ctbicon(:tagsrmv); ctbstate(1);} 
  elseif (exists(<curitem>) == 2 && ctbicon() == ":tagsrmv") {
    seticons("+<curitem>\>$f_ico",a);
    ctbicon(:tagsadd); ctbstate(0);
    unset $f_ico;}
the only question here left- is there some way to show custom tips on hover or change name of button via script?

as whole theme of "seticons" was born here, question to you Don: is it possible to make seticons( ,d) more versatile and allow to send only part of line?

Code: Select all

seticons("H:\xyplorer_14.20_beta_noinstall> ", d);
Win 7 SP1 x64 100% 1366x768|1900x1080

klownboy
Posts: 4459
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8037 at 100% 2560x1440

Re: Folder Icon Setting [need help]

Post by klownboy »

I'm thinking of another version with a little modification of both when I get a chance. As in eil's if you have a pre-selected an icon or exe works as it currently does, but if you do not have an icon or exe pre-selected, you'd be sent to your XY icon folder to select one...ideally in a small l thumbnail view so you can see the icons. Once that is done, on the second click of the CTB if you run it without a folder selected it will give you the opportunity to select one. So it should be still on the fly if you selected and icon and later a folder but if you neglect to, it will give you a chance to do so.

I notice both eil's and Sammay's version fails if the folder selection is in the tree since <curitem> along with "exists" doesn't work there. I like the capability to select a folder from the tree. <curpath> works on a folder selected in the tree. I've been experimenting with the use of <focitem>. It does seem to work properly if the folder is selected in the tree or list depending on focus.
Thanks,
Ken

eil
Posts: 1866
Joined: 13 Jan 2011 19:44

Re: Folder Icon Setting [need help]

Post by eil »

klownboy wrote:ideally in a small l thumbnail view so you can see the icons.
i couldn't imaging an existable way to do this that's why i took on-the-fly way, but it would be intresting to see your realisation.
correct, i didn't take tree in my plan initialy.
Last edited by eil on 22 Jun 2014 09:43, edited 1 time in total.
Win 7 SP1 x64 100% 1366x768|1900x1080

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

Re: Folder Icon Setting [need help]

Post by bdeshi »

klownboy wrote:I'm thinking of another version with a little modification of both
That's a great idea. I suppose the travels will be in a new tab.
And on accounting for tree selection, well, I hardly ever use the tree ! (can't even climb one!) :)
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

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

Re: Folder Icon Setting [need help]

Post by TheQwerty »

admin wrote:That did not change since before the revamp. But maybe TheQwerty was right to have the "a" mode as default? I'm not sure about the usage of the function, I'm just hacking in what TheQwerty writes down for me. :biggrin:
As I said earlier, this function didn't get the amount of thought I prefer to give to my wishes, but Ken is correct, I went with add being the default since it was least destructive.
admin wrote:Does everybody agree? Please only vote if you are actually using this function.
Granted I haven't yet found the time to play with this, and it seems I'm no longer on the hook to write the script, so I guess my very late vote doesn't matter anyhow. :P

klownboy
Posts: 4459
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8037 at 100% 2560x1440

Re: Folder Icon Setting [need help]

Post by klownboy »

Hi, I mentioned above that I would try another version of a Folder Icon Setter. I attempted to keep this as simple as possible with little to no mouse presses needed except for the selection of the icon, the folder, and the assigned CTB. So for quick use, you'd have an icon pre-selected, hit the CTB you have assigned the script, and then select the folder in the tree or list and press the CTB again. If you neglect or forget, the script will prompt you to do so in a timed message that you don't have to wait for to make your selection. It will send you to the <xyicons> folder if you forgot to pre-select an icon/exe file, and it will nag you again and again with a timed message if you neglect to select a folder.

Code: Select all

Snip: CTB 1
  XYplorer 14.20.0206, 6/23/2014 3:34:55 PM
Action
  NewUserButton
Name
  Folder Icon Setter
Icon
  :tagsadd
ScriptL
   global $t_msg;
  if (isset($f_ico) == "1" && ctbicon() == ":tagsrmv") {
   if (get("FocusedControl",) == "T" && exists(<focitem>) == 2) {$icon_folder = <focitem>}
   elseif(get("FocusedControl",) == "L" && exists(<curitem>) == 2) {$icon_folder = <curitem>}
   else {$t_msg = "You did not select a folder. Please do so and click the CTB again.";
   sub "_Timed_Message";end(1==1)}
   
      seticons("+$icon_folder\>$f_ico",a);
      ctbicon(:tagsadd); ctbstate(0);
      if(isset($new_tab) == "1") {tab("close", 1, $new_tab);} else { }
      goto $icon_folder; delete 0, 0, "<xyscripts>\tempVBS.vbs";
      unset $f_ico, $new_tab;}

  elseif (exists(<curitem>) == 1 && isset($f_ico) == "0" && (<curext> == "exe" || <curext> == "ico")) {  //icon already selected
   perm $f_ico = <curitem>;
   ctbicon(:tagsrmv); ctbstate(1);
   status "After icon selection, press the CTB again and then select a folder to which to assign the icon.";
   $t_msg = "Select folder to which the icon will be assigned and then press the CTB again.";
   sub "_Timed_Message";end(1==1)} 
   
  elseif (get("CountSelected") == "0" && isset($f_ico) == "0" || exists(<focitem>) != "2" || (<curext> != "exe" || <curext> != "ico") {
    $t_msg = "An ICON or EXE file has not been selected. Please do so and click the Toolbar button again.";
	perm $new_tab = tab("new", "<xyicons>|*.ico"); if (get("View") < 4) {#306;}
	status "Select folder to which the icon will be assigned and then press the CTB again";
 	sub "_Timed_Message";end(1==1)}

"_Timed_Message";
  global $t_msg;		  
  $waitSec = 4;

  $out="";
  foreach($line, $t_msg, "<crlf>"){ $out = $out . chr(34) . $line . chr(34) . " & vbCRLF _<crlf> & ";}
  $out = replace($out, "&", "", ,strlen($out) -3, 1);

  //Create the VBS file:
  $VBS =        "text =  $out" . "<crlf>";
  $VBS = $VBS . "SET WS = CreateObject(""WScript.Shell"")" . "<crlf>";
  $VBS = $VBS . "'//WshShell.Popup   strMessage [,intSecondsToWait] [,strTitle] [,intType]" . "<crlf>";
  $VBS = $VBS . "WS.popup text, $waitSec" . "<crlf>";
  writefile("<xyscripts>\tempVBS.vbs", $VBS);
  run ("wscript ""<xyscripts>\tempVBS.vbs""");
ScriptR
  
FireClick
  0
You can play around with it and assign a bunch of icons to folders and easily delete them later if you want. They'll be in the CFI or Portable File Icons dialog - at the top.
folder_icon_selector.zip
Thanks to Stefan for his fine timed message VBS code. http://www.xyplorer.com/xyfc/viewtopic. ... it+message
Please let me know if you have any issues. I may do another update for better icons and an intermediate icon for when the icon is selected but you haven't yet assigned the folder.
Thanks,
Ken

Edit: I don't know why I bothered to use "inputfolder" when the user neglected to assign a folder. I modified the script to simply send the script back to the beginning after a timed message.
To see the attached files, you need to log into the forum.

klownboy
Posts: 4459
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8037 at 100% 2560x1440

Re: Folder Icon Setting [need help]

Post by klownboy »

Updated a FolderIconSelector script using PowerShell for timed messages and for a tray icon balloon tip (just for jollies). The script will provide a little tray message using the icon selected for your folder. Pre-selecting the folder before running will speed the icon assignment, but it's not necessary. The script should be assigned to a CTB. The only issue I'm aware of is every once in a while the XYplorer window goes to the background at the end of the script. I haven't been able to figure out why even stepping through the script. It also occurred when I used SC load http://www.xyplorer.com/xyfc/viewtopic. ... 15#p111484 and a Visual basic script for a message so I don't believe it has anything to do with the fact that it's using PowerShell. Maybe someone can figure out why.
tray_balloon_capture.PNG
FolderIconSelector.zip
Thanks,
Ken
To see the attached files, you need to log into the forum.

Post Reply