General :  K-Meleon Web Browser Forum
General discussion about K-Meleon 
How to use addtoolbar & addbutton functions?
Posted by: spirit
Date: November 15, 2015 09:52PM

Hi everyone!
I'm trying to write my first macros, and I can not add a button.
The toolbar has been added, but it is empty.
Can anyone show a simple example with the addition of a toolbar and buttons?
Thank you.
PS: kmeleon 75.1



Edited 1 time(s). Last edit at 11/15/2015 09:57PM by spirit.

Options: ReplyQuote
Re: How to use addtoolbar & addbutton functions?
Posted by: siria
Date: November 15, 2015 10:51PM

(_HOWTO_ howto create toolbar button by macro)

If those 2 are the only ones, you probably need to add an image too:
KM75 Image for everywhere incl. menus:
setcmdicon("macros(xy)","imagexy.bmp")

There is also a command
setbuttonimg(toolbar,command,icons)
This is only needed if you want a DIFFERENT button image and menuicon, or to change the button pic later during a session.
In KM75.0 that was also needed to avoid zooming of the toolbar buttons, which looked awful.

(Just experimented a lot with that stuff, but next month will probably have it forgotten again ;-)

--------
Shamelessly copying a button from JamesD here, ultrashort version for KM75.1 smiling smiley
("targets" is the toolbar name)

_dragTarget_buttons {
addtoolbar("targets") ;
addbutton("targets", "openLinkInNewTab");
setcmdicon("openLinkInNewTab", "newTab.png" );
}


--------

Personally I still prefer to work with variables for button creation, although it's not necessary any more since KM75 and looks much longer. Using that as template:

mymacro_buildButton{
$_toolbar="My Toolbar";
$_command= "macros(mine)";
$_icons="MyImage.bmp";
$_right_menu="My right-click menu";
$_tooltip="My Tooltip (avoid commas)";
#
addtoolbar($_toolbar);
addbutton( $_toolbar,$_command,$_right_menu,$_tooltip);
setcmdicon($_command,$_icons);
$_toolbar=""; $_command=""; $_right_menu=""; $_tooltip=""; $_icons="";
}



Edited 5 time(s). Last edit at 10/06/2019 01:12PM by siria.

Options: ReplyQuote
Re: How to use addtoolbar & addbutton functions?
Posted by: spirit
Date: November 16, 2015 02:26PM

Thanks
I use first version:
For the others newbies I should note - instead of the command "openLinkInNewTab", you need to write "macros(YourMacrosName)" because other methods not working.

Anyway, I still have a couple of questions:
1) Currently I use icons from the folder "skins".
I tried to make my own icons in different sizes, formats and color sets, but the program does not see them.

2) How to move the icons to a subfolder? K-meleon not see them in their own folder. This example didnt work:
setcmdicon("macros(StartMacro)", ("macros\\1\\trash.png"))


Also this code didnt work:
$myMacrPath = getfolder(MacroFolder);     
setcmdicon("macros(StartMacro)", ($myMacrPath . "\\trash.png"))

But in the variable is correct path.

3) What is better(more stable) method for js: $JS_doit or injectJS ?

Options: ReplyQuote
Re: How to use addtoolbar & addbutton functions?
Posted by: JamesD
Date: November 16, 2015 06:57PM

Quote
spirit
For the others newbies I should note - instead of the command "openLinkInNewTab", you need to write "macros(YourMacrosName)" because other methods not working.

The "openLinkInNewTab" does work in the context for which it was written. "openLinkInNewTab" is a command name. You are quite correct in that the normal requirement of running a macro from the button press should be "macros(YourMacrosName)".

Quote
spirit
How to move the icons to a subfolder? K-meleon not see them in their own folder.

Image files for buttons must be in one of four places. They are:
root\skins\skin name
root\skins\shared
user Profile\skins\skin name
user Profile\skins\shared

Quote
spirit
I tried to make my own icons in different sizes,

Modern versions of K-Meleon, 75 and later, can adjust image size to match the tool bar size. I now make all my images 32 pix size. Toolbars of size 16 and 24 easily scale them down. Siria has noted that scaling up from 16 to 24 reduces the clarity of the image.

Quote
spirit
What is better(more stable) method for js: $JS_doit or injectJS ?

I doubt that one method is more stable than the other, but everyone knows that I am not a js expert. I use injectJS() but only because I haven't the time to go and learn the $JS_doit method.

Options: ReplyQuote
Re: How to use addtoolbar & addbutton functions?
Posted by: JohnHell
Date: November 16, 2015 09:40PM

Quote
JamesD
Quote
spirit
What is better(more stable) method for js: $JS_doit or injectJS ?

I doubt that one method is more stable than the other, but everyone knows that I am not a js expert. I use injectJS() but only because I haven't the time to go and learn the $JS_doit method.


Go to main.kmm and just read the comments (after #) from the "JavaScript Document Handling" section (search this text in the file to go directly).

The difference is that injectJS, with self-invoked function, is for the current document and using $JS_doit with JS_hndlDocs, is for all in the document, including iframes, if exists, not only the main document.

But would be better explained by Dorian as I may be wrong, even it is what the main.kmm says.

No one is more stable. Use at your wish. What matters is how good and/or optimized is your JavaScript code.



Edited 1 time(s). Last edit at 11/16/2015 09:42PM by JohnHell.

Options: ReplyQuote
Re: How to use addtoolbar & addbutton functions?
Posted by: siria
Date: November 16, 2015 09:50PM

That's how I consider it too. Both methods are similar, both are macros, JSdoit just offers ready-made modules to shorten more complicated code. So, if you can get what you want with a short injectJS, that's fine. If you need to do something to every frame on the page, you can use a shorter code if you combine it with JShandlDocS. If for example you need to check every link on the page (like macro LinkToggle), JSdoit is a LOT simpler to use. The js-context modules are quite helpful for such things.



(sig) New unofficial K-Meleon 76.4 (KMG76.4) available, in own subforum.
Based on Goanna engine, called 'test' builds forever but more stable as 75.1 acc. forum members. It's 1-2 generations ahead of predecessor KM76RC-2016
K-Meleon FAQ (link missing in forum sidebar)
Tips&Tricks - Learning new stuff every day
New to K-Meleon? What do you like? What not?

Options: ReplyQuote
Re: How to use addtoolbar & addbutton functions?
Posted by: rodocop
Date: November 19, 2015 03:28PM

Quote
JamesD
Image files for buttons must be in one of four places. They are:
root\skins\skin name
root\skins\shared
user Profile\skins\skin name
user Profile\skins\shared

also both skins\default paths still work too though this isn't good for new skinning system

Options: ReplyQuote


K-Meleon forum is powered by Phorum.