kexi

kexiscripteditor.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2003 Lucijan Busch <lucijan@gmx.at>
00003    Copyright (C) 2004-2005 Jaroslaw Staniek <js@iidea.pl>
00004    Copyright (C) 2005 Cedric Pasteur <cedric.pasteur@free.fr>
00005    Copyright (C) 2005 Sebastian Sauer <mail@dipe.org>
00006 
00007    This program is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public License
00018    along with this program; see the file COPYING.  If not, write to
00019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020  * Boston, MA 02110-1301, USA.
00021 */
00022 
00023 #include "kexiscripteditor.h"
00024 
00025 #include <kross/main/scriptaction.h>
00026 
00027 #include <kdebug.h>
00028 //#include <kparts/factory.h>
00029 //#include <klibloader.h>
00030 //#include <kmdimainfrm.h>
00031 //#include <kmainwindow.h>
00032 #include <kpopupmenu.h>
00033 
00034 #include <kexidialogbase.h>
00035 
00037 class KexiScriptEditor::Private
00038 {
00039     public:
00040         Kross::Api::ScriptAction* scriptaction;
00041         Private() : scriptaction(0) {}
00042 };
00043 
00044 KexiScriptEditor::KexiScriptEditor(KexiMainWindow *mainWin, QWidget *parent, const char *name)
00045     : KexiEditor(mainWin, parent, name)
00046     , d( new Private() )
00047 {
00048 }
00049 
00050 KexiScriptEditor::~KexiScriptEditor()
00051 {
00052     delete d;
00053 }
00054 
00055 bool KexiScriptEditor::isInitialized() const
00056 {
00057     return d->scriptaction != 0;
00058 }
00059 
00060 void KexiScriptEditor::initialize(Kross::Api::ScriptAction* scriptaction)
00061 {
00062     d->scriptaction = scriptaction;
00063     Q_ASSERT(d->scriptaction);
00064 
00065     disconnect(this, SIGNAL(textChanged()), this, SLOT(slotTextChanged()));
00066 
00067     QString code = d->scriptaction->getCode();
00068     if(code.isNull()) {
00069         // If there is no code we just add some informations.
00071         code = "# " + QStringList::split("\n", i18n(
00072             "This note will appear for a user in the script's source code " 
00073             "as a comment. Keep every row not longer than 60 characters and use '\n.'",
00074 
00075             "This is Technology Preview (BETA) version of scripting\n"
00076             "support in Kexi. The scripting API may change in details\n"
00077             "in the next Kexi version.\n"
00078             "For more information and documentation see\n%1"
00079         ).arg("http://www.kexi-project.org/scripting/"), true).join("\n# ") + "\n";
00080     }
00081     KexiEditor::setText(code);
00082     // We assume Kross and the HighlightingInterface are using same
00083     // names for the support languages...
00084     setHighlightMode(d->scriptaction->getInterpreterName());
00085 
00086     clearUndoRedo();
00087     KexiEditor::setDirty(false);
00088     connect(this, SIGNAL(textChanged()), this, SLOT(slotTextChanged()));
00089 }
00090 
00091 void KexiScriptEditor::slotTextChanged()
00092 {
00093     KexiScriptEditor::setDirty(true);
00094     if(d->scriptaction)
00095         d->scriptaction->setCode( KexiEditor::text() );
00096 }
00097 
00098 void KexiScriptEditor::setLineNo(long lineno)
00099 {
00100     setCursorPosition(lineno, 0);
00101 }
00102 
00103 #include "kexiscripteditor.moc"
00104 
KDE Home | KDE Accessibility Home | Description of Access Keys