[Kst] kdeextragear-2/kst/kst/extensions/js
George Staikos
staikos at kde.org
Mon Apr 4 18:06:41 CEST 2005
CVS commit by staikos:
ability to load and save Kst files
M +65 -0 bind_kst.cpp 1.10
M +2 -0 bind_kst.h 1.8
--- kdeextragear-2/kst/kst/extensions/js/bind_kst.cpp #1.9:1.10
@@ -37,4 +37,6 @@
#include <kdebug.h>
+#include <qfile.h>
+
using namespace KJSEmbed;
@@ -74,4 +76,6 @@ static KstBindings kstBindings[] = {
{ "resetInterpreter", &KstBindKst::resetInterpreter },
{ "purge", &KstBindKst::purge },
+ { "load", &KstBindKst::load },
+ { "save", &KstBindKst::save },
{ 0L, 0L }
};
@@ -195,4 +199,65 @@ KJS::Value KstBindKst::purge(KJS::ExecSt
+KJS::Value KstBindKst::load(KJS::ExecState *exec, const KJS::List& args) {
+ if (args.size() != 1) {
+ KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError);
+ exec->setException(eobj);
+ return KJS::Boolean(false);
+ }
+
+ if (args[0].type() != KJS::StringType) {
+ KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
+ exec->setException(eobj);
+ return KJS::Boolean(false);
+ }
+
+ KURL u;
+ QString p = args[0].toString(exec).qstring();
+ if (QFile::exists(p)) {
+ u.setPath(p);
+ } else {
+ u = KURL::fromPathOrURL(p);
+ }
+
+ return KJS::Boolean(KstApp::inst()->slotFileOpenRecent(u));
+}
+
+
+KJS::Value KstBindKst::save(KJS::ExecState *exec, const KJS::List& args) {
+ if (args.size() > 1) {
+ KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError);
+ exec->setException(eobj);
+ return KJS::Boolean(false);
+ }
+
+ KstApp *app = KstApp::inst();
+
+ if (args.size() == 1) {
+ if (args[0].type() != KJS::StringType) {
+ KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
+ exec->setException(eobj);
+ return KJS::Boolean(false);
+ }
+ // Warning: this can still block. FIXME. KstDoc::saveDocument needs a
+ // non-blocking flag
+ app->slotUpdateStatusMsg(i18n("Saving file..."));
+ bool rc = app->document()->saveDocument(args[0].toString(exec).qstring());
+ app->slotUpdateStatusMsg(i18n("Ready"));
+ return KJS::Boolean(rc);
+ }
+
+ if (app->document()->title() == "Untitled") {
+ return KJS::Boolean(false);
+ }
+
+ // Warning: this can still block. FIXME. KstDoc::saveDocument needs a
+ // non-blocking flag
+ app->slotUpdateStatusMsg(i18n("Saving file..."));
+ bool rc = app->document()->saveDocument(app->document()->absFilePath());
+ app->slotUpdateStatusMsg(i18n("Ready"));
+ return KJS::Boolean(rc);
+}
+
+
KJS::Value KstBindKst::vectors(KJS::ExecState *exec) const {
return KJS::Object(new KstBindVectorCollection(exec));
--- kdeextragear-2/kst/kst/extensions/js/bind_kst.h #1.7:1.8
@@ -40,4 +40,6 @@ class KstBindKst : public KstBinding {
KJS::Value resetInterpreter(KJS::ExecState *exec, const KJS::List& args);
KJS::Value purge(KJS::ExecState *exec, const KJS::List& args);
+ KJS::Value load(KJS::ExecState *exec, const KJS::List& args);
+ KJS::Value save(KJS::ExecState *exec, const KJS::List& args);
KJS::Value dataSources(KJS::ExecState *exec) const;
More information about the Kst
mailing list