summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Haumann <dhaumann@kde.org>2014-01-20 13:51:23 (GMT)
committerDominik Haumann <dhaumann@kde.org>2014-01-20 13:51:36 (GMT)
commit1170457cb72e03a67c50c2303a3092604ecd0192 (patch)
treee71aa2b48aacfff4a6650e47980e468d73bacef3
parenta23814ba19d6193d482067fdfd79486bdbff258b (diff)
astyle: format code
-rw-r--r--addons/kate/xmltools/plugin_katexmltools.cpp1521
-rw-r--r--addons/kate/xmltools/plugin_katexmltools.h100
-rw-r--r--addons/kate/xmltools/pseudo_dtd.cpp664
-rw-r--r--addons/kate/xmltools/pseudo_dtd.h46
4 files changed, 1147 insertions, 1184 deletions
diff --git a/addons/kate/xmltools/plugin_katexmltools.cpp b/addons/kate/xmltools/plugin_katexmltools.cpp
index 6cd2b40..89c9cb1 100644
--- a/addons/kate/xmltools/plugin_katexmltools.cpp
+++ b/addons/kate/xmltools/plugin_katexmltools.cpp
@@ -4,8 +4,8 @@
List elements, attributes, attribute values and entities allowed by DTD.
Needs a DTD in XML format ( as produced by dtdparse ) for most features.
- copyright : ( C ) 2001-2002 by Daniel Naber
- email : daniel.naber@t-online.de
+ copyright : ( C ) 2001-2002 by Daniel Naber
+ email : daniel.naber@t-online.de
Copyright (C) 2005 by Anders Lund <anders@alweb.dk>
@@ -100,11 +100,11 @@ TODO:
#include <kxmlguifactory.h>
#include <kurl.h>
-K_PLUGIN_FACTORY_WITH_JSON (PluginKateXMLToolsFactory,
- "katexmltools.json",
- registerPlugin<PluginKateXMLTools>();)
+K_PLUGIN_FACTORY_WITH_JSON(PluginKateXMLToolsFactory,
+ "katexmltools.json",
+ registerPlugin<PluginKateXMLTools>();)
-PluginKateXMLTools::PluginKateXMLTools( QObject* const parent, const QVariantList& )
+PluginKateXMLTools::PluginKateXMLTools(QObject *const parent, const QVariantList &)
: KTextEditor::Plugin(parent)
{
}
@@ -115,282 +115,267 @@ PluginKateXMLTools::~PluginKateXMLTools()
QObject *PluginKateXMLTools::createView(KTextEditor::MainWindow *mainWindow)
{
- return new PluginKateXMLToolsView(this, mainWindow);
+ return new PluginKateXMLToolsView(this, mainWindow);
}
PluginKateXMLToolsView::PluginKateXMLToolsView(KTextEditor::Plugin *plugin,
- KTextEditor::MainWindow *mainWin)
- : QObject(mainWin)
- , KXMLGUIClient()
- , m_mainWindow(mainWin)
- , m_model(this)
+ KTextEditor::MainWindow *mainWin)
+ : QObject(mainWin)
+ , KXMLGUIClient()
+ , m_mainWindow(mainWin)
+ , m_model(this)
{
- //qDebug() << "PluginKateXMLTools constructor called";
+ //qDebug() << "PluginKateXMLTools constructor called";
- KXMLGUIClient::setComponentName(QLatin1String("katexmltools"), i18n ("Kate XML Tools"));
- setXMLFile(QLatin1String("ui.rc"));
+ 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 );
- connect( actionInsert, SIGNAL(triggered()), &m_model, SLOT(slotInsertElement()) );
- actionCollection()->addAction( "xml_tool_insert_element", actionInsert );
+ KAction *actionInsert = new KAction(i18n("&Insert Element..."), this);
+ actionInsert->setShortcut(Qt::CTRL + Qt::Key_Return);
+ connect(actionInsert, SIGNAL(triggered()), &m_model, SLOT(slotInsertElement()));
+ actionCollection()->addAction("xml_tool_insert_element", actionInsert);
- KAction *actionClose = new KAction ( i18n("&Close Element"), this );
- actionClose->setShortcut( Qt::CTRL+Qt::Key_Less );
- connect( actionClose, SIGNAL(triggered()), &m_model, SLOT(slotCloseElement()) );
- actionCollection()->addAction( "xml_tool_close_element", actionClose );
+ KAction *actionClose = new KAction(i18n("&Close Element"), this);
+ actionClose->setShortcut(Qt::CTRL + Qt::Key_Less);
+ connect(actionClose, SIGNAL(triggered()), &m_model, SLOT(slotCloseElement()));
+ actionCollection()->addAction("xml_tool_close_element", actionClose);
- KAction *actionAssignDTD = new KAction ( i18n("Assign Meta &DTD..." ), this );
- connect( actionAssignDTD, SIGNAL(triggered()), &m_model, SLOT(getDTD()) );
- actionCollection()->addAction( "xml_tool_assign", actionAssignDTD );
+ KAction *actionAssignDTD = new KAction(i18n("Assign Meta &DTD..."), this);
+ connect(actionAssignDTD, SIGNAL(triggered()), &m_model, SLOT(getDTD()));
+ actionCollection()->addAction("xml_tool_assign", actionAssignDTD);
- mainWin->guiFactory()->addClient( this );
+ mainWin->guiFactory()->addClient(this);
- connect( KTextEditor::Editor::instance()->application(), SIGNAL(documentDeleted(KTextEditor::Document*)),
- &m_model, SLOT(slotDocumentDeleted(KTextEditor::Document*)) );
+ connect(KTextEditor::Editor::instance()->application(), SIGNAL(documentDeleted(KTextEditor::Document *)),
+ &m_model, SLOT(slotDocumentDeleted(KTextEditor::Document *)));
}
PluginKateXMLToolsView::~PluginKateXMLToolsView()
{
- m_mainWindow->guiFactory()->removeClient (this);
+ m_mainWindow->guiFactory()->removeClient(this);
- //qDebug() << "xml tools descructor 1...";
- //TODO: unregister the model
+ //qDebug() << "xml tools descructor 1...";
+ //TODO: unregister the model
}
-PluginKateXMLToolsCompletionModel::PluginKateXMLToolsCompletionModel( QObject* const parent )
- : CodeCompletionModel (parent)
- , m_viewToAssignTo(0)
- , m_mode(none)
- , m_correctPos(0)
+PluginKateXMLToolsCompletionModel::PluginKateXMLToolsCompletionModel(QObject *const parent)
+ : CodeCompletionModel(parent)
+ , m_viewToAssignTo(0)
+ , m_mode(none)
+ , m_correctPos(0)
{
}
PluginKateXMLToolsCompletionModel::~PluginKateXMLToolsCompletionModel()
{
- qDeleteAll( m_dtds );
- m_dtds.clear();
+ qDeleteAll(m_dtds);
+ m_dtds.clear();
}
-void PluginKateXMLToolsCompletionModel::slotDocumentDeleted( KTextEditor::Document *doc )
+void PluginKateXMLToolsCompletionModel::slotDocumentDeleted(KTextEditor::Document *doc)
{
- // Remove the document from m_DTDs, and also delete the PseudoDTD
- // if it becomes unused.
- if ( m_docDtds.contains (doc) )
- {
- qDebug()<<"XMLTools:slotDocumentDeleted: documents: "<<m_docDtds.count()<<", DTDs: "<<m_dtds.count();
- PseudoDTD *dtd = m_docDtds.take( doc );
-
- if ( m_docDtds.key( dtd ) )
- return;
-
- QHash<QString, PseudoDTD *>::iterator it;
- for ( it = m_dtds.begin() ; it != m_dtds.end() ; ++it )
- {
- if ( it.value() == dtd )
- {
- m_dtds.erase(it);
- delete dtd;
- return;
- }
+ // Remove the document from m_DTDs, and also delete the PseudoDTD
+ // if it becomes unused.
+ if (m_docDtds.contains(doc)) {
+ qDebug() << "XMLTools:slotDocumentDeleted: documents: " << m_docDtds.count() << ", DTDs: " << m_dtds.count();
+ PseudoDTD *dtd = m_docDtds.take(doc);
+
+ if (m_docDtds.key(dtd)) {
+ return;
+ }
+
+ QHash<QString, PseudoDTD *>::iterator it;
+ for (it = m_dtds.begin() ; it != m_dtds.end() ; ++it) {
+ if (it.value() == dtd) {
+ m_dtds.erase(it);
+ delete dtd;
+ return;
+ }
+ }
}
- }
}
void PluginKateXMLToolsCompletionModel::completionInvoked(KTextEditor::View *kv,
- const KTextEditor::Range &range,
- const InvocationType invocationType)
+ const KTextEditor::Range &range,
+ const InvocationType invocationType)
{
- Q_UNUSED( range )
- Q_UNUSED( invocationType )
-
- qDebug() << "xml tools completionInvoked";
-
- KTextEditor::Document *doc = kv->document();
- if( ! m_docDtds[ doc ] )
- // no meta DTD assigned yet
- return;
-
- // debug to test speed:
- //QTime t; t.start();
-
- beginResetModel();
- m_allowed.clear();
-
- // get char on the left of the cursor:
- KTextEditor::Cursor curpos = kv->cursorPosition();
- uint line = curpos.line(), col = curpos.column();
-
- QString lineStr = kv->document()->line( line );
- QString leftCh = lineStr.mid( col-1, 1 );
- QString secondLeftCh = lineStr.mid( col-2, 1 );
-
- if( leftCh == "&" )
- {
- qDebug() << "Getting entities";
- m_allowed = m_docDtds[doc]->entities(QString());
- m_mode = entities;
- }
- else if( leftCh == "<" )
- {
- qDebug() << "*outside tag -> get elements";
- QString parentElement = getParentElement( *kv, 1 );
- qDebug() << "parent: " << parentElement;
- m_allowed = m_docDtds[doc]->allowedElements(parentElement );
- m_mode = elements;
- }
- else if ( leftCh == "/" && secondLeftCh == "<" )
- {
- qDebug() << "*close parent element";
- QString parentElement = getParentElement( *kv, 2 );
-
- if ( ! parentElement.isEmpty() )
- {
- m_mode = closingtag;
- m_allowed = QStringList( parentElement );
- }
- }
- else if( leftCh == " " || (isQuote(leftCh) && secondLeftCh == "=") )
- {
- // TODO: check secondLeftChar, too?! then you don't need to trigger
- // with space and we yet save CPU power
- QString currentElement = insideTag( *kv );
- QString currentAttribute;
- if( ! currentElement.isEmpty() )
- currentAttribute = insideAttribute( *kv );
-
- qDebug() << "Tag: " << currentElement;
- qDebug() << "Attr: " << currentAttribute;
-
- if( ! currentElement.isEmpty() && ! currentAttribute.isEmpty() )
+ Q_UNUSED(range)
+ Q_UNUSED(invocationType)
+
+ qDebug() << "xml tools completionInvoked";
+
+ KTextEditor::Document *doc = kv->document();
+ if (! m_docDtds[ doc ])
+ // no meta DTD assigned yet
{
- qDebug() << "*inside attribute -> get attribute values";
- m_allowed = m_docDtds[doc]->attributeValues(currentElement, currentAttribute );
- if( m_allowed.count() == 1 &&
- (m_allowed[0] == "CDATA" || m_allowed[0] == "ID" || m_allowed[0] == "IDREF" ||
- m_allowed[0] == "IDREFS" || m_allowed[0] == "ENTITY" || m_allowed[0] == "ENTITIES" ||
- m_allowed[0] == "NMTOKEN" || m_allowed[0] == "NMTOKENS" || m_allowed[0] == "NAME") )
- {
- // these must not be taken literally, e.g. don't insert the string "CDATA"
- m_allowed.clear();
- }
- else
- {
- m_mode = attributevalues;
- }
+ return;
}
- else if( ! currentElement.isEmpty() )
- {
- qDebug() << "*inside tag -> get attributes";
- m_allowed = m_docDtds[doc]->allowedAttributes(currentElement );
- m_mode = attributes;
+
+ // debug to test speed:
+ //QTime t; t.start();
+
+ beginResetModel();
+ m_allowed.clear();
+
+ // get char on the left of the cursor:
+ KTextEditor::Cursor curpos = kv->cursorPosition();
+ uint line = curpos.line(), col = curpos.column();
+
+ QString lineStr = kv->document()->line(line);
+ QString leftCh = lineStr.mid(col - 1, 1);
+ QString secondLeftCh = lineStr.mid(col - 2, 1);
+
+ if (leftCh == "&") {
+ qDebug() << "Getting entities";
+ m_allowed = m_docDtds[doc]->entities(QString());
+ m_mode = entities;
+ } else if (leftCh == "<") {
+ qDebug() << "*outside tag -> get elements";
+ QString parentElement = getParentElement(*kv, 1);
+ qDebug() << "parent: " << parentElement;
+ m_allowed = m_docDtds[doc]->allowedElements(parentElement);
+ m_mode = elements;
+ } else if (leftCh == "/" && secondLeftCh == "<") {
+ qDebug() << "*close parent element";
+ QString parentElement = getParentElement(*kv, 2);
+
+ if (! parentElement.isEmpty()) {
+ m_mode = closingtag;
+ m_allowed = QStringList(parentElement);
+ }
+ } else if (leftCh == " " || (isQuote(leftCh) && secondLeftCh == "=")) {
+ // TODO: check secondLeftChar, too?! then you don't need to trigger
+ // with space and we yet save CPU power
+ QString currentElement = insideTag(*kv);
+ QString currentAttribute;
+ if (! currentElement.isEmpty()) {
+ currentAttribute = insideAttribute(*kv);
+ }
+
+ qDebug() << "Tag: " << currentElement;
+ qDebug() << "Attr: " << currentAttribute;
+
+ if (! currentElement.isEmpty() && ! currentAttribute.isEmpty()) {
+ qDebug() << "*inside attribute -> get attribute values";
+ m_allowed = m_docDtds[doc]->attributeValues(currentElement, currentAttribute);
+ if (m_allowed.count() == 1 &&
+ (m_allowed[0] == "CDATA" || m_allowed[0] == "ID" || m_allowed[0] == "IDREF" ||
+ m_allowed[0] == "IDREFS" || m_allowed[0] == "ENTITY" || m_allowed[0] == "ENTITIES" ||
+ m_allowed[0] == "NMTOKEN" || m_allowed[0] == "NMTOKENS" || m_allowed[0] == "NAME")) {
+ // these must not be taken literally, e.g. don't insert the string "CDATA"
+ m_allowed.clear();
+ } else {
+ m_mode = attributevalues;
+ }
+ } else if (! currentElement.isEmpty()) {
+ qDebug() << "*inside tag -> get attributes";
+ m_allowed = m_docDtds[doc]->allowedAttributes(currentElement);
+ m_mode = attributes;
+ }
}
- }
- //qDebug() << "time elapsed (ms): " << t.elapsed();
- qDebug() << "Allowed strings: " << m_allowed.count();
+ //qDebug() << "time elapsed (ms): " << t.elapsed();
+ qDebug() << "Allowed strings: " << m_allowed.count();
- if( m_allowed.count() >= 1 && m_allowed[0] != "__EMPTY" )
- {
- m_allowed = sortQStringList( m_allowed );
- }
- setRowCount( m_allowed.count() );
- endResetModel();
+ if (m_allowed.count() >= 1 && m_allowed[0] != "__EMPTY") {
+ m_allowed = sortQStringList(m_allowed);
+ }
+ setRowCount(m_allowed.count());
+ endResetModel();
}
-int PluginKateXMLToolsCompletionModel::columnCount(const QModelIndex&) const
+int PluginKateXMLToolsCompletionModel::columnCount(const QModelIndex &) const
{
- return 1;
+ return 1;
}
int PluginKateXMLToolsCompletionModel::rowCount(const QModelIndex &parent) const
{
- if (!m_allowed.isEmpty()) // Is there smth to complete?
- {
- if (!parent.isValid()) // Return the only one group node for root
- return 1;
- if (parent.internalId() == groupNode) // Return available rows count for group level node
- return m_allowed.size();
- }
- return 0;
+ if (!m_allowed.isEmpty()) { // Is there smth to complete?
+ if (!parent.isValid()) { // Return the only one group node for root
+ return 1;
+ }
+ if (parent.internalId() == groupNode) { // Return available rows count for group level node
+ return m_allowed.size();
+ }
+ }
+ return 0;
}
-QModelIndex PluginKateXMLToolsCompletionModel::parent(const QModelIndex& index) const
+QModelIndex PluginKateXMLToolsCompletionModel::parent(const QModelIndex &index) const
{
- if (!index.isValid()) // Is root/invalid index?
- return QModelIndex(); // Nothing to return...
- if (index.internalId() == groupNode) // Return a root node for group
- return QModelIndex();
- // Otherwise, this is a leaf level, so return the only group as a parent
- return createIndex(0, 0, groupNode);
+ if (!index.isValid()) { // Is root/invalid index?
+ return QModelIndex(); // Nothing to return...
+ }
+ if (index.internalId() == groupNode) { // Return a root node for group
+ return QModelIndex();
+ }
+ // Otherwise, this is a leaf level, so return the only group as a parent
+ return createIndex(0, 0, groupNode);
}
QModelIndex PluginKateXMLToolsCompletionModel::index(const int row,
- const int column,
- const QModelIndex &parent) const
+ const int column,
+ const QModelIndex &parent) const
{
- if (!parent.isValid())
- {
- // At 'top' level only 'header' present, so nothing else than row 0 can be here...
- return row == 0 ? createIndex(row, column, groupNode) : QModelIndex();
- }
- 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, (void*)0); // Just return a leaf-level index
- }
- // Leaf node has no children... nothing to return
- return QModelIndex();
+ if (!parent.isValid()) {
+ // At 'top' level only 'header' present, so nothing else than row 0 can be here...
+ return row == 0 ? createIndex(row, column, groupNode) : QModelIndex();
+ }
+ 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, (void *)0); // Just return a leaf-level index
+ }
+ }
+ // Leaf node has no children... nothing to return
+ return QModelIndex();
}
QVariant PluginKateXMLToolsCompletionModel::data(const QModelIndex &index, int role) const
{
- if (!index.isValid()) // Nothing to do w/ invalid index
- return QVariant();
+ if (!index.isValid()) { // Nothing to do w/ invalid index
+ return QVariant();
+ }
- if (index.internalId() == groupNode) // Return group level node data
- {
- switch (role)
- {
- case KTextEditor::CodeCompletionModel::GroupRole:
- return QVariant(Qt::DisplayRole);
- case Qt::DisplayRole:
- return currentModeToString();
- default:
- break;
+ if (index.internalId() == groupNode) { // Return group level node data
+ switch (role) {
+ case KTextEditor::CodeCompletionModel::GroupRole:
+ return QVariant(Qt::DisplayRole);
+ case Qt::DisplayRole:
+ return currentModeToString();
+ default:
+ break;
+ }
+ return QVariant(); // Nothing to return for other roles
}
- return QVariant(); // Nothing to return for other roles
- }
- switch (role)
- {
+ switch (role) {
case Qt::DisplayRole:
- switch (index.column())
- {
+ switch (index.column()) {
case KTextEditor::CodeCompletionModel::Name:
- return m_allowed.at(index.row());
+ return m_allowed.at(index.row());
default:
- break;
- }
+ break;
+ }
default:
- break;
- }
- return QVariant();
+ break;
+ }
+ return QVariant();
}
-bool PluginKateXMLToolsCompletionModel::shouldStartCompletion( KTextEditor::View *view,
- const QString &insertedText,
- bool userInsertion,
- const KTextEditor::Cursor &position )
+bool PluginKateXMLToolsCompletionModel::shouldStartCompletion(KTextEditor::View *view,
+ const QString &insertedText,
+ bool userInsertion,
+ const KTextEditor::Cursor &position)
{
- Q_UNUSED( view )
- Q_UNUSED( userInsertion )
- Q_UNUSED( position )
- const QString triggerChars = "&</ '\""; // these are subsequently handled by completionInvoked()
+ Q_UNUSED(view)
+ Q_UNUSED(userInsertion)
+ Q_UNUSED(position)
+ const QString triggerChars = "&</ '\""; // these are subsequently handled by completionInvoked()
- return triggerChars.contains( insertedText.right(1) );
+ return triggerChars.contains(insertedText.right(1));
}
@@ -400,160 +385,153 @@ bool PluginKateXMLToolsCompletionModel::shouldStartCompletion( KTextEditor::View
*/
void PluginKateXMLToolsCompletionModel::getDTD()
{
- if ( !KTextEditor::Editor::instance()->application()->activeMainWindow() )
- return;
-
- KTextEditor::View *kv = KTextEditor::Editor::instance()->application()->activeMainWindow()->activeView();
- if( ! kv )
- {
- qDebug() << "Warning: no KTextEditor::View";
- return;
- }
-
- // ### replace this with something more sane
- // Start where the supplied XML-DTDs are fed by default unless
- // user changed directory last time:
- QString defaultDir = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "katexmltools") + "/katexmltools/";
- if( m_urlString.isNull() ) {
- m_urlString = defaultDir;
- }
- KUrl url;
-
- // Guess the meta DTD by looking at the doctype's public identifier.
- // XML allows comments etc. before the doctype, so look further than
- // just the first line.
- // Example syntax:
- // <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
- uint checkMaxLines = 200;
- QString documentStart = kv->document()->text( KTextEditor::Range(0, 0, checkMaxLines+1, 0) );
- QRegExp re( "<!DOCTYPE\\s+(.*)\\s+PUBLIC\\s+[\"'](.*)[\"']", Qt::CaseInsensitive );
- re.setMinimal( true );
- int matchPos = re.indexIn( documentStart );
- QString filename;
- QString doctype;
- QString topElement;
-
- if( matchPos != -1 ) {
- topElement = re.cap( 1 );
- doctype = re.cap( 2 );
- qDebug() << "Top element: " << topElement;
- qDebug() << "Doctype match: " << doctype;
- // XHTML:
- if( doctype == "-//W3C//DTD XHTML 1.0 Transitional//EN" )
- filename = "xhtml1-transitional.dtd.xml";
- else if( doctype == "-//W3C//DTD XHTML 1.0 Strict//EN" )
- filename = "xhtml1-strict.dtd.xml";
- else if( doctype == "-//W3C//DTD XHTML 1.0 Frameset//EN" )
- filename = "xhtml1-frameset.dtd.xml";
- // HTML 4.0:
- else if ( doctype == "-//W3C//DTD HTML 4.01 Transitional//EN" )
- filename = "html4-loose.dtd.xml";
- else if ( doctype == "-//W3C//DTD HTML 4.01//EN" )
- filename = "html4-strict.dtd.xml";
- // KDE Docbook:
- else if ( doctype == "-//KDE//DTD DocBook XML V4.1.2-Based Variant V1.1//EN" )
- filename = "kde-docbook.dtd.xml";
- }
- else if( documentStart.indexOf("<xsl:stylesheet" ) != -1 &&
- documentStart.indexOf( "xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"") != -1 )
- {
- /* XSLT doesn't have a doctype/DTD. We look for an xsl:stylesheet tag instead.
- Example:
- <xsl:stylesheet version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns="http://www.w3.org/TR/xhtml1/strict">
- */
- filename = "xslt-1.0.dtd.xml";
- doctype = "XSLT 1.0";
- }
- else
- qDebug() << "No doctype found";
-
- if( filename.isEmpty() )
- {
- // no meta dtd found for this file
- url = KFileDialog::getOpenUrl(m_urlString, "*.xml",
- 0, i18n( "Assign Meta DTD in XML Format") );
- }
- else
- {
- url.setFileName( defaultDir + filename );
- KMessageBox::information(0, i18n("The current file has been identified "
- "as a document of type \"%1\". The meta DTD for this document type "
- "will now be loaded.", doctype ),
- i18n( "Loading XML Meta DTD" ),
- QString::fromLatin1( "DTDAssigned") );
- }
-
- if( url.isEmpty() )
- return;
-
- m_urlString = url.url(); // remember directory for next time
-
- if ( m_dtds[ m_urlString ] )
- assignDTD( m_dtds[ m_urlString ], kv );
- else
- {
- m_dtdString.clear();
- m_viewToAssignTo = kv;
-
- KApplication::setOverrideCursor( Qt::WaitCursor );
- KIO::Job *job = KIO::get( url );
- connect( job, SIGNAL(result(KJob*)), this, SLOT(slotFinished(KJob*)) );
- connect( job, SIGNAL(data(KIO::Job*,QByteArray)),
- this, SLOT(slotData(KIO::Job*,QByteArray)) );
- }
- qDebug()<<"XMLTools::getDTD: Documents: "<<m_docDtds.count()<<", DTDs: "<<m_dtds.count();
+ if (!KTextEditor::Editor::instance()->application()->activeMainWindow()) {
+ return;
+ }
+
+ KTextEditor::View *kv = KTextEditor::Editor::instance()->application()->activeMainWindow()->activeView();
+ if (! kv) {
+ qDebug() << "Warning: no KTextEditor::View";
+ return;
+ }
+
+ // ### replace this with something more sane
+ // Start where the supplied XML-DTDs are fed by default unless
+ // user changed directory last time:
+ QString defaultDir = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "katexmltools") + "/katexmltools/";
+ if (m_urlString.isNull()) {
+ m_urlString = defaultDir;
+ }
+ KUrl url;
+
+ // Guess the meta DTD by looking at the doctype's public identifier.
+ // XML allows comments etc. before the doctype, so look further than
+ // just the first line.
+ // Example syntax:
+ // <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
+ uint checkMaxLines = 200;
+ QString documentStart = kv->document()->text(KTextEditor::Range(0, 0, checkMaxLines + 1, 0));
+ QRegExp re("<!DOCTYPE\\s+(.*)\\s+PUBLIC\\s+[\"'](.*)[\"']", Qt::CaseInsensitive);
+ re.setMinimal(true);
+ int matchPos = re.indexIn(documentStart);
+ QString filename;
+ QString doctype;
+ QString topElement;
+
+ if (matchPos != -1) {
+ topElement = re.cap(1);
+ doctype = re.cap(2);
+ qDebug() << "Top element: " << topElement;
+ qDebug() << "Doctype match: " << doctype;
+ // XHTML:
+ if (doctype == "-//W3C//DTD XHTML 1.0 Transitional//EN") {
+ filename = "xhtml1-transitional.dtd.xml";
+ } else if (doctype == "-//W3C//DTD XHTML 1.0 Strict//EN") {
+ filename = "xhtml1-strict.dtd.xml";
+ } else if (doctype == "-//W3C//DTD XHTML 1.0 Frameset//EN") {
+ filename = "xhtml1-frameset.dtd.xml";
+ }
+ // HTML 4.0:
+ else if (doctype == "-//W3C//DTD HTML 4.01 Transitional//EN") {
+ filename = "html4-loose.dtd.xml";
+ } else if (doctype == "-//W3C//DTD HTML 4.01//EN") {
+ filename = "html4-strict.dtd.xml";
+ }
+ // KDE Docbook:
+ else if (doctype == "-//KDE//DTD DocBook XML V4.1.2-Based Variant V1.1//EN") {
+ filename = "kde-docbook.dtd.xml";
+ }
+ } else if (documentStart.indexOf("<xsl:stylesheet") != -1 &&
+ documentStart.indexOf("xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"") != -1) {
+ /* XSLT doesn't have a doctype/DTD. We look for an xsl:stylesheet tag instead.
+ Example:
+ <xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns="http://www.w3.org/TR/xhtml1/strict">
+ */
+ filename = "xslt-1.0.dtd.xml";
+ doctype = "XSLT 1.0";
+ } else {
+ qDebug() << "No doctype found";
+ }
+
+ if (filename.isEmpty()) {
+ // no meta dtd found for this file
+ url = KFileDialog::getOpenUrl(m_urlString, "*.xml",
+ 0, i18n("Assign Meta DTD in XML Format"));
+ } else {
+ url.setFileName(defaultDir + filename);
+ KMessageBox::information(0, i18n("The current file has been identified "
+ "as a document of type \"%1\". The meta DTD for this document type "
+ "will now be loaded.", doctype),
+ i18n("Loading XML Meta DTD"),
+ QString::fromLatin1("DTDAssigned"));
+ }
+
+ if (url.isEmpty()) {
+ return;
+ }
+
+ m_urlString = url.url(); // remember directory for next time
+
+ if (m_dtds[ m_urlString ]) {
+ assignDTD(m_dtds[ m_urlString ], kv);
+ } else {
+ m_dtdString.clear();
+ m_viewToAssignTo = kv;
+
+ KApplication::setOverrideCursor(Qt::WaitCursor);
+ KIO::Job *job = KIO::get(url);
+ connect(job, SIGNAL(result(KJob *)), this, SLOT(slotFinished(KJob *)));
+ connect(job, SIGNAL(data(KIO::Job *, QByteArray)),
+ this, SLOT(slotData(KIO::Job *, QByteArray)));
+ }
+ qDebug() << "XMLTools::getDTD: Documents: " << m_docDtds.count() << ", DTDs: " << m_dtds.count();
}
-void PluginKateXMLToolsCompletionModel::slotFinished( KJob *job )
+void PluginKateXMLToolsCompletionModel::slotFinished(KJob *job)
{
- if( job->error() )
- {
- //qDebug() << "XML Plugin error: DTD in XML format (" << filename << " ) could not be loaded";
- static_cast<KIO::Job*>(job)->ui()->showErrorMessage();
- }
- else if ( static_cast<KIO::TransferJob *>(job)->isErrorPage() )
- {
- // catch failed loading loading via http:
- KMessageBox::error(0, i18n("The file '%1' could not be opened. "
- "The server returned an error.", m_urlString ),
- i18n( "XML Plugin Error") );
- }
- else
- {
- PseudoDTD *dtd = new PseudoDTD();
- dtd->analyzeDTD( m_urlString, m_dtdString );
-
- m_dtds.insert( m_urlString, dtd );
- assignDTD( dtd, m_viewToAssignTo );
-
- // clean up a bit
- m_viewToAssignTo = 0;
- m_dtdString.clear();
- }
- QApplication::restoreOverrideCursor();
+ if (job->error()) {
+ //qDebug() << "XML Plugin error: DTD in XML format (" << filename << " ) could not be loaded";
+ static_cast<KIO::Job *>(job)->ui()->showErrorMessage();
+ } else if (static_cast<KIO::TransferJob *>(job)->isErrorPage()) {
+ // catch failed loading loading via http:
+ KMessageBox::error(0, i18n("The file '%1' could not be opened. "
+ "The server returned an error.", m_urlString),
+ i18n("XML Plugin Error"));
+ } else {
+ PseudoDTD *dtd = new PseudoDTD();
+ dtd->analyzeDTD(m_urlString, m_dtdString);
+
+ m_dtds.insert(m_urlString, dtd);
+ assignDTD(dtd, m_viewToAssignTo);
+
+ // clean up a bit
+ m_viewToAssignTo = 0;
+ m_dtdString.clear();
+ }
+ QApplication::restoreOverrideCursor();
}
-void PluginKateXMLToolsCompletionModel::slotData( KIO::Job *, const QByteArray &data )
+void PluginKateXMLToolsCompletionModel::slotData(KIO::Job *, const QByteArray &data)
{
- m_dtdString += QString( data );
+ m_dtdString += QString(data);
}
-void PluginKateXMLToolsCompletionModel::assignDTD( PseudoDTD *dtd, KTextEditor::View *view)
+void PluginKateXMLToolsCompletionModel::assignDTD(PseudoDTD *dtd, KTextEditor::View *view)
{
- m_docDtds.insert( view->document(), dtd );
-
- //TODO:perhaps foreach views()?
- KTextEditor::CodeCompletionInterface *cci = qobject_cast<KTextEditor::CodeCompletionInterface *>(view);
-
- if (cci) {
- cci->registerCompletionModel( this );
- cci->setAutomaticInvocationEnabled( true );
- qDebug() << "PluginKateXMLToolsView: completion model registered";
- } else {
- qWarning() << "PluginKateXMLToolsView: completion interface unavailable";
- }
+ m_docDtds.insert(view->document(), dtd);
+
+ //TODO:perhaps foreach views()?
+ KTextEditor::CodeCompletionInterface *cci = qobject_cast<KTextEditor::CodeCompletionInterface *>(view);
+
+ if (cci) {
+ cci->registerCompletionModel(this);
+ cci->setAutomaticInvocationEnabled(true);
+ qDebug() << "PluginKateXMLToolsView: completion model registered";
+ } else {
+ qWarning() << "PluginKateXMLToolsView: completion interface unavailable";
+ }
}
/**
@@ -563,73 +541,74 @@ void PluginKateXMLToolsCompletionModel::assignDTD( PseudoDTD *dtd, KTextEditor::
*/
void PluginKateXMLToolsCompletionModel::slotInsertElement()
{
- if ( !KTextEditor::Editor::instance()->application()->activeMainWindow() )
- return;
-
- KTextEditor::View *kv = KTextEditor::Editor::instance()->application()->activeMainWindow()->activeView();
- if( ! kv )
- {
- qDebug() << "Warning: no KTextEditor::View";
- return;
- }
-
- KTextEditor::Document *doc = kv->document();
- PseudoDTD *dtd = m_docDtds[doc];
- QString parentElement = getParentElement( *kv, 0 );
- QStringList allowed;
-
- if( dtd )
- allowed = dtd->allowedElements(parentElement );
-
- InsertElement *dialog = new InsertElement(
- ( QWidget *)KTextEditor::Editor::instance()->application()->activeMainWindow()->activeView(), "insertXml" );
- QString text = dialog->showDialog( allowed );
- delete dialog;
-
- if( !text.isEmpty() )
- {
- QStringList list = text.split( QChar(' ') );
- QString pre;
- QString post;
- // anders: use <tagname/> if the tag is required to be empty.
- // In that case maybe we should not remove the selection? or overwrite it?
- int adjust = 0; // how much to move cursor.
- // if we know that we have attributes, it goes
- // just after the tag name, otherwise between tags.
- if ( dtd && dtd->allowedAttributes(list[0]).count() )
- adjust++; // the ">"
-
- if ( dtd && dtd->allowedElements(list[0]).contains("__EMPTY") )
- {
- pre = '<' + text + "/>";
- if ( adjust )
- adjust++; // for the "/"
+ if (!KTextEditor::Editor::instance()->application()->activeMainWindow()) {
+ return;
}
- else
- {
- pre = '<' + text + '>';
- post ="</" + list[0] + '>';
+
+ KTextEditor::View *kv = KTextEditor::Editor::instance()->application()->activeMainWindow()->activeView();
+ if (! kv) {
+ qDebug() << "Warning: no KTextEditor::View";
+ return;
+ }
+
+ KTextEditor::Document *doc = kv->document();
+ PseudoDTD *dtd = m_docDtds[doc];
+ QString parentElement = getParentElement(*kv, 0);
+ QStringList allowed;
+
+ if (dtd) {
+ allowed = dtd->allowedElements(parentElement);
}
- QString marked;
- if ( ! post.isEmpty() )
- marked = kv->selectionText();
+ InsertElement *dialog = new InsertElement(
+ (QWidget *)KTextEditor::Editor::instance()->application()->activeMainWindow()->activeView(), "insertXml");
+ QString text = dialog->showDialog(allowed);
+ delete dialog;
+
+ if (!text.isEmpty()) {
+ QStringList list = text.split(QChar(' '));
+ QString pre;
+ QString post;
+ // anders: use <tagname/> if the tag is required to be empty.
+ // In that case maybe we should not remove the selection? or overwrite it?
+ int adjust = 0; // how much to move cursor.
+ // if we know that we have attributes, it goes
+ // just after the tag name, otherwise between tags.
+ if (dtd && dtd->allowedAttributes(list[0]).count()) {
+ adjust++; // the ">"
+ }
+
+ if (dtd && dtd->allowedElements(list[0]).contains("__EMPTY")) {
+ pre = '<' + text + "/>";
+ if (adjust) {
+ adjust++; // for the "/"
+ }
+ } else {
+ pre = '<' + text + '>';
+ post = "</" + list[0] + '>';
+ }
+
+ QString marked;
+ if (! post.isEmpty()) {
+ marked = kv->selectionText();
+ }
- doc->startEditing();
+ doc->startEditing();
- if( ! marked.isEmpty() )
- kv->removeSelectionText();
+ if (! marked.isEmpty()) {
+ kv->removeSelectionText();
+ }
- // with the old selection now removed, curPos points to the start of pre
- KTextEditor::Cursor curPos = kv->cursorPosition();
- curPos.setColumn( curPos.column() + pre.length() - adjust );
+ // with the old selection now removed, curPos points to the start of pre
+ KTextEditor::Cursor curPos = kv->cursorPosition();
+ curPos.setColumn(curPos.column() + pre.length() - adjust);
- kv->insertText( pre + marked + post );
+ kv->insertText(pre + marked + post);
- kv->setCursorPosition( curPos );
+ kv->setCursorPosition(curPos);
- doc->endEditing();
- }
+ doc->endEditing();
+ }
}
/**
@@ -637,120 +616,119 @@ void PluginKateXMLToolsCompletionModel::slotInsertElement()
*/
void PluginKateXMLToolsCompletionModel::slotCloseElement()
{
- if ( !KTextEditor::Editor::instance()->application()->activeMainWindow() )
- return;
-
- KTextEditor::View *kv = KTextEditor::Editor::instance()->application()->activeMainWindow()->activeView();
- if( ! kv )
- {
- qDebug() << "Warning: no KTextEditor::View";
- return;
- }
- QString parentElement = getParentElement( *kv, 0 );
-
- //qDebug() << "parentElement: '" << parentElement << "'";
- QString closeTag = "</" + parentElement + '>';
- if( ! parentElement.isEmpty() )
- kv->insertText( closeTag );
+ if (!KTextEditor::Editor::instance()->application()->activeMainWindow()) {
+ return;
+ }
+
+ KTextEditor::View *kv = KTextEditor::Editor::instance()->application()->activeMainWindow()->activeView();
+ if (! kv) {
+ qDebug() << "Warning: no KTextEditor::View";
+ return;
+ }
+ QString parentElement = getParentElement(*kv, 0);
+
+ //qDebug() << "parentElement: '" << parentElement << "'";
+ QString closeTag = "</" + parentElement + '>';
+ if (! parentElement.isEmpty()) {
+ kv->insertText(closeTag);
+ }
}
// modify the completion string before it gets inserted
void PluginKateXMLToolsCompletionModel::executeCompletionItem(KTextEditor::View *view,
- const KTextEditor::Range &word,
- const QModelIndex &index) const
+ 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;
-
- int 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 );
-
- int posCorrection = 0; // where to move the cursor after completion ( >0 = move right )
- if( m_mode == entities )
- {
- text = text + ';';
- }
-
- else if( m_mode == attributes )
- {
- text = text + "=\"\"";
- posCorrection = -1;
- if( !rightCh.isEmpty() && rightCh != ">" && rightCh != "/" && rightCh != " " )
- { // TODO: other whitespaces
- // add space in front of the next attribute
- text = text + ' ';
- posCorrection--;
+ KTextEditor::Range toReplace = word;
+ KTextEditor::Document *document = view->document();
+
+ QString text = data(index.sibling(index.row(), Name), Qt::DisplayRole).toString();
+
+ qDebug() << "executeCompletionItem text: " << text;
+
+ int 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);
+
+ int posCorrection = 0; // where to move the cursor after completion ( >0 = move right )
+ if (m_mode == entities) {
+ text = text + ';';
}
- }
- else if( m_mode == attributevalues )
- {
- // TODO: support more than one line
- uint startAttValue = 0;
- uint endAttValue = 0;
+ else if (m_mode == attributes) {
+ text = text + "=\"\"";
+ posCorrection = -1;
+ if (!rightCh.isEmpty() && rightCh != ">" && rightCh != "/" && rightCh != " ") {
+ // TODO: other whitespaces
+ // add space in front of the next attribute
+ text = text + ' ';
+ posCorrection--;
+ }
+ }
- // find left quote:
- for( startAttValue = col; startAttValue > 0; startAttValue-- )
- {
- QString ch = lineStr.mid( startAttValue-1, 1 );
- if( isQuote(ch) )
- break;
+ else if (m_mode == attributevalues) {
+ // TODO: support more than one line
+ uint startAttValue = 0;
+ uint endAttValue = 0;
+
+ // find left quote:
+ for (startAttValue = col; startAttValue > 0; startAttValue--) {
+ QString ch = lineStr.mid(startAttValue - 1, 1);
+ if (isQuote(ch)) {
+ break;
+ }
+ }
+
+ // find right quote:
+ for (endAttValue = col; endAttValue <= (uint) lineStr.length(); endAttValue++) {
+ QString ch = lineStr.mid(endAttValue - 1, 1);
+ if (isQuote(ch)) {
+ break;
+ }
+ }
+
+ // replace the current contents of the attribute
+ if (startAttValue < endAttValue) {
+ toReplace = KTextEditor::Range(line, startAttValue, line, endAttValue - 1);
+ }
}
- // find right quote:
- for( endAttValue = col; endAttValue <= (uint) lineStr.length(); endAttValue++ )
- {
- QString ch = lineStr.mid( endAttValue-1, 1 );
- if( isQuote(ch) )
- break;
+ else if (m_mode == elements) {
+ // anders: if the tag is marked EMPTY, insert in form <tagname/>
+ QString str;
+ bool isEmptyTag = m_docDtds[document]->allowedElements(text).contains("__EMPTY");
+ if (isEmptyTag) {
+ str = text + "/>";
+ } else {
+ str = text + "></" + text + '>';
+ }
+
+ // Place the cursor where it is most likely wanted:
+ // always inside the tag if the tag is empty AND the DTD indicates that there are attribs)
+ // outside for open tags, UNLESS there are mandatory attributes
+ if (m_docDtds[document]->requiredAttributes(text).count()
+ || (isEmptyTag && m_docDtds[document]->allowedAttributes(text).count())) {
+ posCorrection = text.length() - str.length();
+ } else if (! isEmptyTag) {
+ posCorrection = text.length() - str.length() + 1;
+ }
+
+ text = str;
}
- // replace the current contents of the attribute
- if( startAttValue < endAttValue )
- toReplace = KTextEditor::Range( line, startAttValue, line, endAttValue-1 );
- }
-
- else if( m_mode == elements )
- {
- // anders: if the tag is marked EMPTY, insert in form <tagname/>
- QString str;
- bool isEmptyTag =m_docDtds[document]->allowedElements(text).contains( "__EMPTY" );
- if ( isEmptyTag )
- str = text + "/>";
- else
- str = text + "></" + text + '>';
-
- // Place the cursor where it is most likely wanted:
- // always inside the tag if the tag is empty AND the DTD indicates that there are attribs)
- // outside for open tags, UNLESS there are mandatory attributes
- if ( m_docDtds[document]->requiredAttributes(text).count()
- || ( isEmptyTag && m_docDtds[document]->allowedAttributes(text).count() ) )
- posCorrection = text.length() - str.length();
- else if ( ! isEmptyTag )
- posCorrection = text.length() - str.length() + 1;
-
- text = str;
- }
-
- else if( m_mode == closingtag )
- {
- text += '>';
- }
-
- document->replaceText( toReplace, text );
-
- // move the cursor to desired position
- KTextEditor::Cursor curPos = view->cursorPosition();
- curPos.setColumn( curPos.column() + posCorrection );
- view->setCursorPosition( curPos );
+ else if (m_mode == closingtag) {
+ text += '>';
+ }
+
+ document->replaceText(toReplace, text);
+
+ // move the cursor to desired position
+ KTextEditor::Cursor curPos = view->cursorPosition();
+ curPos.setColumn(curPos.column() + posCorrection);
+ view->setCursorPosition(curPos);
}
@@ -762,45 +740,43 @@ void PluginKateXMLToolsCompletionModel::executeCompletionItem(KTextEditor::View
* if "<" occurs before ">" occurs ( on the left side of the cursor ).
* Return the tag name, return "" if we cursor is outside a tag.
*/
-QString PluginKateXMLToolsCompletionModel::insideTag( KTextEditor::View &kv )
+QString PluginKateXMLToolsCompletionModel::insideTag(KTextEditor::View &kv)
{
- int line, col;
- kv.cursorPosition().position( line, col );
- int y = line; // another variable because uint <-> int
+ int line, col;
+ kv.cursorPosition().position(line, col);
+ int y = line; // another variable because uint <-> int
+
+ do {
+ QString lineStr = kv.document()->line(y);
+ for (uint x = col; x > 0; x--) {
+ QString ch = lineStr.mid(x - 1, 1);
+ if (ch == ">") { // cursor is outside tag
+ return QString();
+ }
- do {
- QString lineStr = kv.document()->line(y );
- for( uint x = col; x > 0; x-- )
- {
- QString ch = lineStr.mid( x-1, 1 );
- if( ch == ">" ) // cursor is outside tag
- return QString();
-
- if( ch == "<" )
- {
- QString tag;
- // look for white space on the right to get the tag name
- for( int z = x; z <= lineStr.length() ; ++z )
- {
- ch = lineStr.mid( z-1, 1 );
- if( ch.at(0).isSpace() || ch == "/" || ch == ">" )
- return tag.right( tag.length()-1 );
-
- if( z == lineStr.length() )
- {
- tag += ch;
- return tag.right( tag.length()-1 );
- }
-
- tag += ch;
+ if (ch == "<") {
+ QString tag;
+ // look for white space on the right to get the tag name
+ for (int z = x; z <= lineStr.length() ; ++z) {
+ ch = lineStr.mid(z - 1, 1);
+ if (ch.at(0).isSpace() || ch == "/" || ch == ">") {
+ return tag.right(tag.length() - 1);
+ }
+
+ if (z == lineStr.length()) {
+ tag += ch;
+ return tag.right(tag.length() - 1);
+ }
+
+ tag += ch;
+ }
+ }
}
- }
- }
- y--;
- col = kv.document()->line(y).length();
- } while( y >= 0 );
+ y--;
+ col = kv.document()->line(y).length();
+ } while (y >= 0);
- return QString();
+ return QString();
}
/**
@@ -813,52 +789,52 @@ QString PluginKateXMLToolsCompletionModel::insideTag( KTextEditor::View &kv )
* Note: only call when insideTag() == true.
* TODO: allow whitespace around "="
*/
-QString PluginKateXMLToolsCompletionModel::insideAttribute( KTextEditor::View &kv )
+QString PluginKateXMLToolsCompletionModel::insideAttribute(KTextEditor::View &kv)
{
- int line, col;
- kv.cursorPosition().position( line, col );
- int y = line; // another variable because uint <-> int
- uint x = 0;
- QString lineStr;
- QString ch;
-
- do {
- lineStr = kv.document()->line(y );
- for( x = col; x > 0; x-- )
- {
- ch = lineStr.mid( x-1, 1 );
- QString chLeft = lineStr.mid( x-2, 1 );
- // TODO: allow whitespace
- if( isQuote(ch) && chLeft == "=" )
- break;
- else if( isQuote(ch) && chLeft != "=" )
- return QString();
- else if( ch == "<" || ch == ">" )
- return QString();
- }
- y--;
- col = kv.document()->line(y).length();
- } while( !isQuote(ch) );
-
- // look for next white space on the left to get the tag name
- QString attr;
- for( int z = x; z >= 0; z-- )
- {
- ch = lineStr.mid( z-1, 1 );
-
- if( ch.at(0).isSpace() )
- break;
-
- if( z == 0 )
- { // start of line == whitespace
- attr += ch;
- break;
- }
+ int line, col;
+ kv.cursorPosition().position(line, col);
+ int y = line; // another variable because uint <-> int
+ uint x = 0;
+ QString lineStr;
+ QString ch;
+
+ do {
+ lineStr = kv.document()->line(y);
+ for (x = col; x > 0; x--) {
+ ch = lineStr.mid(x - 1, 1);
+ QString chLeft = lineStr.mid(x - 2, 1);
+ // TODO: allow whitespace
+ if (isQuote(ch) && chLeft == "=") {
+ break;
+ } else if (isQuote(ch) && chLeft != "=") {
+ return QString();
+ } else if (ch == "<" || ch == ">") {
+ return QString();
+ }
+ }
+ y--;
+ col = kv.document()->line(y).length();
+ } while (!isQuote(ch));
+
+ // look for next white space on the left to get the tag name
+ QString attr;
+ for (int z = x; z >= 0; z--) {
+ ch = lineStr.mid(z - 1, 1);
- attr = ch + attr;
- }
+ if (ch.at(0).isSpace()) {
+ break;
+ }
- return attr.left( attr.length()-2 );
+ if (z == 0) {
+ // start of line == whitespace
+ attr += ch;
+ break;
+ }
+
+ attr = ch + attr;
+ }
+
+ return attr.left(attr.length() - 2);
}
/**
@@ -871,165 +847,168 @@ QString PluginKateXMLToolsCompletionModel::insideAttribute( KTextEditor::View &k
* <p> foo <img/> bar X
* <p> foo bar X
*/
-QString PluginKateXMLToolsCompletionModel::getParentElement( KTextEditor::View &kv, int skipCharacters )
+QString PluginKateXMLToolsCompletionModel::getParentElement(KTextEditor::View &kv, int skipCharacters)
{
- enum {
- parsingText,
- parsingElement,
- parsingElementBoundary,
- parsingNonElement,
- parsingAttributeDquote,
- parsingAttributeSquote,
- parsingIgnore
- } parseState;
- parseState = (skipCharacters > 0) ? parsingIgnore : parsingText;
-
- int nestingLevel = 0;
-
- int line, col;
- kv.cursorPosition().position( line, col );
- QString str = kv.document()->line(line );
-
- while( true )
- {
- // move left a character
- if( !col-- )
- {
- do
- {
- if( !line-- ) return QString(); // reached start of document
- str = kv.document()->line(line );
- col = str.length();
- } while( !col );
- --col;
- }
+ enum {
+ parsingText,
+ parsingElement,
+ parsingElementBoundary,
+ parsingNonElement,
+ parsingAttributeDquote,
+ parsingAttributeSquote,
+ parsingIgnore
+ } parseState;
+ parseState = (skipCharacters > 0) ? parsingIgnore : parsingText;
+
+ int nestingLevel = 0;
+
+ int line, col;
+ kv.cursorPosition().position(line, col);
+ QString str = kv.document()->line(line);
+
+ while (true) {
+ // move left a character
+ if (!col--) {
+ do {
+ if (!line--) {
+ return QString(); // reached start of document
+ }
+ str = kv.document()->line(line);
+ col = str.length();
+ } while (!col);
+ --col;
+ }
- ushort ch = str.at( col).unicode();
+ ushort ch = str.at(col).unicode();
- switch( parseState )
- {
- case parsingIgnore:
- // ignore the specified number of characters
- parseState = ( --skipCharacters > 0 ) ? parsingIgnore : parsingText;
- break;
+ switch (parseState) {
+ case parsingIgnore:
+ // ignore the specified number of characters
+ parseState = (--skipCharacters > 0) ? parsingIgnore : parsingText;
+ break;
- case parsingText:
- switch( ch )
- {
- case '<':
- // hmm... we were actually inside an element
- return QString();
+ case parsingText:
+ switch (ch) {
+ case '<':
+ // hmm... we were actually inside an element
+ return QString();
- case '>':
- // we just hit an element boundary
- parseState = parsingElementBoundary;
+ case '>':
+ // we just hit an element boundary
+ parseState = parsingElementBoundary;
+ break;
+ }
break;
- }
- break;
- case parsingElement:
- switch( ch )
- {
- case '"': // attribute ( double quoted )
- parseState = parsingAttributeDquote;
- break;
+ case parsingElement:
+ switch (ch) {
+ case '"': // attribute ( double quoted )
+ parseState = parsingAttributeDquote;
+ break;
case '\'': // attribute ( single quoted )
- parseState = parsingAttributeSquote;
- break;
+ parseState = parsingAttributeSquote;
+ break;
- case '/': // close tag
+ case '/': // close tag
parseState = parsingNonElement;
++nestingLevel;
break;
- case '<':
- // we just hit the start of the element...
- if( nestingLevel-- ) break;
+ case '<':
+ // we just hit the start of the element...
+ if (nestingLevel--) {
+ break;
+ }
+
+ QString tag = str.mid(col + 1);
+ for (uint pos = 0, len = tag.length(); pos < len; ++pos) {
+ ch = tag.at(pos).unicode();
+ if (ch == ' ' || ch == '\t' || ch == '>') {
+ tag.truncate(pos);
+ break;
+ }
+ }
+ return tag;
+ }
+ break;
- QString tag = str.mid( col + 1 );
- for( uint pos = 0, len = tag.length(); pos < len; ++pos ) {
- ch = tag.at( pos).unicode();
- if( ch == ' ' || ch == '\t' || ch == '>' ) {
- tag.truncate( pos );
+ case parsingElementBoundary:
+ switch (ch) {
+ case '?': // processing instruction
+ case '-': // comment
+ case '/': // empty element
+ parseState = parsingNonElement;
break;
- }
- }
- return tag;
- }
- break;
- case parsingElementBoundary:
- switch( ch )
- {
- case '?': // processing instruction
- case '-': // comment
- case '/': // empty element
- parseState = parsingNonElement;
- break;
+ case '"':
+ parseState = parsingAttributeDquote;
+ break;
+
+ case '\'':
+ parseState = parsingAttributeSquote;
+ break;
- case '"':
- parseState = parsingAttributeDquote;
+ case '<': // empty tag ( bad XML )
+ parseState = parsingText;
+ break;
+
+ default:
+ parseState = parsingElement;
+ }
break;
- case '\'':
- parseState = parsingAttributeSquote;
+ case parsingAttributeDquote:
+ if (ch == '"') {
+ parseState = parsingElement;
+ }
break;
- case '<': // empty tag ( bad XML )
- parseState = parsingText;
+ case parsingAttributeSquote:
+ if (ch == '\'') {
+ parseState = parsingElement;
+ }
break;
- default:
- parseState = parsingElement;
+ case parsingNonElement:
+ if (ch == '<') {
+ parseState = parsingText;
+ }
+ break;
}
- break;
-
- case parsingAttributeDquote:
- if( ch == '"' ) parseState = parsingElement;
- break;
-
- case parsingAttributeSquote:
- if( ch == '\'' ) parseState = parsingElement;
- break;
-
- case parsingNonElement:
- if( ch == '<' ) parseState = parsingText;
- break;
}
- }
}
/**
* Return true if the tag is neither a closing tag
* nor an empty tag, nor a comment, nor processing instruction.
*/
-bool PluginKateXMLToolsCompletionModel::isOpeningTag( const QString& tag )
+bool PluginKateXMLToolsCompletionModel::isOpeningTag(const QString &tag)
{
- return ( !isClosingTag(tag) && !isEmptyTag(tag ) &&
- !tag.startsWith( "<?") && !tag.startsWith("<!") );
+ return (!isClosingTag(tag) && !isEmptyTag(tag) &&
+ !tag.startsWith("<?") && !tag.startsWith("<!"));
}
/**
* Return true if the tag is a closing tag. Return false
* if the tag is an opening tag or an empty tag ( ! )
*/
-bool PluginKateXMLToolsCompletionModel::isClosingTag( const QString& tag )
+bool PluginKateXMLToolsCompletionModel::isClosingTag(const QString &tag)
{
- return ( tag.startsWith("</") );
+ return (tag.startsWith("</"));
}
-bool PluginKateXMLToolsCompletionModel::isEmptyTag( const QString& tag )
+bool PluginKateXMLToolsCompletionModel::isEmptyTag(const QString &tag)
{
- return ( tag.right(2) == "/>" );
+ return (tag.right(2) == "/>");
}
/**
* Return true if ch is a single or double quote. Expects ch to be of length 1.
*/
-bool PluginKateXMLToolsCompletionModel::isQuote( const QString& ch )
+bool PluginKateXMLToolsCompletionModel::isQuote(const QString &ch)
{
- return ( ch == "\"" || ch == "'" );
+ return (ch == "\"" || ch == "'");
}
@@ -1039,99 +1018,99 @@ bool PluginKateXMLToolsCompletionModel::isQuote( const QString& ch )
/// Get string describing current mode
QString PluginKateXMLToolsCompletionModel::currentModeToString() const
{
- switch (m_mode)
- {
+ switch (m_mode) {
case entities:
- return i18n("XML entities");
+ return i18n("XML entities");
case attributevalues:
- return i18n("XML attribute values");
+ return i18n("XML attribute values");
case attributes:
- return i18n("XML attributes");
+ return i18n("XML attributes");
case elements:
case closingtag:
- return i18n("XML elements");
+ return i18n("XML elements");
default:
- break;
- }
- return QString();
+ break;
+ }
+ return QString();
}
/** Sort a QStringList case-insensitively. Static. TODO: make it more simple. */
-QStringList PluginKateXMLToolsCompletionModel::sortQStringList( QStringList list ) {
- // Sort list case-insensitive. This looks complicated but using a QMap
- // is even suggested by the Qt documentation.
- QMap<QString,QString> mapList;
- for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )
- {
- QString str = *it;
- if( mapList.contains(str.toLower()) )
- {
- // do not override a previous value, e.g. "Auml" and "auml" are two different
- // entities, but they should be sorted next to each other.
- // TODO: currently it's undefined if e.g. "A" or "a" comes first, it depends on
- // the meta DTD ( really? it seems to work okay?!? )
- mapList[str.toLower()+'_'] = str;
+QStringList PluginKateXMLToolsCompletionModel::sortQStringList(QStringList list)
+{
+ // Sort list case-insensitive. This looks complicated but using a QMap
+ // is even suggested by the Qt documentation.
+ QMap<QString, QString> mapList;
+ for (QStringList::Iterator it = list.begin(); it != list.end(); ++it) {
+ QString str = *it;
+ if (mapList.contains(str.toLower())) {
+ // do not override a previous value, e.g. "Auml" and "auml" are two different
+ // entities, but they should be sorted next to each other.
+ // TODO: currently it's undefined if e.g. "A" or "a" comes first, it depends on
+ // the meta DTD ( really? it seems to work okay?!? )
+ mapList[str.toLower() + '_'] = str;
+ } else {
+ mapList[str.toLower()] = str;
+ }
}
- else
- mapList[str.toLower()] = str;
- }
- list.clear();
- QMap<QString,QString>::Iterator it;
+ list.clear();
+ QMap<QString, QString>::Iterator it;
- // Qt doc: "the items are alphabetically sorted [by key] when iterating over the map":
- for( it = mapList.begin(); it != mapList.end(); ++it )
- list.append( it.value() );
+ // Qt doc: "the items are alphabetically sorted [by key] when iterating over the map":
+ for (it = mapList.begin(); it != mapList.end(); ++it) {
+ list.append(it.value());
+ }
- return list;
+ return list;
}
//BEGIN InsertElement dialog
-InsertElement::InsertElement( QWidget* const parent, const char *name )
- :KDialog( parent)
+InsertElement::InsertElement(QWidget *const parent, const char *name)
+ : KDialog(parent)
{
- Q_UNUSED( name )
+ Q_UNUSED(name)
- setCaption(i18n("Insert XML Element" ));
- setButtons(KDialog::Ok|KDialog::Cancel);
- setDefaultButton(KDialog::Ok);
- setModal(true);
+ setCaption(i18n("Insert XML Element"));
+ setButtons(KDialog::Ok | KDialog::Cancel);
+ setDefaultButton(KDialog::Ok);
+ setModal(true);
}
InsertElement::~InsertElement()
{
}
-void InsertElement::slotHistoryTextChanged( const QString& text )
+void InsertElement::slotHistoryTextChanged(const QString &text)
{
- enableButtonOk( !text.isEmpty() );
+ enableButtonOk(!text.isEmpty());
}
-QString InsertElement::showDialog( QStringList &completions )
+QString InsertElement::showDialog(QStringList &completions)
{
- QWidget *page = new QWidget( this );
- setMainWidget( page );
- QVBoxLayout *topLayout = new QVBoxLayout( page );
-
- KHistoryComboBox *combo = new KHistoryComboBox( page );
- combo->setHistoryItems( completions, true );
- connect( combo->lineEdit(), SIGNAL(textChanged(QString)),
- this, SLOT(slotHistoryTextChanged(QString)) );
- QString text = i18n( "Enter XML tag name and attributes (\"<\", \">\" and closing tag will be supplied):" );
- QLabel *label = new QLabel( text, page );
-
- topLayout->addWidget( label );
- topLayout->addWidget( combo );
-
- combo->setFocus();
- slotHistoryTextChanged( combo->lineEdit()->text() );
- if( exec() )
- return combo->currentText();
-
- return QString();
+ QWidget *page = new QWidget(this);
+ setMainWidget(page);
+ QVBoxLayout *topLayout = new QVBoxLayout(page);
+
+ KHistoryComboBox *combo = new KHistoryComboBox(page);
+ combo->setHistoryItems(completions, true);
+ connect(combo->lineEdit(), SIGNAL(textChanged(QString)),
+ this, SLOT(slotHistoryTextChanged(QString)));
+ QString text = i18n("Enter XML tag name and attributes (\"<\", \">\" and closing tag will be supplied):");
+ QLabel *label = new QLabel(text, page);
+
+ topLayout->addWidget(label);
+ topLayout->addWidget(combo);
+
+ combo->setFocus();
+ slotHistoryTextChanged(combo->lineEdit()->text());
+ if (exec()) {
+ return combo->currentText();
+ }
+
+ return QString();
}
//END InsertElement dialog
#include "plugin_katexmltools.moc"
-// kate: space-indent on; indent-width 2; replace-tabs on; mixed-indent off;
+// kate: space-indent on; indent-width 4; replace-tabs on; mixed-indent off;
diff --git a/addons/kate/xmltools/plugin_katexmltools.h b/addons/kate/xmltools/plugin_katexmltools.h
index 98ed188..40996b3 100644
--- a/addons/kate/xmltools/plugin_katexmltools.h
+++ b/addons/kate/xmltools/plugin_katexmltools.h
@@ -1,8 +1,8 @@
- /***************************************************************************
- pluginKatexmltools.cpp
- copyright : (C) 2001-2002 by Daniel Naber
- email : daniel.naber@t-online.de
- ***************************************************************************/
+/***************************************************************************
+ pluginKatexmltools.cpp
+ copyright : (C) 2001-2002 by Daniel Naber
+ email : daniel.naber@t-online.de
+***************************************************************************/
/***************************************************************************
This program is free software; you can redistribute it and/or
@@ -43,78 +43,78 @@
class PluginKateXMLTools : public KTextEditor::Plugin
{
- Q_OBJECT
+ Q_OBJECT
- public:
- explicit PluginKateXMLTools( QObject* parent = 0, const QVariantList& = QVariantList() );
+public:
+ explicit PluginKateXMLTools(QObject *parent = 0, const QVariantList& = QVariantList());
~PluginKateXMLTools();
virtual QObject *createView(KTextEditor::MainWindow *mainWindow);
};
class PluginKateXMLToolsCompletionModel
- : public KTextEditor::CodeCompletionModel
- , public KTextEditor::CodeCompletionModelControllerInterface
+ : public KTextEditor::CodeCompletionModel
+ , public KTextEditor::CodeCompletionModelControllerInterface
{
- Q_OBJECT
- Q_INTERFACES(KTextEditor::CodeCompletionModelControllerInterface)
+ Q_OBJECT
+ Q_INTERFACES(KTextEditor::CodeCompletionModelControllerInterface)
- public:
- PluginKateXMLToolsCompletionModel( QObject *parent );
+public:
+ PluginKateXMLToolsCompletionModel(QObject *parent);
virtual ~PluginKateXMLToolsCompletionModel();
- //
- // KTextEditor::CodeCompletionModel
- //
- public:
- virtual int columnCount(const QModelIndex&) const;
+//
+// 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 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 executeCompletionItem(KTextEditor::View *view,
const KTextEditor::Range &word,
const QModelIndex &index) const;
- //
- // KTextEditor::CodeCompletionModelControllerInterface
- //
- public:
+//
+// KTextEditor::CodeCompletionModelControllerInterface
+//
+public:
virtual bool shouldStartCompletion(KTextEditor::View *view,
const QString &insertedText,
bool userInsertion,
const KTextEditor::Cursor &position);
- public Q_SLOTS:
+public Q_SLOTS:
void getDTD();
void slotInsertElement();
void slotCloseElement();
- void slotFinished( KJob *job );
- void slotData( KIO::Job *, const QByteArray &data );
+ void slotFinished(KJob *job);
+ void slotData(KIO::Job *, const QByteArray &data);
- void completionInvoked( KTextEditor::View *kv, const KTextEditor::Range &range, InvocationType invocationType );
+ void completionInvoked(KTextEditor::View *kv, const KTextEditor::Range &range, InvocationType invocationType);
/// Connected to the document manager, to manage the dtd collection.
- void slotDocumentDeleted( KTextEditor::Document *doc );
+ void slotDocumentDeleted(KTextEditor::Document *doc);
- protected:
+protected:
QString currentModeToString() const;
- static QStringList sortQStringList( QStringList list );
+ static QStringList sortQStringList(QStringList list);
//bool eventFilter( QObject *object, QEvent *event );
- QString insideTag( KTextEditor::View &kv );
- QString insideAttribute( KTextEditor::View &kv );
+ QString insideTag(KTextEditor::View &kv);
+ QString insideAttribute(KTextEditor::View &kv);
- static bool isOpeningTag( const QString& tag );
- static bool isClosingTag( const QString& tag );
- static bool isEmptyTag( const QString& tag );
- static bool isQuote( const QString& ch );
+ static bool isOpeningTag(const QString &tag);
+ static bool isClosingTag(const QString &tag);
+ static bool isEmptyTag(const QString &tag);
+ static bool isQuote(const QString &ch);
- QString getParentElement( KTextEditor::View &view, int skipCharacters );
+ QString getParentElement(KTextEditor::View &view, int skipCharacters);
enum Mode {none, entities, attributevalues, attributes, elements, closingtag};
enum PopupMode {noPopup, tagname, attributename, attributevalue, entityname};
@@ -137,7 +137,7 @@ class PluginKateXMLToolsCompletionModel
int m_correctPos;
// code completion stuff:
- KTextEditor::CodeCompletionInterface* m_codeInterface;
+ KTextEditor::CodeCompletionInterface *m_codeInterface;
/// maps KTE::Document -> DTD
QHash<KTextEditor::Document *, PseudoDTD *> m_docDtds;
@@ -148,14 +148,14 @@ class PluginKateXMLToolsCompletionModel
class PluginKateXMLToolsView : public QObject, public KXMLGUIClient
{
- Q_OBJECT
+ Q_OBJECT
- public:
+public:
explicit PluginKateXMLToolsView(KTextEditor::Plugin *plugin, KTextEditor::MainWindow *mainWin);
virtual ~PluginKateXMLToolsView();
- protected:
+protected:
KTextEditor::MainWindow *m_mainWindow;
PluginKateXMLToolsCompletionModel m_model;
};
@@ -163,17 +163,17 @@ class PluginKateXMLToolsView : public QObject, public KXMLGUIClient
class InsertElement : public KDialog
{
- Q_OBJECT
+ Q_OBJECT
- public:
- InsertElement( QWidget *parent, const char *name );
+public:
+ InsertElement(QWidget *parent, const char *name);
~InsertElement();
- QString showDialog( QStringList &completions );
- private Q_SLOTS:
- void slotHistoryTextChanged( const QString& );
+ QString showDialog(QStringList &completions);
+private Q_SLOTS:
+ void slotHistoryTextChanged(const QString &);
};
#endif // PLUGIN_KATEXMLTOOLS_H
-// kate: space-indent on; indent-width 2; replace-tabs on; mixed-indent off;
+// kate: space-indent on; indent-width 4; replace-tabs on; mixed-indent off;
diff --git a/addons/kate/xmltools/pseudo_dtd.cpp b/addons/kate/xmltools/pseudo_dtd.cpp
index 4dc2a89..7879977 100644
--- a/addons/kate/xmltools/pseudo_dtd.cpp
+++ b/addons/kate/xmltools/pseudo_dtd.cpp
@@ -1,7 +1,7 @@
/***************************************************************************
- pseudoDtd.cpp
- copyright : (C) 2001-2002 by Daniel Naber
- email : daniel.naber@t-online.de
+ pseudoDtd.cpp
+ copyright : (C) 2001-2002 by Daniel Naber
+ email : daniel.naber@t-online.de
***************************************************************************/
/***************************************************************************
@@ -32,60 +32,62 @@
PseudoDTD::PseudoDTD()
{
- // "SGML support" only means case-insensivity, because HTML is case-insensitive up to version 4:
- m_sgmlSupport = true; // TODO: make this an run-time option ( maybe automatically set )
+ // "SGML support" only means case-insensivity, because HTML is case-insensitive up to version 4:
+ m_sgmlSupport = true; // TODO: make this an run-time option ( maybe automatically set )
}
PseudoDTD::~PseudoDTD()
{
}
-void PseudoDTD::analyzeDTD( QString &metaDtdUrl, QString &metaDtd )
+void PseudoDTD::analyzeDTD(QString &metaDtdUrl, QString &metaDtd)
{
- QDomDocument doc( "dtdIn_xml" );
- if ( ! doc.setContent( metaDtd) )
- {
- KMessageBox::error(0, i18n("The file '%1' could not be parsed. "
- "Please check that the file is well-formed XML.", metaDtdUrl ),
- i18n( "XML Plugin Error") );
- return;
- }
-
- if ( doc.doctype().name() != "dtd" )
- {
- KMessageBox::error(0, i18n("The file '%1' is not in the expected format. "
- "Please check that the file is of this type:\n"
- "-//Norman Walsh//DTD DTDParse V2.0//EN\n"
- "You can produce such files with dtdparse. "
- "See the Kate Plugin documentation for more information.", metaDtdUrl ),
- i18n("XML Plugin Error") );
- return;
- }
-
- uint listLength = 0;
- listLength += doc.elementsByTagName( "entity" ).count();
- listLength += doc.elementsByTagName( "element" ).count();
- // count this twice, as it will be iterated twice ( TODO: optimize that? ):
- listLength += doc.elementsByTagName( "attlist" ).count() * 2;
-
- QProgressDialog progress( i18n("Analyzing meta DTD..."), i18n("Cancel"), 0, listLength );
- progress.setMinimumDuration( 400 );
- progress.setValue(0);
-
- // Get information from meta DTD and put it in Qt data structures for fast access:
- if( ! parseEntities( &doc, &progress ) )
- return;
-
- if( ! parseElements( &doc, &progress ) )
- return;
-
- if( ! parseAttributes( &doc, &progress ) )
- return;
-
- if( ! parseAttributeValues( &doc, &progress ) )
- return;
-
- progress.setValue( listLength ); // just to make sure the dialog disappears
+ QDomDocument doc("dtdIn_xml");
+ if (! doc.setContent(metaDtd)) {
+ KMessageBox::error(0, i18n("The file '%1' could not be parsed. "
+ "Please check that the file is well-formed XML.", metaDtdUrl),
+ i18n("XML Plugin Error"));
+ return;
+ }
+
+ if (doc.doctype().name() != "dtd") {
+ KMessageBox::error(0, i18n("The file '%1' is not in the expected format. "
+ "Please check that the file is of this type:\n"
+ "-//Norman Walsh//DTD DTDParse V2.0//EN\n"
+ "You can produce such files with dtdparse. "
+ "See the Kate Plugin documentation for more information.", metaDtdUrl),
+ i18n("XML Plugin Error"));
+ return;
+ }
+
+ uint listLength = 0;
+ listLength += doc.elementsByTagName("entity").count();
+ listLength += doc.elementsByTagName("element").count();
+ // count this twice, as it will be iterated twice ( TODO: optimize that? ):
+ listLength += doc.elementsByTagName("attlist").count() * 2;
+
+ QProgressDialog progress(i18n("Analyzing meta DTD..."), i18n("Cancel"), 0, listLength);
+ progress.setMinimumDuration(400);
+ progress.setValue(0);
+
+ // Get information from meta DTD and put it in Qt data structures for fast access:
+ if (! parseEntities(&doc, &progress)) {
+ return;
+ }
+
+ if (! parseElements(&doc, &progress)) {
+ return;
+ }
+
+ if (! parseAttributes(&doc, &progress)) {
+ return;
+ }
+
+ if (! parseAttributeValues(&doc, &progress)) {
+ return;
+ }
+
+ progress.setValue(listLength); // just to make sure the dialog disappears
}
@@ -96,98 +98,96 @@ void PseudoDTD::analyzeDTD( QString &metaDtdUrl, QString &metaDtd )
* Iterate through the XML to get a mapping which sub-elements are allowed for
* all elements.
*/
-bool PseudoDTD::parseElements( QDomDocument *doc, QProgressDialog *progress )
+bool PseudoDTD::parseElements(QDomDocument *doc, QProgressDialog *progress)
{
- m_elementsList.clear();
- // We only display a list, i.e. we pretend that the content model is just
- // a set, so we use a map. This is necessay e.g. for xhtml 1.0's head element,
- // which would otherwise display some elements twice.
- QMap<QString,bool> subelementList; // the bool is not used
-
- QDomNodeList list = doc->elementsByTagName( "element" );
- uint listLength = list.count(); // speedup (really! )
-
- for( uint i = 0; i < listLength; i++ )
- {
- if( progress->wasCanceled() )
- return false;
-
- progress->setValue( progress->value()+1 );
- // FIXME!:
- //qApp->processEvents();
-
- subelementList.clear();
- QDomNode node = list.item( i );
- QDomElement elem = node.toElement();
-
- if( !elem.isNull() )
- {
- // Enter the expanded content model, which may also include stuff not allowed.
- // We do not care if it's a <sequence-group> or whatever.
- QDomNodeList contentModelList = elem.elementsByTagName( "content-model-expanded" );
- QDomNode contentModelNode = contentModelList.item(0);
- QDomElement contentModelElem = contentModelNode.toElement();
- if( ! contentModelElem.isNull() )
- {
- // check for <pcdata/>:
- QDomNodeList pcdataList = contentModelElem.elementsByTagName( "pcdata" );
-
- // check for other sub elements:
- QDomNodeList subList = contentModelElem.elementsByTagName( "element-name" );
- uint subListLength = subList.count();
- for( uint l = 0; l < subListLength; l++ )
- {
- QDomNode subNode = subList.item(l);
- QDomElement subElem = subNode.toElement();
- if( !subElem.isNull() )
- subelementList[subElem.attribute( "name" )] = true;
+ m_elementsList.clear();
+ // We only display a list, i.e. we pretend that the content model is just
+ // a set, so we use a map. This is necessay e.g. for xhtml 1.0's head element,
+ // which would otherwise display some elements twice.
+ QMap<QString, bool> subelementList; // the bool is not used
+
+ QDomNodeList list = doc->elementsByTagName("element");
+ uint listLength = list.count(); // speedup (really! )
+
+ for (uint i = 0; i < listLength; i++) {
+ if (progress->wasCanceled()) {
+ return false;
}
- // anders: check if this is an EMPTY element, and put "__EMPTY" in the
- // sub list, so that we can insert tags in empty form if required.
- QDomNodeList emptyList = elem.elementsByTagName( "empty" );
- if ( emptyList.count() )
- subelementList["__EMPTY"] = true;
- }
-
- // Now remove the elements not allowed (e.g. <a> is explicitly not allowed in <a>
- // in the HTML 4.01 Strict DTD):
- QDomNodeList exclusionsList = elem.elementsByTagName( "exclusions" );
- if( exclusionsList.length() > 0 )
- { // sometimes there are no exclusions ( e.g. in XML DTDs there are never exclusions )
- QDomNode exclusionsNode = exclusionsList.item(0);
- QDomElement exclusionsElem = exclusionsNode.toElement();
- if( ! exclusionsElem.isNull() )
- {
- QDomNodeList subList = exclusionsElem.elementsByTagName( "element-name" );
- uint subListLength = subList.count();
- for( uint l = 0; l < subListLength; l++ )
- {
- QDomNode subNode = subList.item(l);
- QDomElement subElem = subNode.toElement();
- if( !subElem.isNull() )
- {
- QMap<QString,bool>::Iterator it = subelementList.find( subElem.attribute( "name" ) );
- if( it != subelementList.end() )
- subelementList.erase(it);
+ progress->setValue(progress->value() + 1);
+ // FIXME!:
+ //qApp->processEvents();
+
+ subelementList.clear();
+ QDomNode node = list.item(i);
+ QDomElement elem = node.toElement();
+
+ if (!elem.isNull()) {
+ // Enter the expanded content model, which may also include stuff not allowed.
+ // We do not care if it's a <sequence-group> or whatever.
+ QDomNodeList contentModelList = elem.elementsByTagName("content-model-expanded");
+ QDomNode contentModelNode = contentModelList.item(0);
+ QDomElement contentModelElem = contentModelNode.toElement();
+ if (! contentModelElem.isNull()) {
+ // check for <pcdata/>:
+ QDomNodeList pcdataList = contentModelElem.elementsByTagName("pcdata");
+
+ // check for other sub elements:
+ QDomNodeList subList = contentModelElem.elementsByTagName("element-name");
+ uint subListLength = subList.count();
+ for (uint l = 0; l < subListLength; l++) {
+ QDomNode subNode = subList.item(l);
+ QDomElement subElem = subNode.toElement();
+ if (!subElem.isNull()) {
+ subelementList[subElem.attribute("name")] = true;
+ }
+ }
+
+ // anders: check if this is an EMPTY element, and put "__EMPTY" in the
+ // sub list, so that we can insert tags in empty form if required.
+ QDomNodeList emptyList = elem.elementsByTagName("empty");
+ if (emptyList.count()) {
+ subelementList["__EMPTY"] = true;
+ }
+ }
+
+ // Now remove the elements not allowed (e.g. <a> is explicitly not allowed in <a>
+ // in the HTML 4.01 Strict DTD):
+ QDomNodeList exclusionsList = elem.elementsByTagName("exclusions");
+ if (exclusionsList.length() > 0) {
+ // sometimes there are no exclusions ( e.g. in XML DTDs there are never exclusions )
+ QDomNode exclusionsNode = exclusionsList.item(0);
+ QDomElement exclusionsElem = exclusionsNode.toElement();
+ if (! exclusionsElem.isNull()) {
+ QDomNodeList subList = exclusionsElem.elementsByTagName("element-name");
+ uint subListLength = subList.count();
+ for (uint l = 0; l < subListLength; l++) {
+ QDomNode subNode = subList.item(l);
+ QDomElement subElem = subNode.toElement();
+ if (!subElem.isNull()) {
+ QMap<QString, bool>::Iterator it = subelementList.find(subElem.attribute("name"));
+ if (it != subelementList.end()) {
+ subelementList.erase(it);
+ }
+ }
+ }
+ }
}
- }
- }
- }
- // turn the map into a list:
- QStringList subelementListTmp;
- QMap<QString,bool>::Iterator it;
- for( it = subelementList.begin(); it != subelementList.end(); ++it )
- subelementListTmp.append( it.key() );
+ // turn the map into a list:
+ QStringList subelementListTmp;
+ QMap<QString, bool>::Iterator it;
+ for (it = subelementList.begin(); it != subelementList.end(); ++it) {
+ subelementListTmp.append(it.key());
+ }
- m_elementsList.insert( elem.attribute( "name" ), subelementListTmp );
+ m_elementsList.insert(elem.attribute("name"), subelementListTmp);
- }
+ }
- } // end iteration over all <element> nodes
- return true;
+ } // end iteration over all <element> nodes
+ return true;
}
/**
@@ -195,151 +195,142 @@ bool PseudoDTD::parseElements( QDomDocument *doc, QProgressDialog *progress )
* a list of allowed elements, but it doesn't care about order or if only a certain
* number of occurrences is allowed.
*/
-QStringList PseudoDTD::allowedElements( QString parentElement )
+QStringList PseudoDTD::allowedElements(QString parentElement)
{
- if( m_sgmlSupport )
- {
- // find the matching element, ignoring case:
- QMap<QString,QStringList>::Iterator it;
- for( it = m_elementsList.begin(); it != m_elementsList.end(); ++it )
- {
- if( it.key().compare( parentElement, Qt::CaseInsensitive ) == 0 )
- return it.value();
+ if (m_sgmlSupport) {
+ // find the matching element, ignoring case:
+ QMap<QString, QStringList>::Iterator it;
+ for (it = m_elementsList.begin(); it != m_elementsList.end(); ++it) {
+ if (it.key().compare(parentElement, Qt::CaseInsensitive) == 0) {
+ return it.value();
+ }
+ }
+ } else if (m_elementsList.contains(parentElement)) {
+ return m_elementsList[parentElement];
}
- }
- else if( m_elementsList.contains(parentElement) )
- return m_elementsList[parentElement];
- return QStringList();
+ return QStringList();
}
/**
* Iterate through the XML to get a mapping which attributes are allowed inside
* all elements.
*/
-bool PseudoDTD::parseAttributes( QDomDocument *doc, QProgressDialog *progress )
+bool PseudoDTD::parseAttributes(QDomDocument *doc, QProgressDialog *progress)
{
- m_attributesList.clear();
+ m_attributesList.clear();
// QStringList allowedAttributes;
- QDomNodeList list = doc->elementsByTagName( "attlist" );
- uint listLength = list.count();
-
- for( uint i = 0; i < listLength; i++ )
- {
- if( progress->wasCanceled() )
- return false;
-
- progress->setValue( progress->value()+1 );
- // FIXME!!
- //qApp->processEvents();
-
- ElementAttributes attrs;
- QDomNode node = list.item(i);
- QDomElement elem = node.toElement();
- if( !elem.isNull() )
- {
- QDomNodeList attributeList = elem.elementsByTagName( "attribute" );
- uint attributeListLength = attributeList.count();
- for( uint l = 0; l < attributeListLength; l++ )
- {
- QDomNode attributeNode = attributeList.item(l);
- QDomElement attributeElem = attributeNode.toElement();
-
- if( ! attributeElem.isNull() )
- {
- if ( attributeElem.attribute("type") == "#REQUIRED" )
- attrs.requiredAttributes.append( attributeElem.attribute("name") );
- else
- attrs.optionalAttributes.append( attributeElem.attribute("name") );
+ QDomNodeList list = doc->elementsByTagName("attlist");
+ uint listLength = list.count();
+
+ for (uint i = 0; i < listLength; i++) {
+ if (progress->wasCanceled()) {
+ return false;
+ }
+
+ progress->setValue(progress->value() + 1);
+ // FIXME!!
+ //qApp->processEvents();
+
+ ElementAttributes attrs;
+ QDomNode node = list.item(i);
+ QDomElement elem = node.toElement();
+ if (!elem.isNull()) {
+ QDomNodeList attributeList = elem.elementsByTagName("attribute");
+ uint attributeListLength = attributeList.count();
+ for (uint l = 0; l < attributeListLength; l++) {
+ QDomNode attributeNode = attributeList.item(l);
+ QDomElement attributeElem = attributeNode.toElement();
+
+ if (! attributeElem.isNull()) {
+ if (attributeElem.attribute("type") == "#REQUIRED") {
+ attrs.requiredAttributes.append(attributeElem.attribute("name"));
+ } else {
+ attrs.optionalAttributes.append(attributeElem.attribute("name"));
+ }
+ }
+ }
+ m_attributesList.insert(elem.attribute("name"), attrs);
}
- }
- m_attributesList.insert( elem.attribute("name"), attrs );
}
- }
- return true;
+ return true;
}
/** Check which attributes are allowed for an element.
*/
-QStringList PseudoDTD::allowedAttributes( QString element )
+QStringList PseudoDTD::allowedAttributes(QString element)
{
- if( m_sgmlSupport )
- {
- // find the matching element, ignoring case:
- QMap<QString,ElementAttributes>::Iterator it;
- for( it = m_attributesList.begin(); it != m_attributesList.end(); ++it ) {
- if( it.key().compare( element, Qt::CaseInsensitive ) == 0 )
- {
- return it.value().optionalAttributes + it.value().requiredAttributes;
- }
+ if (m_sgmlSupport) {
+ // find the matching element, ignoring case:
+ QMap<QString, ElementAttributes>::Iterator it;
+ for (it = m_attributesList.begin(); it != m_attributesList.end(); ++it) {
+ if (it.key().compare(element, Qt::CaseInsensitive) == 0) {
+ return it.value().optionalAttributes + it.value().requiredAttributes;
+ }
+ }
+ } else if (m_attributesList.contains(element)) {
+ return m_attributesList[element].optionalAttributes + m_attributesList[element].requiredAttributes;
}
- }
- else if( m_attributesList.contains(element) )
- return m_attributesList[element].optionalAttributes + m_attributesList[element].requiredAttributes;
- return QStringList();
+ return QStringList();
}
-QStringList PseudoDTD::requiredAttributes( const QString &element ) const
+QStringList PseudoDTD::requiredAttributes(const QString &element) const
{
- if ( m_sgmlSupport )
- {
- QMap<QString,ElementAttributes>::ConstIterator it;
- for( it = m_attributesList.begin(); it != m_attributesList.end(); ++it )
- {
- if( it.key().compare( element, Qt::CaseInsensitive ) == 0 )
- return it.value().requiredAttributes;
+ if (m_sgmlSupport) {
+ QMap<QString, ElementAttributes>::ConstIterator it;
+ for (it = m_attributesList.begin(); it != m_attributesList.end(); ++it) {
+ if (it.key().compare(element, Qt::CaseInsensitive) == 0) {
+ return it.value().requiredAttributes;
+ }
+ }
+ } else if (m_attributesList.contains(element)) {
+ return m_attributesList[element].requiredAttributes;
}
- }
- else if( m_attributesList.contains(element) )
- return m_attributesList[element].requiredAttributes;
- return QStringList();
+ return QStringList();
}
/**
* Iterate through the XML to get a mapping which attribute values are allowed
* for all attributes inside all elements.
*/
-bool PseudoDTD::parseAttributeValues( QDomDocument *doc, QProgressDialog *progress )
+bool PseudoDTD::parseAttributeValues(QDomDocument *doc, QProgressDialog *progress)
{
- m_attributevaluesList.clear(); // 1 element : n possible attributes
- QMap<QString,QStringList> attributevaluesTmp; // 1 attribute : n possible values
- QDomNodeList list = doc->elementsByTagName( "attlist" );
- uint listLength = list.count();
-
- for( uint i = 0; i < listLength; i++ )
- {
- if( progress->wasCanceled() )
- return false;
-
- progress->setValue( progress->value()+1 );
- // FIXME!
- //qApp->processEvents();
-
- attributevaluesTmp.clear();
- QDomNode node = list.item(i);
- QDomElement elem = node.toElement();
- if( !elem.isNull() )
- {
- // Enter the list of <attribute>:
- QDomNodeList attributeList = elem.elementsByTagName( "attribute" );
- uint attributeListLength = attributeList.count();
- for( uint l = 0; l < attributeListLength; l++ )
- {
- QDomNode attributeNode = attributeList.item(l);
- QDomElement attributeElem = attributeNode.toElement();
- if( ! attributeElem.isNull() )
- {
- QString value = attributeElem.attribute( "value" );
- attributevaluesTmp.insert( attributeElem.attribute("name"), value.split( QChar(' ') ) );
+ m_attributevaluesList.clear(); // 1 element : n possible attributes
+ QMap<QString, QStringList> attributevaluesTmp; // 1 attribute : n possible values
+ QDomNodeList list = doc->elementsByTagName("attlist");
+ uint listLength = list.count();
+
+ for (uint i = 0; i < listLength; i++) {
+ if (progress->wasCanceled()) {
+ return false;
+ }
+
+ progress->setValue(progress->value() + 1);
+ // FIXME!
+ //qApp->processEvents();
+
+ attributevaluesTmp.clear();
+ QDomNode node = list.item(i);
+ QDomElement elem = node.toElement();
+ if (!elem.isNull()) {
+ // Enter the list of <attribute>:
+ QDomNodeList attributeList = elem.elementsByTagName("attribute");
+ uint attributeListLength = attributeList.count();
+ for (uint l = 0; l < attributeListLength; l++) {
+ QDomNode attributeNode = attributeList.item(l);
+ QDomElement attributeElem = attributeNode.toElement();
+ if (! attributeElem.isNull()) {
+ QString value = attributeElem.attribute("value");
+ attributevaluesTmp.insert(attributeElem.attribute("name"), value.split(QChar(' ')));
+ }
+ }
+ m_attributevaluesList.insert(elem.attribute("name"), attributevaluesTmp);
}
- }
- m_attributevaluesList.insert( elem.attribute("name"), attributevaluesTmp );
}
- }
- return true;
+ return true;
}
/**
@@ -347,120 +338,113 @@ bool PseudoDTD::parseAttributeValues( QDomDocument *doc, QProgressDialog *progre
* (the element is necessary because e.g. "href" inside <a> could be different
* to an "href" inside <link>):
*/
-QStringList PseudoDTD::attributeValues( QString element, QString attribute )
+QStringList PseudoDTD::attributeValues(QString element, QString attribute)
{
- // Direct access would be faster than iteration of course but not always correct,
- // because we need to be case-insensitive.
- if( m_sgmlSupport ) {
- // first find the matching element, ignoring case:
- QMap< QString,QMap<QString,QStringList> >::Iterator it;
- for( it = m_attributevaluesList.begin(); it != m_attributevaluesList.end(); ++it )
- {
- if( it.key().compare( element, Qt::CaseInsensitive ) == 0 )
- {
- QMap<QString,QStringList> attrVals = it.value();
- QMap<QString,QStringList>::Iterator itV;
- // then find the matching attribute for that element, ignoring case:
- for( itV = attrVals.begin(); itV != attrVals.end(); ++itV )
- {
- if( itV.key().compare( attribute, Qt::CaseInsensitive ) == 0 )
- return( itV.value() );
+ // Direct access would be faster than iteration of course but not always correct,
+ // because we need to be case-insensitive.
+ if (m_sgmlSupport) {
+ // first find the matching element, ignoring case:
+ QMap< QString, QMap<QString, QStringList> >::Iterator it;
+ for (it = m_attributevaluesList.begin(); it != m_attributevaluesList.end(); ++it) {
+ if (it.key().compare(element, Qt::CaseInsensitive) == 0) {
+ QMap<QString, QStringList> attrVals = it.value();
+ QMap<QString, QStringList>::Iterator itV;
+ // then find the matching attribute for that element, ignoring case:
+ for (itV = attrVals.begin(); itV != attrVals.end(); ++itV) {
+ if (itV.key().compare(attribute, Qt::CaseInsensitive) == 0) {
+ return(itV.value());
+ }
+ }
+ }
+ }
+ } else if (m_attributevaluesList.contains(element)) {
+ QMap<QString, QStringList> attrVals = m_attributevaluesList[element];
+ if (attrVals.contains(attribute)) {
+ return attrVals[attribute];
}
- }
}
- }
- else if( m_attributevaluesList.contains(element) )
- {
- QMap<QString,QStringList> attrVals = m_attributevaluesList[element];
- if( attrVals.contains(attribute) )
- return attrVals[attribute];
- }
-
- // no predefined values available:
- return QStringList();
+
+ // no predefined values available:
+ return QStringList();
}
/**
* Iterate through the XML to get a mapping of all entity names and their expanded
* version, e.g. nbsp => &#160;. Parameter entities are ignored.
*/
-bool PseudoDTD::parseEntities( QDomDocument *doc, QProgressDialog *progress )
+bool PseudoDTD::parseEntities(QDomDocument *doc, QProgressDialog *progress)
{
- m_entityList.clear();
- QDomNodeList list = doc->elementsByTagName( "entity" );
- uint listLength = list.count();
-
- for( uint i = 0; i < listLength; i++ )
- {
- if( progress->wasCanceled() )
- return false;
-
- progress->setValue( progress->value()+1 );
- //FIXME!!
- //qApp->processEvents();
- QDomNode node = list.item(i);
- QDomElement elem = node.toElement();
- if( !elem.isNull()
- && elem.attribute( "type" ) != "param" )
- { // TODO: what's cdata <-> gen ?
- QDomNodeList expandedList = elem.elementsByTagName( "text-expanded" );
- QDomNode expandedNode = expandedList.item(0);
- QDomElement expandedElem = expandedNode.toElement();
- if( ! expandedElem.isNull() )
- {
- QString exp = expandedElem.text();
- // TODO: support more than one &#...; in the expanded text
- /* TODO include do this when the unicode font problem is solved:
- if( exp.contains(QRegExp("^&#x[a-zA-Z0-9]+;$")) ) {
- // hexadecimal numbers, e.g. "&#x236;"
- uint end = exp.find( ";" );
- exp = exp.mid( 3, end-3 );
- exp = QChar();
- } else if( exp.contains(QRegExp("^&#[0-9]+;$")) ) {
- // decimal numbers, e.g. "&#236;"
- uint end = exp.find( ";" );
- exp = exp.mid( 2, end-2 );
- exp = QChar( exp.toInt() );
- }
- */
- m_entityList.insert( elem.attribute("name"), exp );
- }
- else
- {
- m_entityList.insert( elem.attribute("name"), QString() );
- }
+ m_entityList.clear();
+ QDomNodeList list = doc->elementsByTagName("entity");
+ uint listLength = list.count();
+
+ for (uint i = 0; i < listLength; i++) {
+ if (progress->wasCanceled()) {
+ return false;
+ }
+
+ progress->setValue(progress->value() + 1);
+ //FIXME!!
+ //qApp->processEvents();
+ QDomNode node = list.item(i);
+ QDomElement elem = node.toElement();
+ if (!elem.isNull()
+ && elem.attribute("type") != "param") {
+ // TODO: what's cdata <-> gen ?
+ QDomNodeList expandedList = elem.elementsByTagName("text-expanded");
+ QDomNode expandedNode = expandedList.item(0);
+ QDomElement expandedElem = expandedNode.toElement();
+ if (! expandedElem.isNull()) {
+ QString exp = expandedElem.text();
+ // TODO: support more than one &#...; in the expanded text
+ /* TODO include do this when the unicode font problem is solved:
+ if( exp.contains(QRegExp("^&#x[a-zA-Z0-9]+;$")) ) {
+ // hexadecimal numbers, e.g. "&#x236;"
+ uint end = exp.find( ";" );
+ exp = exp.mid( 3, end-3 );
+ exp = QChar();
+ } else if( exp.contains(QRegExp("^&#[0-9]+;$")) ) {
+ // decimal numbers, e.g. "&#236;"
+ uint end = exp.find( ";" );
+ exp = exp.mid( 2, end-2 );
+ exp = QChar( exp.toInt() );
+ }
+ */
+ m_entityList.insert(elem.attribute("name"), exp);
+ } else {
+ m_entityList.insert(elem.attribute("name"), QString());
+ }
+ }
}
- }
- return true;
+ return true;
}
/**
* Get a list of all ( non-parameter ) entities that start with a certain string.
*/
-QStringList PseudoDTD::entities( QString start )
+QStringList PseudoDTD::entities(QString start)
{
- QStringList entities;
- QMap<QString,QString>::Iterator it;
- for( it = m_entityList.begin(); it != m_entityList.end(); ++it ) {
- if( (*it).startsWith(start) )
- {
- QString str = it.key();
- /* TODO: show entities as unicode character
- if( !it.data().isEmpty() ) {
- //str += " -- " + it.data();
- QRegExp re( "&#(\\d+);" );
- if( re.search(it.data()) != -1 ) {
- uint ch = re.cap( 1).toUInt();
- str += " -- " + QChar( ch).decomposition();
- }
- //qDebug() << "#" << it.data();
- }
- */
- entities.append( str );
- // TODO: later use a table view
+ QStringList entities;
+ QMap<QString, QString>::Iterator it;
+ for (it = m_entityList.begin(); it != m_entityList.end(); ++it) {
+ if ((*it).startsWith(start)) {
+ QString str = it.key();
+ /* TODO: show entities as unicode character
+ if( !it.data().isEmpty() ) {
+ //str += " -- " + it.data();
+ QRegExp re( "&#(\\d+);" );
+ if( re.search(it.data()) != -1 ) {
+ uint ch = re.cap( 1).toUInt();
+ str += " -- " + QChar( ch).decomposition();
+ }
+ //qDebug() << "#" << it.data();
+ }
+ */
+ entities.append(str);
+ // TODO: later use a table view
+ }
}
- }
- return entities;
+ return entities;
}
-// kate: space-indent on; indent-width 2; replace-tabs on; mixed-indent off;
+// kate: space-indent on; indent-width 4; replace-tabs on; mixed-indent off;
diff --git a/addons/kate/xmltools/pseudo_dtd.h b/addons/kate/xmltools/pseudo_dtd.h
index 22aed46..13186b2 100644
--- a/addons/kate/xmltools/pseudo_dtd.h
+++ b/addons/kate/xmltools/pseudo_dtd.h
@@ -1,8 +1,8 @@
- /***************************************************************************
- pseudoDtd.cpp
- copyright : (C) 2001-2002 by Daniel Naber
- email : daniel.naber@t-online.de
- ***************************************************************************/
+/***************************************************************************
+ pseudoDtd.cpp
+ copyright : (C) 2001-2002 by Daniel Naber
+ email : daniel.naber@t-online.de
+***************************************************************************/
/***************************************************************************
This program is free software; you can redistribute it and/or
@@ -33,7 +33,7 @@
*/
class ElementAttributes
{
- public:
+public:
QStringList optionalAttributes;
QStringList requiredAttributes;
};
@@ -41,38 +41,38 @@ class ElementAttributes
class PseudoDTD
{
- public:
+public:
PseudoDTD();
~PseudoDTD();
- void analyzeDTD( QString &metaDtdUrl, QString &metaDtd );
+ void analyzeDTD(QString &metaDtdUrl, QString &metaDtd);
- QStringList allowedElements( QString parentElement );
- QStringList allowedAttributes( QString parentElement );
- QStringList attributeValues( QString element, QString attribute );
- QStringList entities( QString start );
- QStringList requiredAttributes( const QString &parentElement ) const;
+ QStringList allowedElements(QString parentElement);
+ QStringList allowedAttributes(QString parentElement);
+ QStringList attributeValues(QString element, QString attribute);
+ QStringList entities(QString start);
+ QStringList requiredAttributes(const QString &parentElement) const;
- protected:
+protected:
- bool parseElements( QDomDocument *doc, QProgressDialog *progress );
- bool parseAttributes( QDomDocument *doc, QProgressDialog *progress );
- bool parseAttributeValues( QDomDocument *doc, QProgressDialog *progress );
- bool parseEntities( QDomDocument *doc, QProgressDialog *progress );
+ bool parseElements(QDomDocument *doc, QProgressDialog *progress);
+ bool parseAttributes(QDomDocument *doc, QProgressDialog *progress);
+ bool parseAttributeValues(QDomDocument *doc, QProgressDialog *progress);
+ bool parseEntities(QDomDocument *doc, QProgressDialog *progress);
bool m_sgmlSupport;
// Entities, e.g. <"nbsp", "160">
- QMap<QString,QString> m_entityList;
+ QMap<QString, QString> m_entityList;
// Elements, e.g. <"a", ( "b", "i", "em", "strong" )>
- QMap<QString,QStringList> m_elementsList;
+ QMap<QString, QStringList> m_elementsList;
// Attributes e.g. <"a", ( "href", "lang", "title" )>
- QMap<QString,ElementAttributes> m_attributesList;
+ QMap<QString, ElementAttributes> m_attributesList;
// Attribute values e.g. <"td", <"align", ( "left", "right", "justify" )>>
- QMap< QString,QMap<QString,QStringList> > m_attributevaluesList;
+ QMap< QString, QMap<QString, QStringList> > m_attributevaluesList;
};
#endif // PSEUDO_DTD_H
-// kate: space-indent on; indent-width 2; replace-tabs on; mixed-indent off;
+// kate: space-indent on; indent-width 4; replace-tabs on; mixed-indent off;