K-Meleon
 

Home/News
Screenshots
Download
Documentation
Resources
Get Involved
Forum
Bugs
Development

SourceForge Logo
Spam Chongqed

 

 

 

 

 

 

K-Meleon

Documentation - Macros and Macro Scripting - Changing Text Size Using Macro Scripting

Introduction

This document presents an example of how to use the macro scripting in K-Meleon to configure preference settings during runtime, enabling you to enable/disable javascript, cookies, image loading, or most other things that are determined by settings in the prefs.js file. The changing of font size will be used for demonstration purposes as it's a feature people have requested, and also because it's an operation that seems to work fairly well as of this writing (beta 0.6); Other preferences, such as image loading behavior, don't always work as expected when altered with macros at this point. Keep that in mind if you decide to experiment with them.

Defining the Macro

All of the operations described here can be performed within the Preferences dialog of K-Meleon. It isn't necessary to open the individual .cfg files in a text editor. Go to the 'Configs' page of the preferences dialog, and click on the 'Macros' tab. This is where we will define the macro. First, we give it a name - I'm going to call mine 'fontsize' - then we give it an action, chosen from the list of available commands (given in the upper '#commented' portion of the macro.cfg file). Since we're using the macro to change a preference setting, we'll use the command 'togglepref(type, pref, values...)' with the preference 'font.size.variable.x-western' (assuming that we're using western fonts). Then we need to decide on the array of values to move through each time the macro is executed, which in this case represents the pixel size of the font. The default is 16. For this example, we'll give ourselves two additional sizes to cycle through - one smaller and one larger than the default - say, 12 and 20. (You might eventually want to set up TWO font-sizing macros, one that cycles through several larger-than-default sizes, and one that does the same with smaller-than-default sizes... or maybe you only need two different sizes to toggle between... configurable is beautiful!)

Putting it all together, it looks like this:

fontsize 	{
	togglepref(INT, font.size.variable.x-western, 12,20,16)
}

The 'INT' merely specifies that the value type is an integer; Some preferences require 'BOOL' (boolean) values like 'true' or 'false', and some require 'STRING' values, such as the name of a font or a URL. Note that the order in which the values are listed is the order in which they will be cycled through, so in this case executing the macro changes the fonts to small (12), executing it again changes them to large (20), and doing it once more returns to default (16) and it starts all over again.

If you put those lines into the macro definition file, you will have a macro for changing the font size, but you still need some way of executing the macro. You can bind it to a toolbar button or accelerator keys or add it to a menu or all of the above.

Adding a Menu Entry for the Macro

First we'll look at menus. Click on the 'Menus' tab (if you added the lines for the macro, you will be asked if you want to save changes... if you click 'no', you will lose anything that was added). The menu definitions file is structured from the bottom up, so to speak, with sub-menus defined above the menus that contain them. For this example, we'll add an entry under 'View' on the main menu. Scroll down past the 'File' and 'Edit' definitions to the one for 'View'. Here you will insert one simple line: 'macros(fontsize)'. It can go near the top or bottom, or anywhere else amongst the existing lines. Here it's shown inserted near the middle, below 'Source'.

&View {
	:&Toolbars
	-
	&Stop\tEsc = ID_NAV_STOP
	&Reload\tCtrl+R = ID_NAV_RELOAD
	&Source\tCtrl+U = ID_VIEW_SOURCE
	macros(fontsize)
	-
	Next Window\tF7 = ID_WINDOW_NEXT
	Previous Window\tShift+F7 = ID_WINDOW_PREV
%ifplugin fullscreen
	-
	fullscreen(&Full Screen\tF11)
%endif
}

After adding this line, you can click 'OK' to close the preferences dialog (be sure and answer 'yes' when asked if you want to save changes) and exit K-Meleon (if you have the symbiotic loader installed, you may have to re-boot). When you start it back up, there should be a menu item 'fontsize' in the 'View' menu, assuming all went well. If you want the menu to display a pretty name for the macro, you can do this by adding a line to the macro definition, as shown:


fontsize 	{
	menu = Font Si&ze
	togglepref(INT, font.size.variable.x-western, 12,20,16)
}

Besides looking nice, this will allow you to use Z to execute the macro from the 'View' menu.

Adding a Toolbar Button

What if you want a toolbar button? Click on the 'Toolbars' tab on the 'Configs' page of the preferences dialog. Here we have the toolbar definitions. You'll see the default buttons for the default toolbar defined, and you can add a button to these with the following lines:

   Font Size {
      macros(fontsize)
      tool2.bmp[8]
      tool1.bmp[8]
   }

The '[8]' is the index for the font sizing icon that exists on the tool1 and tool2 bitmaps included with K-Meleon. You can use any bitmap you want. In that case, just use the path to that file in place of tool1.bmp, etc. If the bitmap is a single button image, you don't need to use the [n] index. If you list more than one bitmap, the first will be shown when the cursor is hovering over the button, the second will be shown when it's not, and the third will be shown when the button is disabled.

Creating a Short-Cut (Accelerator) Key Combination

To bind an accelerator key combination to the macro, click on the 'Accelerators' tab to view the accelerator definitions. The trick here is to pick a combination that isn't already being used by something else. I'm going to use Alt+Up, like this:

ALT VK_UP = macros(fontsize)

That's all there is to it. However, be advised that currently (beta 0.6) there seem to be some issues related to macros via accelerators. What seems to work best for me is to define the accelerators in the same order as that of the macro definitions themselves. You may also find this to be the case.

This document, like K-Meleon itself, should be considered open and subject to improvement. Hopefully some light has been shed on the subject at hand. Not being on familiar terms with the internal workings of the program, I can't answer any of the deeper questions related to this matter. Your best bet is to poke around and experiment. - viva!

Wrtten by pobelly with the generous support of sticky.

Preference References

Preferences used by K-Meleon include those specific to K-Meleon only and those that are defined by Mozilla. The following links list those preferences that are available for use.

» K-Meleon Specific Preferences
» Mozilla Preferences

Last updated: January 5, 2002
Created: November 8, 2001

(c) 2000-2001 kmeleon.org. All rights reserved.
design by splif.