# Defining your own formatting tags

In the Formatting menu there are two items for inserting formatting tags. You can define your own formatting tags by defining procs for how the text should be indented within the tags. Let us say you want to define formatting tags called MY-SCRIPT-FORMATTING.

First write a proc which correctly indents a line inside MY-SCRIPT-FORMATTING tags.

    proc myScriptIndent {} {
        code goes here
    }

Then you can optionally define a proc for reformatting a region of text. By default the proc ::indentRegion is used, which simply indents line after line in the region. If you need a more sophisticated reformatting write a new proc.

    proc myScriptIndentRegion {} {
        code goes here
    }

Then finally you register it by adding a line of the form

    html::RegisterFormattingStyle "style" "menu item text" "indent line proc" "reformat region proc"

to your HTML preferences file. When you are in HTML mode open it using Config -> HTML Mode Prefs - > Edit Prefs File.

Let us say that in this case you want the menu item text "My Script Formatting". Then the line would be

    html::RegisterFormattingStyle "MY-SCRIPT-FORMATTING" "My Script Formatting" "myScriptIndent" "myScriptIndentRegion"

Optionally you can omit the last argument if you have no special reformatting proc:

    html::RegisterFormattingStyle "MY-SCRIPT-FORMATTING" "My Script Formatting" "myScriptIndent"

# Making your own palettes

With a little bit of programming you can create your own palettes with your frequently used menu items in the two HTML menus. What you need to do is the following:

A palette is created by first defining a menu. This is done with code like this

    Menu -n "Palette title" -m -p myPaletteProc {
        "Button text 1"
        "Button text 2"
        "Button text 3"
        "Button text 4"
    }

You can of course add as many buttons as you like. myPaletteProc is the function which will be called when you click a button. It is called with two arguments, the first is the palette title and the second is the button text. To attach each button to a menu item in one of the two HTML menus myPaletteProc has to be defined like this:

    proc myPaletteProc {themenu theitem} {
        switch $theitem {
            "Button text 1" {html::MenuItem "submenu" "menu item"}
            "Button text 2" {html::MenuItem "submenu" "menu item"}
            "Button text 3" {html::UtilsMenuItem "submenu" "menu item"}
            "Button text 4" {html::UtilsMenuItem "submenu" "menu item"}
        }
    }

submenu is here a submenu of one of the HTML menus and menu item is the menu item in the submenu you want the button to be attached to. In this example the first argument "themenu" of myPaletteProc is never used, but it has to be there since Alpha sends two arguments to myPaletteProc. For items in any of the submenus of the HTML menu use "html::MenuItem" and for any of the submenus of the HTML Utilities menu use "html::UtilsMenuItem".

As an explicit example we create a palette with two buttons attached to "Table Template" and "Insert Paragraphs". The menu defining the palette is

    Menu -n "My palette" -m -p myPaletteProc {
        "Table Template"
        "Insert Paragraphs"
    }

Two things to notice:

- The palette title can be anything you like, except that it can't be the same as the name of any of the menus or submenus in Alpha.
- The button texts can be anything you like and does not have to be the same as the menu item you attach it to.

The function myPaletteProc should in our example be define as

    proc myPaletteProc {themenu theitem} {
        switch $theitem {
            "Table Template" {html::MenuItem "Tables" "Table Template"}
            "Insert Paragraphs" {html::MenuItem "Blocks and Dividers" "Insert Paragraphs"}
        }
    }

One important detail is that if a menu item ends by ... this trailing ... must be omitted as was done in html::MenuItem "Tables" "Table Template".

What about if we want one of the menu items at top level in the two HTML menus? To clarify this we extend the example by adding two more buttons to the palette:

    Menu -n "My palette" -m -p myPaletteProc {
        "Table Template"
        "Insert Paragraphs"
        "New Document"
        "Last Modified"
    }

    proc myPaletteProc {themenu theitem} {
        global htmlMenu htmlUtilsMenu
        switch $theitem {
            "Table Template" {html::MenuItem "Tables" "Table Template"}
            "Insert Paragraphs" {html::MenuItem "Blocks and Dividers" "Insert Paragraphs"}
            "New Document" {html::MenuItem $htmlMenu "New Document"}
            "Last Modified" {html::UtilsMenuItem $htmlUtilsMenu "Last Modified"}
        }
    }

To refer to the two HTML menus we use the variables htmlMenu and htmlUtilsMenu in the way shown above. First we add the line

        global htmlMenu htmlUtilsMenu

and then we write $htmlMenu when we want the HTML menu and $htmlUtilsMenu when we want the HTML Utilities menu.

This code defining your palette(s) should be put in your HTML prefs file. When you are in HTML mode open it using Config -> HTML Mode Prefs - > Edit Prefs File.

OK, we have now defined a palette but how do we open it? For this to be possible we have to add one line to the global prefs file. Open the global prefs file by using Config -> Preferences -> Edit Prefs File. The line to add is

    set customHTMLpalettes {"Palette title 1" "Palette title 2"}

where "Palette title 1" etc. are the titles of your palettes. In our example we would have added the line

    set customHTMLpalettes {"My palette"}

The reason that this line has to be in the global prefs file is that is has to be loaded before HTML mode.

The next time you launch Alpha you will now get an extra submenu in the HTML menu called Palettes where the menu items are the titles of your palettes.

Selecting a menu item in the 'Palettes' menu opens the palette. These palettes are such that they disappear when you leave HTML mode and reappear when you go back to HTML mode. This behavior is the same as when you pull off one of the two HTML menus, but unfortunately not when you pull off a submenu.

# Modifying the menus

If you write some new procs and want to add them to the two HTML menus it can be done easily.

- If you want to add a menu item called "New Menu Item" the your proc has to be called html::NewMenuItem.
- Insert the menu item to a submenu by with putting the line
  menu::insert "submenu name" items end "New Menu Item"
  in your HTML preferences file.

Note! For the following submenus this does not work: Browsers, Preferences, Character Entities, Colors, URLs, Windows.

Previous page Next page