Difference between revisions of "Projects/KDevelop4/LanguagePlugin"

Jump to: navigation, search
(Created page with "= .desktop file = In order to find your language support plugin, KDE needs a .desktop file with some meta information. * <code>X-KDE-Library=...</code> this must be the same...")
 
(the plugin)
 
(4 intermediate revisions by one user not shown)
Line 4: Line 4:
  
 
* <code>X-KDE-Library=...</code> this must be the same as the name of your library, i.e. look into the <code>CMakeLists.txt</code> for your <code>kde4_add_plugin</code> line and use the same name
 
* <code>X-KDE-Library=...</code> this must be the same as the name of your library, i.e. look into the <code>CMakeLists.txt</code> for your <code>kde4_add_plugin</code> line and use the same name
* <code>X-KDE-PluginInfo-Name=...</code> this must be the same as the name of your plugin in the code, i.e. look into your main plugin .cpp file and find the <code>K_EXPORT_PLUGIN</code> line, more exactly the first argument to the <code>KAboutData</code>.
+
* <code>X-KDE-PluginInfo-Name=...</code> this must be a unique name that is used to reference and find your plugin.
  
 
After installing your plugin, make sure to run <code>kbuildsycoca4</code>. For testing, try duchainify or ktraderclient.
 
After installing your plugin, make sure to run <code>kbuildsycoca4</code>. For testing, try duchainify or ktraderclient.
 +
 +
= the plugin =
 +
 +
A basic plugin's header looks like this:
 +
 +
<pre>
 +
#include <interfaces/iplugin.h>
 +
#include <language/interfaces/ilanguagesupport.h>
 +
 +
class KDevTestLangPlugin : public KDevelop::IPlugin, public KDevelop::ILanguageSupport
 +
{
 +
    Q_OBJECT
 +
    Q_INTERFACES( KDevelop::ILanguageSupport )
 +
    public:
 +
        explicit KDevTestLangPlugin( QObject* parent, const QVariantList& args = QVariantList() );
 +
       
 +
        virtual KDevelop::ParseJob* createParseJob(const KDevelop::IndexedString& url);
 +
        virtual QString name() const;
 +
};
 +
</pre>
 +
 +
An implementation could look like this:
 +
 +
<pre>
 +
 +
#include "kdevtestlangplugin.h"
 +
#include <KPluginFactory>
 +
#include <KAboutData>
 +
 +
#include "testlangparsejob.h"
 +
 +
K_PLUGIN_FACTORY(KDevTestLangSupportFactory, registerPlugin<KDevTestLangPlugin>(); )
 +
K_EXPORT_PLUGIN(KDevTestLangSupportFactory(KAboutData("kdevtestlangsupport",0, ki18n("TestLanguage Support"), "0.1", ki18n("Support for Some Test Language"), KAboutData::License_GPL)))
 +
 +
using namespace KDevelop;
 +
 +
KDevTestLangPlugin::KDevTestLangPlugin(QObject* parent, const QVariantList& )
 +
    : IPlugin( KDevTestLangSupportFactory::componentData(), parent )
 +
    , ILanguageSupport()
 +
{
 +
    // NOTE: this is important!
 +
    KDEV_USE_EXTENSION_INTERFACE(ILanguageSupport)
 +
}
 +
 +
ParseJob* KDevTestLangPlugin::createParseJob(const IndexedString& url)
 +
{
 +
    return new TestLangParseJob(url, this);
 +
}
 +
 +
QString KDevTestLangPlugin::name() const
 +
{
 +
    // some unique id for your language
 +
    return "testlang";
 +
}
 +
</pre>

Latest revision as of 01:26, 25 October 2012

[edit] .desktop file

In order to find your language support plugin, KDE needs a .desktop file with some meta information.

  • X-KDE-Library=... this must be the same as the name of your library, i.e. look into the CMakeLists.txt for your kde4_add_plugin line and use the same name
  • X-KDE-PluginInfo-Name=... this must be a unique name that is used to reference and find your plugin.

After installing your plugin, make sure to run kbuildsycoca4. For testing, try duchainify or ktraderclient.

[edit] the plugin

A basic plugin's header looks like this:

#include <interfaces/iplugin.h>
#include <language/interfaces/ilanguagesupport.h>

class KDevTestLangPlugin : public KDevelop::IPlugin, public KDevelop::ILanguageSupport
{
    Q_OBJECT
    Q_INTERFACES( KDevelop::ILanguageSupport )
    public:
        explicit KDevTestLangPlugin( QObject* parent, const QVariantList& args = QVariantList() );
        
        virtual KDevelop::ParseJob* createParseJob(const KDevelop::IndexedString& url);
        virtual QString name() const;
};

An implementation could look like this:


#include "kdevtestlangplugin.h"
#include <KPluginFactory>
#include <KAboutData>

#include "testlangparsejob.h"

K_PLUGIN_FACTORY(KDevTestLangSupportFactory, registerPlugin<KDevTestLangPlugin>(); )
K_EXPORT_PLUGIN(KDevTestLangSupportFactory(KAboutData("kdevtestlangsupport",0, ki18n("TestLanguage Support"), "0.1", ki18n("Support for Some Test Language"), KAboutData::License_GPL)))

using namespace KDevelop;

KDevTestLangPlugin::KDevTestLangPlugin(QObject* parent, const QVariantList& )
     : IPlugin( KDevTestLangSupportFactory::componentData(), parent )
     , ILanguageSupport()
{
    // NOTE: this is important!
    KDEV_USE_EXTENSION_INTERFACE(ILanguageSupport)
}

ParseJob* KDevTestLangPlugin::createParseJob(const IndexedString& url)
{
    return new TestLangParseJob(url, this);
}

QString KDevTestLangPlugin::name() const
{
    // some unique id for your language
    return "testlang";
}

This page was last modified on 25 October 2012, at 01:26. This page has been accessed 1,389 times. Content is available under Creative Commons License SA 3.0 as well as the GNU Free Documentation License 1.2.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal