summaryrefslogtreecommitdiffstats
path: root/parts/texttools/texttoolspart.cpp
blob: 3697b89fefbdf742ac8d8682f029282f95e9d883 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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 <tqwhatsthis.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(TQObject *tqparent, const char *name, const TQStringList &)
    : KDevPlugin(&data, tqparent, name ? name : "TextToolsPart")
{
    setInstance(TextToolsFactory::instance());
    //    setXMLFile("kdevfileview.rc");

    m_widget = 0;
    
    connect( partController(), TQT_SIGNAL(activePartChanged(KParts::Part*)),
             this, TQT_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"));
    TQWhatsThis::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;
    TQString 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"