summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Haumann <dhaumann@kde.org>2014-01-20 13:48:22 (GMT)
committerDominik Haumann <dhaumann@kde.org>2014-01-20 13:51:36 (GMT)
commita23814ba19d6193d482067fdfd79486bdbff258b (patch)
tree6e025848d407f2e9f9eaadb10f5f41abc7618d6f
parentf4585e8a37eadac4931c42aa9a1450e7c125d890 (diff)
initial port of xml completion plugin
-rw-r--r--addons/kate/xmltools/CMakeLists.txt77
-rw-r--r--addons/kate/xmltools/katexmltools.desktop3
-rw-r--r--addons/kate/xmltools/plugin_katexmltools.cpp120
-rw-r--r--addons/kate/xmltools/plugin_katexmltools.h56
4 files changed, 119 insertions, 137 deletions
diff --git a/addons/kate/xmltools/CMakeLists.txt b/addons/kate/xmltools/CMakeLists.txt
index 05474a7..6e77569 100644
--- a/addons/kate/xmltools/CMakeLists.txt
+++ b/addons/kate/xmltools/CMakeLists.txt
@@ -1,59 +1,38 @@
+project(katexmltoolsplugin)
+# Load the frameworks we need
+find_package(KF5 CONFIG REQUIRED COMPONENTS KDE4Support)
+# TODO: Remove these later
+remove_definitions(-DQT_NO_CAST_TO_ASCII)
+remove_definitions(-DQT_NO_CAST_FROM_ASCII)
+remove_definitions(-DQT_NO_URL_CAST_FROM_STRING)
+remove_definitions(-DQT_NO_CAST_FROM_BYTEARRAY)
+set(katexmltoolsplugin_PART_SRCS
+ pseudo_dtd.cpp
+ plugin_katexmltools.cpp
+)
-########### next target ###############
+add_library(katexmltoolsplugin MODULE ${katexmltoolsplugin_PART_SRCS})
-set(katexmltoolsplugin_PART_SRCS pseudo_dtd.cpp plugin_katexmltools.cpp )
-
-
-kde4_add_plugin(katexmltoolsplugin ${katexmltoolsplugin_PART_SRCS})
-
-
-
-target_link_libraries(katexmltoolsplugin ${KDE4_KDECORE_LIBS} kateinterfaces ktexteditor)
+target_link_libraries(katexmltoolsplugin
+ KF5::TextEditor
+ KF5::Parts
+ KF5::IconThemes
+ KF5::I18n
+ KF5::Service
+ KF5::KDE4Support
+)
+########### install files ###############
install(TARGETS katexmltoolsplugin DESTINATION ${PLUGIN_INSTALL_DIR} )
+install( FILES ui.rc DESTINATION ${DATA_INSTALL_DIR}/katexmltools )
+install( FILES html4-loose.dtd.xml html4-strict.dtd.xml kde-docbook.dtd.xml simplify_dtd.xsl
+ xhtml1-frameset.dtd.xml xhtml1-strict.dtd.xml xhtml1-transitional.dtd.xml xslt-1.0.dtd.xml
+ testcases.xml language.dtd.xml kpartgui.dtd.xml kcfg.dtd.xml
+ DESTINATION ${DATA_INSTALL_DIR}/katexmltools )
-########### install files ###############
-
-install( FILES ui.rc DESTINATION ${DATA_INSTALL_DIR}/kate/plugins/katexmltools )
-install( FILES html4-loose.dtd.xml html4-strict.dtd.xml kde-docbook.dtd.xml simplify_dtd.xsl xhtml1-frameset.dtd.xml xhtml1-strict.dtd.xml xhtml1-transitional.dtd.xml xslt-1.0.dtd.xml testcases.xml language.dtd.xml kpartgui.dtd.xml kcfg.dtd.xml DESTINATION ${DATA_INSTALL_DIR}/katexmltools )
+kservice_desktop_to_json (katexmltools.desktop)
install( FILES katexmltools.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
-
-
-
-
-#original Makefile.am contents follow:
-
-#INCLUDES = $(all_includes)
-#METASOURCES = AUTO
-#
-## Install this plugin in the KDE modules directory
-#kde_module_LTLIBRARIES = katexmltoolsplugin.la
-#
-## This is all standard. Remove the LIB_KHTML reference if you are not
-## using the KHTML Part
-#katexmltoolsplugin_la_SOURCES = pseudo_dtd.cpp plugin_katexmltools.cpp
-#katexmltoolsplugin_la_LIBADD = -lkateinterfaces
-#katexmltoolsplugin_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries)
-#
-## Install the .rc file in the Part's directory (in this case, the part
-## is KHTMLPart)
-#pluginsdir = $(kde_datadir)/kate/plugins/katexmltools
-#plugins_DATA = ui.rc
-#
-#xmldir = $(kde_datadir)/katexmltools
-#xml_DATA = html4-loose.dtd.xml html4-strict.dtd.xml kde-docbook.dtd.xml \
-# simplify_dtd.xsl xhtml1-frameset.dtd.xml xhtml1-strict.dtd.xml \
-# xhtml1-transitional.dtd.xml xslt-1.0.dtd.xml \
-# testcases.xml language.dtd.xml kpartgui.dtd.xml kcfg.dtd.xml
-#
-##deskdir=$(kde_datadir)/kate/plugins
-##desk_DATA=katexmltools.desktop
-#
-#kde_services_DATA = katexmltools.desktop
-#
-#messages: rc.cpp
-# $(XGETTEXT) *.cpp -o $(podir)/katexmltools.pot
diff --git a/addons/kate/xmltools/katexmltools.desktop b/addons/kate/xmltools/katexmltools.desktop
index 4a3a31b..db03b70 100644
--- a/addons/kate/xmltools/katexmltools.desktop
+++ b/addons/kate/xmltools/katexmltools.desktop
@@ -1,8 +1,7 @@
[Desktop Entry]
Type=Service
-ServiceTypes=Kate/Plugin
+ServiceTypes=KTextEditor/Plugin
X-KDE-Library=katexmltoolsplugin
-X-Kate-Version=2.9
Name=XML Completion
Name[ast]=Terminación XML
Name[bg]=Довършване на XML
diff --git a/addons/kate/xmltools/plugin_katexmltools.cpp b/addons/kate/xmltools/plugin_katexmltools.cpp
index 0ae8b86..6cd2b40 100644
--- a/addons/kate/xmltools/plugin_katexmltools.cpp
+++ b/addons/kate/xmltools/plugin_katexmltools.cpp
@@ -66,7 +66,6 @@ TODO:
*/
#include "plugin_katexmltools.h"
-#include "plugin_katexmltools.moc"
#include <assert.h>
@@ -80,8 +79,11 @@ TODO:
#include <qtimer.h>
#include <QLabel>
#include <QVBoxLayout>
-
#include <QAction>
+#include <QStandardPaths>
+
+#include <ktexteditor/editor.h>
+#include <kaction.h>
#include <kactioncollection.h>
#include <kapplication.h>
#include <klineedit.h>
@@ -94,15 +96,16 @@ TODO:
#include <kmessagebox.h>
#include <kstandarddirs.h>
#include <kpluginfactory.h>
+#include <kxmlguiclient.h>
+#include <kxmlguifactory.h>
+#include <kurl.h>
-K_PLUGIN_FACTORY(PluginKateXMLToolsFactory, registerPlugin<PluginKateXMLTools>();)
-K_EXPORT_PLUGIN(PluginKateXMLToolsFactory("katexmltools"))
-
-using Kate::application;
-
+K_PLUGIN_FACTORY_WITH_JSON (PluginKateXMLToolsFactory,
+ "katexmltools.json",
+ registerPlugin<PluginKateXMLTools>();)
PluginKateXMLTools::PluginKateXMLTools( QObject* const parent, const QVariantList& )
- : Kate::Plugin ( (Kate::Application *)parent )
+ : KTextEditor::Plugin(parent)
{
}
@@ -110,18 +113,23 @@ PluginKateXMLTools::~PluginKateXMLTools()
{
}
-Kate::PluginView *PluginKateXMLTools::createView(Kate::MainWindow *mainWindow)
+QObject *PluginKateXMLTools::createView(KTextEditor::MainWindow *mainWindow)
{
- return new PluginKateXMLToolsView(mainWindow);
+ return new PluginKateXMLToolsView(this, mainWindow);
}
-PluginKateXMLToolsView::PluginKateXMLToolsView(Kate::MainWindow* const win)
- : Kate::PluginView ( win ), Kate::XMLGUIClient ( PluginKateXMLToolsFactory::componentData() ),
- m_model ( this )
+PluginKateXMLToolsView::PluginKateXMLToolsView(KTextEditor::Plugin *plugin,
+ KTextEditor::MainWindow *mainWin)
+ : QObject(mainWin)
+ , KXMLGUIClient()
+ , m_mainWindow(mainWin)
+ , m_model(this)
{
//qDebug() << "PluginKateXMLTools constructor called";
+ KXMLGUIClient::setComponentName(QLatin1String("katexmltools"), i18n ("Kate XML Tools"));
+ setXMLFile(QLatin1String("ui.rc"));
KAction *actionInsert = new KAction ( i18n("&Insert Element..."), this );
actionInsert->setShortcut( Qt::CTRL+Qt::Key_Return );
@@ -137,24 +145,23 @@ PluginKateXMLToolsView::PluginKateXMLToolsView(Kate::MainWindow* const win)
connect( actionAssignDTD, SIGNAL(triggered()), &m_model, SLOT(getDTD()) );
actionCollection()->addAction( "xml_tool_assign", actionAssignDTD );
- win->guiFactory()->addClient( this );
+ mainWin->guiFactory()->addClient( this );
- connect( application()->documentManager(), SIGNAL(documentDeleted(KTextEditor::Document*)),
+ connect( KTextEditor::Editor::instance()->application(), SIGNAL(documentDeleted(KTextEditor::Document*)),
&m_model, SLOT(slotDocumentDeleted(KTextEditor::Document*)) );
-
}
PluginKateXMLToolsView::~PluginKateXMLToolsView()
{
- mainWindow()->guiFactory()->removeClient (this);
+ m_mainWindow->guiFactory()->removeClient (this);
//qDebug() << "xml tools descructor 1...";
//TODO: unregister the model
}
PluginKateXMLToolsCompletionModel::PluginKateXMLToolsCompletionModel( QObject* const parent )
- : CodeCompletionModel2 (parent)
- , m_docToAssignTo(0)
+ : CodeCompletionModel (parent)
+ , m_viewToAssignTo(0)
, m_mode(none)
, m_correctPos(0)
{
@@ -192,11 +199,9 @@ void PluginKateXMLToolsCompletionModel::slotDocumentDeleted( KTextEditor::Docume
}
-void PluginKateXMLToolsCompletionModel::completionInvoked(
- KTextEditor::View *kv
- , const KTextEditor::Range &range
- , const InvocationType invocationType
- )
+void PluginKateXMLToolsCompletionModel::completionInvoked(KTextEditor::View *kv,
+ const KTextEditor::Range &range,
+ const InvocationType invocationType)
{
Q_UNUSED( range )
Q_UNUSED( invocationType )
@@ -322,7 +327,9 @@ QModelIndex PluginKateXMLToolsCompletionModel::parent(const QModelIndex& index)
return createIndex(0, 0, groupNode);
}
-QModelIndex PluginKateXMLToolsCompletionModel::index(const int row, const int column, const QModelIndex &parent) const
+QModelIndex PluginKateXMLToolsCompletionModel::index(const int row,
+ const int column,
+ const QModelIndex &parent) const
{
if (!parent.isValid())
{
@@ -332,7 +339,7 @@ QModelIndex PluginKateXMLToolsCompletionModel::index(const int row, const int co
if (parent.internalId() == groupNode) // Is this a group node?
{
if (0 <= row && row < m_allowed.size()) // Make sure to return only valid indices
- return createIndex(row, column, 0); // Just return a leaf-level index
+ return createIndex(row, column, (void*)0); // Just return a leaf-level index
}
// Leaf node has no children... nothing to return
return QModelIndex();
@@ -393,10 +400,10 @@ bool PluginKateXMLToolsCompletionModel::shouldStartCompletion( KTextEditor::View
*/
void PluginKateXMLToolsCompletionModel::getDTD()
{
- if ( !application()->activeMainWindow() )
+ if ( !KTextEditor::Editor::instance()->application()->activeMainWindow() )
return;
- KTextEditor::View *kv = application()->activeMainWindow()->activeView();
+ KTextEditor::View *kv = KTextEditor::Editor::instance()->application()->activeMainWindow()->activeView();
if( ! kv )
{
qDebug() << "Warning: no KTextEditor::View";
@@ -406,8 +413,7 @@ void PluginKateXMLToolsCompletionModel::getDTD()
// ### replace this with something more sane
// Start where the supplied XML-DTDs are fed by default unless
// user changed directory last time:
-
- QString defaultDir = KGlobal::dirs()->findResourceDir("data", "katexmltools/" ) + "katexmltools/";
+ QString defaultDir = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "katexmltools") + "/katexmltools/";
if( m_urlString.isNull() ) {
m_urlString = defaultDir;
}
@@ -485,11 +491,11 @@ void PluginKateXMLToolsCompletionModel::getDTD()
m_urlString = url.url(); // remember directory for next time
if ( m_dtds[ m_urlString ] )
- assignDTD( m_dtds[ m_urlString ], kv->document() );
+ assignDTD( m_dtds[ m_urlString ], kv );
else
{
m_dtdString.clear();
- m_docToAssignTo = kv->document();
+ m_viewToAssignTo = kv;
KApplication::setOverrideCursor( Qt::WaitCursor );
KIO::Job *job = KIO::get( url );
@@ -520,10 +526,10 @@ void PluginKateXMLToolsCompletionModel::slotFinished( KJob *job )
dtd->analyzeDTD( m_urlString, m_dtdString );
m_dtds.insert( m_urlString, dtd );
- assignDTD( dtd, m_docToAssignTo );
+ assignDTD( dtd, m_viewToAssignTo );
// clean up a bit
- m_docToAssignTo = 0;
+ m_viewToAssignTo = 0;
m_dtdString.clear();
}
QApplication::restoreOverrideCursor();
@@ -534,20 +540,19 @@ void PluginKateXMLToolsCompletionModel::slotData( KIO::Job *, const QByteArray &
m_dtdString += QString( data );
}
-void PluginKateXMLToolsCompletionModel::assignDTD( PseudoDTD *dtd, KTextEditor::Document *doc )
+void PluginKateXMLToolsCompletionModel::assignDTD( PseudoDTD *dtd, KTextEditor::View *view)
{
- m_docDtds.insert( doc, dtd );
+ m_docDtds.insert( view->document(), dtd );
//TODO:perhaps foreach views()?
- KTextEditor::CodeCompletionInterface *cci = qobject_cast<KTextEditor::CodeCompletionInterface *>(doc->activeView());
+ KTextEditor::CodeCompletionInterface *cci = qobject_cast<KTextEditor::CodeCompletionInterface *>(view);
- if( cci ) {
+ if (cci) {
cci->registerCompletionModel( this );
cci->setAutomaticInvocationEnabled( true );
qDebug() << "PluginKateXMLToolsView: completion model registered";
- }
- else {
- kWarning() << "PluginKateXMLToolsView: completion interface unavailable";
+ } else {
+ qWarning() << "PluginKateXMLToolsView: completion interface unavailable";
}
}
@@ -558,10 +563,10 @@ void PluginKateXMLToolsCompletionModel::assignDTD( PseudoDTD *dtd, KTextEditor::
*/
void PluginKateXMLToolsCompletionModel::slotInsertElement()
{
- if ( !application()->activeMainWindow() )
+ if ( !KTextEditor::Editor::instance()->application()->activeMainWindow() )
return;
- KTextEditor::View *kv = application()->activeMainWindow()->activeView();
+ KTextEditor::View *kv = KTextEditor::Editor::instance()->application()->activeMainWindow()->activeView();
if( ! kv )
{
qDebug() << "Warning: no KTextEditor::View";
@@ -577,7 +582,7 @@ void PluginKateXMLToolsCompletionModel::slotInsertElement()
allowed = dtd->allowedElements(parentElement );
InsertElement *dialog = new InsertElement(
- ( QWidget *)application()->activeMainWindow()->activeView(), "insertXml" );
+ ( QWidget *)KTextEditor::Editor::instance()->application()->activeMainWindow()->activeView(), "insertXml" );
QString text = dialog->showDialog( allowed );
delete dialog;
@@ -632,10 +637,10 @@ void PluginKateXMLToolsCompletionModel::slotInsertElement()
*/
void PluginKateXMLToolsCompletionModel::slotCloseElement()
{
- if ( !application()->activeMainWindow() )
+ if ( !KTextEditor::Editor::instance()->application()->activeMainWindow() )
return;
- KTextEditor::View *kv = application()->activeMainWindow()->activeView();
+ KTextEditor::View *kv = KTextEditor::Editor::instance()->application()->activeMainWindow()->activeView();
if( ! kv )
{
qDebug() << "Warning: no KTextEditor::View";
@@ -651,25 +656,19 @@ void PluginKateXMLToolsCompletionModel::slotCloseElement()
// modify the completion string before it gets inserted
-void PluginKateXMLToolsCompletionModel::executeCompletionItem2( KTextEditor::Document *document,
- const KTextEditor::Range &word,
- const QModelIndex &index ) const
+void PluginKateXMLToolsCompletionModel::executeCompletionItem(KTextEditor::View *view,
+ const KTextEditor::Range &word,
+ const QModelIndex &index) const
{
KTextEditor::Range toReplace = word;
+ KTextEditor::Document * document = view->document();
QString text = data( index.sibling( index.row(), Name ), Qt::DisplayRole ).toString();
qDebug() << "executeCompletionItem text: " << text;
- KTextEditor::View *kv = document->activeView();
- if( ! kv )
- {
- qDebug() << "Warning (filterInsertString() ): no KTextEditor::View";
- return;
- }
-
int line, col;
- kv->cursorPosition().position( line, col );
+ view->cursorPosition().position( line, col );
QString lineStr = document->line( line );
QString leftCh = lineStr.mid( col-1, 1 );
QString rightCh = lineStr.mid( col, 1 );
@@ -749,9 +748,9 @@ void PluginKateXMLToolsCompletionModel::executeCompletionItem2( KTextEditor::Doc
document->replaceText( toReplace, text );
// move the cursor to desired position
- KTextEditor::Cursor curPos = kv->cursorPosition();
+ KTextEditor::Cursor curPos = view->cursorPosition();
curPos.setColumn( curPos.column() + posCorrection );
- kv->setCursorPosition( curPos );
+ view->setCursorPosition( curPos );
}
@@ -1132,4 +1131,7 @@ QString InsertElement::showDialog( QStringList &completions )
return QString();
}
//END InsertElement dialog
+
+#include "plugin_katexmltools.moc"
+
// kate: space-indent on; indent-width 2; replace-tabs on; mixed-indent off;
diff --git a/addons/kate/xmltools/plugin_katexmltools.h b/addons/kate/xmltools/plugin_katexmltools.h
index b33d82c..98ed188 100644
--- a/addons/kate/xmltools/plugin_katexmltools.h
+++ b/addons/kate/xmltools/plugin_katexmltools.h
@@ -27,11 +27,9 @@
#include <qstring.h>
-#include <kate/plugin.h>
-#include <kate/application.h>
-#include <kate/documentmanager.h>
-#include <kate/mainwindow.h>
-
+#include <ktexteditor/plugin.h>
+#include <ktexteditor/application.h>
+#include <ktexteditor/mainwindow.h>
#include <ktexteditor/document.h>
#include <ktexteditor/view.h>
#include <ktexteditor/codecompletioninterface.h>
@@ -39,22 +37,22 @@
#include <ktexteditor/codecompletionmodelcontrollerinterface.h>
#include <kcombobox.h>
-#include <kdialog.h>
+#include <KDE4Support/kdialog.h>
#include <QVariantList>
-class PluginKateXMLTools : public Kate::Plugin
+class PluginKateXMLTools : public KTextEditor::Plugin
{
Q_OBJECT
public:
explicit PluginKateXMLTools( QObject* parent = 0, const QVariantList& = QVariantList() );
~PluginKateXMLTools();
- Kate::PluginView *createView(Kate::MainWindow *mainWindow);
+ virtual QObject *createView(KTextEditor::MainWindow *mainWindow);
};
class PluginKateXMLToolsCompletionModel
- : public KTextEditor::CodeCompletionModel2
+ : public KTextEditor::CodeCompletionModel
, public KTextEditor::CodeCompletionModelControllerInterface
{
Q_OBJECT
@@ -64,24 +62,28 @@ class PluginKateXMLToolsCompletionModel
PluginKateXMLToolsCompletionModel( QObject *parent );
virtual ~PluginKateXMLToolsCompletionModel();
+ //
+ // KTextEditor::CodeCompletionModel
+ //
+ public:
virtual int columnCount(const QModelIndex&) const;
virtual int rowCount(const QModelIndex &parent) const;
virtual QModelIndex parent(const QModelIndex& index) const;
virtual QModelIndex index(int row, int column, const QModelIndex& parent) const;
virtual QVariant data(const QModelIndex &idx, int role) const;
- virtual void executeCompletionItem2(
- KTextEditor::Document *document
- , const KTextEditor::Range &word
- , const QModelIndex &index
- ) const;
+ virtual void executeCompletionItem(KTextEditor::View *view,
+ const KTextEditor::Range &word,
+ const QModelIndex &index) const;
- virtual bool shouldStartCompletion(
- KTextEditor::View *view
- , const QString &insertedText
- , bool userInsertion
- , const KTextEditor::Cursor &position
- );
+ //
+ // KTextEditor::CodeCompletionModelControllerInterface
+ //
+ public:
+ virtual bool shouldStartCompletion(KTextEditor::View *view,
+ const QString &insertedText,
+ bool userInsertion,
+ const KTextEditor::Cursor &position);
public Q_SLOTS:
@@ -119,13 +121,13 @@ class PluginKateXMLToolsCompletionModel
enum Level {groupNode = 1};
- /// Assign the PseudoDTD @p dtd to the Kate::Document @p doc
- void assignDTD( PseudoDTD *dtd, KTextEditor::Document *doc );
+ /// Assign the PseudoDTD @p dtd to the Kate::View @p view
+ void assignDTD(PseudoDTD *dtd, KTextEditor::View *view);
/// temporary placeholder for the metaDTD file
QString m_dtdString;
- /// temporary placeholder for the document to assign a DTD to while the file is loaded
- KTextEditor::Document *m_docToAssignTo;
+ /// temporary placeholder for the view to assign a DTD to while the file is loaded
+ KTextEditor::View *m_viewToAssignTo;
/// URL of the last loaded meta DTD
QString m_urlString;
@@ -144,18 +146,18 @@ class PluginKateXMLToolsCompletionModel
QHash<QString, PseudoDTD *> m_dtds;
};
-class PluginKateXMLToolsView : public Kate::PluginView, public Kate::XMLGUIClient
+class PluginKateXMLToolsView : public QObject, public KXMLGUIClient
{
Q_OBJECT
public:
- explicit PluginKateXMLToolsView( Kate::MainWindow *win);
+ explicit PluginKateXMLToolsView(KTextEditor::Plugin *plugin, KTextEditor::MainWindow *mainWin);
virtual ~PluginKateXMLToolsView();
protected:
+ KTextEditor::MainWindow *m_mainWindow;
PluginKateXMLToolsCompletionModel m_model;
- Kate::DocumentManager *m_documentManager;
};
class InsertElement : public KDialog