Re-Open Tabs Macro
Posted by: MSlayer
Date: June 22, 2009 09:41PM

OK, I've been on coding this, it works, but is not perfect. Thanks for your help on this
#  K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)
#
# Reopen closed Tabs.
# Author: MSLAYER

_myOption{
$_opt = $ARG ;
$_opt!="dummy"?opentab($_opt):0;

 }

myOption_BuildMenu{
setmenu("&Edit",popup,"Hey",-1);
setmenu( "Hey","macro","Nothing yet","_myOption(dummy)");
setmenu( "Hey",separator,-1);

 }



createList{
	$index = $index + 1;
      $data = $URL;
	
 setmenu( "Hey" , macro , $data , "_myOption(".$data.")");

	if $index==4{
			$index=0;
	            }

 #end createList
 }


$OnInit=$OnInit."myOption_BuildMenu;";
$OnCloseTab=$OnCloseTab."createList;";
#_______________________________________
$macroModules=$macroModules."myOption;";
Is not supposed to be under the edit menu, and the new menu is not going to be called 'Hey'. This is just for testing purposes.
The last Tab is not detected.

Re: Re-Open Tabs Macro
Posted by: desga2
Date: June 22, 2009 10:50PM

I'm not sure that this is really needed.
You can use History for this.
If you load and close a lot of tabs in a session you obtain a very big menu.
Working in K-Meleon with a very big menu can do it inestable.

But is a good work with an interesting idea.

I don't know why people want to use History as Bookmarks and created menus to use as History, or use menus as Bookmars (like ndebord).

I think this world is going crazy. :s

Someone tried to use a car in the sea?
It may float... a little time at least. :drool:

K-Meleon in Spanish



Edited 2 time(s). Last edit at 06/22/2009 10:57PM by desga2.

Re: Re-Open Tabs Macro
Posted by: MSlayer
Date: June 22, 2009 11:04PM

Yes it needs a limit at some point. But I don't know so much about this Macro Language. The 'Nothing yet' option is supposed to be a clear button.
My idea was
createList{
	$index = $index + 1;
Incrementing the $index variable. Then use that variable as a menu position. But it doesn't work.
#doesn't work the last parameter
setmenu( "Hey" , macro , $data , "_myOption(".$data.")", index$);
When $index reaches maybe 10, it must be reset ( $index=0; ).

Re: Re-Open Tabs Macro
Posted by: Alex.Tarantul
Date: June 24, 2009 01:12PM

Hi! I adapted this macro for the Russian version of the Kmeleon. Also I have made little change which does work of a macro more conveniently. Look a code:

# K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)
#
# Reopen closed Tabs.
# Author: MSLAYER
# Russian translation and some fixes: Alex.Tarantul

_myOption{
$_opt = $ARG ;
$_opt!="dummy"?opentab($_opt):0;

}

myOption_BuildMenu{
setmenu("&Edit",popup,"Отменить закрытие вкладки",-1);
setmenu( "Отменить закрытие вкладки","macro","Ранее закрытые вкладки:","_myOption(dummy)");
setmenu( "Отменить закрытие вкладки",separator,-1);

}



createList{
$index = $index + 1;
$data = $TITLE;

setmenu( "Отменить закрытие вкладки" , macro , $data , "_myOption(".$data.")");

if $index==4{
$index=0;
}

#end createList
}


$OnInit=$OnInit."myOption_BuildMenu;";
$OnCloseTab=$OnCloseTab."createList;";
#_______________________________________
$macroModules=$macroModules."myOption;";

My blog about K-Meleon
http://kmeleon-ru.blogspot.com/

Re: Re-Open Tabs Macro
Posted by: MSlayer
Date: June 24, 2009 06:18PM

Hi, can you please translate it to English?
Have you found a way to clear the menu? The list will start to get bigger, how do we limit it size?
I found that I can re-use menu options, but not with a loop. This makes the code bigger, 'cause the SETMENUs.
I think that this is the code, my computer is somewhat slow, and it takes me time to debug the code.

# JUST For TESTING purposes
#  K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)
#  Re Open last Closed Tabs.
#  by MSlayer. 

_myOption1{
	$data1!="dummy"?opentab($data1):0;
}

_myOption2{
	$data2!="dummy"?opentab($data2):0;
}

_myOption3{
	$data3!="dummy"?opentab($data3):0;
}

_myOption4{
	$data4!="dummy"?opentab($data4):0;
}

myOption_BuildMenu{
setmenu("&Edit",popup,"Hey",-1);
setmenu( "Hey",separator,-1);
setmenu( "Hey", macro, "dummy", _myOption1, 1);
setmenu( "Hey", macro, "dummy", _myOption2, 2);
setmenu( "Hey", macro, "dummy", _myOption3, 3);
setmenu( "Hey", macro, "dummy", _myOption4, 4);

}


createList{
	$index = $index + 1;
      $data = $URL;
	
	if $index==1{
		$data1 = $data;
		setmenu( "Hey" , macro , $data , _myOption1 , 1 );
	 }
	if $index==2{
		$data2 = $data;
		setmenu( "Hey" , macro , $data , _myOption2 , 2 );
	 }
	if $index==3{
		$data3 = $data;
		setmenu( "Hey" , macro , $data , _myOption3 , 3 );
	 }
	if $index==4{
		$data4 = $data;
		$index=0;
		setmenu( "Hey" , macro , $data , _myOption4 , 4 );
	 }


		
	if $TabNumber==1{
		if $URL!="about:blank"{
	 	alert( $URL ,$TabNumber ,INFO);
		  }
		}

#end createList
}






#---------------------------------------------
$OnCloseTab=$OnCloseTab."createList;";
#$OnCloseWindow=$OnCloseWindow."createList;";

$OnInit=$OnInit."myOption_BuildMenu;";
$macroModules=$macroModules."myOption;";


Thanks a lot.

Re: Re-Open Tabs Macro
Posted by: Alex.Tarantul
Date: June 25, 2009 05:55PM

Here is translated in English:

myOption_BuildMenu{
setmenu("&Edit",popup,"Undo Closed Tabs",-1);
setmenu( "Undo Closed Tabs","macro","Previously Closed Tabs:","_myOption(dummy)");
setmenu( "Undo Closed Tabs",separator,-1);

...

setmenu( "Undo Closed Tabs" , macro , $data , "_myOption(".$data.")");

I have not yet found a way to reduce the list, but your idea of limiting the list is good smiling smiley

My blog about K-Meleon
http://kmeleon-ru.blogspot.com/

Re: Re-Open Tabs Macro
Posted by: Alex.Tarantul
Date: June 25, 2009 05:59PM

By the way, if change $URL on $TITLE there is a bug: If you close a single tab, and then try to open it again, the tab will not open ... sad smiley

Re: Re-Open Tabs Macro
Posted by: desga2
Date: June 25, 2009 06:49PM

Change by this line:

setmenu( "Undo Closed Tabs" , macro , $TITLE , "_myOption(".$URL.")");

$data variable isn't needed.

For delete you can read in Macro Documentation: (in setmenu() section)

Quote
Macro Documentation

(1) LABEL must be specified for all item types except "separator". If LABEL is an empty string, this is a deletion.
(2) COMMAND must be specified for item types "command" and "macro". If COMMAND is an empty string and LABEL is not, this is a deletion.

And after you can found rebuildmenu() macro function:

Quote
Macro Documentation

rebuildmenu (menuName);

This method is used to rebuild a menu that was created by a setmenu() statement. Note that a menu must be rebuilt by rebuildmenu() inside the same macro where it was built by setmenu(). The rebuildmenu() statement takes effect only when the hosting macro is (directly or indirectly) called from the menus. See proxy.kmm for a usage demonstration.

P.S:; Is recomended short the $TITLE to 10 or 15 characters to avoid very wide menus. You can use this macro statement for it: (from Macro Documentation)

$SUB = substr( s, i [, n] );

Returns the at most n-character substring of s starting at i. If n is omitted, the rest of s is used.

K-Meleon in Spanish



Edited 4 time(s). Last edit at 06/26/2009 11:29PM by desga2.

Re: Re-Open Tabs Macro
Posted by: MSlayer
Date: June 25, 2009 08:14PM

@Alex, thanks for the translation, I will test the code.

@desga:
I've been using a variable to hold some content, that way I can use the same variable at different spots or functions, without changing all the code.
I will try the deletion method. About the rebuild menu, I already tried it without success, is there an example code? It says to look proxy.kmm, but it is not there.

Currently this Menu works under the &Edit Menu, but I would like to have the option in another place, maybe right-clicking the new tab button?

The main purpose of this Macro is to have a temporal History list of Sites, that will be erased when you close KM. It also would be cool to show their favicons.

Thanks.

Re: Re-Open Tabs Macro
Posted by: JamesD
Date: June 25, 2009 08:43PM

@ Mslayer

See this macro for rebuildmenu example. http://kmeleon.sourceforge.net/wiki/KmmPgLdSound

Re: Re-Open Tabs Macro
Posted by: Alex.Tarantul
Date: June 26, 2009 01:23PM

@desga2
Thanks a lot! Now macros with $TITLE works perfectly!smiling smiley

My blog about K-Meleon
http://kmeleon-ru.blogspot.com/

Re: Re-Open Tabs Macro
Posted by: MSLAYER
Date: June 26, 2009 10:28PM

@James,
Thanks for the link. But I'm still having problems with the rebuild statement. I would like to use it to erase the whole list. But I get duplicated menus instead.
@Alex,
I've not used the $TITLE because some pages have the same title, but its addresses are different.
@desga2,
I was trying to remove a menu, but it requires to know the LABEL or COMMAND, and both are not hard-coded, they are created on the fly, so my question here is, does exist a way to store all the $URLs in an indexed way, like an Array? That way I will be able to remove the menu when I want to, using a variable.
My try was:
$data_url = $URL;
$x = $x + 1;
$list.$x = $data_url ; #Not possible, it changes $x

Thanks everybody.

Re: Re-Open Tabs Macro
Posted by: desga2
Date: June 27, 2009 12:04AM

$data_url = $URL;
Isn't needed because is a Global variable (only read).

We use strings as arrays, only need add a not used character in string like separator between elements. For example in this case we can use this characters not permited in urls.

$list = $list."|".$data_url; # Add element to array

# For delete element in array use: $SUB = sub( r, s, t );
# For search if an element exist in array use: $I = index( s, t );

setmenu( "Hey" , macro , "" , _myOption1 , 1 ); # Deletion menu
rebuild("Hey"); # Rebuild the menu

But i don't know why you like delete element in menu if in your code you have only 4 elements, you can replace his values $dataX.
If you like show last four urls visited you have;

Option1 -> data1
Option2 -> data2
Option3 -> data3
Option4 -> data4

Now you load a new url and replace old url moving the data values to above possition:

Option1 -> data2
Option2 -> data3
Option3 -> data4
Option4 -> data1 (data5)

K-Meleon in Spanish



Edited 1 time(s). Last edit at 06/27/2009 12:06AM by desga2.

Re: Re-Open Tabs Macro
Posted by: JamesD
Date: June 28, 2009 12:15PM

@ MSLAYER


Hold everything! Clear list is not working. More checking to do, I think. Working now I think I have the clear list working now. Sorry for the delay. Check to see if you have version .5 of the file.

I have an example of a good menu system for this project. I will include it with this post. PriorTabs.kmm is not meant for use. It will run but there issues using an ini file for the data. I tried that way only to see what issues would appear.

I cannot take credit for the menu system. I just copied and modified one desga2 created for Groups2.kmm. It is elegant and works quite well.

A better solution than the ini file for holding the data would be desga2's suggestion of a delimited string.

Issues using the ini file are:

1) Always has one closed tab when you close the KM window.
2) What will happen if you have two KM windows running?
3) Iniread and iniwrite are only available in KM ver 1.5.3.

There is some code in _PriorTabs_CheckListForDup that is to keep the list in the order the tabs were closed. You will have to make up your own mind as to whether you need to that. Also I have not yet put limit on the number of closed tabs to keep. I was thinking about using nine for that.

#  K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)
# File name: PriorTabs.kmm
# ---------- Re-Open Prior Tabs for K-Meleon 1.5.3 ----
#
# Dependencies        : main.kmm KM version 1.5 tabs
# Resources           : - 
# Preferences         : - 
# Version             : 0.5 2009-06-28
# Author              : JamesD 
# --------------------------------------------------------------------------------

_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 = 2 ;
&_PriorTabs_BuildListMenu ;
}

_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 = $ARG;
opentab($_PriorTabs_URL) ;
}

_PriorTabs_CreateList{
&_PriorTabs_CheckListForDup ;
$_PriorTabs_Count = $_PriorTabs_Count + 1 ;
iniwrite("List", $_PriorTabs_Count, $URL, $_PriorTabs_Path);
&_PriorTabs_BuildListMenu ;
}

_PriorTabs_CheckListForDup{
    $PT__cntr = 0;
	#alert($PT__cntr, "$PT__cntr CheckListForDup DEBUG", INFO);
	#alert($_PriorTabs_Count, "$_PriorTabs_Count CheckListForDup DEBUG", INFO);
    while($PT__cntr < $_PriorTabs_Count) { 
		#alert($PT__cntr, "$PT__cntr WHILE DEBUG", INFO);
		#alert($_PriorTabs_Count, "$_PriorTabs_Count WHILE DEBUG", INFO);
		$_PriorTabs_EName = iniread("List", $PT__cntr +1, $_PriorTabs_ini_Value, $_PriorTabs_Path);
		if ($_PriorTabs_EName == $URL) {
			# overwrite downward from $_PriorTabs_Count to current key
			$PT__cntr_D = $PT__cntr ;
			while( $PT__cntr_D < $_PriorTabs_Count) {
				#alert($PT__cntr_D, "$PT__cntr_D  overwrite DEBUG", INFO);
				$_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 ;        
               }
		$_PriorTabs_Count = $_PriorTabs_Count -1 ;	
		}
		$PT__cntr = $PT__cntr + 1 ;
	}
}


_PriorTabs_BuildMenu{
if($kTabs){
        $PT__g="Prior Tabs";
        setmenu("&Edit",popup,$PT__g,-1);
        $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;
    while($PT__cntr < $_PriorTabs_Count) { 
		$_PriorTabs_EName = iniread("List", $PT__cntr +1, $_PriorTabs_ini_Value, $_PriorTabs_Path);
		if ($_PriorTabs_Clearing == 2) {
        setmenu($PT__m2,macro,$_PriorTabs_EName,"");        
        } else {
		setmenu($PT__m2,macro,$_PriorTabs_EName,"_PriorTabs_OpenTab(".$_PriorTabs_EName.")");
		}
		$PT__cntr = $PT__cntr + 1 ;
		}
	} 
$_PriorTabs_Clearing == 1 ? rebuildmenu($PT__g):0;
rebuildmenu($PT__m2);
$_PriorTabs_Clearing = 1 ;
}

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

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



Edited 2 time(s). Last edit at 06/28/2009 07:08PM by JamesD.

Re: Re-Open Tabs Macro
Posted by: Alex.Tarantul
Date: June 29, 2009 03:32PM

Re-open tabs macro incorrectly processes URL's like that: http://kmeleonbrowser.org/forum/read.php?1,94047
That is from a comma in URL. By a call from the list of closed tabs after a comma all is cut off, and the main page of this forum opens. Where in a macro it is necessary to change something?
Try to close tab which now read, and then to open it. Will open http://kmeleonbrowser.org/forum/list.php?1 not http://kmeleonbrowser.org/forum/read.php?1,94047 Where the bug? sad smiley

My blog about K-Meleon
http://kmeleon-ru.blogspot.com/

Re: Re-Open Tabs Macro
Posted by: JamesD
Date: June 29, 2009 05:57PM

The comma and items after the comma are getting lost using the @ARG in the setmenu function. When I look at $_PriorTabs_URL after setting it the value of $ARG the comma and items after it are gone.

_PriorTabs_OpenTab{
$_PriorTabs_URL = $ARG;
opentab($_PriorTabs_URL) ;
}

The problem is going to be in the setmenu statement. Somehow the comma is not transfering to the #ARG value there.
setmenu($PT__m2,macro,$_PriorTabs_EName,"_PriorTabs_OpenTab(".$_PriorTabs_EName.")");

I will have to do some checking to see what needs to be done to correct the problem.

Re: Re-Open Tabs Macro
Posted by: desga2
Date: June 29, 2009 06:32PM

You need encode the URL ','=%2C.
Try with this:

Quote
Macro Documentation
$VALID_URL = urlencode( TEXT );

Encodes TEXT for use in an URL.

Another interesant web service to encode/decode URLs.

P.S.; Remember this current bug in urlencode() macro function, but in this case isn't affected by this bug.

- Note: Since 1.5 version also exist an undocumented urldecode() macro function: Macros2/functions.h
  872 	Value urldecode(FunctionData* data)
  873 	{
  874 		checkArgs(__FUNCTION__, data, 1);
  875 		char* str = strdup(data->getstr(1));
  876 		nsUnescape(str);
  877 		Value ret(str);
  878 		free(str);
  879 		return ret;
  880 	}

$TEXT = urldecode( VALID_URL );

Decodes VALID_URL for use as normal text.

K-Meleon in Spanish



Edited 8 time(s). Last edit at 06/29/2009 06:50PM by desga2.

Re: Re-Open Tabs Macro
Posted by: JamesD
Date: June 29, 2009 06:57PM

I don't think it is the url that has the problem. The problem is the $ARG does not handle the comma in setmenu. I added a line to sub the | for the comma for a new variable to be used in setmenu.

        } else {
		$_PriorTabs_ENameA = gsub( ",", "|",$_PriorTabs_EName);
		setmenu($PT__m2,macro,$_PriorTabs_EName,"_PriorTabs_OpenTab(".$_PriorTabs_ENameA.")");

And I added to the line reading the $ARG variable to change the | back to a comma.


_PriorTabs_OpenTab{
$_PriorTabs_URL = gsub( "|", ",",$ARG);
opentab($_PriorTabs_URL) ;
}

I just hope the | is not used in URLs. I wonder if this is bug in $ARG?

Re: Re-Open Tabs Macro
Posted by: JamesD
Date: June 29, 2009 07:17PM

Very good desga2. The urlencode and urldecode functions work just fine.

        } else {
		$_PriorTabs_ENameA = urlencode($_PriorTabs_EName);
		setmenu($PT__m2,macro,$_PriorTabs_EName,"_PriorTabs_OpenTab(".$_PriorTabs_ENameA.")");
and
_PriorTabs_OpenTab{
$_PriorTabs_URL = urldecode( $ARG );
opentab($_PriorTabs_URL) ;

That is one more item to update in MacroLanguage2. I will work on that soon.

The question still remains about passing a comma in the $ARG statement. Is that a bug?

Re: Re-Open Tabs Macro
Posted by: desga2
Date: June 29, 2009 08:15PM

Quote
JamesD
That is one more item to update in MacroLanguage2. I will work on that soon.

The question still remains about passing a comma in the $ARG statement. Is that a bug?

Thanks for your work to maintenance updated MacroLanguage2 wiki page. smiling smiley

About $ARG, I don't know but is possible to be a bug.
We need more test to know if problem is only to setmenu() macro function or is a bug to all macro functions that try to use the $ARG global variable.

K-Meleon in Spanish

Re: Re-Open Tabs Macro
Posted by: desga2
Date: June 29, 2009 08:43PM

Quote
JamesD
That is one more item to update in MacroLanguage2. I will work on that soon.

A little off this topic, but in the same Macos2/functions.h (link in above post) you can found all macro functions list: (undocumented and new since 1.5.x in bold)

 1395 void InitFunctions(Mac* m)
 1396 {
 1397 	MACROSFUNC_ADD(_);
 1398 	MACROSFUNC_ADD(setcheck);
 1399 	MACROSFUNC_ADD(open);
 1400 	MACROSFUNC_ADD(opennew);
 1401 	MACROSFUNC_ADD(openbg);
 1402 	MACROSFUNC_ADD(opentab);
 1403 	MACROSFUNC_ADD(openbgtab);
 1404 	MACROSFUNC_ADD(setpref);
 1405 	MACROSFUNC_ADD(getpref);
 1406 	MACROSFUNC_ADD(delpref);
 1407 	MACROSFUNC_ADD(togglepref);
 1408 	MACROSFUNC_ADD(exec);
 1409 	MACROSFUNC_ADD(id);
 1410 	MACROSFUNC_ADD(plugin);
 1411 	MACROSFUNC_ADD(statusbar);
 1412 	MACROSFUNC_ADD(alert);
 1413 	MACROSFUNC_ADD(confirm);
 1414 	MACROSFUNC_ADD(prompt);
 1415 	MACROSFUNC_ADD(getclipboard);
 1416 	MACROSFUNC_ADD(setclipboard);
 1417 	MACROSFUNC_ADD(macros);
 1418 	MACROSFUNC_ADD(pluginmsg);
 1419 	MACROSFUNC_ADD(pluginmsgex);
 1420 	MACROSFUNC_ADD(gensub);
 1421 	MACROSFUNC_ADD(gsub);
 1422 	MACROSFUNC_ADD(index);
 1423 	MACROSFUNC_ADD(length);
 1424 	MACROSFUNC_ADD(sub);
 1425 	MACROSFUNC_ADD(substr);
 1426 	MACROSFUNC_ADD(urlencode);
 1427 	MACROSFUNC_ADD(urldecode);
 1428 	MACROSFUNC_ADD(getfolder);
 1429 	MACROSFUNC_ADD(basename);
 1430 	MACROSFUNC_ADD(dirname);
 1431 	MACROSFUNC_ADD(hostname);
 1432 	MACROSFUNC_ADD(injectJS);
 1433 	MACROSFUNC_ADD(injectCSS);
 1434 	MACROSFUNC_ADD(readfile);
 1435 	MACROSFUNC_ADD(readreg);
 1436 	MACROSFUNC_ADD(promptforfile);
 1437 	MACROSFUNC_ADD(promptforfolder);
 1438 	MACROSFUNC_ADD(forcecharset);
 1439 	MACROSFUNC_ADD(setmenu);
 1440 	MACROSFUNC_ADD(setaccel);
 1441 	MACROSFUNC_ADD(rebuildmenu);
 1442 	MACROSFUNC_ADD(getwinvar);
 1443 	MACROSFUNC_ADD(setwinvar);
 1444 	MACROSFUNC_ADD(iniread);
 1445 	MACROSFUNC_ADD(iniwrite);
 1446 }

News for you: getwinvar() and setwinvar() to get or set K-Meleon current window variables/properties. Undocumented since previus 1.5.0, but not more useful because you can use his global variables more easilly, for example; $URL, $URLBAR, ...

I think that only "CommandLine" is a global variable undocumented.

$VAR=getwinvar(win_var);

- Possibles win_var values:
SelectedText
TextZoom
WindowNumber
TabNumber
URLBAR
URL
TITLE
LinkURL
ImageURL
FrameURL
CHARSET
CommandLine

setwinvar(winvar, value);

- Possibles win_var values:
TextZoom
URLBAR
URL
TITLE

(Rest of global vars are onlyread)

Note: winvars are case sensitive.

K-Meleon in Spanish



Edited 4 time(s). Last edit at 06/29/2009 08:48PM by desga2.

Re: Re-Open Tabs Macro
Posted by: JamesD
Date: June 30, 2009 12:07AM

@ desga2

So $CommandLine is a special global variable. Yes, I have tried it. Was it added in ver 1.5.0 ? I need to update that also. I checked the list before but my eyes are getting not so good. I just plain missed urldecode. I saw getwinvar but did not spot CommandLine. I will try update MacroLanguage soon.

@ MSLAYER

PriorTabs was not supposed to become a project. I had only intended to provide to you some help with rebuildmenu. Sad to say I still don't have the menu updating for a duplicate. I am aware of the problem and I am working on it.

I have to go to dentist tomorrow so will not have much time for KM. I will get to these things as soon as I can.

Re: Re-Open Tabs Macro
Posted by: JamesD
Date: June 30, 2009 02:09AM

This is my current code for PriorTabs.kmm. I still have a problem getting the menu to update correct after a duplicate. The ini file is in the correct order but the menu is not. I don't know if it is connected to another problem with the iniread function or not. See here http://kmeleonbrowser.org/forum/read.php?3,94354

#  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 tabs
# Resources           : PriorTabs.ini 
# Preferences         : - 
# Version             : 0.8 2009-06-29
# Author              : JamesD 
# --------------------------------------------------------------------------------

_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_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 );
opentab($_PriorTabs_URL) ;
}

_PriorTabs_CreateList{
&_PriorTabs_CheckListForDup ;
$_PriorTabs_Count = $_PriorTabs_Count + 1 ;
if ($_PriorTabs_WasDup == 0) {
	iniwrite("List", $_PriorTabs_Count, $URL, $_PriorTabs_Path);
	}
&_PriorTabs_BuildListMenu ;
}

_PriorTabs_CheckListForDup{
    $PT__cntr = 0;
    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("&Edit",popup,$PT__g,-1);
        $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;
    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_Clearing = 0 ; $_PriorTabs_WasDup = 0 ;
}

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

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


Re: Re-Open Tabs Macro
Posted by: JamesD
Date: June 30, 2009 12:26PM

@ desga2

MacroLanguage2 is updated.

Re: Re-Open Tabs Macro
Posted by: JamesD
Date: June 30, 2009 04:12PM

@ MSLAYER

I finally have PriorTabs rebuilding the menu correctly after a duplicate. Feel free to use any part of it for your own use.

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 tabs
# Resources           : PriorTabs.ini 
# Preferences         : - 
# Version             : 0.9 2009-06-29
# Author              : JamesD 
# --------------------------------------------------------------------------------

_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 );
opentab($_PriorTabs_URL) ;
}

_PriorTabs_CreateList{
&_PriorTabs_CheckListForDup ;
$_PriorTabs_Count = $_PriorTabs_Count + 1 ;
if ($_PriorTabs_WasDup == 0) {
	iniwrite("List", $_PriorTabs_Count, $URL, $_PriorTabs_Path);
	}

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

_PriorTabs_CheckListForDup{
    $PT__cntr = 0;
    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("&Edit",popup,$PT__g,-1);
        $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;
    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 ;
}

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


Re: Re-Open Tabs Macro
Posted by: desga2
Date: June 30, 2009 09:12PM

Quote
JamesD
@ desga2

So $CommandLine is a special global variable. Yes, I have tried it. Was it added in ver 1.5.0 ? I need to update that also. I checked the list before but my eyes are getting not so good. I just plain missed urldecode. I saw getwinvar but did not spot CommandLine. I will try update MacroLanguage soon.

getwinvar() and setwinvar() is since 1.0 or 1.1, I don't know exactlly, but $CommandLine exist since 1.5.2.

urldecode() is since 1.5.0.

K-Meleon in Spanish

Re: Re-Open Tabs Macro
Posted by: MSlayer
Date: June 30, 2009 10:58PM

Hey! I've been without Internet for a couple of days, and then I was trying to fix my connection, this is the third time I try to post here, I hope it works.
@James: I will try your code, if I understand it correctly, it does what I want, re open closed tabs?
@desga: thanks for the information that you supplied. I will play with the "simulated" arrays.

Re: Re-Open Tabs Macro
Posted by: JamesD
Date: June 30, 2009 11:00PM

@ desga2

I think I have the dates updated now. I did not do getwinvar() and setwinvar() since ithey are already in Special Global Variables.

Re: Re-Open Tabs Macro
Posted by: JamesD
Date: June 30, 2009 11:05PM

@ MSlayer

I hope the code helps you. The rebuild after a duplicate was tricky. Since setmenu() won't accept two items with the same command (macro), you must first set all the menu to "" and then reset the items from the ini file.

Note, there is no limit in the code yet. I had 20 priors listed, but that filled the whole page when I clicked on the menu.

Re: Re-Open Tabs Macro
Posted by: siria
Date: February 07, 2010 11:07AM

That's a function that I started missing more and more, now am glad that it works, thanks guys smiling smiley
Couldn't this be really finished and posted with the other extensions...?

HOW it works is way beyond my level of course (really scary code hey!), would just like to make some menu suggestions :cool:
Below "Undo Last Closed" in the Sessions menu:
setmenu("&Sessions",popup,"Prior Tabs","&Options...");
And in the View menu, below History, Tabs and Windows List:
setmenu("NavEx",popup,"Prior Tabs");

And the name is fine, just something like "Last Closed Pages" or such would fit better to the default function "Undo Last Closed".

BTW the error console listed tons of errors, until I tried exchanging "$_PriorTabs_ini_Value" simply with "", for lack of any clue, but hey, it still works grinning smiley

One thing I'd really prefer though is to list the titles instead the URLs, or perhaps that could even be a user pref. Otherwise all the threads in forums (like here) get only numbers, that doesn't help much for guessing the right one. But no idea if that's even possible technically...



Edited 1 time(s). Last edit at 02/10/2010 11:45AM by siria.

K-Meleon forum is powered by Phorum.