3 #include "branchitem.h"
4 #include "confluence-agent.h"
6 #include "mainwindow.h"
8 #include "vymmodelwrapper.h"
12 extern Main *mainWindow;
13 extern QString vymVersion;
15 ///////////////////////////////////////////////////////////////////////////
16 void logError(QScriptContext *context, QScriptContext::Error error,
20 context->throwError(error, text);
22 qDebug() << "VymWrapper: " << text;
25 ///////////////////////////////////////////////////////////////////////////
26 VymScriptContext::VymScriptContext() {}
28 QString VymScriptContext::setResult(const QString &r)
30 context()->engine()->globalObject().setProperty("lastResult", r);
34 bool VymScriptContext::setResult(bool r)
36 context()->engine()->globalObject().setProperty("lastResult", r);
40 int VymScriptContext::setResult(int r)
42 context()->engine()->globalObject().setProperty("lastResult", r);
46 uint VymScriptContext::setResult(uint r)
48 context()->engine()->globalObject().setProperty("lastResult", r);
52 ///////////////////////////////////////////////////////////////////////////
53 VymWrapper::VymWrapper() {}
55 void VymWrapper::clearConsole() { mainWindow->clearScriptOutput(); }
57 bool VymWrapper::isConfluenceAgentAvailable()
59 return ConfluenceAgent::available();
62 QObject *VymWrapper::currentMap()
64 return mainWindow->getCurrentModelWrapper();
67 void VymWrapper::editHeading()
69 MapEditor *me = mainWindow->currentMapEditor();
70 if (me) me->editHeading();
73 bool VymWrapper::loadMap(const QString &filename)
76 if (File::Success == mainWindow->fileLoad(filename, NewMap, VymMap))
83 int VymWrapper::mapCount()
85 context()->engine()->globalObject().setProperty("lastResult",
86 mainWindow->modelCount());
87 return setResult(mainWindow->modelCount());
90 void VymWrapper::gotoMap(uint n)
92 if (!mainWindow->gotoWindow(n)) {
93 logError(context(), QScriptContext::RangeError,
94 QString("Map '%1' not available.").arg(n));
98 bool VymWrapper::closeMapWithID(uint n)
100 bool r = mainWindow->closeModelWithID(n);
102 logError(context(), QScriptContext::RangeError,
103 QString("Map '%1' not available.").arg(n));
107 void VymWrapper::selectQuickColor(int n)
109 mainWindow->selectQuickColor(n);
112 QString VymWrapper::currentColor()
114 return mainWindow->getCurrentColor().name();
117 uint VymWrapper::currentMapID()
119 uint id = mainWindow->currentMapID();
120 return setResult(id);
123 void VymWrapper::toggleTreeEditor() { mainWindow->windowToggleTreeEditor(); }
125 QString VymWrapper::loadFile(
127 &filename) // FIXME-3 error handling missing (in vymmodel and here)
130 loadStringFromDisk(filename, s);
134 void VymWrapper::saveFile(
135 const QString &filename,
136 const QString &s) // FIXME-3 error handling missing (in vymmodel and here)
138 saveStringToDisk(filename, s);
141 QString VymWrapper::version() { return setResult(vymVersion); }
143 // See also http://doc.qt.io/qt-5/qscriptengine.html#newFunction
144 Selection::Selection() { modelWrapper = NULL; }
146 void Selection::test()
148 qDebug() << "Selection::testSelection called"; // TODO debug
150 modelWrapper->setHeadingPlainText("huhu!");
153 void Selection::setModel(VymModelWrapper *mw)
155 qDebug() << "Selection::setModel called: " << mw; // TODO debug