1.8.69 Some more scripting functionality (for testing)
authorinsilmaril
Tue, 06 Mar 2007 19:37:39 +0000
changeset 434c585be63ec69
parent 433 310f1d82cf89
child 435 bd71dfb2292c
1.8.69 Some more scripting functionality (for testing)
main.cpp
mainwindow.cpp
mainwindow.h
mapeditor.cpp
mapeditor.h
simplescripteditor.cpp
simplescripteditor.h
tex/vym.changelog
vym.pro
     1.1 --- a/main.cpp	Mon Mar 05 23:22:51 2007 +0000
     1.2 +++ b/main.cpp	Tue Mar 06 19:37:39 2007 +0000
     1.3 @@ -1,5 +1,4 @@
     1.4  #include <QApplication>
     1.5 -#include <q3network.h>
     1.6  
     1.7  #include "flagrowobj.h"
     1.8  #include "mainwindow.h"
     1.9 @@ -50,6 +49,7 @@
    1.10  	options.add ("local", SwitchOption, "l", "local");
    1.11  	options.add ("help", SwitchOption, "h", "help");
    1.12  	options.add ("quit", SwitchOption, "q", "quit");
    1.13 +	options.add ("run", StringOption, "r", "run");
    1.14  	options.add ("test", StringOption, "t", "test");
    1.15  	options.setHelpText (
    1.16  		"VYM - View Your Mind\n"
    1.17 @@ -113,9 +113,6 @@
    1.18  		return 0;	
    1.19  	}	
    1.20  
    1.21 -    q3InitNetworkProtocols();
    1.22 -
    1.23 -
    1.24  	// Initialize translations
    1.25  	QTranslator translator (0);
    1.26  	translator.load( QString("vym_")+QTextCodec::locale(), vymBaseDir.path() + "/lang");
    1.27 @@ -140,7 +137,31 @@
    1.28  	m.fileNew();
    1.29  	m.loadCmdLine();
    1.30  
    1.31 -	// For benchmarking we may want to quit immediatly after drawing
    1.32 +	// Run script
    1.33 +	if (options.isOn ("run"))
    1.34 +	{
    1.35 +		QString script;
    1.36 +		QString fn=options.getArg ("run");
    1.37 +		if ( !fn.isEmpty() )
    1.38 +		{
    1.39 +			QFile f( fn );
    1.40 +			if ( !f.open( QIODevice::ReadOnly ) )
    1.41 +			{
    1.42 +				QMessageBox::warning(0, 
    1.43 +					QObject::tr("Error"),
    1.44 +					QObject::tr("Couldn't open %1.\n").arg(fn));
    1.45 +				return 0;
    1.46 +			}	
    1.47 +
    1.48 +			QTextStream ts( &f );
    1.49 +			script= ts.read();
    1.50 +			f.close();
    1.51 +			m.setScript (script);
    1.52 +			m.runScript (script);
    1.53 +		}
    1.54 +	}		
    1.55 +	
    1.56 +	// For benchmarking we may want to quit instead of entering event loop
    1.57  	if (options.isOn ("quit"))
    1.58  	{
    1.59  		return 0;
     2.1 --- a/mainwindow.cpp	Mon Mar 05 23:22:51 2007 +0000
     2.2 +++ b/mainwindow.cpp	Tue Mar 06 19:37:39 2007 +0000
     2.3 @@ -3429,12 +3429,15 @@
     2.4  	actionViewToggleNoteEditor->setOn (false);
     2.5  }
     2.6  
     2.7 -void Main::runScript (QString script)
     2.8 +void Main::setScript (const QString &script)
     2.9 +{
    2.10 +	scriptEditor->setScript (script);
    2.11 +}
    2.12 +
    2.13 +void Main::runScript (const QString &script)
    2.14  {
    2.15  	if (currentMapEditor())
    2.16  		currentMapEditor()->runScript (script);
    2.17 -		
    2.18 -	
    2.19  }
    2.20  
    2.21  void Main::showPropertyDialog()
     3.1 --- a/mainwindow.h	Mon Mar 05 23:22:51 2007 +0000
     3.2 +++ b/mainwindow.h	Tue Mar 06 19:37:39 2007 +0000
     3.3 @@ -172,9 +172,10 @@
     3.4  	bool autoEdit();
     3.5  	bool autoSelectHeading();
     3.6  	bool useFlagGroups();
     3.7 +	void setScript(const QString &);
     3.8 +	void runScript(const QString &);
     3.9  
    3.10  private slots:
    3.11 -	void runScript(QString);
    3.12  	void showPropertyDialog();
    3.13  	void windowNextEditor();
    3.14  	void windowPreviousEditor();
     4.1 --- a/mapeditor.cpp	Mon Mar 05 23:22:51 2007 +0000
     4.2 +++ b/mapeditor.cpp	Tue Mar 06 19:37:39 2007 +0000
     4.3 @@ -489,7 +489,7 @@
     4.4  			if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
     4.5  			addMapReplaceInt(selb->getSelectString(),t);	
     4.6  		}
     4.7 -	} else if (com==QString("addMparsernsert"))
     4.8 +	} else if (com==QString("addMapInsert"))
     4.9  	{
    4.10  		if (xelection.isEmpty())
    4.11  		{
    4.12 @@ -552,9 +552,9 @@
    4.13  		if (xelection.isEmpty())
    4.14  		{
    4.15  			parser.setError (Aborted,"Nothing selected");
    4.16 -		} else if (! selb )
    4.17 +		} else if (xelection.type() != Branch && xelection.type() != FloatImage )
    4.18  		{
    4.19 -			parser.setError (Aborted,"Type of selection is not a branch");
    4.20 +			parser.setError (Aborted,"Type of selection is wrong.");
    4.21  		} else if (parser.checkParamCount(0))
    4.22  		{	
    4.23  			deleteSelection();
    4.24 @@ -722,6 +722,21 @@
    4.25  		{	
    4.26  			paste();
    4.27  		}	
    4.28 +	} else if (com=="saveImage")
    4.29 +	{
    4.30 +		FloatImageObj *fio=xelection.getFloatImage();
    4.31 +		if (!fio)
    4.32 +		{
    4.33 +			parser.setError (Aborted,"Type of selection is not an image");
    4.34 +		} else if (parser.checkParamCount(2))
    4.35 +		{
    4.36 +			s=parser.parString(ok,0);
    4.37 +			if (ok)
    4.38 +			{
    4.39 +				t=parser.parString(ok,1);
    4.40 +				if (ok) saveFloatImageInt (fio,t,s);
    4.41 +			}
    4.42 +		}	
    4.43  	} else if (com=="scroll")
    4.44  	{
    4.45  		if (xelection.isEmpty() )
    4.46 @@ -758,6 +773,22 @@
    4.47  			selectInt (bo);	
    4.48  				
    4.49  		}	
    4.50 +	} else if (com=="selectLastImage")
    4.51 +	{
    4.52 +		if (xelection.isEmpty() )
    4.53 +		{
    4.54 +			parser.setError (Aborted,"Nothing selected");
    4.55 +		} else if (! selb )
    4.56 +		{				  
    4.57 +			parser.setError (Aborted,"Type of selection is not a branch");
    4.58 +		} else if (parser.checkParamCount(0))
    4.59 +		{	
    4.60 +			FloatImageObj *fio=selb->getLastFloatImage();
    4.61 +			if (!fio)
    4.62 +				parser.setError (Aborted,"Could not select last image");
    4.63 +			selectInt (fio);	
    4.64 +				
    4.65 +		}	
    4.66  	} else if (com=="setMapAuthor")
    4.67  	{
    4.68  		if (parser.checkParamCount(1))
    4.69 @@ -827,11 +858,38 @@
    4.70  		} else if (! selb)
    4.71  		{				  
    4.72  			parser.setError (Aborted,"Type of selection is not a branch or floatimage");
    4.73 +			//FIXME selb is never a floatimage!!
    4.74  		} else if (parser.checkParamCount(1))
    4.75  		{
    4.76  			b=parser.parBool(ok,0);
    4.77  			if (ok) setHideExport (b);
    4.78  		}
    4.79 +	} else if (com=="setIncludeImagesHorizontally")
    4.80 +	{
    4.81 +		if (xelection.isEmpty() )
    4.82 +		{
    4.83 +			parser.setError (Aborted,"Nothing selected");
    4.84 +		} else if (! selb)
    4.85 +		{				  
    4.86 +			parser.setError (Aborted,"Type of selection is not a branch");
    4.87 +		} else if (parser.checkParamCount(1))
    4.88 +		{
    4.89 +			b=parser.parBool(ok,0);
    4.90 +			if (ok) setIncludeImagesHor(b);
    4.91 +		}
    4.92 +	} else if (com=="setIncludeImagesVertically")
    4.93 +	{
    4.94 +		if (xelection.isEmpty() )
    4.95 +		{
    4.96 +			parser.setError (Aborted,"Nothing selected");
    4.97 +		} else if (! selb)
    4.98 +		{				  
    4.99 +			parser.setError (Aborted,"Type of selection is not a branch");
   4.100 +		} else if (parser.checkParamCount(1))
   4.101 +		{
   4.102 +			b=parser.parBool(ok,0);
   4.103 +			if (ok) setIncludeImagesVer(b);
   4.104 +		}
   4.105  	} else if (com=="setURL")
   4.106  	{
   4.107  		if (xelection.isEmpty() )
   4.108 @@ -3130,6 +3188,11 @@
   4.109  	}
   4.110  }
   4.111  
   4.112 +void MapEditor::saveFloatImageInt  (FloatImageObj *fio, const QString &type, const QString &fn)
   4.113 +{
   4.114 +	fio->save (fn,type);
   4.115 +}
   4.116 +
   4.117  void MapEditor::saveFloatImage ()
   4.118  {
   4.119  	FloatImageObj *fio=xelection.getFloatImage();
   4.120 @@ -3144,13 +3207,14 @@
   4.121  		fd->show();
   4.122  
   4.123  		QString fn;
   4.124 -		if ( fd->exec() == QDialog::Accepted )
   4.125 +		if ( fd->exec() == QDialog::Accepted && fd->selectedFiles().count()==1)
   4.126  		{
   4.127 -			if (QFile (fd->selectedFile()).exists() )
   4.128 +			fn=fd->selectedFiles().at(0);
   4.129 +			if (QFile (fn).exists() )
   4.130  			{
   4.131  				QMessageBox mb( vymName,
   4.132  					tr("The file %1 exists already.\n"
   4.133 -					"Do you want to overwrite it?").arg(fd->selectedFile()),
   4.134 +					"Do you want to overwrite it?").arg(fn),
   4.135  				QMessageBox::Warning,
   4.136  				QMessageBox::Yes | QMessageBox::Default,
   4.137  				QMessageBox::Cancel | QMessageBox::Escape,
   4.138 @@ -3170,7 +3234,7 @@
   4.139  						break;
   4.140  				}
   4.141  			}
   4.142 -			fio->save (fd->selectedFile(),imageIO.getType (fd->selectedFilter() ) );
   4.143 +			saveFloatImageInt (fio,fd->selectedFilter(),fn );
   4.144  		}
   4.145  		delete (fd);
   4.146  	}
   4.147 @@ -3192,6 +3256,16 @@
   4.148  	BranchObj *bo=xelection.getBranch();
   4.149  	if (bo)
   4.150  	{
   4.151 +		QString u= b ? "false" : "true";
   4.152 +		QString r=!b ? "false" : "true";
   4.153 +		
   4.154 +		saveState(
   4.155 +			bo,
   4.156 +			QString("setIncludeImagesVertically (%1)").arg(u),
   4.157 +			bo, 
   4.158 +			QString("setIncludeImagesVertically (%1)").arg(r),
   4.159 +			QString("Include images vertically in %1").arg(getName(bo))
   4.160 +		);	
   4.161  		bo->setIncludeImagesVer(b);
   4.162  		mapCenter->reposition();
   4.163  	}	
   4.164 @@ -3202,6 +3276,16 @@
   4.165  	BranchObj *bo=xelection.getBranch();
   4.166  	if (bo)
   4.167  	{
   4.168 +		QString u= b ? "false" : "true";
   4.169 +		QString r=!b ? "false" : "true";
   4.170 +		
   4.171 +		saveState(
   4.172 +			bo,
   4.173 +			QString("setIncludeImagesHorizontally (%1)").arg(u),
   4.174 +			bo, 
   4.175 +			QString("setIncludeImagesHorizontally (%1)").arg(r),
   4.176 +			QString("Include images horizontally in %1").arg(getName(bo))
   4.177 +		);	
   4.178  		bo->setIncludeImagesHor(b);
   4.179  		mapCenter->reposition();
   4.180  	}	
     5.1 --- a/mapeditor.h	Mon Mar 05 23:22:51 2007 +0000
     5.2 +++ b/mapeditor.h	Tue Mar 06 19:37:39 2007 +0000
     5.3 @@ -168,6 +168,9 @@
     5.4  	FloatImageObj* loadFloatImageInt (QString);
     5.5  public:	
     5.6  	void loadFloatImage ();
     5.7 +private:	
     5.8 +	void saveFloatImageInt (FloatImageObj*, const QString &, const QString &);
     5.9 +public:	
    5.10  	void saveFloatImage ();
    5.11  	void setFrame(const FrameType &);
    5.12  	void setIncludeImagesVer(bool);
     6.1 --- a/simplescripteditor.cpp	Mon Mar 05 23:22:51 2007 +0000
     6.2 +++ b/simplescripteditor.cpp	Tue Mar 06 19:37:39 2007 +0000
     6.3 @@ -15,9 +15,18 @@
     6.4  	connect ( ui.loadButton, SIGNAL (clicked() ), this, SLOT (loadScriptClicked() ));
     6.5  	connect ( ui.saveButton, SIGNAL (clicked() ), this, SLOT (saveScriptClicked() ));
     6.6  	connect ( ui.runButton,  SIGNAL (clicked() ), this, SLOT (runScriptClicked() ));
     6.7 +
     6.8 +
     6.9 +	// Initialize Editor
    6.10 +	QFont font;
    6.11 +	font.setFamily("Courier");
    6.12 +	font.setFixedPitch(true);
    6.13 +	font.setPointSize(10);
    6.14 +	ui.editor->setFont(font);
    6.15 +
    6.16 +	highlighter = new Highlighter(ui.editor->document());
    6.17  }
    6.18  
    6.19 -
    6.20  void SimpleScriptEditor::saveScript()
    6.21  {
    6.22  	QFile f( filename );
    6.23 @@ -31,6 +40,11 @@
    6.24  	f.close();
    6.25  }
    6.26  
    6.27 +void SimpleScriptEditor::setScript(const QString &s)
    6.28 +{
    6.29 +	ui.editor->setText(s);
    6.30 +}
    6.31 +
    6.32  void SimpleScriptEditor::saveScriptClicked()
    6.33  {
    6.34  	QString fn = QFileDialog::getSaveFileName( 
    6.35 @@ -100,7 +114,6 @@
    6.36  		ui.editor->setText( ts.read() );
    6.37  		f.close();
    6.38  	}
    6.39 -
    6.40  }
    6.41  
    6.42  void SimpleScriptEditor::runScriptClicked()
     7.1 --- a/simplescripteditor.h	Mon Mar 05 23:22:51 2007 +0000
     7.2 +++ b/simplescripteditor.h	Tue Mar 06 19:37:39 2007 +0000
     7.3 @@ -3,6 +3,8 @@
     7.4  
     7.5  #include "ui_simplescripteditor.h"
     7.6  
     7.7 +#include "highlighter.h"
     7.8 +
     7.9  class SimpleScriptEditor:public QDialog
    7.10  {
    7.11      Q_OBJECT
    7.12 @@ -10,6 +12,7 @@
    7.13  public:
    7.14      SimpleScriptEditor (QWidget* parent = 0);
    7.15  	void saveScript ();
    7.16 +	void setScript(const QString &);
    7.17  
    7.18  public slots:
    7.19  	void saveScriptClicked();
    7.20 @@ -22,6 +25,7 @@
    7.21  private:
    7.22      Ui::SimpleScriptEditor ui;
    7.23  	QString filename;
    7.24 +	Highlighter *highlighter;
    7.25  };
    7.26  
    7.27  
     8.1 --- a/tex/vym.changelog	Mon Mar 05 23:22:51 2007 +0000
     8.2 +++ b/tex/vym.changelog	Tue Mar 06 19:37:39 2007 +0000
     8.3 @@ -1,8 +1,9 @@
     8.4  -------------------------------------------------------------------
     8.5 -Mon Mar  5 22:10:26 CET 2007 - uwe
     8.6 +Mon Mar  6 22:10:26 CET 2007 - uwe
     8.7  
     8.8  - Version: 1.8.69
     8.9  - Feature: Simple Editor for scripts
    8.10 +- Feature: Added syntax highlighting for editor
    8.11  
    8.12  -------------------------------------------------------------------
    8.13  Tue Feb 20 22:16:09 CET 2007 - uwe
     9.1 --- a/vym.pro	Mon Mar 05 23:22:51 2007 +0000
     9.2 +++ b/vym.pro	Tue Mar 06 19:37:39 2007 +0000
     9.3 @@ -24,6 +24,7 @@
     9.4  	floatobj.h \
     9.5  	frameobj.h \
     9.6  	headingobj.h \
     9.7 +	highlighter.h \
     9.8  	historywindow.h \
     9.9  	imageobj.h \
    9.10  	imports.h \
    9.11 @@ -66,6 +67,7 @@
    9.12  	floatobj.cpp \
    9.13  	frameobj.cpp \
    9.14  	headingobj.cpp \
    9.15 +	highlighter.cpp \
    9.16  	historywindow.cpp \
    9.17  	imageobj.cpp \
    9.18  	imports.cpp \