23#include "kexiscriptdesignview.h"
24#include "kexiscripteditor.h"
26#include <kross/main/manager.h>
27#include <kross/main/scriptcontainer.h>
28#include <kross/main/scriptaction.h>
29#include <kross/api/interpreter.h>
32#include <tqsplitter.h>
34#include <tqdatetime.h>
36#include <tqstylesheet.h>
37#include <ktextbrowser.h>
40#include <kexidialogbase.h>
41#include <kexidb/connection.h>
44class KexiScriptDesignViewPrivate
52 Kross::Api::ScriptAction* scriptaction;
55 KexiScriptEditor* editor;
58 KoProperty::Set* properties;
61 bool updatesProperties;
64 KTextBrowser* statusbrowser;
68 : KexiViewBase(
mainWin, parent,
"KexiScriptDesignView")
69 , d( new KexiScriptDesignViewPrivate() )
71 d->scriptaction = scriptaction;
72 d->updatesProperties =
false;
74 TQSplitter* splitter =
new TQSplitter(
this);
75 splitter->setOrientation(TQt::Vertical);
76 TQHBoxLayout* layout =
new TQHBoxLayout(
this);
77 layout->addWidget(splitter);
80 splitter->setFocusProxy(d->editor);
81 addChildView(d->editor);
82 setViewWidget(d->editor);
84 d->statusbrowser =
new KTextBrowser(splitter,
"ScriptStatusBrowser");
85 d->statusbrowser->setReadOnly(
true);
86 d->statusbrowser->setTextFormat(TQTextBrowser::RichText);
88 d->statusbrowser->installEventFilter(
this);
89 splitter->setResizeMode(d->statusbrowser, TQSplitter::KeepSize);
93 plugSharedAction(
"script_config_editor", d->editor, TQ_SLOT(slotConfigureEditor()) );
97 d->properties =
new KoProperty::Set(
this,
"KexiScripting");
98 connect(d->properties, TQ_SIGNAL( propertyChanged(KoProperty::Set&, KoProperty::Property&) ),
99 this, TQ_SLOT( slotPropertyChanged(KoProperty::Set&, KoProperty::Property&) ));
102 TQTimer::singleShot(50,
this, TQ_SLOT( initialize() ));
107 delete d->properties;
113 return d->scriptaction;
116void KexiScriptDesignView::initialize()
122void KexiScriptDesignView::updateProperties()
124 if(d->updatesProperties)
126 d->updatesProperties =
true;
128 Kross::Api::Manager* manager = Kross::Api::Manager::scriptManager();
130 TQString interpretername = d->scriptaction->getInterpreterName();
131 Kross::Api::InterpreterInfo* info = interpretername.isEmpty() ? 0 : manager->getInterpreterInfo(interpretername);
136 list <<
"python" <<
"ruby";
137 TQStringList::ConstIterator it( list.constBegin() ), end( list.constEnd() );
138 while( (! info) && (it != end) ) {
139 interpretername = (*it);
140 info = manager->getInterpreterInfo(interpretername);
142 d->scriptaction->setInterpreterName(interpretername);
148 d->properties->clear();
150 TQStringList interpreters = manager->getInterpreters();
151 KoProperty::Property::ListData* proplist =
new KoProperty::Property::ListData(interpreters, interpreters);
152 KoProperty::Property* prop =
new KoProperty::Property(
155 d->scriptaction->getInterpreterName(),
157 i18n(
"The used scripting interpreter."),
160 d->properties->addProperty(prop);
162 Kross::Api::InterpreterInfo::Option::Map options = info->getOptions();
163 Kross::Api::InterpreterInfo::Option::Map::ConstIterator it, end( options.constEnd() );
164 for( it = options.constBegin(); it != end; ++it) {
165 Kross::Api::InterpreterInfo::Option* option = it.data();
166 KoProperty::Property* prop =
new KoProperty::Property(
168 d->scriptaction->getOption(it.key(), option->value),
173 d->properties->addProperty(prop);
179 d->updatesProperties =
false;
184 return d->properties;
187void KexiScriptDesignView::slotPropertyChanged(KoProperty::Set& , KoProperty::Property& property)
189 if(property.isNull())
192 if(property.name() ==
"language") {
193 TQString language =
property.value().toString();
194 kdDebug() << TQString(
"KexiScriptDesignView::slotPropertyChanged() language=%1").arg(language) << endl;
195 d->scriptaction->setInterpreterName( language );
202 bool ok = d->scriptaction->setOption( property.name(), property.value() );
204 kdWarning() << TQString(
"KexiScriptDesignView::slotPropertyChanged() unknown property '%1'.").arg(TQString(property.name())) << endl;
212void KexiScriptDesignView::execute()
214 d->statusbrowser->clear();
217 d->statusbrowser->append( i18n(
"Execution of the script \"%1\" started.").arg(d->scriptaction->name()) );
219 d->scriptaction->activate();
220 if( d->scriptaction->hadException() ) {
221 TQString errormessage = d->scriptaction->getException()->getError();
222 d->statusbrowser->append(TQString(
"<b>%2</b><br>").arg(TQStyleSheet::escape(errormessage)) );
224 TQString tracedetails = d->scriptaction->getException()->getTrace();
225 d->statusbrowser->append( TQStyleSheet::escape(tracedetails) );
227 long lineno = d->scriptaction->getException()->getLineNo();
229 d->editor->setLineNo(lineno);
232 d->statusbrowser->append( i18n(
"Successfully executed. Time elapsed: %1ms").arg(time.elapsed()) );
236bool KexiScriptDesignView::loadData()
240 kexipluginsdbg <<
"KexiScriptDesignView::loadData(): no DataBlock" << endl;
248 TQDomDocument domdoc;
249 bool parsed = domdoc.setContent(data,
false, &errMsg, &errLine, &errCol);
252 kexipluginsdbg <<
"KexiScriptDesignView::loadData() XML parsing error line: " << errLine <<
" col: " << errCol <<
" message: " << errMsg << endl;
256 TQDomElement scriptelem = domdoc.namedItem(
"script").toElement();
257 if(scriptelem.isNull()) {
258 kexipluginsdbg <<
"KexiScriptDesignView::loadData(): script domelement is null" << endl;
262 TQString interpretername = scriptelem.attribute(
"language");
263 Kross::Api::Manager* manager = Kross::Api::Manager::scriptManager();
264 Kross::Api::InterpreterInfo* info = interpretername.isEmpty() ? 0 : manager->getInterpreterInfo(interpretername);
266 d->scriptaction->setInterpreterName(interpretername);
268 Kross::Api::InterpreterInfo::Option::Map options = info->getOptions();
269 Kross::Api::InterpreterInfo::Option::Map::ConstIterator it, end = options.constEnd();
270 for( it = options.constBegin(); it != end; ++it) {
271 TQString value = scriptelem.attribute( it.data()->name );
272 if(! value.isNull()) {
274 if( v.cast( it.data()->value.type() ) )
275 d->scriptaction->setOption(it.data()->name, v);
280 d->scriptaction->setCode( scriptelem.text() );
288 kexipluginsdbg <<
"KexiScriptDesignView::storeNewData(): new id:" << s->id() << endl;
296 kdWarning() <<
"KexiScriptDesignView::storeNewData Failed to store the data." << endl;
311 TQDomDocument domdoc(
"script");
312 TQDomElement scriptelem = domdoc.createElement(
"script");
313 domdoc.appendChild(scriptelem);
315 TQString language = d->scriptaction->getInterpreterName();
316 scriptelem.setAttribute(
"language", language);
318 Kross::Api::InterpreterInfo* info = Kross::Api::Manager::scriptManager()->getInterpreterInfo(language);
320 Kross::Api::InterpreterInfo::Option::Map defoptions = info->getOptions();
321 TQStringVariantMap& options = d->scriptaction->getOptions();
322 TQStringVariantMap::ConstIterator it, end( options.constEnd() );
323 for( it = options.constBegin(); it != end; ++it) {
324 if( defoptions.contains(it.key()) ) {
325 scriptelem.setAttribute(it.key(), it.data().toString());
330 TQDomText scriptcode = domdoc.createTextNode(d->scriptaction->getCode());
331 scriptelem.appendChild(scriptcode);
336#include "kexiscriptdesignview.moc"
void plugSharedAction(const char *action_name, TQObject *receiver, const char *slot)
Provides database connection, allowing queries and data modification.
bool removeObject(uint objId)
KexiPart::Item * partItem() const
static bool isAdvancedEditor()
void setHighlightMode(const TQString &highlightmodename)
Set the highlight-mode to highlightmodename .
Kexi's main window interface This interface is implemented by KexiMainWindowImpl class.
virtual KexiProject * project()=0
Project data of currently opened project or NULL if no project here yet.
KexiDB::Connection * dbConnection() const
virtual KexiDB::SchemaData * storeNewData(const KexiDB::SchemaData &sdata, bool &cancel)
Try to call storeData with new data we like to store.
virtual KoProperty::Set * propertySet()
KexiScriptDesignView(KexiMainWindow *mainWin, TQWidget *parent, Kross::Api::ScriptAction *scriptaction)
Constructor.
virtual tristate storeData(bool dontAsk=false)
Try to store the modified data in the already opened and currently used KexiDB::SchemaData instance.
Kross::Api::ScriptAction * scriptAction() const
virtual ~KexiScriptDesignView()
Destructor.
The KexiEditor class embeds text editor for editing scripting code.
void initialize(Kross::Api::ScriptAction *scriptaction)
Initializes the editor.
virtual KexiDB::SchemaData * storeNewData(const KexiDB::SchemaData &sdata, bool &cancel)
void propertySetReloaded(bool preservePrevSelection=false, const TQCString &propertyToSelect=TQCString())
bool storeDataBlock(const TQString &dataString, const TQString &dataID=TQString())
bool loadDataBlock(TQString &dataString, const TQString &dataID=TQString(), bool canBeEmpty=false)
KexiDialogBase * parentDialog() const
KexiMainWindow * mainWin() const
3-state logical type with three values: true, false and cancelled and convenient operators.