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
|
/*
* File : snippet_part.cpp
*
* Author: Robert Gruber <rgruber@users.sourceforge.net>
*
* Copyright: See COPYING file that comes with this distribution
*/
#include "snippet_part.h"
#include <qwhatsthis.h>
#include <kaction.h>
#include <kiconloader.h>
#include <klocale.h>
#include <kaboutdata.h>
#include <qvbox.h>
#include <kdialogbase.h>
#include <klineedit.h>
#include <qcheckbox.h>
#include <qbuttongroup.h>
#include <ktrader.h>
#include "kdevcore.h"
#include <kdevproject.h>
#include "kdevmainwindow.h"
#include <kdevgenericfactory.h>
#include <kdevplugininfo.h>
#include <kdebug.h>
#include "snippet_widget.h"
#include "snippetitem.h"
#include "snippetsettings.h"
#include "snippetconfig.h"
static const KDevPluginInfo data("kdevsnippet");
typedef KDevGenericFactory<SnippetPart> snippetFactory;
K_EXPORT_COMPONENT_FACTORY( libkdevsnippet, snippetFactory( data ) )
SnippetPart::SnippetPart(QObject *parent, const char *name, const QStringList& )
: KDevPlugin(&data, parent, name ? name : "SnippetPart" )
{
setInstance(snippetFactory::instance());
setXMLFile("kdevpart_snippet.rc");
m_widget = new SnippetWidget(this);
m_widget->setCaption(i18n("Code Snippets"));
m_widget->setIcon(SmallIcon( info()->icon() ));
QWhatsThis::add(m_widget, i18n("<b>Code Snippet</b><p>This is a list of available snippets."));
mainWindow()->embedSelectViewRight( m_widget, i18n("Code Snippets"), i18n("Insert a code snippet") );
connect( core(), SIGNAL( configWidget( KDialogBase * ) ), this, SLOT( slotConfigWidget( KDialogBase * ) ) );
/*The next two connects are used to check if certain SnippetGroups need to be opened
according to the languages supported by this project*/
connect( core(), SIGNAL( projectOpened() ), m_widget, SLOT( languageChanged() ) );
connect( core(), SIGNAL( languageChanged() ), m_widget, SLOT( languageChanged() ) );
setupActions();
}
SnippetPart::~SnippetPart()
{
if ( m_widget )
{
mainWindow()->removeView( m_widget );
}
delete m_widget;
}
void SnippetPart::setupActions()
{
new KAction( i18n("Show Snippet Tree"), CTRL+ALT+SHIFT+Key_S, this, SLOT(slotShowView()), actionCollection(), "snippet_showview");
}
/*!
\fn SnippetPart::aboutData()
*/
KAboutData* SnippetPart::aboutData()
{
KAboutData *data = new KAboutData ("snippetpart", I18N_NOOP("SnippetPart"), "1.1",
I18N_NOOP( "SnippetPart for KDevelop" ),
KAboutData::License_LGPL_V2,
I18N_NOOP( "(c) 2003" ), 0, "http://www.kdevelop.org");
data->addAuthor ("Robert Gruber", I18N_NOOP("Author"), "rgruber@users.sourceforge.net", "http://kmp3indexer.sf.net");
return data;
}
/*!
\fn SnippetPart::slotConfigWidget( KDialogBase *dlg )
*/
void SnippetPart::slotConfigWidget( KDialogBase *dlg )
{
QVBox *vbox = dlg->addVBoxPage( i18n("Code Snippets"), i18n("Code Snippets"), BarIcon( info()->icon(), KIcon::SizeMedium ) );
SnippetSettings * w = new SnippetSettings( m_widget, vbox );
w->btnGroup->setButton(m_widget->getSnippetConfig()->getInputMethod());
w->leDelimiter->setText(m_widget->getSnippetConfig()->getDelimiter());
w->cbToolTip->setChecked(m_widget->getSnippetConfig()->useToolTips());
w->btnGroupAutoOpen->setButton(m_widget->getSnippetConfig()->getAutoOpenGroups());
connect( dlg, SIGNAL(okClicked()), w, SLOT(slotOKClicked()) );
}
QStringList SnippetPart::getAllLanguages()
{
KTrader::OfferList languageSupportOffers =
KTrader::self()->query(QString::fromLatin1("KDevelop/LanguageSupport"),
QString::fromLatin1("[X-KDevelop-Version] == %1"
).arg( KDEVELOP_PLUGIN_VERSION ));
QStringList languages;
for (KTrader::OfferList::ConstIterator it = languageSupportOffers.begin(); it != languageSupportOffers.end(); ++it)
{
QString language = (*it)->property("X-KDevelop-Language").toString();
languages.append(language);
kdDebug(9035) << "Found language: " << (*it)->property("X-KDevelop-Language").toString() << endl <<
"genericName(): " <<(*it)->genericName() << endl <<
"comment(): " <<(*it)->comment() << endl << endl;
}
return languages;
}
QStringList SnippetPart::getProjectLanguages()
{
QStringList languages;
if (!projectDom())
return languages;
QDomDocument m_projectDom = *projectDom();
if (m_widget->getSnippetConfig()->getAutoOpenGroups() == 1)
languages = DomUtil::readListEntry(m_projectDom, "/general/secondaryLanguages", "language");
languages.prepend( DomUtil::readEntry(m_projectDom, "/general/primarylanguage") );
return languages;
}
void SnippetPart::slotShowView()
{
mainWindow()->raiseView( m_widget );
}
#include "snippet_part.moc"
|