1
/* Description : Kate CTags plugin
3
* Copyright (C) 2008-2011 by Kare Sars <kare.sars@iki.fi>
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public
7
* License as published by the Free Software Foundation; either
8
* version 2.1 of the License, or (at your option) version 3, or any
9
* later version accepted by the membership of KDE e.V. (or its
10
* successor approved by the membership of KDE e.V.), which shall
11
* act as a proxy defined in Section 6 of version 3 of the license.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* General Public License for more details.
18
* You should have received a copy of the GNU General Public
19
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
22
#include "kate_ctags_plugin.h"
25
#include <KFileDialog>
29
#include <kactioncollection.h>
30
#include <kstringhandler.h>
31
#include <kmessagebox.h>
32
#include <kstandarddirs.h>
34
#include <kpluginfactory.h>
35
#include <kpluginloader.h>
36
#include <kaboutdata.h>
38
K_PLUGIN_FACTORY(KateCTagsPluginFactory, registerPlugin<KateCTagsPlugin>();)
39
K_EXPORT_PLUGIN(KateCTagsPluginFactory(KAboutData("katectags", "kate-ctags-plugin",
40
ki18n("CTags Plugin"), "0.2",
41
ki18n( "CTags Plugin"))))
43
/******************************************************************/
44
KateCTagsPlugin::KateCTagsPlugin(QObject* parent, const QList<QVariant>&):
45
Kate::Plugin ((Kate::Application*)parent), m_view(0)
47
KGlobal::locale()->insertCatalog("kate-ctags-plugin");
50
/******************************************************************/
51
Kate::PluginView *KateCTagsPlugin::createView(Kate::MainWindow *mainWindow)
53
m_view = new KateCTagsView(mainWindow, KateCTagsPluginFactory::componentData());
58
/******************************************************************/
59
Kate::PluginConfigPage *KateCTagsPlugin::configPage (uint number, QWidget *parent, const char *)
61
if (number != 0) return 0;
62
return new KateCTagsConfigPage(parent, this);
65
/******************************************************************/
66
QString KateCTagsPlugin::configPageName (uint number) const
68
if (number != 0) return QString();
72
/******************************************************************/
73
QString KateCTagsPlugin::configPageFullName (uint number) const
75
if (number != 0) return QString();
76
return i18n("CTags Settings");
79
/******************************************************************/
80
KIcon KateCTagsPlugin::configPageIcon (uint number) const
82
if (number != 0) return KIcon();
83
return KIcon("text-x-csrc");
86
/******************************************************************/
87
void KateCTagsPlugin::readConfig()
94
/******************************************************************/
95
KateCTagsConfigPage::KateCTagsConfigPage( QWidget* parent, KateCTagsPlugin *plugin )
96
: Kate::PluginConfigPage( parent )
99
m_confUi.setupUi(this);
100
m_confUi.cmdEdit->setText(DEFAULT_CTAGS_CMD);
102
m_confUi.addButton->setToolTip(i18n("Add a directory to index."));
103
m_confUi.addButton->setIcon(KIcon("list-add"));
105
m_confUi.delButton->setToolTip(i18n("Remove a directory."));
106
m_confUi.delButton->setIcon(KIcon("list-remove"));
108
m_confUi.updateDB->setToolTip(i18n("(Re-)generate the common CTags database."));
109
m_confUi.updateDB->setIcon(KIcon("view-refresh"));
111
connect(m_confUi.updateDB, SIGNAL(clicked()), this, SLOT(updateGlobalDB()));
112
connect(m_confUi.addButton, SIGNAL(clicked()), this, SLOT(addGlobalTagTarget()));
113
connect(m_confUi.delButton, SIGNAL(clicked()), this, SLOT(delGlobalTagTarget()));
115
connect(&m_proc, SIGNAL(finished(int,QProcess::ExitStatus)),
116
this, SLOT(updateDone(int,QProcess::ExitStatus)));
121
/******************************************************************/
122
void KateCTagsConfigPage::apply()
124
KConfigGroup config(KGlobal::config(), "CTags");
125
config.writeEntry("GlobalCommand", m_confUi.cmdEdit->text());
127
config.writeEntry("GlobalNumTargets", m_confUi.targetList->count());
130
for (int i=0; i<m_confUi.targetList->count(); i++) {
131
nr = QString("%1").arg(i,3);
132
config.writeEntry("GlobalTarget_"+nr, m_confUi.targetList->item(i)->text());
137
/******************************************************************/
138
void KateCTagsConfigPage::reset()
140
KConfigGroup config(KGlobal::config(), "CTags");
141
m_confUi.cmdEdit->setText(config.readEntry("GlobalCommand", DEFAULT_CTAGS_CMD));
143
int numEntries = config.readEntry("GlobalNumTargets", 0);
146
for (int i=0; i<numEntries; i++) {
147
nr = QString("%1").arg(i,3);
148
target = config.readEntry("GlobalTarget_"+nr, QString());
149
if (!listContains(target)) {
150
new QListWidgetItem(target, m_confUi.targetList);
157
/******************************************************************/
158
void KateCTagsConfigPage::addGlobalTagTarget()
160
KFileDialog dialog(KUrl(), QString(), 0, 0);
161
dialog.setMode(KFile::Directory | KFile::Files | KFile::ExistingOnly | KFile::LocalOnly);
163
// i18n("CTags Database Location"));
164
if (dialog.exec() != QDialog::Accepted) {
168
QStringList urls = dialog.selectedFiles();
170
for (int i=0; i<urls.size(); i++) {
171
if (!listContains(urls[i])) {
172
new QListWidgetItem(urls[i], m_confUi.targetList);
179
/******************************************************************/
180
void KateCTagsConfigPage::delGlobalTagTarget()
182
delete m_confUi.targetList->currentItem ();
186
/******************************************************************/
187
bool KateCTagsConfigPage::listContains(const QString &target)
189
for (int i=0; i<m_confUi.targetList->count(); i++) {
190
if (m_confUi.targetList->item(i)->text() == target) {
197
/******************************************************************/
198
void KateCTagsConfigPage::updateGlobalDB()
200
if (m_proc.state() != QProcess::NotRunning) {
206
for (int i=0; i<m_confUi.targetList->count(); i++) {
207
target = m_confUi.targetList->item(i)->text();
208
if (target.endsWith('/') || target.endsWith('\\')) {
209
target = target.left(target.size() - 1);
211
targets += target + " ";
214
QString file = KStandardDirs::locateLocal("appdata", "plugins/katectags/common_db", true);
216
if (targets.isEmpty()) {
221
QString command = QString("%1 -f %2 %3").arg(m_confUi.cmdEdit->text()).arg(file).arg(targets) ;
223
m_proc.setShellCommand(command);
224
m_proc.setOutputChannelMode(KProcess::SeparateChannels);
227
if(!m_proc.waitForStarted(500)) {
228
KMessageBox::error(0, i18n("Failed to run \"%1\". exitStatus = %2", command, m_proc.exitStatus()));
231
m_confUi.updateDB->setDisabled(true);
232
QApplication::setOverrideCursor(QCursor(Qt::BusyCursor));
235
/******************************************************************/
236
void KateCTagsConfigPage::updateDone(int exitCode, QProcess::ExitStatus status)
238
if (status == QProcess::CrashExit) {
239
KMessageBox::error(this, i18n("The CTags executable crashed."));
241
else if (exitCode != 0) {
242
KMessageBox::error(this, i18n("The CTags command exited with code %1", exitCode));
245
m_confUi.updateDB->setDisabled(false);
246
QApplication::restoreOverrideCursor();