# HG changeset patch # User insilmaril # Date 1173136971 0 # Node ID f867269ab8a1d6ed19dd9b2bad0d22d9335f3dc4 # Parent c2ffbc9b832dc535eeca2d3b2891d99b122d99ba 1.8.69 Some more scripting functionality (for testing) diff -r c2ffbc9b832d -r f867269ab8a1 api.cpp --- a/api.cpp Sat Feb 24 12:32:53 2007 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,215 +0,0 @@ -#include "api.h" - -#include - -API::API() -{ - initCommand(); -} - -void API::initCommand() -{ - com=""; - paramList.clear(); - resetError(); -} - -void API::parseInput (const QString &s) -{ - initCommand(); - input=s; - QRegExp re; - int pos; - - // Get command - re.setPattern ("(.*)\\s"); - re.setMinimal (true); - pos=re.search (s); - if (pos>=0) - com=re.cap(1); - - // Get parameters - paramList.clear(); - re.setPattern ("\\((.*)\\)"); - pos=re.search (s); - if (pos>=0) - { - QString s=re.cap(1); - QString a; - bool inquote=false; - pos=0; - if (!s.isEmpty()) - { - while (pos plist) -{ - QStringList expList; - QString expected; - for (int i=0; i paramList.count()) - { - errLevel=Aborted; - errDescription=QString("Parameter index %1 is outside of parameter list").arg(index); - return false; - } else - { - paramList[index].toInt (&ok, 10); - if (!ok) - { - errLevel=Aborted; - errDescription=QString("Parameter %1 is not an integer").arg(index); - return false; - } - } - return true; -} - -int API::parInt (bool &ok,const uint &index) -{ - if (checkParamIsInt (index)) - return paramList[index].toInt (&ok, 10); - ok=false; - return 0; -} - -QString API::parString (bool &ok,const int &index) -{ - // return the string at index, this could be also stored in - // a variable later - QString r; - QRegExp re("\"(.*)\""); - int pos=re.search (paramList[index]); - if (pos>=0) - r=re.cap (1); - else - r=""; - ok=true; - return r; -} - -bool API::parBool (bool &ok,const int &index) -{ - // return the bool at index, this could be also stored in - // a variable later - QString r; - ok=true; - QString p=paramList[index]; - if (p=="true" || p=="1") - return true; - else if (p=="false" || p=="0") - return false; - ok=false; - return ok; -} - -QColor API::parColor(bool &ok,const int &index) -{ - // return the QColor at index - ok=true; - return QColor (paramList[index]); -} - diff -r c2ffbc9b832d -r f867269ab8a1 api.h --- a/api.h Sat Feb 24 12:32:53 2007 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -#ifndef API_H -#define API_H - -#include -#include - -enum ErrorLevel {NoError,Warning,Aborted}; - -class API -{ -public: - API(); - void initCommand(); - void parseInput (const QString &input); - QString command(); - QStringList parameters(); - int paramCount(); - QString errorMessage(); - QString errorDescription(); - ErrorLevel errorLevel(); - void setError (ErrorLevel level,const QString &description); - void resetError(); - bool checkParamCount (QList plist); - bool checkParamCount (const int &index); - bool checkParamIsInt (const int &index); - int parInt (bool &,const uint &index); - QString parString(bool &ok,const int &index); - bool parBool (bool &ok, const int &index); - QColor parColor (bool &ok, const int &index); -private: - QString input; - QString com; - QStringList paramList; - QString errMessage; - QString errDescription; - ErrorLevel errLevel; -}; - -#endif diff -r c2ffbc9b832d -r f867269ab8a1 exports.cpp --- a/exports.cpp Sat Feb 24 12:32:53 2007 +0000 +++ b/exports.cpp Mon Mar 05 23:22:51 2007 +0000 @@ -166,12 +166,11 @@ if (mapCenter) me=mapCenter->getMapEditor(); if (me) { - cout << "starting KDE export\n"; WarningDialog dia; dia.showCancelButton (true); dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE")); dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE")); - dia.setShowAgainName("/vym/warnings/overwriteKDEBookmarks"); + dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks"); if (dia.exec()==QDialog::Accepted) { me->exportXML(tmpDir.path()); @@ -180,11 +179,9 @@ p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml"); p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml"); p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl"); - cout << "Trying to call vym2kde\n"; p.process(); QString ub=vymBaseDir.path()+"/scripts/update-bookmarks"; - cout << "Trying to call "<start( ub); if (!proc->waitForStarted()) diff -r c2ffbc9b832d -r f867269ab8a1 mainwindow.cpp --- a/mainwindow.cpp Sat Feb 24 12:32:53 2007 +0000 +++ b/mainwindow.cpp Mon Mar 05 23:22:51 2007 +0000 @@ -98,6 +98,13 @@ branchPropertyWindow = new BranchPropertyWindow(); branchPropertyWindow->move (20,20); + // Initialize script editor + scriptEditor = new SimpleScriptEditor(); + scriptEditor->move (50,50); + + connect( scriptEditor, SIGNAL( runScript ( QString ) ), + this, SLOT( runScript( QString ) ) ); + // Initialize some settings, which are platform dependant QString p,s; @@ -187,6 +194,9 @@ settings.setValue( "/mapeditor/editmode/useFlagGroups",actionSettingsUseFlagGroups->isOn() ); settings.setValue( "/export/useHideExport",actionSettingsUseHideExport->isOn() ); + //FIXME save branchPropWindow settings + //FIXME save scriptEditor settings + // call the destructors delete (textEditor); delete historyWindow; @@ -3419,6 +3429,14 @@ actionViewToggleNoteEditor->setOn (false); } +void Main::runScript (QString script) +{ + if (currentMapEditor()) + currentMapEditor()->runScript (script); + + +} + void Main::showPropertyDialog() { if(currentMapEditor()) @@ -3464,10 +3482,13 @@ void Main::testCommand() { if (!currentMapEditor()) return; + scriptEditor->show(); + /* bool ok; QString com = QInputDialog::getText( vymName, "Enter Command:", QLineEdit::Normal,"command", &ok, this ); if (ok) currentMapEditor()->parseAtom(com); + */ } void Main::helpDoc() diff -r c2ffbc9b832d -r f867269ab8a1 mainwindow.h --- a/mainwindow.h Sat Feb 24 12:32:53 2007 +0000 +++ b/mainwindow.h Mon Mar 05 23:22:51 2007 +0000 @@ -8,6 +8,7 @@ #include "findwindow.h" #include "historywindow.h" #include "mapeditor.h" +#include "simplescripteditor.h" #include "texteditor.h" #include "xml.h" @@ -173,6 +174,7 @@ bool useFlagGroups(); private slots: + void runScript(QString); void showPropertyDialog(); void windowNextEditor(); void windowPreviousEditor(); @@ -201,6 +203,7 @@ HistoryWindow *historyWindow; BranchPropertyWindow *branchPropertyWindow; + SimpleScriptEditor *scriptEditor; QList actionListBranches; diff -r c2ffbc9b832d -r f867269ab8a1 mapeditor.cpp --- a/mapeditor.cpp Sat Feb 24 12:32:53 2007 +0000 +++ b/mapeditor.cpp Mon Mar 05 23:22:51 2007 +0000 @@ -8,7 +8,7 @@ #include "version.h" -#include "api.h" +#include "parser.h" #include "editxlinkdialog.h" #include "exports.h" #include "extrainfodialog.h" @@ -427,35 +427,34 @@ void MapEditor::parseAtom(const QString &atom) { BranchObj *selb=xelection.getBranch(); - API api; QString s,t; int x,y; bool b,ok; // Split string s into command and parameters - api.parseInput (atom); - QString com=api.command(); + parser.parseAtom (atom); + QString com=parser.command(); // External commands if (com=="addBranch") { if (xelection.isEmpty()) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); + parser.setError (Aborted,"Type of selection is not a branch"); } else { QList pl; pl << 0 <<1; - if (api.checkParamCount(pl)) + if (parser.checkParamCount(pl)) { - if (api.paramCount()==0) + if (parser.paramCount()==0) addNewBranchInt (-2); else { - y=api.parInt (ok,0); + y=parser.parInt (ok,0); if (ok ) addNewBranchInt (y); } } @@ -464,13 +463,13 @@ { if (xelection.isEmpty()) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); + parser.setError (Aborted,"Type of selection is not a branch"); } else { - if (api.paramCount()==0) + if (parser.paramCount()==0) { addNewBranchBefore (); } @@ -479,31 +478,31 @@ { if (xelection.isEmpty()) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(1)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(1)) { - //s=api.parString (ok,0); // selection - t=api.parString (ok,0); // path to map + //s=parser.parString (ok,0); // selection + t=parser.parString (ok,0); // path to map if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t); addMapReplaceInt(selb->getSelectString(),t); } - } else if (com==QString("addMapInsert")) + } else if (com==QString("addMparsernsert")) { if (xelection.isEmpty()) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); + parser.setError (Aborted,"Type of selection is not a branch"); } else { - if (api.checkParamCount(2)) + if (parser.checkParamCount(2)) { - t=api.parString (ok,0); // path to map - y=api.parInt(ok,1); // position + t=parser.parString (ok,0); // path to map + y=parser.parInt(ok,1); // position if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t); addMapInsertInt(t,y); } @@ -512,39 +511,39 @@ { if (xelection.isEmpty()) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(1)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(1)) { - QColor c=api.parColor (ok,0); + QColor c=parser.parColor (ok,0); if (ok) colorBranch (c); } } else if (com=="colorSubtree") { if (xelection.isEmpty()) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(1)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(1)) { - QColor c=api.parColor (ok,0); + QColor c=parser.parColor (ok,0); if (ok) colorSubtree (c); } } else if (com=="cut") { if (xelection.isEmpty()) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if ( xelection.type()!=Branch && xelection.type()!=MapCenter && xelection.type()!=FloatImage ) { - api.setError (Aborted,"Type of selection is not a branch or floatimage"); - } else if (api.checkParamCount(0)) + parser.setError (Aborted,"Type of selection is not a branch or floatimage"); + } else if (parser.checkParamCount(0)) { cut(); } @@ -552,11 +551,11 @@ { if (xelection.isEmpty()) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(0)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(0)) { deleteSelection(); } @@ -564,11 +563,11 @@ { if (xelection.isEmpty()) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(0)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(0)) { deleteKeepChilds(); } @@ -576,11 +575,11 @@ { if (xelection.isEmpty()) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(0)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(0)) { deleteChilds(); } @@ -588,32 +587,32 @@ { if (xelection.isEmpty()) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if ( selb) { - if (api.checkParamCount(4)) + if (parser.checkParamCount(4)) { // 0 selectstring of parent // 1 num in parent (for branches) // 2,3 x,y of mainbranch or mapcenter - s=api.parString(ok,0); + s=parser.parString(ok,0); LinkableMapObj *dst=mapCenter->findObjBySelect (s); if (dst) { if (typeid(*dst) == typeid(BranchObj) ) { // Get number in parent - x=api.parInt (ok,1); + x=parser.parInt (ok,1); if (ok) selb->linkTo ((BranchObj*)(dst),x); } else if (typeid(*dst) == typeid(MapCenterObj) ) { selb->linkTo ((BranchObj*)(dst),-1); // Get coordinates of mainbranch - x=api.parInt (ok,2); + x=parser.parInt (ok,2); if (ok) { - y=api.parInt (ok,3); + y=parser.parInt (ok,3); if (ok) selb->move (x,y); } } @@ -621,10 +620,10 @@ } } else if ( xelection.type() == FloatImage) { - if (api.checkParamCount(1)) + if (parser.checkParamCount(1)) { // 0 selectstring of parent - s=api.parString(ok,0); + s=parser.parString(ok,0); LinkableMapObj *dst=mapCenter->findObjBySelect (s); if (dst) { @@ -632,19 +631,32 @@ typeid(*dst) == typeid(MapCenterObj)) linkTo (dst->getSelectString()); } else - api.setError (Aborted,"Destination is not a branch"); + parser.setError (Aborted,"Destination is not a branch"); } } else - api.setError (Aborted,"Type of selection is not a floatimage or branch"); + parser.setError (Aborted,"Type of selection is not a floatimage or branch"); + } else if (com=="loadImage") + { + if (xelection.isEmpty()) + { + parser.setError (Aborted,"Nothing selected"); + } else if (! selb ) + { + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(1)) + { + s=parser.parString(ok,0); + if (ok) loadFloatImageInt (s); + } } else if (com=="moveBranchUp") { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(0)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(0)) { moveBranchUp(); } @@ -652,11 +664,11 @@ { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(0)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(0)) { moveBranchDown(); } @@ -664,18 +676,18 @@ { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if ( xelection.type()!=Branch && xelection.type()!=MapCenter && xelection.type()!=FloatImage ) { - api.setError (Aborted,"Type of selection is not a branch or floatimage"); - } else if (api.checkParamCount(2)) + parser.setError (Aborted,"Type of selection is not a branch or floatimage"); + } else if (parser.checkParamCount(2)) { - x=api.parInt (ok,0); + x=parser.parInt (ok,0); if (ok) { - y=api.parInt (ok,1); + y=parser.parInt (ok,1); if (ok) move (x,y); } } @@ -683,18 +695,18 @@ { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if ( xelection.type()!=Branch && xelection.type()!=MapCenter && xelection.type()!=FloatImage ) { - api.setError (Aborted,"Type of selection is not a branch or floatimage"); - } else if (api.checkParamCount(2)) + parser.setError (Aborted,"Type of selection is not a branch or floatimage"); + } else if (parser.checkParamCount(2)) { - x=api.parInt (ok,0); + x=parser.parInt (ok,0); if (ok) { - y=api.parInt (ok,1); + y=parser.parInt (ok,1); if (ok) moveRel (x,y); } } @@ -702,11 +714,11 @@ { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(0)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(0)) { paste(); } @@ -714,80 +726,96 @@ { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(0)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(0)) { if (!scrollBranch ()) - api.setError (Aborted,"Could not scroll branch"); + parser.setError (Aborted,"Could not scroll branch"); } } else if (com=="select") { - if (api.checkParamCount(1)) + if (parser.checkParamCount(1)) { - s=api.parString(ok,0); + s=parser.parString(ok,0); if (ok) select (s); } + } else if (com=="selectLastBranch") + { + if (xelection.isEmpty() ) + { + parser.setError (Aborted,"Nothing selected"); + } else if (! selb ) + { + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(0)) + { + BranchObj *bo=selb->getLastBranch(); + if (!bo) + parser.setError (Aborted,"Could not select last branch"); + selectInt (bo); + + } } else if (com=="setMapAuthor") { - if (api.checkParamCount(1)) + if (parser.checkParamCount(1)) { - s=api.parString(ok,0); + s=parser.parString(ok,0); if (ok) setMapAuthor (s); } } else if (com=="setMapComment") { - if (api.checkParamCount(1)) + if (parser.checkParamCount(1)) { - s=api.parString(ok,0); + s=parser.parString(ok,0); if (ok) setMapComment(s); } } else if (com=="setMapBackgroundColor") { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! xelection.getBranch() ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(1)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(1)) { - QColor c=api.parColor (ok,0); + QColor c=parser.parColor (ok,0); if (ok) setMapBackgroundColor (c); } } else if (com=="setMapDefLinkColor") { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(1)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(1)) { - QColor c=api.parColor (ok,0); + QColor c=parser.parColor (ok,0); if (ok) setMapDefLinkColor (c); } } else if (com=="setMapLinkStyle") { - if (api.checkParamCount(1)) + if (parser.checkParamCount(1)) { - s=api.parString (ok,0); + s=parser.parString (ok,0); if (ok) setMapLinkStyle(s); } } else if (com=="setHeading") { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(1)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(1)) { - s=api.parString (ok,0); + s=parser.parString (ok,0); if (ok) setHeading (s); } @@ -795,39 +823,39 @@ { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb) { - api.setError (Aborted,"Type of selection is not a branch or floatimage"); - } else if (api.checkParamCount(1)) + parser.setError (Aborted,"Type of selection is not a branch or floatimage"); + } else if (parser.checkParamCount(1)) { - b=api.parBool(ok,0); + b=parser.parBool(ok,0); if (ok) setHideExport (b); } } else if (com=="setURL") { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(1)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(1)) { - s=api.parString (ok,0); + s=parser.parString (ok,0); if (ok) setURLInt(s); } } else if (com=="setVymLink") { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(1)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(1)) { - s=api.parString (ok,0); + s=parser.parString (ok,0); if (ok) setVymLinkInt(s); } } @@ -835,13 +863,13 @@ { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(1)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(1)) { - s=api.parString(ok,0); + s=parser.parString(ok,0); if (ok) { selb->activateStandardFlag(s); @@ -852,26 +880,26 @@ { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(0)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(0)) { if (!unscrollBranch ()) - api.setError (Aborted,"Could not unscroll branch"); + parser.setError (Aborted,"Could not unscroll branch"); } } else if (com=="unsetFlag") { if (xelection.isEmpty() ) { - api.setError (Aborted,"Nothing selected"); + parser.setError (Aborted,"Nothing selected"); } else if (! selb ) { - api.setError (Aborted,"Type of selection is not a branch"); - } else if (api.checkParamCount(1)) + parser.setError (Aborted,"Type of selection is not a branch"); + } else if (parser.checkParamCount(1)) { - s=api.parString(ok,0); + s=parser.parString(ok,0); if (ok) { selb->deactivateStandardFlag(s); @@ -879,19 +907,43 @@ } } } else - api.setError (Aborted,"Unknown command"); + parser.setError (Aborted,"Unknown command"); // Any errors? - if (api.errorLevel()==NoError) + if (parser.errorLevel()==NoError) + { setChanged(); + mapCenter->reposition(); + } else { // TODO Error handling qWarning("MapEditor::parseAtom: Error!"); - qWarning(api.errorMessage()); + qWarning(parser.errorMessage()); } } +void MapEditor::runScript (QString script) +{ + // TODO "atomize" script, currently each line holds one atom + + QStringList list=script.split("\n"); + QString l; + int pos; + for (int i=0; i=0) l.truncate (pos); + + // Try to ignore empty lines + if (l.contains (QRegExp ("\\w"))) + parseAtom (l); + } + +} bool MapEditor::isDefault() { @@ -3017,6 +3069,21 @@ } } +FloatImageObj* MapEditor::loadFloatImageInt (QString fn) +{ + BranchObj *bo=xelection.getBranch(); + if (bo) + { + FloatImageObj *fio; + bo->addFloatImage(); + fio=bo->getLastFloatImage(); + fio->load(fn); + mapCenter->reposition(); + scene()->update(); + return fio; + } + return NULL; +} void MapEditor::loadFloatImage () { @@ -3035,34 +3102,28 @@ fd->setDir (lastImageDir); fd->show(); - QString fn; if ( fd->exec() == QDialog::Accepted ) { // FIXME loadFIO in QT4 use: lastImageDir=fd->directory(); lastImageDir=QDir (fd->dirPath()); - QStringList flist = fd->selectedFiles(); - QStringList::Iterator it = flist.begin(); + QString s; FloatImageObj *fio; - while( it != flist.end() ) + for (int j=0; jselectedFiles().count(); j++) { - fn = *it; - bo->addFloatImage(); - fio=bo->getLastFloatImage(); - fio->load(*it); - // FIXME loadFIO check if load of fio was successful - saveState( - (LinkableMapObj*)fio, - "delete ()", - bo, - QString ("loadFloatImage (%1)").arg(*it), - QString("Add floatimage %1 to %2").arg(*it).arg(getName(bo)) - ); - bo->getLastFloatImage()->setOriginalFilename(fn); - ++it; + s=fd->selectedFiles().at(j); + fio=loadFloatImageInt (s); + if (fio) + saveState( + (LinkableMapObj*)fio, + "delete ()", + bo, + QString ("loadImage (%1)").arg(s ), + QString("Add image %1 to %2").arg(s).arg(getName(bo)) + ); + else + // FIXME loadFIO error handling + qWarning ("Failed to load "+s); } - - mapCenter->reposition(); - scene()->update(); } delete (p); delete (fd); @@ -3269,16 +3330,19 @@ { // This is the playground + +/* WarningDialog dia; dia.showCancelButton (true); dia.setText("This is a longer \nWarning"); dia.setCaption("Warning: Flux problem"); - dia.setShowAgainName("/warnings/mapeditor"); + dia.setShowAgainName("mapeditor/testDialog"); if (dia.exec()==QDialog::Accepted) cout << "accepted!\n"; else cout << "canceled!\n"; return; +*/ /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere if (hidemode==HideNone) diff -r c2ffbc9b832d -r f867269ab8a1 mapeditor.h --- a/mapeditor.h Sat Feb 24 12:32:53 2007 +0000 +++ b/mapeditor.h Mon Mar 05 23:22:51 2007 +0000 @@ -7,6 +7,7 @@ #include "mapcenterobj.h" #include "file.h" #include "misc.h" +#include "parser.h" #include "selection.h" #include "settings.h" @@ -31,7 +32,8 @@ void saveState(const QString &, const QString &, const QString &, const QString &, const QString &); void saveState(const SaveMode&, const QString &, const QString &, const QString &, const QString &, const QString &, LinkableMapObj *); public: - void parseAtom(const QString &); + void parseAtom (const QString &); + void runScript (QString); private: void addFloatImageInt(const QPixmap &img); @@ -162,6 +164,9 @@ bool unscrollBranch(); void toggleScroll(); void unscrollChilds(); +private: + FloatImageObj* loadFloatImageInt (QString); +public: void loadFloatImage (); void saveFloatImage (); void setFrame(const FrameType &); @@ -229,6 +234,8 @@ bool mapChanged; // Flag if undo is possible bool mapUnsaved; // Flag if map should be saved + Parser parser; // Parser stuff for scripting + bool printFrame; // Print frame around map bool printFooter; // Print footer below map diff -r c2ffbc9b832d -r f867269ab8a1 parser.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/parser.cpp Mon Mar 05 23:22:51 2007 +0000 @@ -0,0 +1,234 @@ +#include "parser.h" + +#include +#include + +using namespace std; + +Parser::Parser() +{ + initCommand(); +} + +void Parser::initCommand() +{ + com=""; + paramList.clear(); + resetError(); +} + +void Parser::parseAtom (const QString &s) +{ + initCommand(); + input=s; + QRegExp re; + int pos; + + // Get command + re.setPattern ("\\b(.*)(\\s|\\()"); + re.setMinimal (true); + pos=re.search (s); + if (pos>=0) + com=re.cap(1); + + // Get parameters + paramList.clear(); + re.setPattern ("\\((.*)\\)"); + pos=re.search (s); + //cout << " s="< plist) +{ + QStringList expList; + QString expected; + for (int i=0; i paramList.count()) + { + errLevel=Aborted; + errDescription=QString("Parameter index %1 is outside of parameter list").arg(index); + return false; + } else + { + paramList[index].toInt (&ok, 10); + if (!ok) + { + errLevel=Aborted; + errDescription=QString("Parameter %1 is not an integer").arg(index); + return false; + } + } + return true; +} + +int Parser::parInt (bool &ok,const uint &index) +{ + if (checkParamIsInt (index)) + return paramList[index].toInt (&ok, 10); + ok=false; + return 0; +} + +QString Parser::parString (bool &ok,const int &index) +{ + // return the string at index, this could be also stored in + // a variable later + QString r; + QRegExp re("\"(.*)\""); + int pos=re.search (paramList[index]); + if (pos>=0) + r=re.cap (1); + else + r=""; + ok=true; + return r; +} + +bool Parser::parBool (bool &ok,const int &index) +{ + // return the bool at index, this could be also stored in + // a variable later + QString r; + ok=true; + QString p=paramList[index]; + if (p=="true" || p=="1") + return true; + else if (p=="false" || p=="0") + return false; + ok=false; + return ok; +} + +QColor Parser::parColor(bool &ok,const int &index) +{ + // return the QColor at index + ok=true; + return QColor (paramList[index]); +} + +void Parser::setScript(const QString &s) +{ + script=s; +} + +QString Parser::getScript() +{ + return script; +} + +void Parser::startScript() +{ +} + diff -r c2ffbc9b832d -r f867269ab8a1 parser.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/parser.h Mon Mar 05 23:22:51 2007 +0000 @@ -0,0 +1,49 @@ +#ifndef PARSER_H +#define PARSER_H + +#include +#include + +enum ErrorLevel {NoError,Warning,Aborted}; + +class Parser +{ +public: + Parser(); + void parseAtom (const QString &input); + QString command(); + QStringList parameters(); + int paramCount(); + QString errorMessage(); + QString errorDescription(); + ErrorLevel errorLevel(); + void setError (ErrorLevel level,const QString &description); + void resetError(); + bool checkParamCount (QList plist); + bool checkParamCount (const int &index); + bool checkParamIsInt (const int &index); + int parInt (bool &,const uint &index); + QString parString(bool &ok,const int &index); + bool parBool (bool &ok, const int &index); + QColor parColor (bool &ok, const int &index); + + void setScript (const QString &); + QString getScript(); + void startScript(); + bool next(); + + +private: + void initCommand(); + + QString input; + QString com; + QStringList paramList; + QString script; + + QString errMessage; + QString errDescription; + ErrorLevel errLevel; +}; + +#endif diff -r c2ffbc9b832d -r f867269ab8a1 simplescripteditor.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/simplescripteditor.cpp Mon Mar 05 23:22:51 2007 +0000 @@ -0,0 +1,109 @@ +#include "simplescripteditor.h" + + +#include +#include +#include + + +extern QString vymName; + +SimpleScriptEditor::SimpleScriptEditor (QWidget *parent):QDialog(parent) +{ + ui.setupUi (this); + + connect ( ui.loadButton, SIGNAL (clicked() ), this, SLOT (loadScriptClicked() )); + connect ( ui.saveButton, SIGNAL (clicked() ), this, SLOT (saveScriptClicked() )); + connect ( ui.runButton, SIGNAL (clicked() ), this, SLOT (runScriptClicked() )); +} + + +void SimpleScriptEditor::saveScript() +{ + QFile f( filename ); + if ( !f.open( QIODevice::WriteOnly ) ) + { + return; + } + + QTextStream t( &f ); + t << ui.editor->text(); + f.close(); +} + +void SimpleScriptEditor::saveScriptClicked() +{ + QString fn = QFileDialog::getSaveFileName( + this, + QString (vymName + " - " +tr("Save script")), + QString (), + "VYM script (HTML) (*.vys);;All files (*)", + 0, + QFileDialog::DontConfirmOverwrite); + + if ( !fn.isEmpty() ) + { + QFile file (fn); + if (file.exists()) + { + QMessageBox mb( vymName, + tr("The file %1\nexists already.\nDo you want to overwrite it?","dialog 'save as'").arg(fn), + QMessageBox::Warning, + QMessageBox::Yes | QMessageBox::Default, + QMessageBox::Cancel | QMessageBox::Escape, + Qt::NoButton ); + mb.setButtonText( QMessageBox::Yes, tr("Overwrite") ); + mb.setButtonText( QMessageBox::No, tr("Cancel")); + switch( mb.exec() ) + { + case QMessageBox::Yes: + // save + filename = fn; + saveScript(); + return; + case QMessageBox::Cancel: + // do nothing + return; + } + } + filename=fn; + saveScript(); + } +} + +void SimpleScriptEditor::loadScriptClicked() +{ + QFileDialog *fd=new QFileDialog( this); + QStringList types; + types<< "VYM scripts (*.vys)" << + "All (*)" ; + fd->setFilters (types); + fd->setDirectory (QDir().current()); + fd->setCaption (vymName + " - " + tr("Load script")); + fd->show(); + QString fn; + if ( fd->exec() == QDialog::Accepted ) + fn = fd->selectedFile(); + + if ( !fn.isEmpty() ) + { + QFile f( fn ); + if ( !f.open( QIODevice::ReadOnly ) ) + { + QMessageBox::warning(0, + tr("Error"), + tr("Couldn't open %1.\n").arg(fn)); + return; + } + + QTextStream ts( &f ); + ui.editor->setText( ts.read() ); + f.close(); + } + +} + +void SimpleScriptEditor::runScriptClicked() +{ + emit runScript (ui.editor->text() ); +} diff -r c2ffbc9b832d -r f867269ab8a1 simplescripteditor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/simplescripteditor.h Mon Mar 05 23:22:51 2007 +0000 @@ -0,0 +1,28 @@ +#ifndef SIMPLESCRIPTEDITOR_H +#define SIMPLESCRIPTEDITOR_H + +#include "ui_simplescripteditor.h" + +class SimpleScriptEditor:public QDialog +{ + Q_OBJECT + +public: + SimpleScriptEditor (QWidget* parent = 0); + void saveScript (); + +public slots: + void saveScriptClicked(); + void loadScriptClicked(); + void runScriptClicked(); + +signals: + void runScript (QString); + +private: + Ui::SimpleScriptEditor ui; + QString filename; +}; + + +#endif diff -r c2ffbc9b832d -r f867269ab8a1 simplescripteditor.ui --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/simplescripteditor.ui Mon Mar 05 23:22:51 2007 +0000 @@ -0,0 +1,97 @@ + + SimpleScriptEditor + + + + 0 + 0 + 551 + 407 + + + + Simple Script Editor + + + + 9 + + + 6 + + + + + + + + 0 + + + 6 + + + + + Run + + + + + + + Load + + + + + + + Save + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Close + + + + + + + + + + + closeButton + clicked() + SimpleScriptEditor + accept() + + + 519 + 390 + + + -25 + -275 + + + + + diff -r c2ffbc9b832d -r f867269ab8a1 tex/vym.changelog --- a/tex/vym.changelog Sat Feb 24 12:32:53 2007 +0000 +++ b/tex/vym.changelog Mon Mar 05 23:22:51 2007 +0000 @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Mon Mar 5 22:10:26 CET 2007 - uwe + +- Version: 1.8.69 +- Feature: Simple Editor for scripts + ------------------------------------------------------------------- Tue Feb 20 22:16:09 CET 2007 - uwe diff -r c2ffbc9b832d -r f867269ab8a1 version.h --- a/version.h Sat Feb 24 12:32:53 2007 +0000 +++ b/version.h Mon Mar 05 23:22:51 2007 +0000 @@ -4,8 +4,8 @@ #include #define __VYM_NAME "VYM" -#define __VYM_VERSION "1.8.68" -#define __VYM_BUILD_DATE "February 20, 2007" +#define __VYM_VERSION "1.8.69" +#define __VYM_BUILD_DATE "March 05, 2007" bool checkVersion(const QString &); diff -r c2ffbc9b832d -r f867269ab8a1 vym.pro --- a/vym.pro Sat Feb 24 12:32:53 2007 +0000 +++ b/vym.pro Mon Mar 05 23:22:51 2007 +0000 @@ -1,7 +1,7 @@ TEMPLATE = app LANGUAGE = C++ -CONFIG += qt warn_on release +CONFIG += qt warn_on release debug CONFIG += x86 ppc ICON =icons/vym.icns @@ -9,7 +9,6 @@ HEADERS += \ aboutdialog.h \ - api.h \ branchobj.h \ branchpropwindow.h\ editxlinkdialog.h \ @@ -38,9 +37,11 @@ noteobj.h \ options.h \ ornamentedobj.h \ + parser.h \ process.h \ showtextdialog.h\ selection.h \ + simplescripteditor.h\ texteditor.h \ version.h \ xml.h \ @@ -50,7 +51,6 @@ SOURCES += \ aboutdialog.cpp \ - api.cpp \ branchobj.cpp \ branchpropwindow.cpp \ editxlinkdialog.cpp \ @@ -80,8 +80,10 @@ noteobj.cpp \ options.cpp \ ornamentedobj.cpp \ + parser.cpp \ process.cpp \ showtextdialog.cpp \ + simplescripteditor.cpp \ selection.cpp \ texteditor.cpp \ version.cpp \ @@ -96,6 +98,7 @@ extrainfodialog.ui \ editxlinkdialog.ui \ historywindow.ui \ + simplescripteditor.ui \ showtextdialog.ui \ warningdialog.ui diff -r c2ffbc9b832d -r f867269ab8a1 warningdialog.cpp --- a/warningdialog.cpp Sat Feb 24 12:32:53 2007 +0000 +++ b/warningdialog.cpp Mon Mar 05 23:22:51 2007 +0000 @@ -1,6 +1,8 @@ #include "warningdialog.h" +#include "settings.h" extern QString iconPath; +extern Settings settings; WarningDialog::WarningDialog(QWidget* parent):QDialog (parent) { @@ -9,12 +11,30 @@ ui.okButton->setText(tr("Proceed")); /* ui.warningSign->setPixmap (QPixmap(iconPath + "icons/vym.png")); + */ ui.showAgainBox->setText (tr("Show this message again")); - */ useShowAgain=false; ui.showAgainBox->hide(); } +int WarningDialog::exec() +{ + int result; + if (settings.value ("/warningDialog/"+showAgainName+"/showAgain",true).toBool() ) + { + result=QDialog::exec(); + if (result==QDialog::Accepted ) + { + settings.setValue ("/warningDialog/"+showAgainName+"/value",result); + settings.setValue ("/warningDialog/"+showAgainName+"/showAgain",ui.showAgainBox->isChecked() ); + } + } else + { + result=settings.value ("/warningDialog/"+showAgainName+"/value",0).toInt(); + } + return result; +} + void WarningDialog::showCancelButton (bool b) { if (b) @@ -27,11 +47,9 @@ void WarningDialog::setShowAgainName (const QString &s) //FIXME not implemented yet { -/* showAgainName=s; useShowAgain=true; ui.showAgainBox->show(); -*/ } void WarningDialog::setText (const QString &s)