summaryrefslogtreecommitdiffstats
path: root/kxsldbg/kxsldbg.cpp
blob: f4de889bc8591ebdf8a0434ea653ff9d7ba15945 (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
 * kxsldbg.cpp
 *
 * Copyright (C) 2001  <kurt@granroth.org>
 */
#include "kxsldbg.h"

#include <kkeydialog.h>
#include <tdeconfig.h>
#include <tdelocale.h>

#include <kedittoolbar.h>

#include <tdeaction.h>
#include <kstdaction.h>

#include <klibloader.h>
#include <tdemessagebox.h>
#include <kstatusbar.h>
#include <tdepopupmenu.h>
#include <tdemenubar.h>
#include <kiconloader.h>

KXsldbg::KXsldbg()
  : DCOPObject("KXsldbg"), KParts::MainWindow( 0L, "kxsldbg" )
{
    // set the shell's ui resource file
    setXMLFile("kxsldbg_shell.rc");

    // then, setup our actions
    setupActions();

    // and a status bar
    statusBar()->show();
    statusBar()->setSizePolicy(TQSizePolicy(TQSizePolicy::Preferred, TQSizePolicy::Preferred));

    // this routine will find and load our Part.  it finds the Part by
    // name which is a bad idea usually.. but it's alright in this
    // case since our Part is made for this Shell
    KLibFactory *factory = KLibLoader::self()->factory("libkxsldbgpart");
    if (factory)
    {
        // now that the Part is loaded, we cast it to a Part to get
        // our hands on it
        m_part = static_cast<KParts::ReadOnlyPart *>(factory->create(TQT_TQOBJECT(this),
                                "kxsldbg_part", "KParts::ReadOnlyPart" ));

        if (m_part)
        {
            // tell the KParts::MainWindow that this is indeed the main widget
            setCentralWidget(m_part->widget());

            // and integrate the part's GUI with the shell's
            createGUI(m_part);

            // connect up signals
            kapp->dcopClient()->attach();
            connectDCOPSignal(0, 0, "debuggerPositionChanged(TQString,int)", "newDebuggerPosition(TQString,int)", false );
            connectDCOPSignal(0, 0, "editorPositionChanged(TQString,int,int)", "newCursorPosition(TQString,int,int)", false );
            
            // Add xsldbg handbook to help menu
            TQMenuBar *mbar = menuBar();
            TDEPopupMenu *help_menu = dynamic_cast<TDEPopupMenu*>
                                      (menuBar()->findItem(mbar->idAt(mbar->count()-1))->popup());
            if (help_menu)
            {
                help_menu->insertItem(SmallIconSet("contents"), i18n("&XSLDbg Handbook"), TQT_TQOBJECT(this),
                                      TQT_SLOT(showXSLDbgHelp()), 0, -1, 1);
            }
        }
    }
    else
    {
        // if we couldn't find our Part, we exit since the Shell by
        // itself can't do anything useful
        KMessageBox::error(this, i18n("Could not find our part."));
        kapp->quit();
    }
}

KXsldbg::~KXsldbg()
{
    if (m_part)
	m_part->closeURL();

    delete m_part;
}

void KXsldbg::quit()
{
    closeURL();
    close();
}

bool KXsldbg::closeURL()
{
    if (m_part)
	m_part->closeURL();

    return true;
}

void KXsldbg::setupActions()
{
    TDEAction *act = KStdAction::quit(TQT_TQOBJECT(kapp), TQT_SLOT(quit()), actionCollection());
    connect(act, TQT_SIGNAL(activated()), this, TQT_SLOT(quit()));

    m_toolbarAction = KStdAction::showToolbar(TQT_TQOBJECT(this), TQT_SLOT(optionsShowToolbar()), actionCollection());
    m_statusbarAction = KStdAction::showStatusbar(TQT_TQOBJECT(this), TQT_SLOT(optionsShowStatusbar()), actionCollection());

    KStdAction::keyBindings(TQT_TQOBJECT(this), TQT_SLOT(optionsConfigureKeys()), actionCollection());
    KStdAction::configureToolbars(TQT_TQOBJECT(this), TQT_SLOT(optionsConfigureToolbars()), actionCollection());
}

void KXsldbg::saveProperties(TDEConfig* /*config*/)
{
    // the 'config' object points to the session managed
    // config file.  anything you write here will be available
    // later when this app is restored
}

void KXsldbg::readProperties(TDEConfig* /*config*/)
{
    // the 'config' object points to the session managed
    // config file.  this function is automatically called whenever
    // the app is being restored.  read in here whatever you wrote
    // in 'saveProperties'
}


void KXsldbg::optionsShowToolbar()
{
    // this is all very cut and paste code for showing/hiding the
    // toolbar
    if (m_toolbarAction->isChecked())
        toolBar()->show();
    else
        toolBar()->hide();
}

void KXsldbg::optionsShowStatusbar()
{
    // this is all very cut and paste code for showing/hiding the
    // statusbar
    if (m_statusbarAction->isChecked())
        statusBar()->show();
    else
        statusBar()->hide();
}

void KXsldbg::optionsConfigureKeys()
{
    KKeyDialog::configure(actionCollection(), "kxsldbg_shell.rc");
}

void KXsldbg::optionsConfigureToolbars()
{
    saveMainWindowSettings(TDEGlobal::config(), "MainWindow");

    // use the standard toolbar editor
    KEditToolbar dlg(factory());
    connect(&dlg, TQT_SIGNAL(newToolbarConfig()),
            this, TQT_SLOT(applyNewToolbarConfig()));
    dlg.exec();
}

void KXsldbg::applyNewToolbarConfig()
{
    applyMainWindowSettings(TDEGlobal::config(), "MainWindow");
}


void KXsldbg::newCursorPosition(const TQString &file, int lineNumber, int columnNumber)
{
    statusBar()->clear();
    statusBar()->message( i18n("File: %1  Line: %2  Col: %3").arg(file).arg(lineNumber).arg(columnNumber));
}

void KXsldbg::newDebuggerPosition(const TQString &file, int lineNumber)
{
    // maybe do something extra here later
    newCursorPosition(file, lineNumber);
}

void KXsldbg::showXSLDbgHelp()
{
    kapp->invokeHelp(TQString(), "xsldbg");
}

#include "kxsldbg.moc"