2
#include "%{APPNAMELC}part.h"
5
#include <qpopupmenu.h>
6
#include <qwhatsthis.h>
10
#include <kdialogbase.h>
11
#include <kiconloader.h>
12
#include <kmessagebox.h>
13
#include <kdevplugininfo.h>
14
#include <kdevgenericfactory.h>
17
#include <kdevmainwindow.h>
18
#include <configwidgetproxy.h>
20
#include "%{APPNAMELC}widget.h"
21
#include "%{APPNAMELC}globalconfig.h"
22
#include "%{APPNAMELC}projectconfig.h"
24
typedef KDevGenericFactory<%{APPNAME}Part> %{APPNAME}Factory;
25
KDevPluginInfo data("kdev%{APPNAMELC}");
26
K_EXPORT_COMPONENT_FACTORY( libkdev%{APPNAMELC}, %{APPNAME}Factory( data ) );
28
#define GLOBALDOC_OPTIONS 1
29
#define PROJECTDOC_OPTIONS 2
31
%{APPNAME}Part::%{APPNAME}Part(QObject *parent, const char *name, const QStringList &/*args*/)
32
: KDevPlugin(&data, parent, name ? name : "%{APPNAME}Part")
34
setInstance(%{APPNAME}Factory::instance());
35
setXMLFile("kdev%{APPNAMELC}.rc");
37
m_widget = new %{APPNAME}Widget(this);
38
m_widget->setCaption("widget caption");
39
m_widget->setIcon(SmallIcon(info()->icon()));
41
QWhatsThis::add(m_widget, i18n("WHAT DOES THIS PART DO?"));
43
// now you decide what should happen to the widget. Take a look at kdevcore.h
44
// or at other plugins how to embed it.
46
// if you want to embed your widget as an outputview, simply uncomment
47
// the following line.
48
// mainWindow()->embedOutputView( m_widget, "name that should appear", "enter a tooltip" );
50
// if you want to embed your widget as a selectview (at the left), simply uncomment
51
// the following line.
52
// mainWindow()->embedSelectView( m_widget, "name that should appear", "enter a tooltip" );
54
// if you want to embed your widget as a selectview (at the right), simply uncomment
55
// the following line.
56
// mainWindow()->embedSelectViewRight( m_widget, "name that should appear", "enter a tooltip" );
60
m_configProxy = new ConfigWidgetProxy(core());
61
m_configProxy->createGlobalConfigPage(i18n("%{APPNAME}"), GLOBALDOC_OPTIONS, info()->icon());
62
m_configProxy->createProjectConfigPage(i18n("%{APPNAME}"), PROJECTDOC_OPTIONS, info()->icon());
63
connect(m_configProxy, SIGNAL(insertConfigWidget(const KDialogBase*, QWidget*, unsigned int )),
64
this, SLOT(insertConfigWidget(const KDialogBase*, QWidget*, unsigned int)));
66
connect(core(), SIGNAL(contextMenu(QPopupMenu *, const Context *)),
67
this, SLOT(contextMenu(QPopupMenu *, const Context *)));
68
connect(core(), SIGNAL(projectOpened()), this, SLOT(projectOpened()));
69
connect(core(), SIGNAL(projectClosed()), this, SLOT(projectClosed()));
72
QTimer::singleShot(0, this, SLOT(init()));
75
%{APPNAME}Part::~%{APPNAME}Part()
77
// if you embed a widget, you need to tell the mainwindow when you remove it
80
// mainWindow()->removeView( m_widget );
86
void %{APPNAME}Part::init()
88
// delayed initialization stuff goes here
91
void %{APPNAME}Part::setupActions()
93
// create XMLGUI actions here
94
action = new KAction(i18n("&Do Something..."), 0,
95
this, SLOT(doSomething()), actionCollection(), "plugin_action" );
96
action->setToolTip(i18n("Do something"));
97
action->setWhatsThis(i18n("<b>Do something</b><p>Describe here what does this action do."));
100
void %{APPNAME}Part::insertConfigWidget(const KDialogBase *dlg, QWidget *page, unsigned int pageNo)
102
// create configuraton dialogs here
105
case GLOBALDOC_OPTIONS:
107
%{APPNAME}GlobalConfig *w = new %{APPNAME}GlobalConfig(this, page, "global config");
108
connect(dlg, SIGNAL(okClicked()), w, SLOT(accept()));
111
case PROJECTDOC_OPTIONS:
113
%{APPNAME}ProjectConfig *w = new %{APPNAME}ProjectConfig(this, page, "project config");
114
connect(dlg, SIGNAL(okClicked()), w, SLOT(accept()));
120
void %{APPNAME}Part::contextMenu(QPopupMenu *popup, const Context *context)
122
// put actions into the context menu here
123
if (context->hasType(Context::EditorContext))
125
// editor context menu
126
const EditorContext *econtext = static_cast<const EditorContext*>(context);
128
// use context and plug actions here
131
// or create menu items on the fly
133
// id = popup->insertItem(i18n("Do Something Here"),
134
// this, SLOT(doSomething()) );
135
// popup->setWhatsThis(id, i18n("<b>Do something here</b><p>Describe here what does this action do."
137
else if (context->hasType(Context::FileContext))
140
const FileContext *fcontext = static_cast<const FileContext*>(context);
142
//use context and plug actions here
144
else if (context->hasType(Context::ProjectModelItemContext))
146
// project tree context menu
147
const ProjectModelItemContext *pcontext = static_cast<const ProjectModelItemContext*>(context);
149
// use context and plug actions here
151
else if (context->hasType(Context::CodeModelItemContext))
153
// class tree context menu
154
const CodeModelItemContext *mcontext = static_cast<const CodeModelItemContext*>(context);
156
// use context and plug actions here
158
else if (context->hasType(Context::DocumentationContext))
160
// documentation viewer context menu
161
const DocumentationContext *dcontext = static_cast<const DocumentationContext*>(context);
163
// use context and plug actions here
167
void %{APPNAME}Part::projectOpened()
169
// do something when the project is opened
172
void %{APPNAME}Part::projectClosed()
174
// do something when the project is closed
177
void %{APPNAME}Part::doSomething()
179
// do something useful here instead of showing the message box
180
KMessageBox::information(m_widget, i18n("This action does nothing."), i18n("%{APPNAME} Plugin"));
183
#include "%{APPNAMELC}part.moc"