Page 1 of 1

SessionManager - Store and Load Tabs

Posted: 06 Sep 2011 08:24
by Stefan
Update for this older script >> Save Tabs using Script

Now storing the sessions in one ini file instead of single file for each session.

Works for me (because i know how it should work). Please test yourself and report back.

Code: Select all

// SessionManager Version 002, 17:05 01.06.2011 ("SessionManager.xys"), http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=6982
// Was yore "Save Tabs using Script (Sessions.xys)", http://www.xyplorer.com/xyfc/viewtopic.php?p=43943#p43943
// v002: converted to store to ini instead of single files


"Store Session/Tabs"

   $myINIFile = "<xydata>\User.ini";
   
   $SectionCount = getkey( "Count", "Sessions",  $myINIFile);
   if ($SectionCount == 20)
   {
      // Only keep the last 20 session:
      //msg "Session store is full, we will delete the oldest.",1;
      
       $iter=1;
       while($iter<$SectionCount)
       {
          $iter++;
            if (strlen($iter)==1){$iter = "0$iter";}
             $Date = getkey( $iter  . "_date", "Sessions",  $myINIFile);
             $Comm = getkey( $iter  . "_comm", "Sessions",  $myINIFile);
             $Icon = getkey( $iter  . "_tabs", "Sessions",  $myINIFile);
          $iter--;
            if (strlen($iter)==1){$iter = "0$iter";}
             setkey $Date, $iter . "_Date",  "Sessions", $myINIFile;
             setkey $Comm, $iter . "_Comm",  "Sessions", $myINIFile;
             setkey $Icon, $iter . "_Tabs",  "Sessions", $myINIFile;
         $iter++; 
       }
       //setkey "19", "Count",  "Sessions", $myINIFile;
       $SectionCount--;
    }
      
   $TabCount = tab(,"c"); 
   $Pane = getinfo("Pane");
   $Loop = 1;
   $Tabs = "";
 
   while ($Loop<=$TabCount)  //for each tab do
   {
     $IFTabNameSet = strlen(tab("get","name",$Loop));
     if ($IFTabNameSet < 1)
     {
     $Tabs = $Tabs . tab("get", "data", $Loop) . "|"; 
     }else{
     $Tabs = $Tabs . tab("get", "data", $Loop) . "?" . tab("get", "name", $Loop) . "|"; 
     }
     incr $Loop;
    }
    $Tabs = substr($Tabs, 0, strlen($Tabs)-1);
   
     $SectionCount++;
     if (strlen($SectionCount)==1){$SectionCount = "0$SectionCount";}
     $Date = "<date yyyy.mm.dd hh:nn> %ComputerName% Pane:$Pane";
     $Comme = Input("Add comment", "Enter an comment for this session (optional)",,"s","");
     
     //setkey value, key, section, [INIfile]
     setkey $SectionCount, "count",           "Sessions", $myINIFile;
     setkey $Date,  $SectionCount . "_Date",  "Sessions", $myINIFile;
     setkey $Tabs,  $SectionCount . "_Tabs",  "Sessions", $myINIFile;
     setkey $Comme, $SectionCount . "_Comm",  "Sessions", $myINIFile;

        

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


// open new tabs from an list of paths (saved tabs):
"Load Session/Tabs"

     $myINIFile = "<xydata>\User.ini";

     $iter=1; 
     $SectionCount = getkey( "Count", "Sessions",  $myINIFile);
     $array="";
     while($iter <= $SectionCount)
     {
       if (strlen($iter)==1){$iter = "0$iter";}
       $date  = getkey( $iter . "_date", "Sessions",  $myINIFile);
       $comm  = getkey( $iter . "_comm", "Sessions",  $myINIFile);
       $tabs  = getkey( $iter . "_tabs", "Sessions",  $myINIFile);
       $tabs  = replace($tabs, "|", ", ");
       $array = $array . "$iter; $date; $comm; $tabs|";
       $iter++;
     }
     
     $newTABs = inputselect("Select ONE stored session to restore:",$array,,2);
     end ($newTABs==""); // [OK] without selection==Quit, [Cancel]==Quit
     
     $newTABs = gettoken($newTABs, 1, ";");
     $newTABs = getkey( $newTABs . "_tabs", "Sessions",  $myINIFile);
     
    

    
    //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($newTABs,$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: SessionManager - Store and Load Tabs

Posted: 06 Sep 2011 09:35
by highend
Hi Stefan,

good idea but this version duplicates (probably the first) tab to the user.ini file.

For testing purposes:

I have only one tab in pane 1 open: D:\Users\Highend\Downloads\Default

No sessions are saved up to now. When I store this session the .ini file will contain:

Code: Select all

[Sessions]
count=01
01_Date=2011.09.06 09:31 UK-DT-01 Pane:1
01_Tabs=D:\Users\Highend\Downloads\Default|D:\Users\Highend\Downloads\Default
instead of:

Code: Select all

[Sessions]
count=01
01_Date=2011.09.06 09:31 UK-DT-01 Pane:1
01_Tabs=D:\Users\Highend\Downloads\Default
Or does the duplication happens for a special reason?

Re: SessionManager - Store and Load Tabs

Posted: 06 Sep 2011 10:48
by Stefan
highend wrote:but this version duplicates (probably the first) tab to the user.ini file.
I don't know why i had done this,
but changing
$Loop = 0;
to
$Loop = 1;
should solve this. (script above corrected already)



Thanks.