Commit 01ee0142 authored by Kåre Särs's avatar Kåre Särs

Port the CTags plugin to frameworks and re-enable building

parent 77f1c74c
......@@ -31,7 +31,7 @@ ecm_optional_add_subdirectory ( backtracebrowser )
#add_subdirectory( filetemplates )
#add_subdirectory( kate-ctags )
add_subdirectory( kate-ctags )
#add_subdirectory( katebuild-plugin )
#add_subdirectory( kttsd )
......
# building separately or as part of kdesdk?
if(NOT KDE4_FOUND)
find_package(KDE4 REQUIRED)
endif(NOT KDE4_FOUND)
include_directories (${KDE4_INCLUDES})
include_directories( ${KDE4_KIO_INCLUDES} )
include_directories( ${CMAKE_CURRENT_BINARY_DIR} )
set(ctagsplugin_SRC
......@@ -15,15 +8,15 @@ set(ctagsplugin_SRC
kate_ctags_plugin.cpp
)
kde4_add_ui_files(ctagsplugin_SRC kate_ctags.ui CTagsGlobalConfig.ui)
kde4_add_plugin(katectagsplugin ${ctagsplugin_SRC})
qt5_wrap_ui(ctagsplugin_SRC kate_ctags.ui CTagsGlobalConfig.ui)
target_link_libraries(katectagsplugin ${KDE4_KDECORE_LIBS} kateinterfaces ktexteditor )
add_library(katectagsplugin MODULE ${ctagsplugin_SRC})
install(TARGETS katectagsplugin DESTINATION ${PLUGIN_INSTALL_DIR} )
target_link_libraries(katectagsplugin KF5::TextEditor KF5::I18n KF5::IconThemes)
########### install files ###############
install(TARGETS katectagsplugin DESTINATION ${PLUGIN_INSTALL_DIR} )
install(FILES ui.rc DESTINATION ${DATA_INSTALL_DIR}/katectags)
install(FILES ui.rc DESTINATION ${DATA_INSTALL_DIR}/kate/plugins/katectags)
kservice_desktop_to_json (katectagsplugin.desktop)
install(FILES katectagsplugin.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
......@@ -10,7 +10,7 @@
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="KListWidget" name="targetList"/>
<widget class="QListWidget" name="targetList"/>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_2">
......@@ -49,7 +49,7 @@
</widget>
</item>
<item row="3" column="0">
<widget class="KPushButton" name="updateDB">
<widget class="QPushButton" name="updateDB">
<property name="text">
<string>Update</string>
</property>
......@@ -67,7 +67,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="KLineEdit" name="cmdEdit">
<widget class="QLineEdit" name="cmdEdit">
<property name="frame">
<bool>true</bool>
</property>
......@@ -78,23 +78,6 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KListWidget</class>
<extends>QListWidget</extends>
<header>klistwidget.h</header>
</customwidget>
<customwidget>
<class>KPushButton</class>
<extends>QPushButton</extends>
<header>kpushbutton.h</header>
</customwidget>
<customwidget>
<class>KLineEdit</class>
<extends>QLineEdit</extends>
<header>klineedit.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
......@@ -274,7 +274,7 @@ static CTagsExtensionMapping extensionMapping[] = {
static CTagsKindMapping *findKindMapping(const QString &extension)
{
const char *pextension = extension.toLocal8Bit();
const char *pextension = extension.toLocal8Bit().constData();
CTagsExtensionMapping *pem = extensionMapping;
while (pem->extension != 0) {
......
......@@ -4,7 +4,7 @@
<widget class="QWidget" name="kateCtags">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="KTabWidget" name="tabWidget">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
......@@ -14,14 +14,14 @@
</attribute>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="KLineEdit" name="inputEdit">
<widget class="QLineEdit" name="inputEdit">
<property name="showClearButton" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="KPushButton" name="updateButton">
<widget class="QPushButton" name="updateButton">
<property name="text">
<string>Update Index</string>
</property>
......@@ -57,7 +57,7 @@
</attribute>
<layout class="QGridLayout" name="gridLayout_2" columnstretch="1,0,0">
<item row="0" column="0" rowspan="4" colspan="2">
<widget class="KListWidget" name="targetList"/>
<widget class="QListWidget" name="targetList"/>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="addButton">
......@@ -121,7 +121,7 @@
</widget>
</item>
<item row="3" column="1">
<widget class="KLineEdit" name="cmdEdit">
<widget class="QLineEdit" name="cmdEdit">
<property name="frame">
<bool>true</bool>
</property>
......@@ -168,27 +168,6 @@
<extends>QFrame</extends>
<header>kurlrequester.h</header>
</customwidget>
<customwidget>
<class>KListWidget</class>
<extends>QListWidget</extends>
<header>klistwidget.h</header>
</customwidget>
<customwidget>
<class>KPushButton</class>
<extends>QPushButton</extends>
<header>kpushbutton.h</header>
</customwidget>
<customwidget>
<class>KLineEdit</class>
<extends>QLineEdit</extends>
<header>klineedit.h</header>
</customwidget>
<customwidget>
<class>KTabWidget</class>
<extends>QTabWidget</extends>
<header>ktabwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
......
......@@ -22,65 +22,65 @@
#include "kate_ctags_plugin.h"
#include <QFileInfo>
#include <KFileDialog>
#include <QFileDialog>
#include <QCheckBox>
#include <kmenu.h>
#include <KConfigGroup>
#include <kactioncollection.h>
#include <kstringhandler.h>
#include <kmessagebox.h>
#include <kstandarddirs.h>
#include <ktexteditor/editor.h>
#include <klocalizedstring.h>
#include <kpluginfactory.h>
#include <kpluginloader.h>
#include <kaboutdata.h>
K_PLUGIN_FACTORY(KateCTagsPluginFactory, registerPlugin<KateCTagsPlugin>();)
K_EXPORT_PLUGIN(KateCTagsPluginFactory(KAboutData("katectags", "kate-ctags-plugin",
ki18n("CTags Plugin"), "0.2",
ki18n( "CTags Plugin"))))
K_PLUGIN_FACTORY_WITH_JSON (KateCTagsPluginFactory, "katectagsplugin.json", registerPlugin<KateCTagsPlugin>();)
/******************************************************************/
KateCTagsPlugin::KateCTagsPlugin(QObject* parent, const QList<QVariant>&):
Kate::Plugin ((Kate::Application*)parent), m_view(0)
KTextEditor::Plugin (parent), m_view(0)
{
KGlobal::locale()->insertCatalog("kate-ctags-plugin");
// FIXME KF5
//KGlobal::locale()->insertCatalog("kate-ctags-plugin");
}
/******************************************************************/
Kate::PluginView *KateCTagsPlugin::createView(Kate::MainWindow *mainWindow)
QObject *KateCTagsPlugin::createView(KTextEditor::MainWindow *mainWindow)
{
m_view = new KateCTagsView(mainWindow, KateCTagsPluginFactory::componentData());
m_view = new KateCTagsView(this, mainWindow);
return m_view;
}
/******************************************************************/
KTextEditor::ConfigPage *KateCTagsPlugin::configPage (uint number, QWidget *parent, const char *)
KTextEditor::ConfigPage *KateCTagsPlugin::configPage (int number, QWidget *parent)
{
if (number != 0) return 0;
return new KateCTagsConfigPage(parent, this);
}
/******************************************************************/
QString KateCTagsPlugin::configPageName (uint number) const
QString KateCTagsPlugin::configPageName (int number) const
{
if (number != 0) return QString();
return i18n("CTags");
}
/******************************************************************/
QString KateCTagsPlugin::configPageFullName (uint number) const
QString KateCTagsPlugin::configPageFullName (int number) const
{
if (number != 0) return QString();
return i18n("CTags Settings");
}
/******************************************************************/
KIcon KateCTagsPlugin::configPageIcon (uint number) const
QIcon KateCTagsPlugin::configPageIcon (int number) const
{
if (number != 0) return KIcon();
return KIcon("text-x-csrc");
if (number != 0) return QIcon();
return QIcon::fromTheme(QStringLiteral("text-x-csrc"));
}
/******************************************************************/
......@@ -100,13 +100,13 @@ KateCTagsConfigPage::KateCTagsConfigPage( QWidget* parent, KateCTagsPlugin *plug
m_confUi.cmdEdit->setText(DEFAULT_CTAGS_CMD);
m_confUi.addButton->setToolTip(i18n("Add a directory to index."));
m_confUi.addButton->setIcon(KIcon("list-add"));
m_confUi.addButton->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
m_confUi.delButton->setToolTip(i18n("Remove a directory."));
m_confUi.delButton->setIcon(KIcon("list-remove"));
m_confUi.delButton->setIcon(QIcon::fromTheme(QStringLiteral("list-remove")));
m_confUi.updateDB->setToolTip(i18n("(Re-)generate the common CTags database."));
m_confUi.updateDB->setIcon(KIcon("view-refresh"));
m_confUi.updateDB->setIcon(QIcon::fromTheme(QStringLiteral("view-refresh")));
connect(m_confUi.updateDB, SIGNAL(clicked()), this, SLOT(updateGlobalDB()));
connect(m_confUi.addButton, SIGNAL(clicked()), this, SLOT(addGlobalTagTarget()));
......@@ -121,15 +121,15 @@ KateCTagsConfigPage::KateCTagsConfigPage( QWidget* parent, KateCTagsPlugin *plug
/******************************************************************/
void KateCTagsConfigPage::apply()
{
KConfigGroup config(KGlobal::config(), "CTags");
KConfigGroup config(KSharedConfig::openConfig(), QStringLiteral("CTags"));
config.writeEntry("GlobalCommand", m_confUi.cmdEdit->text());
config.writeEntry("GlobalNumTargets", m_confUi.targetList->count());
QString nr;
for (int i=0; i<m_confUi.targetList->count(); i++) {
nr = QString("%1").arg(i,3);
config.writeEntry("GlobalTarget_"+nr, m_confUi.targetList->item(i)->text());
nr = QStringLiteral("%1").arg(i,3);
config.writeEntry(QStringLiteral("GlobalTarget_")+nr, m_confUi.targetList->item(i)->text());
}
config.sync();
}
......@@ -137,15 +137,15 @@ void KateCTagsConfigPage::apply()
/******************************************************************/
void KateCTagsConfigPage::reset()
{
KConfigGroup config(KGlobal::config(), "CTags");
m_confUi.cmdEdit->setText(config.readEntry("GlobalCommand", DEFAULT_CTAGS_CMD));
KConfigGroup config(KSharedConfig::openConfig(), "CTags");
m_confUi.cmdEdit->setText(config.readEntry(QStringLiteral("GlobalCommand"), DEFAULT_CTAGS_CMD));
int numEntries = config.readEntry("GlobalNumTargets", 0);
int numEntries = config.readEntry(QStringLiteral("GlobalNumTargets"), 0);
QString nr;
QString target;
for (int i=0; i<numEntries; i++) {
nr = QString("%1").arg(i,3);
target = config.readEntry("GlobalTarget_"+nr, QString());
nr = QStringLiteral("%1").arg(i,3);
target = config.readEntry(QStringLiteral("GlobalTarget_")+nr, QString());
if (!listContains(target)) {
new QListWidgetItem(target, m_confUi.targetList);
}
......@@ -157,8 +157,9 @@ void KateCTagsConfigPage::reset()
/******************************************************************/
void KateCTagsConfigPage::addGlobalTagTarget()
{
KFileDialog dialog(KUrl(), QString(), 0, 0);
dialog.setMode(KFile::Directory | KFile::Files | KFile::ExistingOnly | KFile::LocalOnly);
QFileDialog dialog;
dialog.setFileMode(QFileDialog::Directory);
//dialog.setMode(KFile::Directory | KFile::Files | KFile::ExistingOnly | KFile::LocalOnly);
// i18n("CTags Database Location"));
if (dialog.exec() != QDialog::Accepted) {
......@@ -205,24 +206,23 @@ void KateCTagsConfigPage::updateGlobalDB()
QString target;
for (int i=0; i<m_confUi.targetList->count(); i++) {
target = m_confUi.targetList->item(i)->text();
if (target.endsWith('/') || target.endsWith('\\')) {
if (target.endsWith(QLatin1Char('/')) || target.endsWith(QLatin1Char('\\'))) {
target = target.left(target.size() - 1);
}
targets += target + ' ';
targets += target + QLatin1Char(' ');
}
QString file = KStandardDirs::locateLocal("appdata", "plugins/katectags/common_db", true);
QString file = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QLatin1String("/katectags");
QDir().mkpath(file);
file += QLatin1String("/common_db");
if (targets.isEmpty()) {
QFile::remove(file);
return;
}
QString command = QString("%1 -f %2 %3").arg(m_confUi.cmdEdit->text()).arg(file).arg(targets) ;
m_proc.setShellCommand(command);
m_proc.setOutputChannelMode(KProcess::SeparateChannels);
m_proc.start();
QString command = QStringLiteral("%1 -f %2 %3").arg(m_confUi.cmdEdit->text()).arg(file).arg(targets) ;
m_proc.start(command);
if(!m_proc.waitForStarted(500)) {
KMessageBox::error(0, i18n("Failed to run \"%1\". exitStatus = %2", command, m_proc.exitStatus()));
......@@ -246,4 +246,5 @@ void KateCTagsConfigPage::updateDone(int exitCode, QProcess::ExitStatus status)
QApplication::restoreOverrideCursor();
}
#include "kate_ctags_plugin.moc"
......@@ -25,17 +25,17 @@
#include <ktexteditor/view.h>
#include <ktexteditor/document.h>
#include <kate/plugin.h>
#include <kate/application.h>
#include <kate/documentmanager.h>
#include <kate/mainwindow.h>
#include <ktexteditor/application.h>
#include <ktexteditor/mainwindow.h>
#include <ktexteditor/configpageinterface.h>
#include <KTextEditor/ConfigPage>
#include <KTextEditor/Plugin>
#include "kate_ctags_view.h"
#include "ui_CTagsGlobalConfig.h"
//******************************************************************/
class KateCTagsPlugin : public Kate::Plugin, public KTextEditor::ConfigPageInterface
class KateCTagsPlugin : public KTextEditor::Plugin, public KTextEditor::ConfigPageInterface
{
Q_OBJECT
Q_INTERFACES(KTextEditor::ConfigPageInterface)
......@@ -44,14 +44,14 @@ class KateCTagsPlugin : public Kate::Plugin, public KTextEditor::ConfigPageInter
explicit KateCTagsPlugin(QObject* parent = 0, const QList<QVariant> & = QList<QVariant>());
virtual ~KateCTagsPlugin() {}
Kate::PluginView *createView(Kate::MainWindow *mainWindow);
QObject *createView(KTextEditor::MainWindow *mainWindow);
// PluginConfigPageInterface
uint configPages() const { return 1; };
KTextEditor::ConfigPage *configPage (uint number = 0, QWidget *parent = 0, const char *name = 0);
QString configPageName (uint number = 0) const;
QString configPageFullName (uint number = 0) const;
KIcon configPageIcon (uint number = 0) const;
int configPages() const { return 1; };
KTextEditor::ConfigPage *configPage (int number = 0, QWidget *parent = 0);
QString configPageName (int number = 0) const;
QString configPageFullName (int number = 0) const;
QIcon configPageIcon (int number = 0) const;
void readConfig();
KateCTagsView *m_view;
......@@ -78,7 +78,7 @@ private:
bool listContains(const QString &target);
KProcess m_proc;
QProcess m_proc;
KateCTagsPlugin *m_plugin;
Ui_CTagsGlobalConfig m_confUi;
};
......
This diff is collapsed.
......@@ -22,45 +22,46 @@
*/
#include <ktexteditor/view.h>
#include <ktexteditor/document.h>
#include <KTextEditor/View>
#include <KTextEditor/Document>
#include <kate/plugin.h>
#include <kate/application.h>
#include <kate/documentmanager.h>
#include <kate/mainwindow.h>
#include <ktexteditor/configpageinterface.h>
#include <KTextEditor/Application>
#include <KTextEditor/MainWindow>
#include <ktexteditor/sessionconfiginterface.h>
#include <kprocess.h>
#include <kactionmenu.h>
#include <QProcess>
#include <KXMLGUIClient>
#include <QStack>
#include <QTimer>
#include <KActionMenu>
#include <QPointer>
#include "tags.h"
#include "ui_kate_ctags.h"
#define DEFAULT_CTAGS_CMD "ctags -R --c++-types=+px --extra=+q --excmd=pattern --exclude=Makefile --exclude=."
const static QString DEFAULT_CTAGS_CMD = QLatin1String("ctags -R --c++-types=+px --extra=+q --excmd=pattern --exclude=Makefile --exclude=.");
typedef struct
{
KUrl url;
QUrl url;
KTextEditor::Cursor cursor;
} TagJump;
/******************************************************************/
class KateCTagsView : public Kate::PluginView, public Kate::XMLGUIClient
class KateCTagsView : public QObject, public KXMLGUIClient, public KTextEditor::SessionConfigInterface
{
Q_OBJECT
Q_INTERFACES(KTextEditor::SessionConfigInterface)
public:
KateCTagsView(Kate::MainWindow *mw, const KComponentData& componentData);
KateCTagsView(KTextEditor::Plugin *plugin, KTextEditor::MainWindow *mainWin);
~KateCTagsView();
// overwritten: read and write session config
void readSessionConfig (KConfigBase* config, const QString& groupPrefix);
void writeSessionConfig (KConfigBase* config, const QString& groupPrefix);
// reimplemented: read and write session config
void readSessionConfig (const KConfigGroup& config);
void writeSessionConfig (KConfigGroup& config);
public Q_SLOTS:
void gotoDefinition();
......@@ -97,7 +98,7 @@ private:
void jumpToTag(const QString &file, const QString &pattern, const QString &word);
Kate::MainWindow *m_mWin;
KTextEditor::MainWindow *m_mWin;
QWidget *m_toolView;
Ui::kateCtags m_ctagsUi;
......@@ -106,7 +107,7 @@ private:
QAction *m_gotoDec;
QAction *m_lookup;
KProcess m_proc;
QProcess m_proc;
QString m_commonDB;
QTimer m_editTimer;
......
[Desktop Entry]
Type=Service
ServiceTypes=Kate/Plugin
ServiceTypes=KTextEditor/Plugin
X-KDE-Library=katectagsplugin
X-Kate-Version=2.9
Name=CTags
Name[bg]=CTags
Name[bs]=C‑tags
......
......@@ -30,10 +30,10 @@ Tags::TagEntry::TagEntry( const QString & tag, const QString & type, const QStri
bool Tags::hasTag( const QString & tag )
{
ctags::tagFileInfo info;
ctags::tagFile * file = ctags::tagsOpen( _tagsfile.toLocal8Bit(), &info );
ctags::tagFile * file = ctags::tagsOpen( _tagsfile.toLocal8Bit().constData(), &info );
ctags::tagEntry entry;
bool found = ( ctags::tagsFind( file, &entry, tag.toLocal8Bit(), TAG_FULLMATCH | TAG_OBSERVECASE ) == ctags::TagSuccess );
bool found = ( ctags::tagsFind( file, &entry, tag.toLocal8Bit().constData(), TAG_FULLMATCH | TAG_OBSERVECASE ) == ctags::TagSuccess );
ctags::tagsClose( file );
......@@ -47,7 +47,7 @@ unsigned int Tags::numberOfMatches( const QString & tagpart, bool partial )
if ( tagpart.isEmpty() ) return 0;
ctags::tagFileInfo info;
ctags::tagFile * file = ctags::tagsOpen( _tagsfile.toLocal8Bit(), &info );
ctags::tagFile * file = ctags::tagsOpen( _tagsfile.toLocal8Bit().constData(), &info );
ctags::tagEntry entry;
QByteArray tagpartBArray = tagpart.toLocal8Bit(); // for holding the char *
......@@ -72,7 +72,7 @@ Tags::TagList Tags::getMatches( const QString & tagpart, bool partial, const QSt
if ( tagpart.isEmpty() ) return list;
ctags::tagFileInfo info;
ctags::tagFile * file = ctags::tagsOpen( _tagsfile.toLocal8Bit(), &info );
ctags::tagFile * file = ctags::tagsOpen( _tagsfile.toLocal8Bit().constData(), &info );
ctags::tagEntry entry;
QByteArray tagpartBArray = tagpart.toLocal8Bit(); // for holding the char *
......@@ -80,16 +80,16 @@ Tags::TagList Tags::getMatches( const QString & tagpart, bool partial, const QSt
{
do
{
QString type( CTagsKinds::findKind( entry.kind, QString( entry.file ).section( '.', -1 ) ) );
QString file( entry.file );
QString type( CTagsKinds::findKind( entry.kind, QString::fromLocal8Bit(entry.file).section( QLatin1Char('.') , -1 ) ) );
QString file = QString::fromLocal8Bit( entry.file );
if ( type.isEmpty() && file.endsWith( "Makefile" ) )
if ( type.isEmpty() && file.endsWith( QLatin1String("Makefile") ) )
{
type = "macro";
type = QLatin1String("macro");
}
if ( types.isEmpty() || types.contains( entry.kind ) )
if ( types.isEmpty() || types.contains( QString::fromLocal8Bit(entry.kind) ) )
{
list << TagEntry( QString( entry.name ), type, file, QString( entry.address.pattern ) );
list << TagEntry( QString::fromLocal8Bit( entry.name ), type, file, QString::fromLocal8Bit( entry.address.pattern ) );
}
}
while ( ctags::tagsFindNext( file, &entry ) == ctags::TagSuccess );
......@@ -102,7 +102,7 @@ Tags::TagList Tags::getMatches( const QString & tagpart, bool partial, const QSt
void Tags::setTagsFile( const QString & file )
{
_tagsfile = file.toLocal8Bit();
_tagsfile = file;
}
QString Tags::getTagsFile( )
......@@ -148,6 +148,6 @@ Tags::TagList Tags::getMatches( const QString & file, const QString & tagpart,
return getMatches( tagpart, partial, types);
}
// kate: space-indent off; indent-width 4; tab-width 4; show-tabs off;
// kate: space-indent off; indent-width 4; tab-width 4; show-tabs on;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment