Page 2 of 2

Re: Save Tabs using Script

Posted: 23 Oct 2010 22:42
by SkyFrontier
Hi, Sam.
Here's your fix (please report if something went wrong).
It's a dumb solution - but it seems to work fine.
Also, incorporated Mr_Inc's suggestion on the code - seems to work fine.

Code: Select all

//needs latest XYplorer BETA version (v9.30.0014, 25-jul-2010) or newer
//Note: depending on your XY settings something may not work as indented.

// save an list of current open Tabs from current pane to an file:
"Store Session/Tabs"
   $SubFolderName = "%computername%";  //"Work"; //sub-folder in sessions-folder
   $TabCount = tab(,"c"); //how many tabs are open?
   $Pane = getinfo("Pane"); //which pane is active?
   $Loop = 1;
   $Tabs = "";

   while ($Loop<$TabCount+1) //for each tab do
   {
     //if (strlen(tab("get","name") < 1)
     $IFTabNameSet = strlen(tab("get","name",$Loop));
     if ($IFTabNameSet < 1)
     {
     $Tabs = $Tabs . tab("get", "data", $Loop) . "|"; //save the path in array "$Tabs" with | as delimiter
     }else{
     $Tabs = $Tabs . tab("get", "data", $Loop) . "?" . tab("get", "name", $Loop) . "|"; //save the tab caption too
     }
     incr $Loop;
    }
   
    //save the array to an file:
    //$folder = inputfolder("<xydata>\sessions", "Select Folder");
    IF (exists("<xydata>\Sessions\$SubFolderName")==0) {new "<xydata>\Sessions\$SubFolderName", dir;}

    $DefaultFileName = "<xydata>\Sessions\$SubFolderName\<date yyyymmdd hhnn>_Pane" . $Pane . ".ini";
    //
    $SessionFile = Input("Save Session", "Save list of tabs as: (you may add an description into the file name)", $DefaultFileName);
    //$SessionFile = $DefaultFileName;
    //

//    copytext $SessionFile;
    new "$SessionFile";
    writefile($SessionFile, $Tabs, "o");

    $Comment = Input("Session comment", "Enter an comment for this session (optional)",,"s","");
    comment $Comment, $SessionFile;



// ///////////////////////////////////////////////////////////////////////


// open new tabs from an list of paths (saved tabs):
"Load Session/Tabs"
    //read session file into array "$Tabs":
    $SubFolderName = "%computername%";  //"Work"; //sub-folder in sessions-folder
    $SessionFile = inputfile("<xydata>\Sessions\$SubFolderName", "ini", "Load list of tabs");
    $Tabs = readfile($SessionFile);
    $Loop = 1;
   
    //a little bit clean up first?
    $CloseCurrentOpenTabs = confirm("Close current open tabs first?");
    if ($CloseCurrentOpenTabs==0) { ;} elseif (tab(,"c")>1) {#353;} //close all "other" tabs


    $Loop = 1;
    While(1)
    {
      $NewTab = gettoken($Tabs,$Loop,"|");
      if ($NewTab==""){break;}
      if (strpos($NewTab,"?") == -1)
      {
         tab("new", $NewTab); //open new tab with next token from array
      }else{
         tab("new",    gettoken($NewTab,1,"?"));
         tab("rename", gettoken($NewTab,2,"?"));
      }
    incr $Loop;
    }
    if ($CloseCurrentOpenTabs==1){seltab 1;#351;} //close last "old" tab too

-

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

Re: Save Tabs using Script

Posted: 23 Oct 2010 22:58
by SkyFrontier
sam wrote:when i update to new version can tabs be restored?
Well... I made it last week on a set of 3 machines, no problems (besides the one you pinpointed which I thank you for!).
-perhaps if I'd paid attention to Mr_Inc's note my job could have been a bit more easier... well, we're human, after all! :wink:

Re: Save Tabs using Script

Posted: 24 Oct 2010 08:51
by admin
sam wrote:when i update to new version can tabs be restored?
Not sure if I understand the question. You simply install over the old version, and all settings are preserved. There is no need to restore anything after an upgrade. This has been like this since day one with XYplorer.

Re: Save Tabs using Script

Posted: 24 Oct 2010 09:33
by SkyFrontier
I believe s/he's trying to upgrade using another *pre-configured* installment as base, Don, as I did and sometimes do over my machines - so I understand his/her concerning regarding tabs.
---
Can you or another person please explain me what's wrong with the original code?
$DefaultFileName = "<xydata>\Sessions\$SubFolderName\<date yyyymmdd hhnn>_Pane" . $Pane . ".ini";
$SessionFile = Input("Save Session", "Save list of tabs as: (you may add an description into the file name)", $DefaultFileName);
new "$SessionFile"; // I had to do this to make it work outside of <xydata>.
writefile($SessionFile, $Tabs, "o");
writefile seems to fail to create non-existing paths.
Thanks!