texttoolspart.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "texttoolspart.h"
00013
00014 #include <qwhatsthis.h>
00015 #include <kdebug.h>
00016 #include <klocale.h>
00017 #include <kdevgenericfactory.h>
00018 #include <ktexteditor/editinterface.h>
00019
00020 #include "kdevpartcontroller.h"
00021 #include "kdevmainwindow.h"
00022
00023 #include "texttoolswidget.h"
00024
00025
00026 typedef KDevGenericFactory<TextToolsPart> TextToolsFactory;
00027 static const KAboutData data("kdevtexttools", I18N_NOOP("Text Structure"), "1.0");
00028 K_EXPORT_COMPONENT_FACTORY( libkdevtexttools, TextToolsFactory( &data ) )
00029
00030 TextToolsPart::TextToolsPart(QObject *parent, const char *name, const QStringList &)
00031 : KDevPlugin("TextTools", "texttools", parent, name ? name : "TextToolsPart")
00032 {
00033 setInstance(TextToolsFactory::instance());
00034
00035
00036 m_widget = 0;
00037
00038 connect( partController(), SIGNAL(activePartChanged(KParts::Part*)),
00039 this, SLOT(activePartChanged(KParts::Part*)) );
00040 }
00041
00042
00043 TextToolsPart::~TextToolsPart()
00044 {
00045 if (m_widget)
00046 mainWindow()->removeView(m_widget);
00047 delete m_widget;
00048 }
00049
00050
00051 void TextToolsPart::createWidget()
00052 {
00053 if (m_widget)
00054 {
00055
00056 return;
00057 }
00058
00059 m_widget = new TextToolsWidget(this);
00060 m_widget->setCaption(i18n("Text Structure"));
00061 QWhatsThis::add(m_widget, i18n("<b>Text Structure</b><p>"
00062 "This browser shows the structure of the text."));
00063 mainWindow()->embedSelectView(m_widget, i18n("Text Structure"), i18n("Text structure"));
00064 }
00065
00066
00067 void TextToolsPart::activePartChanged(KParts::Part *part)
00068 {
00069 if (m_widget)
00070 m_widget->stop();
00071
00072 if (!part)
00073 return;
00074 KParts::ReadWritePart *rwpart = dynamic_cast<KParts::ReadWritePart*>(part);
00075 if (!rwpart)
00076 return;
00077 QString url = rwpart->url().url();
00078
00079 if (url.endsWith(".html")) {
00080 kdDebug(9030) << "set mode html" << endl;
00081 createWidget();
00082 m_widget->setMode(TextToolsWidget::HTML, rwpart);
00083 } else if (url.endsWith(".docbook")) {
00084 kdDebug(9030) << "set mode Docbook" << endl;
00085 createWidget();
00086 m_widget->setMode(TextToolsWidget::Docbook, rwpart);
00087 } else if (url.endsWith(".tex")) {
00088 kdDebug(9030) << "set mode LaTeX" << endl;
00089 createWidget();
00090 m_widget->setMode(TextToolsWidget::LaTeX, rwpart);
00091 } else if (m_widget) {
00092
00093
00094 m_widget->clear();
00095 }
00096 }
00097
00098 #include "texttoolspart.moc"
This file is part of the documentation for KDevelop Version 3.1.2.