From 84da08d7b7fcda12c85caeb5a10b4903770a6f69 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeaddons@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kate/helloworld/plugin_katehelloworld.cpp | 66 +++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 kate/helloworld/plugin_katehelloworld.cpp (limited to 'kate/helloworld/plugin_katehelloworld.cpp') diff --git a/kate/helloworld/plugin_katehelloworld.cpp b/kate/helloworld/plugin_katehelloworld.cpp new file mode 100644 index 0000000..7499c08 --- /dev/null +++ b/kate/helloworld/plugin_katehelloworld.cpp @@ -0,0 +1,66 @@ + +#include "plugin_katehelloworld.h" +#include "plugin_katehelloworld.moc" + +#include +#include +#include + +K_EXPORT_COMPONENT_FACTORY( katehelloworldplugin, KGenericFactory( "katehelloworld" ) ) + +class PluginView : public KXMLGUIClient +{ + friend class KatePluginHelloWorld; + + public: + Kate::MainWindow *win; +}; + +KatePluginHelloWorld::KatePluginHelloWorld( QObject* parent, const char* name, const QStringList& ) + : Kate::Plugin ( (Kate::Application*)parent, name ) +{ +} + +KatePluginHelloWorld::~KatePluginHelloWorld() +{ +} + +void KatePluginHelloWorld::addView(Kate::MainWindow *win) +{ + // TODO: doesn't this have to be deleted? + PluginView *view = new PluginView (); + + (void) new KAction ( i18n("Insert Hello World"), 0, this, + SLOT( slotInsertHello() ), view->actionCollection(), + "edit_insert_helloworld" ); + + view->setInstance (new KInstance("kate")); + view->setXMLFile("plugins/katehelloworld/ui.rc"); + win->guiFactory()->addClient (view); + view->win = win; + + m_views.append (view); +} + +void KatePluginHelloWorld::removeView(Kate::MainWindow *win) +{ + for (uint z=0; z < m_views.count(); z++) + if (m_views.at(z)->win == win) + { + PluginView *view = m_views.at(z); + m_views.remove (view); + win->guiFactory()->removeClient (view); + delete view; + } +} + +void KatePluginHelloWorld::slotInsertHello() +{ + if (!application()->activeMainWindow()) + return; + + Kate::View *kv = application()->activeMainWindow()->viewManager()->activeView(); + + if (kv) + kv->insertText ("Hello World"); +} -- cgit v1.2.1