~ubuntu-branches/ubuntu/hoary/kvirc/hoary

« back to all changes in this revision

Viewing changes to src/kvirc/script/kvi_codetester.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Robin Verduijn
  • Date: 2004-12-14 15:32:19 UTC
  • mfrom: (0.2.1 upstream) (1.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20041214153219-fdink3gyp2s20b6g
Tags: 2:2.1.3.1-2
* Change Recommends on xmms to a Suggests.
* Rebuild against KDE 3.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// =============================================================================
 
2
//
 
3
//      --- kvi_codetester.cpp ---
 
4
//
 
5
//   This file is part of the KVIrc IRC client distribution
 
6
//   Copyright (C) 1999-2000 Szymon Stefanek (stefanek@tin.it)
 
7
//   Copyright (C) 1999-2000 Till Busch (buti@geocities.com)
 
8
//
 
9
//   This program is FREE software. You can redistribute it and/or
 
10
//   modify it under the terms of the GNU General Public License
 
11
//   as published by the Free Software Foundation; either version 2
 
12
//   of the License, or (at your opinion) any later version.
 
13
//
 
14
//   This program is distributed in the HOPE that it will be USEFUL,
 
15
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
17
//   See the GNU General Public License for more details.
 
18
//
 
19
//   You should have received a copy of the GNU General Public License
 
20
//   along with this program. If not, write to the Free Software Foundation,
 
21
//   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
22
//
 
23
// =============================================================================
 
24
 
 
25
#define _KVI_DEBUG_CHECK_RANGE_
 
26
#define _KVI_DEBUG_CLASS_NAME_ "KviCodeTester"
 
27
 
 
28
#include <qlayout.h>
 
29
 
 
30
#include "kvi_app.h"
 
31
#include "kvi_codetester.h"
 
32
#include "kvi_console.h"
 
33
#include "kvi_frame.h"
 
34
#include "kvi_label.h"
 
35
#include "kvi_lineedit.h"
 
36
#include "kvi_locale.h"
 
37
#include "kvi_pushbutton.h"
 
38
#include "kvi_script_editor.h"
 
39
#include "kvi_string.h"
 
40
#include "kvi_userparser.h"
 
41
#include "kvi_window.h"
 
42
 
 
43
// TODO: Totally missing quick help!
 
44
 
 
45
KviStr g_szLastCodeTesterBuffer = "";
 
46
 
 
47
/*
 
48
        @quickhelp: KviCodeTester
 
49
        @widget: Script tester
 
50
                This tab allows you to test multiline code.<br>
 
51
                Since the commandline widget does not allow multiline code to be executed,
 
52
                you can enter it here and click "Execute".<br>
 
53
                You can specify a window for the command to be executed in.<br>
 
54
                If you do not specify a window, or if the target window does not exist,
 
55
                the command buffer will be executed in the first session's Console.<br>
 
56
                If you still do not understand what this tab does, type in the editor:<br>
 
57
                <example>
 
58
                        <a href="echo.kvihelp">echo</a> "Hello in <a href="s_window.kvihelp">$window</a>!"
 
59
                </example>
 
60
                click "Execute" and watch the Console window.<br>
 
61
*/
 
62
 
 
63
/**
 
64
 *
 
65
 * CODE TESTER
 
66
 *
 
67
 * This widget allows testing of the script code
 
68
 *
 
69
 */
 
70
KviCodeTester::KviCodeTester(QWidget *parent, const char *name)
 
71
        : QWidget(parent, name)
 
72
{
 
73
        QGridLayout *g = new QGridLayout(this, 2, 3, 4, 2);
 
74
 
 
75
        m_pCodeEditor = new KviScriptEditor(this);
 
76
        g->addMultiCellWidget(m_pCodeEditor, 0, 0, 0, 2);
 
77
        m_pCodeEditor->setText(g_szLastCodeTesterBuffer.ptr());
 
78
        KviPushButton *pb = new KviPushButton(_i18n_("E&xecute"), this);
 
79
        g->addWidget(pb, 1, 2);
 
80
        KviLabel *lb = new KviLabel(_i18n_("Window:"), this);
 
81
        g->addWidget(lb, 1, 0);
 
82
        m_pWindowNameEdit = new KviLineEdit(this);
 
83
        g->addWidget(m_pWindowNameEdit, 1, 1);
 
84
        g->setColStretch(1, 1);
 
85
        g->setRowStretch(0, 1);
 
86
        connect(pb, SIGNAL(clicked()), this, SLOT(test()));
 
87
}
 
88
 
 
89
KviCodeTester::~KviCodeTester()
 
90
{
 
91
        // Nothing here
 
92
}
 
93
 
 
94
void KviCodeTester::test()
 
95
{
 
96
        KviStr tmp = m_pCodeEditor->text();
 
97
 
 
98
        KviStr szWnd = m_pWindowNameEdit->text();
 
99
        KviWindow *wnd = 0;
 
100
        KviFrame *theFrame = 0;
 
101
        if( szWnd.hasData() ) {
 
102
                for( KviFrame *f = g_pApp->m_pFrameList->first(); f; f = g_pApp->m_pFrameList->next() ) {
 
103
                        wnd = f->findWindow(szWnd.ptr());
 
104
                        if( wnd ) {
 
105
                                theFrame = f;
 
106
                                break;
 
107
                        }
 
108
                }
 
109
        }
 
110
        if( !wnd ) {
 
111
                theFrame = g_pApp->m_pFrameList->first();
 
112
                wnd = theFrame->m_pConsole;
 
113
        }
 
114
        if( theFrame )
 
115
                theFrame->m_pUserParser->parseCommand(tmp.ptr(), wnd);
 
116
}
 
117
 
 
118
#include "m_kvi_codetester.moc"