1.8.71 Basic support for macros
authorinsilmaril
Tue, 10 Apr 2007 13:22:52 +0000
changeset 44772afe12da1c8
parent 446 c56ce5d81cc3
child 448 2ddab62389ec
1.8.71 Basic support for macros
demos/todo.vym
highlighter.cpp
mainwindow.cpp
mapeditor.cpp
ornamentedobj.cpp
ornamentedobj.h
parser.cpp
parser.h
version.h
vym.pro
     1.1 Binary file demos/todo.vym has changed
     2.1 --- a/highlighter.cpp	Tue Apr 10 13:22:51 2007 +0000
     2.2 +++ b/highlighter.cpp	Tue Apr 10 13:22:52 2007 +0000
     2.3 @@ -36,18 +36,28 @@
     2.4      keywordFormat.setForeground(Qt::darkBlue);
     2.5      keywordFormat.setFontWeight(QFont::Bold);
     2.6      QStringList keywordPatterns;
     2.7 -    keywordPatterns << "\\baddBranch\\b" << "\\baddBranchBefore\\b" 
     2.8 -                    << "\\baddMapInsert\\b" << "\\baddMapReplace\\b"
     2.9 -                    << "\\bcolorBranch\\b" << "\\bcolorSubtree\\b"
    2.10 -                    << "\\bcut\\b" << "\\bdelete\\b" 
    2.11 -					<< "\\bdeletepKeepChilds\\b" << "\\bdeletepChilds\\b"
    2.12 -					<< "\\blinkTo\\b" << "\\bloadImage\\b"
    2.13 -					<< "\\bmoveBranchUp\\b" << "\\bmoveBranchDown\\b"
    2.14 -					<< "\\bmove\\b" << "\\bmoveRel\\b"
    2.15 +    keywordPatterns << "\\baddBranch\\b" 
    2.16 +					<< "\\baddBranchBefore\\b" 
    2.17 +                    << "\\baddMapInsert\\b" 
    2.18 +					<< "\\baddMapReplace\\b"
    2.19 +                    << "\\bcolorBranch\\b" 
    2.20 +					<< "\\bcolorSubtree\\b"
    2.21 +                    << "\\bcut\\b" 
    2.22 +					<< "\\bdelete\\b" 
    2.23 +					<< "\\bdeletepKeepChilds\\b" 
    2.24 +					<< "\\bdeletepChilds\\b"
    2.25 +					<< "\\blinkTo\\b" 
    2.26 +					<< "\\bloadImage\\b"
    2.27 +					<< "\\bmoveBranchUp\\b" 
    2.28 +					<< "\\bmoveBranchDown\\b"
    2.29 +					<< "\\bmove\\b" 
    2.30 +					<< "\\bmoveRel\\b"
    2.31  					<< "\\bpaste\\b" 
    2.32  					<< "\\bsaveImage\\b" 
    2.33  					<< "\\bscroll\\b" 
    2.34 -					<< "\\bselect\\b" << "\\bselectLastBranch\\b" << "\\bselectLastImage\\b"
    2.35 +					<< "\\bselect\\b" 
    2.36 +					<< "\\bselectLastBranch\\b" 
    2.37 +					<< "\\bselectLastImage\\b"
    2.38  					<< "\\bsetMapAuthor\\b" 
    2.39  					<< "\\bsetMapComment\\b" 
    2.40  					<< "\\bsetMapBackgroundColor\\b" 
    2.41 @@ -60,6 +70,7 @@
    2.42  					<< "\\bsetURL\\b" 
    2.43  					<< "\\bsetVymLink\\b" 
    2.44  					<< "\\bsetFlag\\b" 
    2.45 +					<< "\\btoggleFlag\\b" 
    2.46  					<< "\\bunscroll\\b" 
    2.47  					<< "\\bunsetFlag\\b" 
    2.48  					;
    2.49 @@ -84,7 +95,7 @@
    2.50      rule.format = singleLineCommentFormat;
    2.51      highlightingRules.append(rule);
    2.52  
    2.53 -	// Single line comments
    2.54 +	// multiline comments
    2.55      multiLineCommentFormat.setForeground(Qt::red);
    2.56      commentStartExpression = QRegExp("/\\*");
    2.57      commentEndExpression = QRegExp("\\*/");
     3.1 --- a/mainwindow.cpp	Tue Apr 10 13:22:51 2007 +0000
     3.2 +++ b/mainwindow.cpp	Tue Apr 10 13:22:52 2007 +0000
     3.3 @@ -3634,10 +3634,25 @@
     3.4      if (action)
     3.5  	{
     3.6          i=action->data().toInt();
     3.7 -		QString m=settings.value(QString("/macros/macro-%1").arg(i) ).toString();
     3.8 +		QString mDir (settings.value ("macros/macroDir").toString() );
     3.9 +
    3.10 +		QString fn=mDir + QString("/macro-%1.vys").arg(i+1);
    3.11 +		QFile f (fn);
    3.12 +		if ( !f.open( QIODevice::ReadOnly ) )
    3.13 +		{
    3.14 +			QMessageBox::warning(0, 
    3.15 +				tr("Warning"),
    3.16 +				tr("Couldn't find a macro at  %1.\n").arg(fn)+
    3.17 +				tr("Please use Settings->")+tr("Set directory for vym macros"));
    3.18 +			return;
    3.19 +		}	
    3.20 +
    3.21 +		QTextStream ts( &f );
    3.22 +		QString m= ts.read();
    3.23 +
    3.24  		if (! m.isEmpty())
    3.25  		{
    3.26 -			cout <<"Main::callMacro  m="<<m.ascii()<<endl;
    3.27 +			//cout <<"Main::callMacro  m="<<m.ascii()<<endl;
    3.28  			currentMapEditor()->runScript (m);
    3.29  		}	
    3.30  	}	
     4.1 --- a/mapeditor.cpp	Tue Apr 10 13:22:51 2007 +0000
     4.2 +++ b/mapeditor.cpp	Tue Apr 10 13:22:52 2007 +0000
     4.3 @@ -434,7 +434,7 @@
     4.4  
     4.5  	// Split string s into command and parameters
     4.6  	parser.parseAtom (atom);
     4.7 -	QString com=parser.command();
     4.8 +	QString com=parser.getCommand();
     4.9  	
    4.10  	// External commands
    4.11  	if (com=="addBranch")
    4.12 @@ -508,6 +508,19 @@
    4.13  				addMapInsertInt(t,y);	
    4.14  			}
    4.15  		}
    4.16 +	} else if (com=="clearFlags")
    4.17 +	{
    4.18 +		if (xelection.isEmpty() )
    4.19 +		{
    4.20 +			parser.setError (Aborted,"Nothing selected");
    4.21 +		} else if (! selb )
    4.22 +		{				  
    4.23 +			parser.setError (Aborted,"Type of selection is not a branch");
    4.24 +		} else if (parser.checkParamCount(0))
    4.25 +		{
    4.26 +			selb->clearStandardFlags();	
    4.27 +			selb->updateFlagsToolbar();
    4.28 +		}
    4.29  	} else if (com=="colorBranch")
    4.30  	{
    4.31  		if (xelection.isEmpty())
    4.32 @@ -957,6 +970,23 @@
    4.33  			if (ok) 
    4.34  				setFrameType (s);
    4.35  		}
    4.36 +	} else if (com=="toggleFlag")
    4.37 +	{
    4.38 +		if (xelection.isEmpty() )
    4.39 +		{
    4.40 +			parser.setError (Aborted,"Nothing selected");
    4.41 +		} else if (! selb )
    4.42 +		{				  
    4.43 +			parser.setError (Aborted,"Type of selection is not a branch");
    4.44 +		} else if (parser.checkParamCount(1))
    4.45 +		{
    4.46 +			s=parser.parString(ok,0);
    4.47 +			if (ok) 
    4.48 +			{
    4.49 +				selb->toggleStandardFlag(s);	
    4.50 +				selb->updateFlagsToolbar();
    4.51 +			}	
    4.52 +		}
    4.53  	} else if (com=="unscroll")
    4.54  	{
    4.55  		if (xelection.isEmpty() )
    4.56 @@ -1006,11 +1036,10 @@
    4.57  
    4.58  void MapEditor::runScript (QString script)
    4.59  {
    4.60 -	// FIXME "atomize" script, currently each line holds one atom
    4.61 -
    4.62  	parser.setScript (script);
    4.63  	parser.runScript();
    4.64 -
    4.65 +	while (parser.next() ) 
    4.66 +		parseAtom(parser.getAtom());
    4.67  }
    4.68  
    4.69  bool MapEditor::isDefault()
     5.1 --- a/ornamentedobj.cpp	Tue Apr 10 13:22:51 2007 +0000
     5.2 +++ b/ornamentedobj.cpp	Tue Apr 10 13:22:52 2007 +0000
     5.3 @@ -305,6 +305,15 @@
     5.4  }
     5.5  
     5.6  
     5.7 +void OrnamentedObj::clearStandardFlags()
     5.8 +{
     5.9 +	standardFlags->deactivateAll();
    5.10 +	calcBBoxSize();
    5.11 +	positionBBox();
    5.12 +	move (absPos.x(), absPos.y() );
    5.13 +	forceReposition();
    5.14 +}
    5.15 +
    5.16  void OrnamentedObj::toggleStandardFlag(QString f, bool exclusive)
    5.17  {
    5.18  	standardFlags->toggle(f,exclusive);
     6.1 --- a/ornamentedobj.h	Tue Apr 10 13:22:51 2007 +0000
     6.2 +++ b/ornamentedobj.h	Tue Apr 10 13:22:52 2007 +0000
     6.3 @@ -43,7 +43,8 @@
     6.4      virtual void setVymLink (QString);
     6.5      virtual QString getVymLink ();
     6.6  
     6.7 -	virtual void toggleStandardFlag(QString, bool);
     6.8 +	virtual void clearStandardFlags();
     6.9 +	virtual void toggleStandardFlag(QString, bool exclusive=false);
    6.10  	virtual void activateStandardFlag(QString);
    6.11  	virtual void deactivateStandardFlag(QString);
    6.12  	virtual bool isSetStandardFlag(QString);
     7.1 --- a/parser.cpp	Tue Apr 10 13:22:51 2007 +0000
     7.2 +++ b/parser.cpp	Tue Apr 10 13:22:52 2007 +0000
     7.3 @@ -7,26 +7,39 @@
     7.4  
     7.5  Parser::Parser()
     7.6  {
     7.7 -	initCommand();
     7.8 +	initParser();
     7.9  }
    7.10  
    7.11 -void Parser::initCommand()
    7.12 +void Parser::initParser()
    7.13  {
    7.14 +	initAtom();
    7.15 +	current=-1;
    7.16 +}
    7.17 +
    7.18 +void Parser::initAtom()
    7.19 +{
    7.20 +	atom="";
    7.21  	com="";
    7.22  	paramList.clear();
    7.23  	resetError();
    7.24  }
    7.25  
    7.26 -void Parser::parseAtom (const QString &s)
    7.27 +void Parser::parseAtom (QString s)
    7.28  {
    7.29 -	initCommand();
    7.30 -	input=s;
    7.31 +	initAtom();
    7.32 +	atom=s;
    7.33  	QRegExp re;
    7.34  	int pos;
    7.35  
    7.36 +	// Strip WS at beginning
    7.37 +	re.setPattern ("\\w");
    7.38 +	re.setMinimal (true);
    7.39 +	pos=re.search (atom);
    7.40 +	if (pos>=0)
    7.41 +		s=s.right(s.length()-pos);
    7.42 +
    7.43  	// Get command
    7.44  	re.setPattern ("\\b(.*)(\\s|\\()");
    7.45 -	re.setMinimal (true);
    7.46  	pos=re.search (s);
    7.47  	if (pos>=0)
    7.48  		com=re.cap(1);
    7.49 @@ -70,12 +83,17 @@
    7.50  	}	
    7.51  }
    7.52  
    7.53 -QString Parser::command()
    7.54 +QString Parser::getAtom()
    7.55 +{
    7.56 +	return atom;
    7.57 +}
    7.58 +
    7.59 +QString Parser::getCommand()
    7.60  {
    7.61  	return com;
    7.62  }
    7.63  
    7.64 -QStringList Parser::parameters()
    7.65 +QStringList Parser::getParameters()
    7.66  {
    7.67  	return paramList;
    7.68  }
    7.69 @@ -240,9 +258,63 @@
    7.70  
    7.71  void Parser::runScript()
    7.72  {
    7.73 +	current=0;
    7.74  }	
    7.75  
    7.76 -bool Parser::scriptNextAtom()
    7.77 +bool Parser::next()
    7.78  {
    7.79 +	int start=current;
    7.80 +	if (current<0) runScript();
    7.81 +	if (current>=script.length()-1) return false;
    7.82 +
    7.83 +	bool inBracket=false;
    7.84 +	while (true)
    7.85 +	{
    7.86 +		//cout <<"current="<<current<< "   start="<<start<<"  length="<<script.length()<<endl;
    7.87 +
    7.88 +		// Check if we are inside a string
    7.89 +		if (script.at(current)=='"')
    7.90 +		{
    7.91 +			if (inBracket)
    7.92 +				inBracket=false;
    7.93 +			else	
    7.94 +				inBracket=true;
    7.95 +		}
    7.96 +
    7.97 +		// Check if we are in a comment
    7.98 +		if (!inBracket && script.at(current)=='#')
    7.99 +		{
   7.100 +			while (script.at(current)!='\n')
   7.101 +			{
   7.102 +				current++;
   7.103 +				if (current>=script.length()) 
   7.104 +					return false;
   7.105 +			}
   7.106 +			start=current;
   7.107 +		}
   7.108 +
   7.109 +		// Check for end of atom
   7.110 +		if (!inBracket && script.at(current)==';')
   7.111 +		{
   7.112 +			atom=script.mid(start,current-start);
   7.113 +			current++;
   7.114 +			return true;
   7.115 +		}
   7.116 +		
   7.117 +		// Check for end of script
   7.118 +		if (current==script.length() )
   7.119 +		{
   7.120 +			if (inBracket)
   7.121 +			{
   7.122 +				setError (Aborted,"Runaway string");
   7.123 +				return false;
   7.124 +			} else
   7.125 +			{
   7.126 +				atom=script.mid(start);
   7.127 +				return true;
   7.128 +			}
   7.129 +		}
   7.130 +		current++;
   7.131 +	}
   7.132  }	
   7.133  
     8.1 --- a/parser.h	Tue Apr 10 13:22:51 2007 +0000
     8.2 +++ b/parser.h	Tue Apr 10 13:22:52 2007 +0000
     8.3 @@ -10,9 +10,10 @@
     8.4  {
     8.5  public:
     8.6  	Parser();
     8.7 -	void parseAtom (const QString &input);
     8.8 -	QString command();
     8.9 -	QStringList parameters();
    8.10 +	void parseAtom (QString input);
    8.11 +	QString getAtom();
    8.12 +	QString getCommand();
    8.13 +	QStringList getParameters();
    8.14  	int paramCount();
    8.15  	QString errorMessage();
    8.16  	QString errorDescription();
    8.17 @@ -30,15 +31,18 @@
    8.18  	void setScript (const QString &);
    8.19  	QString getScript();
    8.20  	void runScript();
    8.21 -	bool scriptNextAtom();
    8.22 +	bool next();
    8.23  
    8.24  
    8.25  private:
    8.26 -	void initCommand();
    8.27 +	void initParser();
    8.28 +	void initAtom();
    8.29  
    8.30  	QString input;
    8.31 +	QString atom;
    8.32  	QString com;
    8.33  	QStringList paramList;
    8.34 +	int current;
    8.35  	QString script;
    8.36  
    8.37  	QString errMessage;
     9.1 --- a/version.h	Tue Apr 10 13:22:51 2007 +0000
     9.2 +++ b/version.h	Tue Apr 10 13:22:52 2007 +0000
     9.3 @@ -4,8 +4,8 @@
     9.4  #include <QString>
     9.5  
     9.6  #define __VYM_NAME "VYM"
     9.7 -#define __VYM_VERSION "1.8.70"
     9.8 -#define __VYM_BUILD_DATE "April 9, 2007"
     9.9 +#define __VYM_VERSION "1.8.71"
    9.10 +#define __VYM_BUILD_DATE "April 10, 2007"
    9.11  
    9.12  
    9.13  bool checkVersion(const QString &);
    10.1 --- a/vym.pro	Tue Apr 10 13:22:51 2007 +0000
    10.2 +++ b/vym.pro	Tue Apr 10 13:22:52 2007 +0000
    10.3 @@ -125,7 +125,7 @@
    10.4  target.path = $${INSTALLDIR}/bin
    10.5  INSTALLS += target
    10.6  
    10.7 -support.files = styles/ scripts/ icons/ flags/ lang/
    10.8 +support.files = styles/ scripts/ icons/ flags/ lang/ macros/ exports/
    10.9  support.path = $${INSTALLDIR}/share/vym
   10.10  INSTALLS += support 
   10.11  
   10.12 @@ -137,8 +137,3 @@
   10.13  demo.path = $${INSTALLDIR}/share/doc/packages/vym
   10.14  INSTALLS += demo
   10.15  
   10.16 -exports.files = exports/
   10.17 -exports.path =$${INSTALLDIR}/share/vym
   10.18 -INSTALLS += exports
   10.19 -
   10.20 -