~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to languages/cpp/app_templates/kdevpart/kdevpart_part.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
%{CPP_TEMPLATE}
2
 
#include "%{APPNAMELC}part.h"
3
 
 
4
 
#include <qtimer.h>
5
 
#include <qpopupmenu.h>
6
 
#include <qwhatsthis.h>
7
 
 
8
 
#include <klocale.h>
9
 
#include <kaction.h>
10
 
#include <kdialogbase.h>
11
 
#include <kiconloader.h>
12
 
#include <kmessagebox.h>
13
 
#include <kdevplugininfo.h>
14
 
#include <kdevgenericfactory.h>
15
 
 
16
 
#include <kdevcore.h>
17
 
#include <kdevmainwindow.h>
18
 
#include <configwidgetproxy.h>
19
 
 
20
 
#include "%{APPNAMELC}widget.h"
21
 
#include "%{APPNAMELC}globalconfig.h"
22
 
#include "%{APPNAMELC}projectconfig.h"
23
 
 
24
 
typedef KDevGenericFactory<%{APPNAME}Part> %{APPNAME}Factory;
25
 
KDevPluginInfo data("kdev%{APPNAMELC}");
26
 
K_EXPORT_COMPONENT_FACTORY( libkdev%{APPNAMELC}, %{APPNAME}Factory( data ) );
27
 
 
28
 
#define GLOBALDOC_OPTIONS 1
29
 
#define PROJECTDOC_OPTIONS 2
30
 
 
31
 
%{APPNAME}Part::%{APPNAME}Part(QObject *parent, const char *name, const QStringList &/*args*/)
32
 
    : KDevPlugin(&data, parent, name ? name : "%{APPNAME}Part")
33
 
{
34
 
    setInstance(%{APPNAME}Factory::instance());
35
 
    setXMLFile("kdev%{APPNAMELC}.rc");
36
 
 
37
 
    m_widget = new %{APPNAME}Widget(this);
38
 
    m_widget->setCaption("widget caption");
39
 
    m_widget->setIcon(SmallIcon(info()->icon()));
40
 
 
41
 
    QWhatsThis::add(m_widget, i18n("WHAT DOES THIS PART DO?"));
42
 
    
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.
45
 
    
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" );
49
 
    
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" );
53
 
    
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" );
57
 
    
58
 
    setupActions();
59
 
    
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)));
65
 
 
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()));
70
 
  
71
 
        
72
 
    QTimer::singleShot(0, this, SLOT(init()));
73
 
}
74
 
 
75
 
%{APPNAME}Part::~%{APPNAME}Part()
76
 
{
77
 
// if you embed a widget, you need to tell the mainwindow when you remove it
78
 
//     if ( m_widget )
79
 
//     {
80
 
//         mainWindow()->removeView( m_widget );
81
 
//     }
82
 
    delete m_widget;
83
 
    delete m_configProxy;
84
 
}
85
 
 
86
 
void %{APPNAME}Part::init()
87
 
{
88
 
// delayed initialization stuff goes here
89
 
}
90
 
 
91
 
void %{APPNAME}Part::setupActions()
92
 
{
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."));
98
 
}
99
 
 
100
 
void %{APPNAME}Part::insertConfigWidget(const KDialogBase *dlg, QWidget *page, unsigned int pageNo)
101
 
{
102
 
// create configuraton dialogs here
103
 
    switch (pageNo)
104
 
    {
105
 
        case GLOBALDOC_OPTIONS:
106
 
        {
107
 
            %{APPNAME}GlobalConfig *w = new %{APPNAME}GlobalConfig(this, page, "global config");
108
 
            connect(dlg, SIGNAL(okClicked()), w, SLOT(accept()));
109
 
            break;
110
 
        }
111
 
        case PROJECTDOC_OPTIONS:
112
 
        {
113
 
            %{APPNAME}ProjectConfig *w = new %{APPNAME}ProjectConfig(this, page, "project config");
114
 
            connect(dlg, SIGNAL(okClicked()), w, SLOT(accept()));
115
 
            break;
116
 
        }
117
 
    }
118
 
}
119
 
 
120
 
void %{APPNAME}Part::contextMenu(QPopupMenu *popup, const Context *context)
121
 
{
122
 
// put actions into the context menu here
123
 
    if (context->hasType(Context::EditorContext))
124
 
    {
125
 
        // editor context menu
126
 
        const EditorContext *econtext = static_cast<const EditorContext*>(context);
127
 
        
128
 
        // use context and plug actions here
129
 
        action->plug(popup);
130
 
        
131
 
        // or create menu items on the fly
132
 
        // int id = -1;
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."
136
 
    }
137
 
    else if (context->hasType(Context::FileContext)) 
138
 
    {
139
 
        // file context menu
140
 
        const FileContext *fcontext = static_cast<const FileContext*>(context);
141
 
        
142
 
        //use context and plug actions here
143
 
    }
144
 
    else if (context->hasType(Context::ProjectModelItemContext)) 
145
 
    {
146
 
        // project tree context menu
147
 
        const ProjectModelItemContext *pcontext = static_cast<const ProjectModelItemContext*>(context);
148
 
        
149
 
        // use context and plug actions here
150
 
    }
151
 
    else if (context->hasType(Context::CodeModelItemContext)) 
152
 
    {
153
 
        // class tree context menu
154
 
        const CodeModelItemContext *mcontext = static_cast<const CodeModelItemContext*>(context);
155
 
        
156
 
        // use context and plug actions here
157
 
    }
158
 
    else if (context->hasType(Context::DocumentationContext)) 
159
 
    {
160
 
        // documentation viewer context menu
161
 
        const DocumentationContext *dcontext = static_cast<const DocumentationContext*>(context);
162
 
        
163
 
        // use context and plug actions here
164
 
    }
165
 
}
166
 
 
167
 
void %{APPNAME}Part::projectOpened()
168
 
{
169
 
// do something when the project is opened
170
 
}
171
 
 
172
 
void %{APPNAME}Part::projectClosed()
173
 
{
174
 
// do something when the project is closed
175
 
}
176
 
 
177
 
void %{APPNAME}Part::doSomething()
178
 
{
179
 
// do something useful here instead of showing the message box
180
 
    KMessageBox::information(m_widget, i18n("This action does nothing."), i18n("%{APPNAME} Plugin"));
181
 
}
182
 
 
183
 
#include "%{APPNAMELC}part.moc"