summaryrefslogtreecommitdiffstats
path: root/languages/ruby/debugger/rdboutputwidget.cpp
blob: 7c489ed487dc73e851249bdb3e9edf2dfb0c2748 (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
// *************************************************************************
//                          rdboutputwidget.cpp  -  description
//                             -------------------
//    begin                : 10th April 2003
//    copyright            : (C) 2003 by John Birch
//    email                : jbb@kdevelop.org
//	
//                          Adapted for ruby debugging
//                          --------------------------
//    begin                : Mon Nov 1 2004
//   copyright            : (C) 2004 by Richard Dale
//    email                : Richard_Dale@tipitina.demon.co.uk
// **************************************************************************
//
// **************************************************************************
// *                                                                        *
// *   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 "rdboutputwidget.h"
#include "dbgcontroller.h"

#include <kcombobox.h>
#include <kdebug.h>
#include <kiconloader.h>
#include <klocale.h>

#include <tqlabel.h>
#include <tqlayout.h>
#include <tqtextedit.h>
#include <tqtoolbutton.h>
#include <tqtooltip.h>

/***************************************************************************/
/***************************************************************************/
/***************************************************************************/

namespace RDBDebugger
{

/***************************************************************************/

RDBOutputWidget::RDBOutputWidget( TQWidget *parent, const char *name) :
    TQWidget(parent, name),
    m_userRDBCmdEditor(0),
    m_Interrupt(0),
    m_rdbView(0)
{

    m_rdbView = new TQTextEdit (this, name);
    m_rdbView->setReadOnly(true);

    TQBoxLayout *userRDBCmdEntry = new TQHBoxLayout();
    m_userRDBCmdEditor = new KHistoryCombo (this, "rdb-user-cmd-editor");

    TQLabel *label = new TQLabel(i18n("&RDB cmd:"), this);
    label->setBuddy(m_userRDBCmdEditor);
    userRDBCmdEntry->addWidget(label);

    userRDBCmdEntry->addWidget(m_userRDBCmdEditor);
    userRDBCmdEntry->setStretchFactor(m_userRDBCmdEditor, 1);

    m_Interrupt = new TQToolButton( this, "add breakpoint" );
    m_Interrupt->tqsetSizePolicy ( TQSizePolicy ( (TQSizePolicy::SizeType)0,
                                         ( TQSizePolicy::SizeType)0,
                                         0,
                                         0,
                                         m_Interrupt->sizePolicy().hasHeightForWidth())
                                         );
    m_Interrupt->setPixmap ( SmallIcon ( "player_pause" ) );
    userRDBCmdEntry->addWidget(m_Interrupt);
    TQToolTip::add ( m_Interrupt, i18n ( "Pause execution of the app to enter rdb commands" ) );

    TQVBoxLayout *topLayout = new TQVBoxLayout(this, 2);
    topLayout->addWidget(m_rdbView, 10);
    topLayout->addLayout(userRDBCmdEntry);

    slotDbgtqStatus( "", s_dbgNotStarted);

    connect( m_userRDBCmdEditor, TQT_SIGNAL(returnPressed()), TQT_SLOT(slotRDBCmd()) );
    connect( m_Interrupt,        TQT_SIGNAL(clicked()),       TQT_SIGNAL(breakInto()));
}

/***************************************************************************/

RDBOutputWidget::~RDBOutputWidget()
{
    delete m_rdbView;
    delete m_userRDBCmdEditor;
}

/***************************************************************************/

void RDBOutputWidget::clear()
{
    if (m_rdbView)
        m_rdbView->clear();
}

/***************************************************************************/

void RDBOutputWidget::slotReceivedStdout(const char* line)
{
    if (strncmp(line, "(rdb:", 5) == 0)
        m_rdbView->append(TQString("<font color=\"blue\">").append( line ).append("</font>") );
    else
        m_rdbView->append(line);
}

/***************************************************************************/

void RDBOutputWidget::slotReceivedStderr(const char* line)
{
    m_rdbView->append(TQString("<font color=\"red\">").append( line ).append("</font>") );
}

/***************************************************************************/

void RDBOutputWidget::slotRDBCmd()
{
    TQString RDBCmd(m_userRDBCmdEditor->currentText());
    if (!RDBCmd.isEmpty())
    {
        m_userRDBCmdEditor->addToHistory(RDBCmd);
        m_userRDBCmdEditor->clearEdit();
        emit userRDBCmd(RDBCmd);
    }
}

/***************************************************************************/

void RDBOutputWidget::slotDbgtqStatus(const TQString &, int statusFlag)
{
    if (statusFlag & s_dbgNotStarted)
    {
        m_Interrupt->setEnabled(false);
        m_userRDBCmdEditor->setEnabled(false);
        return;
    }

    if (statusFlag & s_appBusy)
    {
        m_Interrupt->setEnabled(true);
        m_userRDBCmdEditor->setEnabled(false);
    }
    else
    {
        m_Interrupt->setEnabled(false);
        m_userRDBCmdEditor->setEnabled(true);
    }
}

/***************************************************************************/

void RDBOutputWidget::focusInEvent(TQFocusEvent */*e*/)
{
    m_userRDBCmdEditor->setFocus();
}

/***************************************************************************/
/***************************************************************************/
/***************************************************************************/
}


#include "rdboutputwidget.moc"