# HG changeset patch # User insilmaril # Date 1173209859 0 # Node ID c585be63ec6981ed1fb95c3ddaccfd19ed6948e8 # Parent 310f1d82cf893b9e9251859d529315e86925a3b1 1.8.69 Some more scripting functionality (for testing) diff -r 310f1d82cf89 -r c585be63ec69 main.cpp --- a/main.cpp Mon Mar 05 23:22:51 2007 +0000 +++ b/main.cpp Tue Mar 06 19:37:39 2007 +0000 @@ -1,5 +1,4 @@ #include -#include #include "flagrowobj.h" #include "mainwindow.h" @@ -50,6 +49,7 @@ options.add ("local", SwitchOption, "l", "local"); options.add ("help", SwitchOption, "h", "help"); options.add ("quit", SwitchOption, "q", "quit"); + options.add ("run", StringOption, "r", "run"); options.add ("test", StringOption, "t", "test"); options.setHelpText ( "VYM - View Your Mind\n" @@ -113,9 +113,6 @@ return 0; } - q3InitNetworkProtocols(); - - // Initialize translations QTranslator translator (0); translator.load( QString("vym_")+QTextCodec::locale(), vymBaseDir.path() + "/lang"); @@ -140,7 +137,31 @@ m.fileNew(); m.loadCmdLine(); - // For benchmarking we may want to quit immediatly after drawing + // Run script + if (options.isOn ("run")) + { + QString script; + QString fn=options.getArg ("run"); + if ( !fn.isEmpty() ) + { + QFile f( fn ); + if ( !f.open( QIODevice::ReadOnly ) ) + { + QMessageBox::warning(0, + QObject::tr("Error"), + QObject::tr("Couldn't open %1.\n").arg(fn)); + return 0; + } + + QTextStream ts( &f ); + script= ts.read(); + f.close(); + m.setScript (script); + m.runScript (script); + } + } + + // For benchmarking we may want to quit instead of entering event loop if (options.isOn ("quit")) { return 0; diff -r 310f1d82cf89 -r c585be63ec69 mainwindow.cpp --- a/mainwindow.cpp Mon Mar 05 23:22:51 2007 +0000 +++ b/mainwindow.cpp Tue Mar 06 19:37:39 2007 +0000 @@ -3429,12 +3429,15 @@ actionViewToggleNoteEditor->setOn (false); } -void Main::runScript (QString script) +void Main::setScript (const QString &script) +{ + scriptEditor->setScript (script); +} + +void Main::runScript (const QString &script) { if (currentMapEditor()) currentMapEditor()->runScript (script); - - } void Main::showPropertyDialog() diff -r 310f1d82cf89 -r c585be63ec69 mainwindow.h --- a/mainwindow.h Mon Mar 05 23:22:51 2007 +0000 +++ b/mainwindow.h Tue Mar 06 19:37:39 2007 +0000 @@ -172,9 +172,10 @@ bool autoEdit(); bool autoSelectHeading(); bool useFlagGroups(); + void setScript(const QString &); + void runScript(const QString &); private slots: - void runScript(QString); void showPropertyDialog(); void windowNextEditor(); void windowPreviousEditor(); diff -r 310f1d82cf89 -r c585be63ec69 mapeditor.cpp --- a/mapeditor.cpp Mon Mar 05 23:22:51 2007 +0000 +++ b/mapeditor.cpp Tue Mar 06 19:37:39 2007 +0000 @@ -489,7 +489,7 @@ if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t); addMapReplaceInt(selb->getSelectString(),t); } - } else if (com==QString("addMparsernsert")) + } else if (com==QString("addMapInsert")) { if (xelection.isEmpty()) { @@ -552,9 +552,9 @@ if (xelection.isEmpty()) { parser.setError (Aborted,"Nothing selected"); - } else if (! selb ) + } else if (xelection.type() != Branch && xelection.type() != FloatImage ) { - parser.setError (Aborted,"Type of selection is not a branch"); + parser.setError (Aborted,"Type of selection is wrong."); } else if (parser.checkParamCount(0)) { deleteSelection(); @@ -722,6 +722,21 @@ { paste(); } + } else if (com=="saveImage") + { + FloatImageObj *fio=xelection.getFloatImage(); + if (!fio) + { + parser.setError (Aborted,"Type of selection is not an image"); + } else if (parser.checkParamCount(2)) + { + s=parser.parString(ok,0); + if (ok) + { + t=parser.parString(ok,1); + if (ok) saveFloatImageInt (fio,t,s); + } + } } else if (com=="scroll") { if (xelection.isEmpty() ) @@ -758,6 +773,22 @@ selectInt (bo); } + } else if (com=="selectLastImage") + { + 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)) + { + FloatImageObj *fio=selb->getLastFloatImage(); + if (!fio) + parser.setError (Aborted,"Could not select last image"); + selectInt (fio); + + } } else if (com=="setMapAuthor") { if (parser.checkParamCount(1)) @@ -827,11 +858,38 @@ } else if (! selb) { parser.setError (Aborted,"Type of selection is not a branch or floatimage"); + //FIXME selb is never a floatimage!! } else if (parser.checkParamCount(1)) { b=parser.parBool(ok,0); if (ok) setHideExport (b); } + } else if (com=="setIncludeImagesHorizontally") + { + 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)) + { + b=parser.parBool(ok,0); + if (ok) setIncludeImagesHor(b); + } + } else if (com=="setIncludeImagesVertically") + { + 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)) + { + b=parser.parBool(ok,0); + if (ok) setIncludeImagesVer(b); + } } else if (com=="setURL") { if (xelection.isEmpty() ) @@ -3130,6 +3188,11 @@ } } +void MapEditor::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn) +{ + fio->save (fn,type); +} + void MapEditor::saveFloatImage () { FloatImageObj *fio=xelection.getFloatImage(); @@ -3144,13 +3207,14 @@ fd->show(); QString fn; - if ( fd->exec() == QDialog::Accepted ) + if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1) { - if (QFile (fd->selectedFile()).exists() ) + fn=fd->selectedFiles().at(0); + if (QFile (fn).exists() ) { QMessageBox mb( vymName, tr("The file %1 exists already.\n" - "Do you want to overwrite it?").arg(fd->selectedFile()), + "Do you want to overwrite it?").arg(fn), QMessageBox::Warning, QMessageBox::Yes | QMessageBox::Default, QMessageBox::Cancel | QMessageBox::Escape, @@ -3170,7 +3234,7 @@ break; } } - fio->save (fd->selectedFile(),imageIO.getType (fd->selectedFilter() ) ); + saveFloatImageInt (fio,fd->selectedFilter(),fn ); } delete (fd); } @@ -3192,6 +3256,16 @@ BranchObj *bo=xelection.getBranch(); if (bo) { + QString u= b ? "false" : "true"; + QString r=!b ? "false" : "true"; + + saveState( + bo, + QString("setIncludeImagesVertically (%1)").arg(u), + bo, + QString("setIncludeImagesVertically (%1)").arg(r), + QString("Include images vertically in %1").arg(getName(bo)) + ); bo->setIncludeImagesVer(b); mapCenter->reposition(); } @@ -3202,6 +3276,16 @@ BranchObj *bo=xelection.getBranch(); if (bo) { + QString u= b ? "false" : "true"; + QString r=!b ? "false" : "true"; + + saveState( + bo, + QString("setIncludeImagesHorizontally (%1)").arg(u), + bo, + QString("setIncludeImagesHorizontally (%1)").arg(r), + QString("Include images horizontally in %1").arg(getName(bo)) + ); bo->setIncludeImagesHor(b); mapCenter->reposition(); } diff -r 310f1d82cf89 -r c585be63ec69 mapeditor.h --- a/mapeditor.h Mon Mar 05 23:22:51 2007 +0000 +++ b/mapeditor.h Tue Mar 06 19:37:39 2007 +0000 @@ -168,6 +168,9 @@ FloatImageObj* loadFloatImageInt (QString); public: void loadFloatImage (); +private: + void saveFloatImageInt (FloatImageObj*, const QString &, const QString &); +public: void saveFloatImage (); void setFrame(const FrameType &); void setIncludeImagesVer(bool); diff -r 310f1d82cf89 -r c585be63ec69 simplescripteditor.cpp --- a/simplescripteditor.cpp Mon Mar 05 23:22:51 2007 +0000 +++ b/simplescripteditor.cpp Tue Mar 06 19:37:39 2007 +0000 @@ -15,9 +15,18 @@ connect ( ui.loadButton, SIGNAL (clicked() ), this, SLOT (loadScriptClicked() )); connect ( ui.saveButton, SIGNAL (clicked() ), this, SLOT (saveScriptClicked() )); connect ( ui.runButton, SIGNAL (clicked() ), this, SLOT (runScriptClicked() )); + + + // Initialize Editor + QFont font; + font.setFamily("Courier"); + font.setFixedPitch(true); + font.setPointSize(10); + ui.editor->setFont(font); + + highlighter = new Highlighter(ui.editor->document()); } - void SimpleScriptEditor::saveScript() { QFile f( filename ); @@ -31,6 +40,11 @@ f.close(); } +void SimpleScriptEditor::setScript(const QString &s) +{ + ui.editor->setText(s); +} + void SimpleScriptEditor::saveScriptClicked() { QString fn = QFileDialog::getSaveFileName( @@ -100,7 +114,6 @@ ui.editor->setText( ts.read() ); f.close(); } - } void SimpleScriptEditor::runScriptClicked() diff -r 310f1d82cf89 -r c585be63ec69 simplescripteditor.h --- a/simplescripteditor.h Mon Mar 05 23:22:51 2007 +0000 +++ b/simplescripteditor.h Tue Mar 06 19:37:39 2007 +0000 @@ -3,6 +3,8 @@ #include "ui_simplescripteditor.h" +#include "highlighter.h" + class SimpleScriptEditor:public QDialog { Q_OBJECT @@ -10,6 +12,7 @@ public: SimpleScriptEditor (QWidget* parent = 0); void saveScript (); + void setScript(const QString &); public slots: void saveScriptClicked(); @@ -22,6 +25,7 @@ private: Ui::SimpleScriptEditor ui; QString filename; + Highlighter *highlighter; }; diff -r 310f1d82cf89 -r c585be63ec69 tex/vym.changelog --- a/tex/vym.changelog Mon Mar 05 23:22:51 2007 +0000 +++ b/tex/vym.changelog Tue Mar 06 19:37:39 2007 +0000 @@ -1,8 +1,9 @@ ------------------------------------------------------------------- -Mon Mar 5 22:10:26 CET 2007 - uwe +Mon Mar 6 22:10:26 CET 2007 - uwe - Version: 1.8.69 - Feature: Simple Editor for scripts +- Feature: Added syntax highlighting for editor ------------------------------------------------------------------- Tue Feb 20 22:16:09 CET 2007 - uwe diff -r 310f1d82cf89 -r c585be63ec69 vym.pro --- a/vym.pro Mon Mar 05 23:22:51 2007 +0000 +++ b/vym.pro Tue Mar 06 19:37:39 2007 +0000 @@ -24,6 +24,7 @@ floatobj.h \ frameobj.h \ headingobj.h \ + highlighter.h \ historywindow.h \ imageobj.h \ imports.h \ @@ -66,6 +67,7 @@ floatobj.cpp \ frameobj.cpp \ headingobj.cpp \ + highlighter.cpp \ historywindow.cpp \ imageobj.cpp \ imports.cpp \