Customizing Kate and KWrite Toolbars

For several years Geany has been the daily text editor in the house network. Along with that is being acclimated to the toolbar layout. The Geany toolbar is easy to customize with the respective GUI dialog.

The Kate and KWrite toolbars can be modified too. Using a similar toolbar layout would help stubborn memory muscle with breaking away from GTK:

  • New
  • Open
  • Save
  • Save As
  • Line separator
  • Cut
  • Copy
  • Paste
  • Line separator
  • Undo
  • Redo
  • Line separator
  • Close
  • Line separator
  • Find
  • Go to line
  • Line separator
  • Spell check
  • Line separator
  • Quit

Rarely are several of these buttons used, such as Cut, Copy, Paste, and Find. Most of the time keyboard shortcuts are faster for these tasks. Nonetheless, memory muscle is challenging to overcome and that desire to have a similar toolbar layout.

While the default toolbars in Kate and KWrite can be customized, using the GUI dialog to do that is Sisyphean.

There are two primary components in the toolbar. Both are named Main Toolbar:

  • Main Toolbar <kate>
  • Main Toolbar <KatePartView>

When customizing KWrite the first tool bar will be named Main Toolbar <kwrite>.

The KatePartView toolbar is common to both Kate and KWrite. Changing that common toolbar in one editor affects the other editor.

The GUI dialog to arrange the toolbars does not support complex changes. The dialog is based on simple presumptions. Because there are two components the dialog provides no straightforward way to move buttons from one toolbar to the other.

The trick is to use the GUI dialog only for an approximate layout. Then close the editor and manually edit the underlying rc files. Do this with neither Kate nor KWrite so the editor interfaces are not interacting with the rc files.

The rc files are XML files. In TDE the files are found at:

  • $TDEHOME/share/apps/kate/kateui.rc
  • $TDEHOME/share/apps/kwrite/kwriteui.rc
  • $TDEHOME/share/apps/katepart/katepartui.rc

In KDE the files are found at:

  • $HOME/.local/share/kxmlgui5/kate/kateui.rc
  • $HOME/.local/share/kxmlgui5/kwrite/kwriteui.rc
  • $HOME/.local/share/kxmlgui5/katepart/katepart5ui.rc

When the editors are set to use default toolbars then no user rc files will exist. When the rc exist then files contain all interface information and not just the toolbars.

To create the rc files, make one change in each toolbar. This can be done in either Kate or KWrite and later copied to the other editor.

In the rc XML files the toolbars can be configured with solitary actions or an action contained within a group. The default groups in the default KatePartView are limited. This is why configuring the toolbars with the GUI is difficult. The trick is creating new KatePartView groups.

Tinkering with the GUI dialog and observing the rc file changes will reveal the names of these groups and actions.

One of the groups is called edit_operations. That group contains several actions:


For the desired toolbar layout a line separator is needed between the Paste and Undo buttons. That cannot be done with the GUI dialog.

In the KatePartView XML file a new group was created named editdo_operations. The edit_undo and edit_redo actions were moved into that group. A separator was added at the end of the group. In each editor rc file that new group name was referenced. Now the Undo and Redo buttons were acted upon separately from the other Edit actions.

In the KatePartView rc file a tools_operations group was created to include the tools_spelling action and a goto_operations group with the go_goto_line action.

With that both the Kate and KWrite toolbars could be configured as desired. Here is the XML snippet for the kateui.rc and kwrite.rc files:

    <ToolBar noMerge="1” name="mainToolBar” >
    <text>Main Toolbar
    <DefineGroup name="file_open” />
    <Action group="file_open” name="file_new” />
    <Action group="file_open” name="file_open” />
    <Separator name="separator_4” />
    <DefineGroup name="file_operations” />
    <DefineGroup name="print_merge” />
    <Separator name="separator_3” />
    <DefineGroup name="edit_operations” />
    <DefineGroup name="editdo_operations” />
    <Action name="file_close” />
    <Separator name="separator_2” />
    <DefineGroup name="find_operations” />
    <DefineGroup name="goto_operations” />
    <DefineGroup name="zoom_operations” />
    <Separator name="separator_1” />
    <DefineGroup name="tools_operations” />
    <Separator name="separator_0” />
    <Action name="file_quit” />

Here is the XML snippet for the katepartui.rc file:

    <ToolBar noMerge="1” name="mainToolBar” >
    <text>Main Toolbar
    <Action group="file_operations” name="file_save” />
    <Action group="file_operations” name="file_save_as” />
    <Action group="edit_operations” name="edit_cut” />
    <Action group="edit_operations” name="edit_copy” />
    <Action group="edit_operations” name="edit_paste” />
    <Separator group="edit_operations” name="separator_1” />
    <Action group="editdo_operations” name="edit_undo” />
    <Action group="editdo_operations” name="edit_redo” />
    <Separator group="editdo_operations” name="separator_0” />
    <Action group="find_operations” name="edit_find” />
    <Action group="goto_operations” name="go_goto_line” />
    <Action group="tools_operations” name="tools_spelling” />

Posted: Category: Tutorial Tagged: KDE

Next: Exploring Desktop Environments — 6

Previous: Updating an Old Virtual Machine