Man 1 ch07s07

From Bluefish Wiki
Jump to: navigation, search


Please consider to upgrade to Bluefish 2!

Please consider to edit the Manual 2!

How To edit the Wiki Manual
7. Custom menu
Prev 
Chapter VII. More than a Text Editor
 Next

7. Custom menu

To customize items in the Custom menu tool bar, you will use the Custom menu element:

Man1 custom menu access.png

Figure VII.22. Accessing the Custom Menu

The Custom menu → Edit custom menu... leads to the Custom Menu Editor. The Load new item allows you to load a new menu in case you have directly changed the custom_menu file located in the .bluefish directory within your HOME directory, while Reset item allows you to return to the default custom menu under the same circumstances.

The custom_menu file is created upon install Bluefish and corresponds to some default entries, the ones you can see in the Custom menu tool bar. These will give you an idea what can be done with the custom menu.

The custom menu operates only on elements of the Custom menu tool bar, and allows you to:

  • add "often used" items to an existing menu
  • search and replace patterns to the Replace menu
  • create new menus

The Custom Menu Editor is the place where you make all changes to the custom menu. The location for entries in the custom menu is defined by their menu path in the Custom Menu Editor:

Man1 custom menu editor.png

Figure VII.23. The Custom Menu Editor

It has four parts:

  • The top one with all action buttons:
    • Add which adds new menu entries, once all necessary fields have been filled in
    • Apply which applies changes to an existing menu entry, once it has been edited
    • Delete which deletes the menu entry currently selected in the Menu path list
    • Close which discards changes
    • Save which saves the changes and exit the editor
  • The Menu Path field below the buttons, to enter either an existing or a new menu path
  • The Menu path list on the left side, which lists existing menu paths. A menu path looks like /Main menu/submenu/item or /Main menu/item. Here's an extract of the default custom menu paths:
    Man1 custom menu default path.png
    Figure VII.24. Extract of the default Custom Menu Path
  • A custom part on the right side, whose contents changes depending of the type of menu. There are two types of items in the Custom Menu Editor:
    • the Custom dialog, which will insert a string, optionally based on values asked in a dialog
    • the Custom Find and Replace, which will run a replace, also optionally based on values asked in a dialog. Here's how the Custom Replace dialog looks like:
      Man1 custom menu replace dialog.png
      Figure VII.25. The Custom Replace Dialog

7.1. Adding a custom menu dialog

The most simple custom dialog item has a menupath, for example /MySite/author, and a Formatstring before, for example written by Olivier. If you add this item, you can add this string by selecting the menu item.

Procedure VII.2. Adding a custom menu based on custom dialog

  1. Choose Custom menu → Edit custom menu... in the custom menu tool bar.
  2. Enter /MySite/author in the Menu Path field of the Custom Menu editor.
  3. Enter written by Olivier in the Formatstring Before field located on the right.
  4. Click on the Add button at the top.
    Notice that upon adding the new entry, it is listed at the bottom of the Menu path list:
    Man1 custom menu add basic.png
    Figure VII.26. A new Custom Entry in the Menu Path List
  5. Click on the Save button. This will add the menu to the Custom menu tool bar:
    Man1 custom menu basic result.png
    Figure VII.27. A new Menu in the Custom Menu Tool Bar

Note that the new menu is placed at the right end of the custom menu tool bar. When closing Bluefish and relaunching it, it will be placed in alphabetical order, except that the Replace menu will always be at the far right side.

In another example, you have a string you often need to set before and after some block of text, for example <div class="MyClass">YourBlockOfText</div>. To do it:

  1. Open the Custom Menu Editor
  2. Enter /MySite/div with class in the Menu Path field
  3. Enter <div class="MyClass"> in the Formatstring Before field
  4. Enter </div> in the Formatstring After field
  5. Click on Add, then on Save. The item will appear in the menu.

If you select some text:

Man1 custom menu div before.png

Figure VII.28. A Block of selected Text before Activating the Menu

And activate this menu item, the first bit of text is now added before the selection, and the second bit after the selection:

Man1 custom menu div after.png

Figure VII.29. A Block of Text after Activating the Menu

Suppose you want to improve this last example. You have both MyClass1 and MyClass2 and want to be able to choose the desired class when activating the menu. Here's how to do it:

  1. Open the Custom Menu Editor
  2. Browse the Menu path list to retrieve the /MySite/class with div entry and click on it to make appear its components in the Menu Path and Custom Dialog fields
  3. Click on the top arrow of the Number of Variables pop up menu to get 1 in the field. As you see a Variables entry appears where you can enter the name for variable %0. As name we enter MyClass number
  4. Now change the FormatString Before field to take this new variable into account, as following: <div class="MyClass%0">
  5. Click on Apply so that your changes will be taken in account, and click on Save to update the menu.

If you now activate this menu after having selected a block of text, you will be presented with a new dialog asking you for the value of MyClass number:

Man1 custom menu div dialog.png

Figure VII.30. The new DIV with Class Dialog

After entering the desired value, the same process as before will occur, using the value you provided. Here we have entered 1 as value:

Man1 custom menu div dialog result.png

Figure VII.31. The Block of Text after Entering the Value


Man1 tip.png You can use the Return and Tab keys to format the output.

Any variable can be used any times you want in the dialog.

7.2. Adding a custom replace dialog

Find and replace items are no different. The dialog has some more options, each of these options corresponds to the regular Replace dialog. Again you can use variables like %0, %1 etc. to make a certain menu item more flexible.

Say you want to add title tags to a selection in a HTML page so that the user agent could render it either as a tool tip or as spoken words. To ease the discussion we will work on the following snippet of code:

<ul>
<li><a href="progsys01|">Process scheduling</a> - 26/10/2002</li>
<li><a href="progsys02|">Fork and Wait</a> - 02/11/2002</li>
</ul>

We will transform it into the following one:

<ul>
<li><a href="progsys01|" title="blah Process scheduling">Process scheduling</a> \
- 26/10/2002</li>
<li><a href="progsys02|" title="blah Fork and Wait">Fork and Wait</a> \
- 02/11/2002</li>
</ul>

where blah is any text you want.

The initial rendering:

Man1 custom menu page before.png

Figure VII.32. The HTML Page before the Transformation

will be transformed as is:

Man1 custom menu page after.png

Figure VII.33. The HTML Page after the Transformation

To do this, we need to express the <a href="yoururl">yourstring</a> part of the initial snippet of code as a Perl regular expression (see Section 5.3, “Find and Replace Using Regular Expressions” for full details):

  • a href=" will be expressed as is and embedded into parentheses to retrieve it as \0 variable.
  • yoururl will be expressed as ([[Man 1 ^"]]+) to match one or more non double quote characters and retrieve it as \1 variable.
  • The second double quote will be expressed as is and embedded into parentheses to retrieve it as \2 variable.
  • The second > sign will be expressed as is and embedded into parentheses to retrieve it as \3 variable.
  • yourstring will be expressed as ([[Man 1 ^>]]+) to match one or more non > characters and retrieve it as \4 variable.
  • </a> will be expressed as is and embedded into parentheses to retrieve it as \5 variable.

Thus, the search string will be: (<a href=")([[Man 1 ^"]]+)(")(>)([[Man 1 ^>]]+)(</a>)

The replace string should be of the form: <a href="yoururl" title="yourvariablestring yourstring">yourstring</a>

Expressed as a regular Perl replacement expression, it will be as simple as: \0\1\2 title=\2%0 \4\2\3\4\5 where %0 will match yourvariablestring, that is the value entered in the Title field of the Replace dialog at activating time.

Procedure VII.3. Adding a custom menu based on replace dialog

  1. Choose Custom menu → Edit custom menu... in the custom menu tool bar.
  2. Browse the Menu path list to retrieve the /Replace/Convert in Selection/<td> to <th> and click on it to make appear its components in the Menu Path and Custom Replace fields.
  3. Change the Menu Path to /Replace/Anchor/Add Title.
  4. Click on the top arrow of the Number of Variables pop up menu to get 1 in the field. Enter Title in the %0 Variables field.
  5. Change the Matching pop up menu to perl regular expressions.
  6. Change the Search Pattern field like this:
    (<a href=")([[Man 1 ^"]]+)(")(>)([[Man 1 ^>]]+)(</a>)
  7. Change the Replace String field like this:
    \0\1\2 title=\2%0 \4\2\3\4\5
  8. Click on the Add button.
    The Custom replace dialog should have the following appearance:
    Man1 custom menu replace dialog new.png
    Figure VII.34. The Custom Menu Replace Dialog filled in
  9. Click on the Save button.

To use the new menu item, select the lines to be changed in the HTML file and activate Replace/Anchor/Add Title in the custom menu bar. Fill in the dialog as follows:

Man1 custom menu add title.png

Figure VII.35. The Add Title Dialog

Click OK to proceed.


Prev 
Up
 Next
6. Customizing the Quick bar
Home | ToC
 8. External programs, filters