Development/Tutorials/Kate/KTextEditor Plugins Advanced

    From KDE TechBase
    Revision as of 23:34, 17 January 2008 by Ereslibre (talk | contribs)
    Creating your first Kate Plugin with configuration dialog
    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.