1
// =============================================================================
3
// --- kvi_script_editor.cpp ---
5
// This file is part of the KVIrc IRC client distribution
6
// Copyright (C) 1999-2000 Szymon Stefanek (stefanek@tin.it)
8
// This program is FREE software. You can redistribute it and/or
9
// modify it under the terms of the GNU General Public License
10
// as published by the Free Software Foundation; either version 2
11
// of the License, or (at your opinion) any later version.
13
// This program is distributed in the HOPE that it will be USEFUL,
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
// See the GNU General Public License for more details.
18
// You should have received a copy of the GNU General Public License
19
// along with this program. If not, write to the Free Software Foundation,
20
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
// =============================================================================
24
#define _KVI_DEBUG_CHECK_RANGE_
25
#define _KVI_DEBUG_CLASS_NAME_ "KviScriptEditor"
29
#include <qtoolbutton.h>
32
#include "kvi_fileutils.h"
33
#include "kvi_label.h"
34
#include "kvi_locale.h"
35
#include "kvi_messagebox.h"
36
#include "kvi_popupmenu.h"
37
#include "kvi_script_editor.h"
38
#include "kvi_script_editorwidget.h"
39
#include "kvi_string.h"
41
KviScriptEditor::KviScriptEditor(QWidget *parent)
44
QGridLayout *g = new QGridLayout(this, 2, 4, 0, 0);
45
m_pEditor = new KviScriptEditorWidget(this);
46
g->addMultiCellWidget(m_pEditor, 0, 0, 0, 3);
47
g->setRowStretch(0, 1);
49
QToolButton *b = new QToolButton(UpArrow, this);
50
g->addWidget(b, 1, 0);
52
KviPopupMenu *pop = new KviPopupMenu(b);
53
pop->insertItem(_i18n_("&Save to File..."), this, SLOT(saveToFile()));
54
pop->insertItem(_i18n_("&Load from File..."), this, SLOT(loadFromFile()));
58
KviLabel *l = new KviLabel(_i18n_("Ctrl+W completes commands and functions"), this);
59
l->setFrameStyle(QFrame::Sunken | QFrame::Panel);
60
g->setColStretch(1, 1);
61
g->addWidget(l, 1, 1);
64
box = new QHBox(this);
65
box->setFrameStyle(QFrame::Sunken | QFrame::Panel);
66
g->addWidget(box, 1, 2);
67
m_pAux1 = new KviLabel(_i18n_("Row: "), box);
68
m_pRowLabel = new KviLabel("0", box);
70
box = new QHBox(this);
71
box->setFrameStyle(QFrame::Sunken | QFrame::Panel);
72
g->addWidget(box, 1, 3);
73
m_pAux2 = new KviLabel(_i18n_("Col: "), box);
74
m_pColLabel = new KviLabel("0", box);
76
QObject::connect(m_pEditor, SIGNAL(cursorRowChanged(int)), this, SLOT(cursorRowChanged(int)));
77
QObject::connect(m_pEditor, SIGNAL(cursorColChanged(int)), this, SLOT(cursorColChanged(int)));
78
QObject::connect(m_pEditor, SIGNAL(message(const QString &)), l, SLOT(setText(const QString &)));
81
KviScriptEditor::~KviScriptEditor()
86
void KviScriptEditor::cursorRowChanged(int row)
90
m_pRowLabel->setText(tmp);
93
void KviScriptEditor::cursorColChanged(int col)
97
m_pColLabel->setText(tmp);
100
void KviScriptEditor::setEnabled(bool bEnabled)
102
QWidget::setEnabled(bEnabled);
103
m_pEditor->setEnabled(bEnabled);
104
m_pAux1->setEnabled(bEnabled);
105
m_pAux2->setEnabled(bEnabled);
106
m_pColLabel->setEnabled(bEnabled);
107
m_pRowLabel->setEnabled(bEnabled);
110
void KviScriptEditor::saveToFile()
112
KviStr fName = kvi_askForSaveFileName();
113
if( fName.hasData() ) {
114
if( kvi_fileExists(fName.ptr()) ) {
115
if( KviMessageBox::warningYesNo(
116
_i18n_("The file already exists. Do you wish to overwrite it?"),
117
_i18n_("Script Center")) == KviMessageBox::No
122
KviStr buffer = text();
123
if( !kvi_writeFile(fName.ptr(), buffer) )
124
g_pApp->warningBox(_i18n_("Cannot open file %s for writing. Save failed."), fName.ptr());
128
void KviScriptEditor::loadFromFile()
130
KviStr fName = kvi_askForOpenFileName();
131
if( fName.hasData() ) {
133
if( kvi_loadFile(fName.ptr(), buffer) )
134
setText(buffer.ptr());
136
g_pApp->warningBox(_i18n_("Unable to to open file %s"), fName.ptr());
140
KviScriptEditorWidget *KviScriptEditor::editor()
145
void KviScriptEditor::setText(const QString &text)
147
m_pEditor->setText(text);
150
QString KviScriptEditor::text()
152
return m_pEditor->text();
155
#include "m_kvi_script_editor.moc"