Page 1 of 1

Edit > Select > Store/Load Selection

Posted: 27 Sep 2010 00:51
by Stefan
Just playing around with SyncTool
and because i go into an selected folder to see what's in
i lost my selection of all the other different items.

So i searched around but didn't find an solution/post/command to store & load an selection.

That's why i suggest this new feature incl. "List Management" support.

- command "Store Current Selection"
>> ask for name, if name exist ask to overwrite, join or to choose an other name
>> store the list of selected items to RAM for this XY-session and to an file on 'save' or 'end' of XY

- command "Load Stored Session"
>> prompt an list to chose from, allow to chose several entries, allow to use this list as additional selection
>> select any found item from this list [too]

- "List Management" support
>> view, edit, delete


Related to SyncTool i would suggest to auto store the found differences
as new selection-storage with current date-time as name.

---

Till you have time to implement such feature i have done an try to do this by an script on my own.

But currently with less features and without much error handling:

Code: Select all

"Store Selection"
  //////Store current selected items to an file:
 
   $StoreName = Input("Unique Name for this selection:"); 
   ////ToDo: if $StoreName already exist... ask
   $SelCount = get("CountSelected");
   $SelItems = $StoreName . "?" . $SelCount . "?" 
                      . get("SelectedItemsNames", "|");
   writefile("%temp%\xySelItems.txt", "<crlf>$SelItems", a);



"Load Selection : Load"
   //////Load items to select from an file:
 
   self $ScriptFile, file;
   $Lines = readfile("%temp%\xySelItems.txt");

   ////get all lines for inputselect()
   $Loop=1; 
   $Names="";
   while(true)
   {
     $Line = gettoken($Lines, $Loop, "<crlf>");
     if ($Line==""){break;}
     $Names = $Names . gettoken($Line, 1, "?") . " ("  
             . gettoken($Line, 2, "?") . " items)" . "|" ;
   $Loop++;
   }

   ////ask user what to load:
   $Load = inputselect( "Choose one to restore an selection:", $Names,,2); 
   if ( strpos($Load, "|") > 0) { msg "Please Choose Only One!   "; 
                  setting "AllowRecursion"; Load $ScriptFile, Load; break;}
   ////clean the string:
   $Load = regexreplace($Load, "(.+)\s\(\d+\sitems\)", "$1"); 

   ////get the right line and select
   $Loop=1; 
   while(true)
   {
    $Line = gettoken($Lines, $Loop, "<crlf>");
    if ($Line==""){break;}
    if (gettoken($Line, 1, "?")==$Load){ 
                  selfilter gettoken($Line, 3, "?"); break;}
   $Loop++;
   }



"Edit this &script : edit"
   self $ScriptFile, file;
   OpenWith "<xypath>\Tools\NotePad2\Notepad2.exe", ,$ScriptFile;

Find me: store selection save selected remember selection selection list

Re: Edit > Select > Store/Load Selection

Posted: 27 Sep 2010 08:10
by admin
Funny, but I had the same idea some days ago! :) I know the feature and its basic UI logic from photoshop.

I will first add a scripting command that makes restoring the selection very easy (selectitems); using UDCs you then can write a fairly simple script that saves and loads selections from an INI file.

Later there will be something with UI...

Re: Edit > Select > Store/Load Selection

Posted: 28 Sep 2010 22:51
by Stefan
admin wrote:Funny, but I had the same idea some days ago! :)
Are this qualified for the two fouls rule ? :D

Code: Select all

v9.50.0108 - 2010-09-27 15:22

    + Scripting got a new command.
      Name:   selectitems
      Action: Selects items in the file list by a list of names.
      Syntax: selectitems itemlist, [ignoreextensions], [focusfirst=1]
Improvement wish:
Add / Remove from the current selection:

Code: Select all

      Syntax: selectitems itemlist, [ignoreextensions], [focusfirst=1], [variety=0]
      variety : 0 or missing = instead of the current selection if any.
                  1 = Add to the current selection.
                  2 = Remove from the current selection.

- - -

Today i tested this improved script.
Now i am using an ini file
"<xydata>\Sessions\Selections.ini"
and tested new selectitems cmd:


EDIT: added code with new features from v9.50.0111

Code: Select all

/*
Script to store current selections and restore them later.
I use an ini file: "<xydata>\Sessions\Selections.ini"

v9.50.0108 - 2010-09-27 15:22
    + Scripting got a new command.
      Name:   selectitems
      Action: Selects items in the file list by a list of names.
      Syntax: selectitems itemlist, [ignoreextensions], [focusfirst=1]
  
v9.50.0111 - 2010-09-29 10:01
    + SC selectitems enhanced. Added a "mode" parameter which allows you
      to add to or remove from current selections. Here is the complete
      updated description:
      Name:   selectitems
      Action: Selects items in the file list by a list of names.
      Syntax: selectitems itemlist, [ignoreextensions], [focusfirst=1], [mode]
         mode:
          n: [Default] New selection (drop current selections).
          a: Add the matches to any current selections.
          r: Remove the matches from any current selections.
      Example:
        ::selectitems "Canary.txt", , , "a"; //add to current selections
*/
  
  
  
"Store Selection : Store"
    ////////Store current selected items to an file:
    
     self $ScriptFile, file;
     $IniFolder = "<xydata>\Sessions";  IF (exists($IniFolder) != 2) {new $IniFolder, dir;}
     $IniFile = "$IniFolder\Selections.ini";
     
     $StoreName = Input("Unique Name for this selection:"); 
     
     ////Don't use []'s in $StoreNames:
     if (strpos($StoreName, "[")>0 || strpos($StoreName, "]")>0) 
     {
       msg "Please don't use '[' or ']' signs in an name.";
       setting "AllowRecursion"; Load $ScriptFile, Store; break; 
     }
     ////getkey(key, [section], INIfile)
     $CheckPresent = getkey("Items", $StoreName,  $IniFile);
     If  ($CheckPresent != "")
    { 
       ////inputselect(header, listdata, [separator=|], [style=1], [cancel], [width], [height], [caption])
       $Choice1 = "Use this name and overwrite previous items";
       $Choice2 = "Let me enter an an alternative name";
       $ASK = inputselect("This name already exist. Chose one of this choices:",  
                    $Choice1|$Choice2 , ,  , "Canceled", 200, 100, "Upps");
          If ($ASK==$Choice1){;}
          If ($ASK==$Choice2){ setting "AllowRecursion"; Load $ScriptFile, Store; break; }
     }
    
    $SelItems =  get("SelectedItemsNames", "|");
    $SelCount = get("CountSelected");
    ////setkey value, key=, [section], INIfile;
    setkey $SelItems,  "Items", $StoreName, $IniFile;
    setkey $SelCount, "Count", $StoreName, $IniFile;
   
///////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
     
"Load Selection : Load"
    ////////Load items to select from an file:
    
    $IniFolder = "<xydata>\Sessions";  
    $IniFile = "$IniFolder\Selections.ini";
    $Lines = readfile($IniFile);
    
    ////get all lines from $IniFile to select all section-names for the inputselect() list:
    $Loop=1; 
    $Values="";
    while(true)
    {
      $Line = gettoken($Lines, $Loop, "<crlf>");
      if ($Line==""){break;}
      if (substr($Line, 0, 1)=="[")
      {
         $Len = strpos($Line, "]") -1;
         $Value = substr($Line, 1, $Len);
         $ItemsCount = getkey("Count", $Value, $IniFile );
         $Values = $Values .  $Value . " ($ItemsCount Items)|";
      }else{;
      }
    incr $Loop;
    }
    
    ////ask user what to load:
    $Setting1 = "[ Setting: Ignore the Extensions on selection ]";
    $Setting2 = "[ Setting: Add the matches to any current selections ]";
    $Setting3 = "[ Setting: Remove the matches from any current selections ]";
    $Values = $Values$Setting1|$Setting2|$Setting3;
    $Load = inputselect( "Choose one to restore an selection:", $Values,,2); 
    
    ////If an setting is checked:
    if ( strpos($Load, $Setting1) > 0)
    {
       $Load = replace($Load, "|$Setting1");
       $IgnoreExtensions=1;
    }
    
    if ( strpos($Load, $Setting2) > 0 && strpos($Load, $Setting3) > 0)
    {
       msg "Please Choose Only One Of This Settings!  (add OR remove) "; 
       setting "AllowRecursion"; 
       self $ScriptFile, file;
       Load $ScriptFile, Load; break;}
    }    
    
    if ( strpos($Load, $Setting2) > 0)
    {
       $Load = replace($Load, "|$Setting2");
       $SelectionMode="a"; //add items to selection
    }
            
    if ( strpos($Load, $Setting3) > 0)
    {
       $Load = replace($Load, "|$Setting3");
       $SelectionMode="r";  //remove items from selection
    }        
    
    ////If more then one stored values are selected:
    if ( strpos($Load, "|") > 0) 
    { 
       msg "Please Choose Only One Of The Stored Selections!   "; 
       setting "AllowRecursion"; 
       self $ScriptFile, file;
       Load $ScriptFile, Load; break;
     }
                  
    ////clean the $Load string:
    $Load = regexreplace($Load, "(.+)\s\(\d+\sitems\)", "$1"); 
    
    ////get the right line and select
    ////getkey(key, [section], INIfile)
    $Selection =  getkey("Items", $Load, $IniFile);
   
    //selfilter $Selection; //old way
    ////selectitems itemlist, [ignoreextensions=0 , 1 = yes], [focusfirst=1], [mode]
    selectitems  $Selection, $IgnoreExtensions,,$SelectionMode;
    
   
///////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
    
"Edit this &script : edit"
    self $ScriptFile, file;
    OpenWith "<xypath>\Tools\NotePad2\Notepad2.exe", ,$ScriptFile;
    //OpenWith "Notepad.exe", ,$ScriptFile;
  
  
////EOF

Unfortunately i have forgotten to add an Remove-Stored-Values feature... :roll:
So just open the ini file to add/modify/remove the entried:
"<xydata>\Sessions\Selections.ini"
[TEST Selection No. 47]
Items=DSC_12 34.PSD|DSC_12 34.XMP|DSC_12 345.PNG
Count=3


An preview how this will look:
Image

Re: Edit > Select > Store/Load Selection

Posted: 29 Sep 2010 08:52
by admin
Stefan wrote:Improvement wish:
Add / Remove from the current selection:

Code: Select all

      Syntax: selectitems itemlist, [ignoreextensions], [focusfirst=1], [variety=0]
      variety : 0 or missing = instead of the current selection if any.
                  1 = Add to the current selection.
                  2 = Remove from the current selection.
Yes, good idea. I made it liek this (and also changed SC sync accordingly):

Code: Select all

        mode:
          n: [Default] New selection (drop current selections).
          a: Add the matches to any current selections.
          r: Remove the matches from any current selections.

Re: Edit > Select > Store/Load Selection

Posted: 29 Sep 2010 22:31
by Stefan
Thank you much.

I have modified the above script and it works for me (simple tests, let's see how it works in real live)


.