Development/Tutorials/Kate/KTextEditor Plugins Advanced
Tutorial Series | Kate Plugin Tutorial (2nd part) |
Previous | C++, Qt, KDE4 development environment |
What's Next | n/a |
Further Reading | CMake, The actual plugin code |
Abstract
The plugin that we developed on the previous part of this tutorial was nice, but probably not enough. We also need it to be configurable, because the user might want to only add to his/her document the date or the time, not both. We are going to create a configuration dialog for the plugin, and make the output form of our time & date configurable by the user.
The Code
The .desktop files
Every plugin needs a .desktop file that describes it. Same for each configuration page/widget. As we only need a page/widget for this plugin, we will only have two desktop files: one for the plugin itself, and another one for configuration the page/widget.
ktexteditor_timedate.desktop
[Desktop Entry]
Encoding=UTF-8
X-KDE-Library=ktexteditor_timedate
X-KDE-PluginKeyword=ktexteditor_timedate
X-KDE-PluginInfo-Author=Konqui the Dragon
[email protected]
X-KDE-PluginInfo-Name=ktexteditortimedate
X-KDE-PluginInfo-Version=0.1
X-KDE-PluginInfo-Website=http://kate.kde.org
X-KDE-PluginInfo-Category=Editor
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=false
X-KDE-ParentApp=kate
X-KDE-Version=4.0
ServiceTypes=KTextEditor/Plugin
Type=Service
Icon=korganizer
Name=Time & Date
Comment=Insert current Time & Date
ktexteditor_timedate_config.desktop
[Desktop Entry]
Type=Service
X-KDE-ServiceTypes=KCModule
X-KDE-Library=ktexteditor_timedate
X-KDE-PluginKeyword=ktexteditor_timedate_config
X-KDE-FactoryName=ktexteditor_timedate_config
X-KDE-ParentComponents=ktexteditortimedate
Name=Format of Time & Date insertion
- X-KDE-ServiceTypes: configuration widgets are always KCModule's.
- X-KDE-Library: you need to specify which library provides this configuration dialog. In this case we are shipping on the same library "ktexteditor_timedate.so" both the plugin itself and its configuration dialog.
- X-KDE-PluginKeyword: since we have two entry points on the library at this time: one for the plugin and another one for the configuration dialog we need to specify which keyword has each one. As you can see I also added this entry to the ktexteditor_timedate.desktop file. Of course they have to be different if we want to see it working.
The resource contents file
This file is the one that will let our plugin merge with the Kate environment (toolbars and/or menubars). In this case when our plugin is loaded this file tells the KDE XML classes that it will add a separator, and that there is an action named "tools_insert_timedate". We will need to interact with this action later.
timedateui.rc
<!DOCTYPE kpartgui>
<kpartplugin name="ktexteditor_timedate" library="ktexteditor_timedate" version="2">
<MenuBar>
<Menu name="tools"><Text>&Tools</Text>
<separator group="tools_operations" />
<Action name="tools_insert_timedate" group="tools_operations"/>
</Menu>
</MenuBar>
</kpartplugin>