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

« back to all changes in this revision

Viewing changes to src/kvirc/script/kvi_script_editor.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_script_editor.cpp ---
 
4
//
 
5
//   This file is part of the KVIrc IRC client distribution
 
6
//   Copyright (C) 1999-2000 Szymon Stefanek (stefanek@tin.it)
 
7
//
 
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.
 
12
//
 
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.
 
17
//
 
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.
 
21
//
 
22
// =============================================================================
 
23
 
 
24
#define _KVI_DEBUG_CHECK_RANGE_
 
25
#define _KVI_DEBUG_CLASS_NAME_ "KviScriptEditor"
 
26
 
 
27
#include <qhbox.h>
 
28
#include <qlayout.h>
 
29
#include <qtoolbutton.h>
 
30
 
 
31
#include "kvi_app.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"
 
40
 
 
41
KviScriptEditor::KviScriptEditor(QWidget *parent)
 
42
        : QWidget(parent)
 
43
{
 
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);
 
48
 
 
49
        QToolButton *b = new QToolButton(UpArrow, this);
 
50
        g->addWidget(b, 1, 0);
 
51
 
 
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()));
 
55
        b->setPopup(pop);
 
56
        b->setPopupDelay(0);
 
57
 
 
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);
 
62
 
 
63
        QHBox *box;
 
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);
 
69
 
 
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);
 
75
 
 
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 &)));
 
79
}
 
80
 
 
81
KviScriptEditor::~KviScriptEditor()
 
82
{
 
83
        //  Nothing here
 
84
}
 
85
 
 
86
void KviScriptEditor::cursorRowChanged(int row)
 
87
{
 
88
        QString tmp;
 
89
        tmp.setNum(row);
 
90
        m_pRowLabel->setText(tmp);
 
91
}
 
92
 
 
93
void KviScriptEditor::cursorColChanged(int col)
 
94
{
 
95
        QString tmp;
 
96
        tmp.setNum(col);
 
97
        m_pColLabel->setText(tmp);
 
98
}
 
99
 
 
100
void KviScriptEditor::setEnabled(bool bEnabled)
 
101
{
 
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);
 
108
}
 
109
 
 
110
void KviScriptEditor::saveToFile()
 
111
{
 
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
 
118
                        ) {
 
119
                                return;
 
120
                        }
 
121
                }
 
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());
 
125
        }
 
126
}
 
127
 
 
128
void KviScriptEditor::loadFromFile()
 
129
{
 
130
        KviStr fName = kvi_askForOpenFileName();
 
131
        if( fName.hasData() ) {
 
132
                KviStr buffer;
 
133
                if( kvi_loadFile(fName.ptr(), buffer) )
 
134
                        setText(buffer.ptr());
 
135
                else
 
136
                        g_pApp->warningBox(_i18n_("Unable to to open file %s"), fName.ptr());
 
137
        }
 
138
}
 
139
 
 
140
KviScriptEditorWidget *KviScriptEditor::editor()
 
141
{
 
142
        return m_pEditor;
 
143
};
 
144
 
 
145
void KviScriptEditor::setText(const QString &text)
 
146
{
 
147
        m_pEditor->setText(text);
 
148
}
 
149
 
 
150
QString KviScriptEditor::text()
 
151
{
 
152
        return m_pEditor->text();
 
153
}
 
154
 
 
155
#include "m_kvi_script_editor.moc"