summaryrefslogtreecommitdiffstats
path: root/languages/cpp/app_templates/kdevpart/kdevpart_part.cpp
blob: 96ddb6ca7ac0cdf2d6b6c785600504da4a117d3a (plain)
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
%{CPP_TEMPLATE}
#include "%{APPNAMELC}part.h"

#include <tqtimer.h>
#include <tqpopupmenu.h>
#include <tqwhatsthis.h>

#include <klocale.h>
#include <kaction.h>
#include <kdialogbase.h>
#include <kiconloader.h>
#include <kmessagebox.h>
#include <kdevplugininfo.h>
#include <kdevgenericfactory.h>

#include <kdevcore.h>
#include <kdevmainwindow.h>
#include <configwidgetproxy.h>

#include "%{APPNAMELC}widget.h"
#include "%{APPNAMELC}globalconfig.h"
#include "%{APPNAMELC}projectconfig.h"

typedef KDevGenericFactory<%{APPNAME}Part> %{APPNAME}Factory;
KDevPluginInfo data("kdev%{APPNAMELC}");
K_EXPORT_COMPONENT_FACTORY( libkdev%{APPNAMELC}, %{APPNAME}Factory( data ) );

#define GLOBALDOC_OPTIONS 1
#define PROJECTDOC_OPTIONS 2

%{APPNAME}Part::%{APPNAME}Part(TQObject *tqparent, const char *name, const TQStringList &/*args*/)
    : KDevPlugin(&data, tqparent, name ? name : "%{APPNAME}Part")
{
    setInstance(%{APPNAME}Factory::instance());
    setXMLFile("kdev%{APPNAMELC}.rc");

    m_widget = new %{APPNAME}Widget(this);
    m_widget->setCaption("widget caption");
    m_widget->setIcon(SmallIcon(info()->icon()));

    TQWhatsThis::add(m_widget, i18n("WHAT DOES THIS PART DO?"));
    
    // now you decide what should happen to the widget. Take a look at kdevcore.h
    // or at other plugins how to embed it.
    
    // if you want to embed your widget as an outputview, simply uncomment
    // the following line.
    // mainWindow()->embedOutputView( m_widget, "name that should appear", "enter a tooltip" );
    
    // if you want to embed your widget as a selectview (at the left), simply uncomment
    // the following line.
    // mainWindow()->embedSelectView( m_widget, "name that should appear", "enter a tooltip" );
    
    // if you want to embed your widget as a selectview (at the right), simply uncomment
    // the following line.
    // mainWindow()->embedSelectViewRight( m_widget, "name that should appear", "enter a tooltip" );
    
    setupActions();
    
    m_configProxy = new ConfigWidgetProxy(core());
    m_configProxy->createGlobalConfigPage(i18n("%{APPNAME}"), GLOBALDOC_OPTIONS, info()->icon());
    m_configProxy->createProjectConfigPage(i18n("%{APPNAME}"), PROJECTDOC_OPTIONS, info()->icon());
    connect(m_configProxy, TQT_SIGNAL(insertConfigWidget(const KDialogBase*, TQWidget*, unsigned int )),
        this, TQT_SLOT(insertConfigWidget(const KDialogBase*, TQWidget*, unsigned int)));

    connect(core(), TQT_SIGNAL(contextMenu(TQPopupMenu *, const Context *)),
        this, TQT_SLOT(contextMenu(TQPopupMenu *, const Context *)));
    connect(core(), TQT_SIGNAL(projectOpened()), this, TQT_SLOT(projectOpened()));
    connect(core(), TQT_SIGNAL(projectClosed()), this, TQT_SLOT(projectClosed()));
  
        
    TQTimer::singleShot(0, this, TQT_SLOT(init()));
}

%{APPNAME}Part::~%{APPNAME}Part()
{
// if you embed a widget, you need to tell the mainwindow when you remove it
//     if ( m_widget )
//     {
//         mainWindow()->removeView( m_widget );
//     }
    delete m_widget;
    delete m_configProxy;
}

void %{APPNAME}Part::init()
{
// delayed initialization stuff goes here
}

void %{APPNAME}Part::setupActions()
{
// create XMLGUI actions here
    action = new KAction(i18n("&Do Something..."), 0,
        this, TQT_SLOT(doSomething()), actionCollection(), "plugin_action" );
    action->setToolTip(i18n("Do something"));
    action->setWhatsThis(i18n("<b>Do something</b><p>Describe here what does this action do."));
}

void %{APPNAME}Part::insertConfigWidget(const KDialogBase *dlg, TQWidget *page, unsigned int pageNo)
{
// create configuraton dialogs here
    switch (pageNo)
    {
        case GLOBALDOC_OPTIONS:
        {
            %{APPNAME}GlobalConfig *w = new %{APPNAME}GlobalConfig(this, page, "global config");
            connect(dlg, TQT_SIGNAL(okClicked()), w, TQT_SLOT(accept()));
            break;
        }
        case PROJECTDOC_OPTIONS:
        {
            %{APPNAME}ProjectConfig *w = new %{APPNAME}ProjectConfig(this, page, "project config");
            connect(dlg, TQT_SIGNAL(okClicked()), w, TQT_SLOT(accept()));
            break;
        }
    }
}

void %{APPNAME}Part::contextMenu(TQPopupMenu *popup, const Context *context)
{
// put actions into the context menu here
    if (context->hasType(Context::EditorContext))
    {
        // editor context menu
        const EditorContext *econtext = static_cast<const EditorContext*>(context);
        
        // use context and plug actions here
        action->plug(popup);
        
        // or create menu items on the fly
        // int id = -1;
        // id = popup->insertItem(i18n("Do Something Here"),
        //     this, TQT_SLOT(doSomething()) );
        // popup->setWhatsThis(id, i18n("<b>Do something here</b><p>Describe here what does this action do."
    }
    else if (context->hasType(Context::FileContext)) 
    {
        // file context menu
        const FileContext *fcontext = static_cast<const FileContext*>(context);
        
        //use context and plug actions here
    }
    else if (context->hasType(Context::ProjectModelItemContext)) 
    {
        // project tree context menu
        const ProjectModelItemContext *pcontext = static_cast<const ProjectModelItemContext*>(context);
        
        // use context and plug actions here
    }
    else if (context->hasType(Context::CodeModelItemContext)) 
    {
        // class tree context menu
        const CodeModelItemContext *mcontext = static_cast<const CodeModelItemContext*>(context);
        
        // use context and plug actions here
    }
    else if (context->hasType(Context::DocumentationContext)) 
    {
        // documentation viewer context menu
        const DocumentationContext *dcontext = static_cast<const DocumentationContext*>(context);
        
        // use context and plug actions here
    }
}

void %{APPNAME}Part::projectOpened()
{
// do something when the project is opened
}

void %{APPNAME}Part::projectClosed()
{
// do something when the project is closed
}

void %{APPNAME}Part::doSomething()
{
// do something useful here instead of showing the message box
    KMessageBox::information(m_widget, i18n("This action does nothing."), i18n("%{APPNAME} Plugin"));
}

#include "%{APPNAMELC}part.moc"