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 };
00042 
00043 KexiScriptEditor::KexiScriptEditor(KexiMainWindow *mainWin, QWidget *parent, const char *name)
00044     : KexiEditor(mainWin, parent, name)
00045     , d( new Private() )
00046 {
00047 }
00048 
00049 KexiScriptEditor::~KexiScriptEditor()
00050 {
00051     delete d;
00052 }
00053 
00054 void KexiScriptEditor::initialize(Kross::Api::ScriptAction* scriptaction)
00055 {
00056     d->scriptaction = scriptaction;
00057     Q_ASSERT(d->scriptaction);
00058 
00059     disconnect(this, SIGNAL(textChanged()), this, SLOT(slotTextChanged()));
00060 
00061     QString code = d->scriptaction->getCode();
00062     if(code.isNull()) {
00063         // If there is no code we just add some informations.
00065         code = "# " + QStringList::split("\n", i18n(
00066             "This note will appear for a user in the script's source code " 
00067             "as a comment. Keep every row not longer than 60 characters and use '\n.'",
00068 
00069             "This is Technology Preview (BETA) version of scripting\n"
00070             "support in Kexi. The scripting API may change in details\n"
00071             "in the next Kexi version.\n"
00072             "For more information and documentation see\n%1"
00073         ).arg("http://www.kexi-project.org/scripting/"), true).join("\n# ") + "\n";
00074     }
00075     KexiEditor::setText(code);
00076     // We assume Kross and the HighlightingInterface are using same
00077     // names for the support languages...
00078     setHighlightMode(d->scriptaction->getInterpreterName());
00079 
00080     clearUndoRedo();
00081     KexiEditor::setDirty(false);
00082     connect(this, SIGNAL(textChanged()), this, SLOT(slotTextChanged()));
00083 }
00084 
00085 void KexiScriptEditor::slotTextChanged()
00086 {
00087     KexiScriptEditor::setDirty(true);
00088     if(d->scriptaction)
00089         d->scriptaction->setCode( KexiEditor::text() );
00090 }
00091 
00092 void KexiScriptEditor::setLineNo(long lineno)
00093 {
00094     setCursorPosition(lineno, 0);
00095 }
00096 
00097 #include "kexiscripteditor.moc"
00098 
KDE Home | KDE Accessibility Home | Description of Access Keys