K-Meleon

KMeleonWiki > Resources > MacroLibrary > KmmPriorTabs

Submitted by: JamesD

Notes:

PriorTabs creates a list of closed tabs for the current session and presents the list as a menu. The user may click on any prior tab to re-open the tab.

Open your User Macro Folder (Edit > Configuration > User-Defined Macros) or your Macro Folder (Edit > Configuration > Macros) and create the following text file:

PriorTabs.kmm

#  K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)
# File name: PriorTabs.kmm
# ---------- Re-Open PriorTabs for K-Meleon 1.5.3 ----
#
# Dependencies        : main.kmm, KM version 1.5.3 and later, tabs
# Resources           : PriorTabs.ini 
# Preferences         : - 
# Version             : 1.1 2010-10-05 
# Author              : JamesD ( extra menu options by jsnj)
# --------------------------------------------------------------------------------

_PriorTabs_ClearList {
##  erase the ini file
exec("cmd /c ERASE \"".$_PriorTabs_Path."\"");
## For user of win9x operating systems, cmd should be replaced with Command in the above line 
$_PriorTabs_Clearing = 1 ; 
&_PriorTabs_BuildListMenu ;
$_PriorTabs_Clearing = 0 ;
}

_PriorTabs_ClearListMenu {
$_PriorTabs_Clearing = 1 ; 
&_PriorTabs_BuildListMenu ;
$_PriorTabs_Clearing = 0 ;
}

_PriorTabs_WipeList {
$_PriorTabs_L = length(readfile($_PriorTabs_Path));
if ( $_PriorTabs_L > 1)  {
        exec("cmd /c ERASE \"".$_PriorTabs_Path."\"");
        ## For user of win9x operating systems, cmd should be replaced with Command in the above line 
        }
}

_PriorTabs_OpenTab {
$_PriorTabs_URL = urldecode( $ARG );
$_PriorTabs_Pt1 = index( $_PriorTabs_URL, "~~" );  
$_PriorTabs_URL = substr($_PriorTabs_URL, $_PriorTabs_Pt1 +2 );
opentab($_PriorTabs_URL) ;
}

_PriorTabs_CreateList {
&_PriorTabs_CheckForLength ;
&_PriorTabs_CheckListForDup ;
$_PriorTabs_CurrType < 2 ? $_PriorTabs_Count = $_PriorTabs_Count + 1 : 0 ;
if ($_PriorTabs_WasDup == 0) {
        $_PriorTabs_CurrType == 0 ? iniwrite("List", $_PriorTabs_Count, $TITLE . "~~" . $URL, $_PriorTabs_Path) :0;
        $_PriorTabs_CurrType == 1 ? iniwrite("List", $_PriorTabs_Count, "~~" . $URL, $_PriorTabs_Path) :0;
        $_PriorTabs_CurrType == 2 ? alert(_("URL length exceeds storage"). "\n" ._("Unable to store tab"), _("PriorTabs"), EXCLAIM) :0;
        }

if ($_PriorTabs_WasDup == 1) {
        &_PriorTabs_ClearListMenu;
        }
&_PriorTabs_BuildListMenu ;
$_PriorTabs_WasDup = 0 ;
}

_PriorTabs_CheckForLength {
$_PriorTabs_CurrType = 0 ;
$_PriorTabs_CurrLength = length($TITLE . "~~" . $URL);
if ( $_PriorTabs_CurrLength > 250 ) {
        $_PriorTabs_CurrType = 1 ;
        $_PriorTabs_CurrLength = length("~~" . $URL) ;
        if ( $_PriorTabs_CurrLength > 250 ) {
                $_PriorTabs_CurrType = 2 ;
        }
}
}

_PriorTabs_CheckListForDup {
    $PT__cntr = 0;
        $_PriorTabs_ini_Value = "";
    while($PT__cntr < $_PriorTabs_Count) { 
                $_PriorTabs_EName = iniread("List", $PT__cntr +1, $_PriorTabs_ini_Value, $_PriorTabs_Path);
                if ($_PriorTabs_EName == $URL) {
                        # Hold the current value in $_PriorTabs_ENameH
                        $_PriorTabs_ENameH = $_PriorTabs_EName ;
                        # overwrite downward from $_PriorTabs_Count to current key
                        $PT__cntr_D = $PT__cntr + 1 ;
                        while( $PT__cntr_D < $_PriorTabs_Count) {
                                $_PriorTabs_EName = iniread("List", $PT__cntr_D +1 , $_PriorTabs_ini_Value, $_PriorTabs_Path);
                                iniwrite("List", $PT__cntr_D, $_PriorTabs_EName, $_PriorTabs_Path);    
                $PT__cntr_D = $PT__cntr_D + 1 ;        
               }
                # If a dup write the new (replaced) item to highest key
                $_PriorTabs_WasDup = 1 ; 
                $_PriorTabs_EName = $_PriorTabs_ENameH ;
                iniwrite("List", $PT__cntr_D, $_PriorTabs_ENameH, $_PriorTabs_Path); 
                $_PriorTabs_Count = $_PriorTabs_Count -1 ;        
                }
                $PT__cntr = $PT__cntr + 1 ;
        }
}

_PriorTabs_BuildMenu {
if($kTabs){
        $PT__g=_("Prior Tabs");
        setmenu("NavEx",popup,$PT__g,3);
        $kSessions ? setmenu("&Sessions",popup,$PT__g,2):0;
        setmenu("TabButtonPopup",popup,$PT__g);
        $PT__m1="Options";
        setmenu($PT__g,inline,$PT__m1);
        setmenu($PT__m1,macro,_("Clear List"),_PriorTabs_ClearList);
        setmenu($PT__m1,separator,1);
        &_PriorTabs_BuildListMenu;
        }
}

_PriorTabs_BuildListMenu{
$PT__g=_("Prior Tabs");
$PT__m2="PriorTabs_List";
setmenu($PT__g,inline,$PT__m2);
if ($_PriorTabs_Count!=0) {
    $PT__cntr = 0;
        $_PriorTabs_ini_Value = "";
    while($PT__cntr < $_PriorTabs_Count) { 
                $_PriorTabs_EName = iniread("List", $PT__cntr +1, $_PriorTabs_ini_Value, $_PriorTabs_Path);
                if ($_PriorTabs_Clearing == 1) {
        setmenu($PT__m2,macro,$_PriorTabs_EName,"");        
        } else {
                $_PriorTabs_ENameA = urlencode($_PriorTabs_EName);
                setmenu($PT__m2,macro,$_PriorTabs_EName,"_PriorTabs_OpenTab(".$_PriorTabs_ENameA.")");
                }
                $PT__cntr = $PT__cntr + 1 ;
                }
        }
if ($_PriorTabs_Clearing + $_PriorTabs_WasDup > 0) {
        rebuildmenu($PT__g);
        }
rebuildmenu($PT__m2);
}

_PriorTabs_GetPath{
$_PriorTabs_Path=getfolder(UserMacroFolder)."\\PriorTabs.ini";
$_PriorTabs_Count = 0 ;  $_PriorTabs_Clearing = 0 ; $_PriorTabs_WasDup = 0 ;
}

#---------------------------------------------
$OnCloseTab=$OnCloseTab."_PriorTabs_CreateList;";
$OnInit=$OnInit."_PriorTabs_GetPath;_PriorTabs_WipeList;_PriorTabs_BuildMenu;";
$OnQuit=$OnQuit."_PriorTabs_WipeList;";
$macroModules=$macroModules."PriorTabs;";

Comments & Questions http://kmeleon.sourceforge.net/forum/read.php?4,110702

K-Meleon

(c) 2000-2010 kmeleonbrowser.org. All rights reserved.
design by splif.