1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
%{CPP_TEMPLATE}
#include "plugin_%{APPNAMELC}.h"
#include <kaction.h>
#include <klocale.h>
#include <kstandarddirs.h>
#include <kfiledialog.h>
#include <qlayout.h>
#include <qlabel.h>
class PluginView : public KXMLGUIClient
{
friend class KatePlugin%{APPNAME};
public:
Kate::MainWindow *win;
};
extern "C"
{
void* init_lib%{APPNAMELC}plugin()
{
KGlobal::locale()->insertCatalogue("kate%{APPNAMELC}");
return new KatePluginFactory;
}
}
KatePluginFactory::KatePluginFactory()
{
s_instance = new KInstance( "kate" );
}
KatePluginFactory::~KatePluginFactory()
{
delete s_instance;
}
QObject* KatePluginFactory::createObject( QObject* parent, const char* name, const char*, const QStringList & )
{
return new KatePlugin%{APPNAME}( parent, name );
}
KInstance* KatePluginFactory::s_instance = 0L;
KatePlugin%{APPNAME}::KatePlugin%{APPNAME}( QObject* parent, const char* name )
: Kate::Plugin ( (Kate::Application*)parent, name )
{
}
KatePlugin%{APPNAME}::~KatePlugin%{APPNAME}()
{
}
void KatePlugin%{APPNAME}::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_%{APPNAMELC}" );
view->setInstance (new KInstance("kate"));
view->setXMLFile("plugins/%{APPNAMELC}/plugin_%{APPNAMELC}.rc");
win->guiFactory()->addClient (view);
view->win = win;
m_views.append (view);
}
void KatePlugin%{APPNAME}::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 KatePlugin%{APPNAME}::slotInsertHello()
{
Kate::View *kv = application()->activeMainWindow()->viewManager()->activeView();
if (kv)
kv->insertText ("Hello World");
}
Kate::PluginConfigPage* KatePlugin%{APPNAME}::configPage (uint, QWidget *w, const char* name)
{
%{APPNAME}ConfigPage* p = new %{APPNAME}ConfigPage(this, w);
initConfigPage( p );
connect( p, SIGNAL(configPageApplyRequest(%{APPNAME}ConfigPage*)), this, SLOT(slotApplyConfig(%{APPNAME}ConfigPage*)) );
return (Kate::PluginConfigPage*)p;
}
void KatePlugin%{APPNAME}::initConfigPage( %{APPNAME}ConfigPage* p )
{
// TODO: initialize %{APPNAME}ConfigPage here
// NOTE: KatePlugin%{APPNAME} is friend of %{APPNAME}ConfigPage
}
void KatePlugin%{APPNAME}::slotApplyConfig( %{APPNAME}ConfigPage* p )
{
// TODO: save %{APPNAME}ConfigPage here
// NOTE: KatePlugin%{APPNAME} is friend of %{APPNAME}ConfigPage
}
/**
* %{APPNAME}ConfigPage
*/
%{APPNAME}ConfigPage::%{APPNAME}ConfigPage (QObject* parent /*= 0L*/, QWidget *parentWidget /*= 0L*/)
: Kate::PluginConfigPage( parentWidget )
{
QVBoxLayout* lo = new QVBoxLayout( this, 0, 0, "config_page_layout" );
lo->setSpacing(KDialogBase::spacingHint());
QLabel* lab = new QLabel("KatePlugin%{APPNAME}'s config page", this);
lo->addWidget(lab);
// TODO: add connection to emit SLOT( changed() )
}
%{APPNAME}ConfigPage::~%{APPNAME}ConfigPage()
{
}
void %{APPNAME}ConfigPage::apply()
{
emit configPageApplyRequest( this );
}
#include "plugin_%{APPNAMELC}.moc"
|