summaryrefslogtreecommitdiffstats
path: root/parts/texttools
diff options
context:
space:
mode:
Diffstat (limited to 'parts/texttools')
-rw-r--r--parts/texttools/Makefile.am18
-rw-r--r--parts/texttools/README.dox49
-rw-r--r--parts/texttools/kdevtexttools.desktop84
-rw-r--r--parts/texttools/texttoolspart.cpp99
-rw-r--r--parts/texttools/texttoolspart.h39
-rw-r--r--parts/texttools/texttoolswidget.cpp400
-rw-r--r--parts/texttools/texttoolswidget.h54
7 files changed, 743 insertions, 0 deletions
diff --git a/parts/texttools/Makefile.am b/parts/texttools/Makefile.am
new file mode 100644
index 00000000..8ebbc6b5
--- /dev/null
+++ b/parts/texttools/Makefile.am
@@ -0,0 +1,18 @@
+# Here resides the text tools part.
+
+INCLUDES = -I$(top_srcdir)/lib/interfaces -I$(top_srcdir)/lib/sourceinfo -I$(top_srcdir)/lib/util $(all_includes)
+
+kde_module_LTLIBRARIES = libkdevtexttools.la
+libkdevtexttools_la_LDFLAGS = $(all_libraries) $(KDE_PLUGIN)
+libkdevtexttools_la_LIBADD = $(top_builddir)/lib/libkdevelop.la
+
+libkdevtexttools_la_SOURCES = texttoolspart.cpp texttoolswidget.cpp
+
+METASOURCES = AUTO
+
+servicedir = $(kde_servicesdir)
+service_DATA = kdevtexttools.desktop
+
+# not used currently
+#rcdir = $(kde_datadir)/kdevtexttools
+#rc_DATA = kdevtexttools.rc
diff --git a/parts/texttools/README.dox b/parts/texttools/README.dox
new file mode 100644
index 00000000..3fd5180b
--- /dev/null
+++ b/parts/texttools/README.dox
@@ -0,0 +1,49 @@
+/** \class TextToolsPart
+Put a brief description here, the brief description ends at the first dot.
+Put a more detailed description of your part in these lines. It can span
+over several lines. You can even use some html commands in these lines like:
+<code>This is code</code>, html links <a href="http://somelocation">link text</a>,
+and images.
+
+\authors <a href="mailto:bernd AT kdevelop.org">Bernd Gehrmann</a>
+
+\maintainer <a href="mailto:$EMAIL$">$AUTHOR$</a>
+\maintainer <a href="mailto:2nd maintainer AT provider.com">2nd maintainer full name</a>
+...
+\maintainer <a href="mailto:nth maintainer AT provider.com">nth maintainer full name</a>
+
+\feature Describe the first feature
+\feature Describe the second feature
+...
+\feature Describe the last feature
+
+\bug Describe a the 1st bug that you know of, but probably hasn't been reported yet.
+..
+\bug Describe a the nth bug that you know of, but probably hasn't been reported yet.
+
+\requirement Describe a the 1st requirement of your part.
+\requirement Describe a the 2nd requirement of your part.
+...
+\requirement Describe a the nth requirement of your part.
+
+\todo Describe a the 1st TODO of your part.
+\todo Describe a the 2nd TODO of your part.
+...
+\todo Describe a the nth TODO of your part.
+
+\faq <b>First frequenly asked question about your part ?</b> Answer.
+\faq <b>Second frequenly asked question about your part ?</b> Answer.
+...
+\faq <b>Last frequenly asked question about your part ?</b> Answer.
+
+\note First note text.
+\note Second note text.
+...
+\note Last note text.
+
+\warning First warning text.
+\warning Second warning text.
+...
+\warning Last warning text.
+
+*/
diff --git a/parts/texttools/kdevtexttools.desktop b/parts/texttools/kdevtexttools.desktop
new file mode 100644
index 00000000..4af1638a
--- /dev/null
+++ b/parts/texttools/kdevtexttools.desktop
@@ -0,0 +1,84 @@
+[Desktop Entry]
+Type=Service
+Exec=blubb
+Comment=Provides a structure overview and navigation for HTML and TEX files
+Comment[ca]=Proporciona una vista de conjunt i navegació per a fitxers HTML i TEX
+Comment[da]=Giver et strukturoverblik og navigering for HTML- og TeX-filer
+Comment[de]=Stellt eine Strukturansicht für HTML- und TeX-Dateien zur Verfügung
+Comment[el]=Προσφέρει μια περίληψη δομής και πλοήγηση για αρχεία HTML και TEX
+Comment[es]=Proporciona una vista general y navegación para archivos HTML y TEX
+Comment[et]=Näitab HTML- ja TEX-failide struktuuri ning võimaldab neis liikuda
+Comment[eu]=HTML eta TEX fitxategien egituren laburpen eta nabigazioa eskeintzen du.
+Comment[fa]=خلاصۀ ساختار و ناوش را برای پرونده‌های زنگام و متن فراهم می‌کند
+Comment[fr]=Fournit une vue d'ensemble et une navigation pour les fichiers HTML et TEX
+Comment[gl]=Proporciona unha vista xeral e navegación da estructura de ficheiros HTML e TEX
+Comment[hu]=Lehetővé teszi a struktúra áttekintését, navigálását HTML és TEX fájloknál
+Comment[it]=Offre un'anteprima di struttura e navigazione per file HTML e TEX
+Comment[ja]=HTML や TeX ファイルの構造の概要やナビゲーションを提供します。
+Comment[ms]=Menyediakan struktur menyeluruh dan navigasi untuk HTML dan fail TEX
+Comment[nds]=Stellt en Struktuuröversicht un dat Stüern för HTML- un TeX-Dateien praat.
+Comment[ne]=HTML र TEX फाइलका लागि नेभिगेसन र बनावट समिक्षा प्रदान गर्दछ
+Comment[nl]=Biedt een overzicht van de structuur van HTML- en TeX-bestanden
+Comment[pl]=Widok struktury tekstu i nawigacja dla plików HTML i TEX
+Comment[pt]=Oferece uma vista geral estruturada e a navegação sobre os ficheiros de HTML e TEX
+Comment[pt_BR]=Fornece uma visão de estrutura e navegação para arquivos HTML e TEX
+Comment[ru]=Показывает структуру документов в формате HTML и TEX, а также предоставляет возможности навигации по ним.
+Comment[sk]=Poskytuje štruktúrovaný náhľad a navigáciu pre HTML a TEX súbory
+Comment[sr]=Обезбеђује преглед структуре и навигацију за HTML и TEX фајлове
+Comment[sr@Latn]=Obezbeđuje pregled strukture i navigaciju za HTML i TEX fajlove
+Comment[sv]=Tillhandahåller en strukturöversikt och navigering för HTML- och Tex-filer
+Comment[ta]=HTML மற்றும் TEX கோப்புகளின் அமைப்பை மேற்பார்வையிட மற்றும் வழி செலுத்த இது உதவும்.
+Comment[tg]=Ҳуҷҷатҳои структуриро дар формати HTML ва TEX тасвир менамояд ва боз ҳам имкони навигатсия намуданро иҷозат медиҳад
+Comment[tr]=HTML ve TEX dosyaları için yapı gözden geçirimi ve dolaşımı sağlar.
+Comment[zh_CN]=提供HTML和TEX文件的结构预览
+Comment[zh_TW]=提供 HTML 與 TEX 檔的結構化的概觀與導覽
+Name=KDevTextTools
+Name[da]=KDevelop tekstværktøjer
+Name[de]=Textstrukturansicht (KDevelop)
+Name[hi]=के-डेव-टेक्स्ट-टूल्स
+Name[nds]=KDevelop-TextWarktüüch
+Name[pl]=KDevNarzędziaTekstowe
+Name[sk]=KDev textové nástroje
+Name[sv]=KDevelop textverktyg
+Name[ta]=KDev உரைக்கருவி
+Name[tg]=Асбобҳои матни KDev
+Name[zh_TW]=KDevelop 文字工具
+GenericName=Text Structure
+GenericName[br]=Skeledenn ar skrid
+GenericName[ca]=Estructura del text
+GenericName[da]=Tekststruktur
+GenericName[de]=Textstruktur-Ansicht
+GenericName[el]=Δομή κειμένου
+GenericName[es]=Estructura de texto
+GenericName[et]=Tekstistruktuur
+GenericName[eu]=Testuaren egitura
+GenericName[fa]=ساختار متن
+GenericName[fr]=Structure du texte
+GenericName[gl]=Estructura do texto
+GenericName[hi]=टेक्स्ट स्ट्रक्चर
+GenericName[hu]=Szövegstruktúra
+GenericName[it]=Struttura testo
+GenericName[ja]=テキスト構造
+GenericName[ms]=Struktur Teks
+GenericName[nds]=Textstruktuur
+GenericName[ne]=पाठ बनावट
+GenericName[nl]=Tekststructuur
+GenericName[pl]=Struktura tekstu
+GenericName[pt]=Estrutura de Texto
+GenericName[pt_BR]=Estrutura de Texto
+GenericName[ru]=Показ структуры текста
+GenericName[sk]=Textové štruktúry
+GenericName[sl]=Besedilna struktura
+GenericName[sr]=Структура текста
+GenericName[sr@Latn]=Struktura teksta
+GenericName[sv]=Textstruktur
+GenericName[ta]=உரை வடிவம்
+GenericName[tg]=Тасвири матни структурӣ
+GenericName[tr]=Metin Yapısı
+GenericName[zh_CN]=文件结构
+GenericName[zh_TW]=文字結構
+ServiceTypes=KDevelop/Plugin
+X-KDE-Library=libkdevtexttools
+X-KDevelop-Version=5
+X-KDevelop-Scope=Global
+X-KDevelop-Properties=CodeNavigation
diff --git a/parts/texttools/texttoolspart.cpp b/parts/texttools/texttoolspart.cpp
new file mode 100644
index 00000000..7eb439da
--- /dev/null
+++ b/parts/texttools/texttoolspart.cpp
@@ -0,0 +1,99 @@
+/***************************************************************************
+ * Copyright (C) 2002 by Bernd Gehrmann *
+ * bernd@kdevelop.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "texttoolspart.h"
+
+#include <qwhatsthis.h>
+#include <kdebug.h>
+#include <klocale.h>
+#include <kdevgenericfactory.h>
+#include <kdevplugininfo.h>
+#include <ktexteditor/editinterface.h>
+
+#include "kdevpartcontroller.h"
+#include "kdevmainwindow.h"
+
+#include "texttoolswidget.h"
+
+
+typedef KDevGenericFactory<TextToolsPart> TextToolsFactory;
+static const KDevPluginInfo data("kdevtexttools");
+K_EXPORT_COMPONENT_FACTORY( libkdevtexttools, TextToolsFactory( data ) )
+
+TextToolsPart::TextToolsPart(QObject *parent, const char *name, const QStringList &)
+ : KDevPlugin(&data, parent, name ? name : "TextToolsPart")
+{
+ setInstance(TextToolsFactory::instance());
+ // setXMLFile("kdevfileview.rc");
+
+ m_widget = 0;
+
+ connect( partController(), SIGNAL(activePartChanged(KParts::Part*)),
+ this, SLOT(activePartChanged(KParts::Part*)) );
+}
+
+
+TextToolsPart::~TextToolsPart()
+{
+ if (m_widget)
+ mainWindow()->removeView(m_widget);
+ delete m_widget;
+}
+
+
+void TextToolsPart::createWidget()
+{
+ if (m_widget)
+ {
+// mainWindow()->embedSelectView(m_widget, i18n("Text Structure"), i18n("Text structure"));
+ return;
+ }
+
+ m_widget = new TextToolsWidget(this);
+ m_widget->setCaption(i18n("Text Structure"));
+ QWhatsThis::add(m_widget, i18n("<b>Text Structure</b><p>"
+ "This browser shows the structure of the text."));
+ mainWindow()->embedSelectView(m_widget, i18n("Text Structure"), i18n("Text structure"));
+}
+
+
+void TextToolsPart::activePartChanged(KParts::Part *part)
+{
+ if (m_widget)
+ m_widget->stop();
+
+ if (!part)
+ return;
+ KParts::ReadWritePart *rwpart = dynamic_cast<KParts::ReadWritePart*>(part);
+ if (!rwpart)
+ return;
+ QString url = rwpart->url().url();
+
+ if (url.endsWith(".html")) {
+ kdDebug(9030) << "set mode html" << endl;
+ createWidget();
+ m_widget->setMode(TextToolsWidget::HTML, rwpart);
+ } else if (url.endsWith(".docbook")) {
+ kdDebug(9030) << "set mode Docbook" << endl;
+ createWidget();
+ m_widget->setMode(TextToolsWidget::Docbook, rwpart);
+ } else if (url.endsWith(".tex")) {
+ kdDebug(9030) << "set mode LaTeX" << endl;
+ createWidget();
+ m_widget->setMode(TextToolsWidget::LaTeX, rwpart);
+ } else if (m_widget) {
+// kdDebug(9030) << "hide output view" << endl;
+// mainWindow()->removeView(m_widget);
+ m_widget->clear();
+ }
+}
+
+#include "texttoolspart.moc"
diff --git a/parts/texttools/texttoolspart.h b/parts/texttools/texttoolspart.h
new file mode 100644
index 00000000..7e7bf9c5
--- /dev/null
+++ b/parts/texttools/texttoolspart.h
@@ -0,0 +1,39 @@
+/***************************************************************************
+ * Copyright (C) 2002 by Bernd Gehrmann *
+ * bernd@kdevelop.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef _TEXTTOOLSPART_H_
+#define _TEXTTOOLSPART_H_
+
+#include <qguardedptr.h>
+#include <kparts/part.h>
+#include "kdevplugin.h"
+
+class TextToolsWidget;
+
+
+class TextToolsPart : public KDevPlugin
+{
+ Q_OBJECT
+
+public:
+ TextToolsPart( QObject *parent, const char *name, const QStringList & );
+ ~TextToolsPart();
+
+private slots:
+ void activePartChanged(KParts::Part *part);
+
+private:
+ void createWidget();
+
+ QGuardedPtr<TextToolsWidget> m_widget;
+};
+
+#endif
diff --git a/parts/texttools/texttoolswidget.cpp b/parts/texttools/texttoolswidget.cpp
new file mode 100644
index 00000000..ff85d0f0
--- /dev/null
+++ b/parts/texttools/texttoolswidget.cpp
@@ -0,0 +1,400 @@
+/***************************************************************************
+ * Copyright (C) 2002 by Bernd Gehrmann *
+ * bernd@kdevelop.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include "texttoolswidget.h"
+
+#include <qheader.h>
+#include <qregexp.h>
+#include <qtimer.h>
+#include <kdebug.h>
+#include <klocale.h>
+#include <kparts/part.h>
+#include <kpopupmenu.h>
+#include <ktexteditor/viewcursorinterface.h>
+#include <ktexteditor/selectioninterface.h>
+#include <ktexteditor/editinterface.h>
+
+#include "kdevmainwindow.h"
+#include "kdevpartcontroller.h"
+#include "texttoolspart.h"
+
+
+class TextStructItem : public QListViewItem
+{
+public:
+ TextStructItem(QListView *parent)
+ : QListViewItem(parent)
+ {}
+ TextStructItem(QListViewItem *parent)
+ : QListViewItem(parent)
+ {
+ QListViewItem *item = this;
+ while (item->nextSibling())
+ item = item->nextSibling();
+ if (item != this)
+ moveItem(item);
+ }
+
+ QString text(int) const
+ {
+ return extra.isNull()? tag : QString("%1: %2").arg(tag).arg(extra);
+ }
+ TextStructItem *parentStructItem()
+ { return static_cast<TextStructItem*>(parent()); }
+
+ QString tag;
+ QString extra;
+ int pos;
+ int endpos;
+};
+
+
+TextToolsWidget::TextToolsWidget(TextToolsPart *part, QWidget *parent, const char *name)
+ : KListView(parent, name)
+{
+ setResizeMode(QListView::LastColumn);
+ setSorting(-1);
+ header()->hide();
+ addColumn(QString::null);
+
+ m_part = part;
+
+ m_timer = new QTimer(this);
+ connect( this, SIGNAL(mouseButtonPressed(int, QListViewItem*, const QPoint&, int)),
+ this, SLOT(slotItemPressed(int,QListViewItem*)) );
+ // connect( this, SIGNAL(doubleClicked(QListViewItem*)),
+ // this, SLOT(slotItemPressed(int,QListViewItem*)) );
+ connect( this, SIGNAL(returnPressed(QListViewItem*)),
+ this, SLOT(slotReturnPressed(QListViewItem*)) );
+ connect( this, SIGNAL(contextMenu(KListView*, QListViewItem*, const QPoint&)),
+ this, SLOT(slotContextMenu(KListView*, QListViewItem*, const QPoint&)) );
+}
+
+
+TextToolsWidget::~TextToolsWidget()
+{}
+
+
+void TextToolsWidget::slotItemPressed(int button, QListViewItem *item)
+{
+ if (!item)
+ return;
+
+ TextStructItem *tsitem = static_cast<TextStructItem*>(item);
+ int searchedPos = tsitem->pos;
+ int searchedEndpos = tsitem->endpos;
+ kdDebug(9030) << "Searched pos " << searchedPos << ", " << searchedEndpos << endl;
+
+ int endline = 0;
+ int endcol = 0;
+ int line = 0;
+ int col = 0;
+
+ int len = m_cachedText.length();
+ int pos = 0;
+ while (pos < len) {
+ if (pos == searchedPos) {
+ line = endline;
+ col = endcol;
+ }
+ if (pos == searchedEndpos)
+ break;
+ QChar ch = m_cachedText[pos];
+ if (ch == '\n') {
+ ++endline;
+ endcol = 0;
+ } else {
+ ++endcol;
+ }
+ ++pos;
+ }
+
+ KParts::Part *rwpart
+ = dynamic_cast<KParts::Part*>(m_part->partController()->activePart());
+ QWidget *view = m_part->partController()->activeWidget();
+
+ KTextEditor::ViewCursorInterface *cursorIface
+ = dynamic_cast<KTextEditor::ViewCursorInterface*>(view);
+ if (cursorIface) {
+ kdDebug(9030) << "set cursor " << line << ", " << col << endl;
+ cursorIface->setCursorPosition(line, col);
+ }
+
+ if (button == MidButton) {
+ KTextEditor::SelectionInterface *selectionIface
+ = dynamic_cast<KTextEditor::SelectionInterface*>(rwpart);
+ if (selectionIface) {
+ kdDebug(9030) << "set selection " << line << ", " << col
+ << ", " << endline << ", " << endcol << endl;
+ selectionIface->setSelection((int)line, (int)col, (int)endline, (int)endcol+1);
+ }
+ }
+
+ m_part->mainWindow()->lowerView(this);
+}
+
+
+void TextToolsWidget::slotReturnPressed(QListViewItem *item)
+{
+ slotItemPressed(LeftButton, item);
+}
+
+
+void TextToolsWidget::slotContextMenu(KListView *, QListViewItem *item, const QPoint &)
+{
+ if (!item)
+ return;
+
+#if 0
+ KPopupMenu popup(i18n("Text Structure"), this);
+ popup.exec(p);
+#endif
+}
+
+
+void TextToolsWidget::stop()
+{
+ disconnect( m_timer );
+ m_relevantTags.clear();
+ m_emptyTags.clear();
+ m_cachedText = QString::null;
+}
+
+
+void TextToolsWidget::setMode(Mode mode, KParts::Part *part)
+{
+ connect( part, SIGNAL(textChanged()),
+ this, SLOT(startTimer()) );
+ m_editIface = dynamic_cast<KTextEditor::EditInterface*>(part);
+
+ switch (mode) {
+ case HTML:
+ m_relevantTags << "h1" << "h2" << "h3" << "h4"
+ << "table" << "tr";
+ m_emptyTags << "br" << "hr" << "img" << "input" << "p" << "meta";
+
+ connect( m_timer, SIGNAL(timeout()),
+ this, SLOT(parseXML()) );
+ break;
+ case Docbook:
+ m_relevantTags << "chapter" << "sect1" << "sect2"
+ << "para" << "formalpara";
+ connect( m_timer, SIGNAL(timeout()),
+ this, SLOT(parseXML()) );
+ break;
+ case LaTeX:
+ connect( m_timer, SIGNAL(timeout()),
+ this, SLOT(parseLaTeX()) );
+ break;
+ default: ;
+ }
+
+ m_timer->start(0, true);
+}
+
+
+void TextToolsWidget::startTimer()
+{
+ kdDebug(9030) << "Starting parse timer" << endl;
+ m_timer->start(1000, true);
+}
+
+
+void TextToolsWidget::parseXML()
+{
+ kdDebug(9030) << "Starting to parse XML" << endl;
+ clear();
+ QString text = m_editIface->text();
+ m_cachedText = text;
+
+ TextStructItem *currentItem = new TextStructItem(this);
+ currentItem->tag = "Root";
+ currentItem->pos = -1;
+ currentItem->endpos = -1;
+
+ int len = text.length();
+ for (int pos=0; pos+1 < len; ++pos) {
+ QChar ch1 = text[pos];
+ QChar ch2 = text[pos+1];
+
+ if (ch1 == '<' && ch2 == '?') {
+
+ // PHP and other similar stuff
+ QString tag;
+ int endpos = pos+2;
+ bool foundspace = false;
+ while (endpos+1 < len) {
+ QChar ch3 = text[endpos];
+ QChar ch4 = text[endpos+1];
+ if ((ch3 == ' ' || ch3 == '\t' || ch3 == '\n') && !foundspace) {
+ tag = text.mid(pos+2, endpos-pos-2).lower();
+ foundspace = true;
+ } else if (ch3 == '?' && ch4 == '>') {
+ if (!foundspace)
+ tag = text.mid(pos+2, endpos-pos-2).lower();
+ break;
+ }
+ ++endpos;
+ }
+
+ TextStructItem *item = new TextStructItem(currentItem);
+ item->tag = "<?" + tag + "?>";
+ item->pos = pos;
+ item->endpos = endpos+1;
+
+ pos = endpos+1;
+
+ } else if (ch1 == '<' && ch2 == '!') {
+
+ // Processing instructions like !DOCTYPE
+ QString tag;
+ int endpos = pos+2;
+ bool foundspace = false;
+ while (endpos+1 < len) {
+ QChar ch3 = text[endpos];
+ if ((ch3 == ' ' || ch3 == '\t' || ch3 == '\n') && !foundspace) {
+ tag = text.mid(pos+2, endpos-pos-2).lower();
+ foundspace = true;
+ } else if (ch3 == '>') {
+ if (!foundspace)
+ tag = text.mid(pos+2, endpos-pos-2).lower();
+ break;
+ }
+ ++endpos;
+ }
+
+ TextStructItem *item = new TextStructItem(currentItem);
+ item->tag = "<!" + tag + ">";
+ item->pos = pos;
+ item->endpos = endpos+1;
+
+ pos = endpos+1;
+
+ } else if (ch1 == '<' && ch2 == '/') {
+
+ QString tag;
+ int endpos = pos+2;
+ while (endpos < len) {
+ QChar ch3 = text[endpos];
+ if (ch3 == '>') {
+ tag = text.mid(pos+2, endpos-pos-2).lower();
+ break;
+ }
+ ++endpos;
+ }
+
+ if (!m_relevantTags.contains(tag)) {
+ pos = endpos;
+ continue;
+ }
+
+ TextStructItem *closingItem = currentItem;
+ while (closingItem->parent() && closingItem->tag != tag)
+ closingItem = closingItem->parentStructItem();
+ if (closingItem->parent()) {
+ closingItem->endpos = endpos;
+ currentItem = closingItem->parentStructItem();
+ } else {
+ kdDebug(9030) << "found no opening tag " << tag << "." << endl;
+ }
+
+ pos = endpos;
+
+ } else if (ch1 == '<') {
+
+ QString tag;
+ int endpos = pos+1;
+ bool foundspace = false;
+ while (endpos < len) {
+ QChar ch3 = text[endpos];
+ if ((ch3 == ' ' || ch3 == '\t' || ch3 == '\n') && !foundspace) {
+ tag = text.mid(pos+1, endpos-pos-1).lower();
+ foundspace = true;
+ } else if (ch3 == '>') {
+ if (!foundspace) {
+ tag = text.mid(pos+1, endpos-pos-1).lower();
+ }
+ break;
+ }
+ ++endpos;
+ }
+
+ if (!m_relevantTags.contains(tag)) {
+ pos = endpos;
+ continue;
+ }
+
+ TextStructItem *item = new TextStructItem(currentItem);
+ item->tag = tag;
+ item->pos = pos;
+ item->endpos = -1;
+
+ if (m_emptyTags.contains(tag))
+ item->endpos = endpos;
+ else
+ currentItem = item;
+ pos = endpos;
+
+ }
+ }
+
+ // firstChild()->setOpen(true);
+ QListViewItemIterator it(this);
+ for (; it.current(); ++it)
+ it.current()->setOpen(true);
+}
+
+
+void TextToolsWidget::parseLaTeX()
+{
+ kdDebug(9030) << "Starting to parse LaTeX" << endl;
+ clear();
+ QString text = m_editIface->text();
+ m_cachedText = text;
+
+ TextStructItem *currentItem = new TextStructItem(this);
+ currentItem->tag = "Root";
+ currentItem->pos = -1;
+ currentItem->endpos = -1;
+
+ QString hierarchyLevels = "Root,chapter,section,subsection,subsubsection";
+ QRegExp re("\n[ \t]*s*\\\\(chapter|section|subsection|subsubsection)\\{([^}]*)\\}");
+
+ int pos=0;
+ for (;;) {
+ pos = re.search(text, pos);
+ if (pos == -1)
+ break;
+ QString tag = re.cap(1);
+ QString title = re.cap(2);
+ kdDebug(9030) << "Match with " << tag << " and title " << title << endl;
+ int level = hierarchyLevels.find(tag);
+ while (currentItem->parent() && level <= hierarchyLevels.find(currentItem->tag))
+ currentItem = currentItem->parentStructItem();
+
+ TextStructItem *item = new TextStructItem(currentItem);
+ item->tag = tag;
+ item->extra = title;
+ item->pos = pos+1;
+ item->endpos = pos+re.matchedLength()-1; // lie
+
+ if (level > hierarchyLevels.find(currentItem->tag))
+ currentItem = item;
+
+ pos = pos+re.matchedLength();
+ }
+
+ QListViewItemIterator it(this);
+ for (; it.current(); ++it)
+ it.current()->setOpen(true);
+}
+
+#include "texttoolswidget.moc"
diff --git a/parts/texttools/texttoolswidget.h b/parts/texttools/texttoolswidget.h
new file mode 100644
index 00000000..680adb34
--- /dev/null
+++ b/parts/texttools/texttoolswidget.h
@@ -0,0 +1,54 @@
+/***************************************************************************
+ * Copyright (C) 2002 by Bernd Gehrmann *
+ * bernd@kdevelop.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#ifndef _TEXTTOOLSWIDGET_H_
+#define _TEXTTOOLSWIDGET_H_
+
+#include <klistview.h>
+#include <qstringlist.h>
+
+class TextToolsPart;
+class QTimer;
+namespace KParts { class Part; }
+namespace KTextEditor { class EditInterface; }
+
+
+class TextToolsWidget : public KListView
+{
+ Q_OBJECT
+
+public:
+ enum Mode { HTML, Docbook, LaTeX };
+
+ TextToolsWidget( TextToolsPart *part, QWidget *parent=0, const char *name=0 );
+ ~TextToolsWidget();
+
+ void setMode(Mode mode, KParts::Part *part);
+ void stop();
+
+private slots:
+ void slotItemPressed(int button, QListViewItem *item);
+ void slotReturnPressed(QListViewItem *item);
+ void slotContextMenu(KListView *, QListViewItem *item, const QPoint &p);
+
+ void startTimer();
+ void parseXML();
+ void parseLaTeX();
+
+private:
+ TextToolsPart *m_part;
+ QTimer *m_timer;
+ QString m_cachedText;
+ KTextEditor::EditInterface *m_editIface;
+ QStringList m_relevantTags, m_emptyTags;
+};
+
+#endif