# HG changeset patch
# User insilmaril
# Date 1176211372 0
# Node ID 72afe12da1c8dc448fb3cd9af61b0fc26df81c68
# Parent  c56ce5d81cc39d43520e2d34a793231de2d6b644
1.8.71 Basic support for macros

diff -r c56ce5d81cc3 -r 72afe12da1c8 demos/todo.vym
Binary file demos/todo.vym has changed
diff -r c56ce5d81cc3 -r 72afe12da1c8 highlighter.cpp
--- a/highlighter.cpp	Tue Apr 10 13:22:51 2007 +0000
+++ b/highlighter.cpp	Tue Apr 10 13:22:52 2007 +0000
@@ -36,18 +36,28 @@
     keywordFormat.setForeground(Qt::darkBlue);
     keywordFormat.setFontWeight(QFont::Bold);
     QStringList keywordPatterns;
-    keywordPatterns << "\\baddBranch\\b" << "\\baddBranchBefore\\b" 
-                    << "\\baddMapInsert\\b" << "\\baddMapReplace\\b"
-                    << "\\bcolorBranch\\b" << "\\bcolorSubtree\\b"
-                    << "\\bcut\\b" << "\\bdelete\\b" 
-					<< "\\bdeletepKeepChilds\\b" << "\\bdeletepChilds\\b"
-					<< "\\blinkTo\\b" << "\\bloadImage\\b"
-					<< "\\bmoveBranchUp\\b" << "\\bmoveBranchDown\\b"
-					<< "\\bmove\\b" << "\\bmoveRel\\b"
+    keywordPatterns << "\\baddBranch\\b" 
+					<< "\\baddBranchBefore\\b" 
+                    << "\\baddMapInsert\\b" 
+					<< "\\baddMapReplace\\b"
+                    << "\\bcolorBranch\\b" 
+					<< "\\bcolorSubtree\\b"
+                    << "\\bcut\\b" 
+					<< "\\bdelete\\b" 
+					<< "\\bdeletepKeepChilds\\b" 
+					<< "\\bdeletepChilds\\b"
+					<< "\\blinkTo\\b" 
+					<< "\\bloadImage\\b"
+					<< "\\bmoveBranchUp\\b" 
+					<< "\\bmoveBranchDown\\b"
+					<< "\\bmove\\b" 
+					<< "\\bmoveRel\\b"
 					<< "\\bpaste\\b" 
 					<< "\\bsaveImage\\b" 
 					<< "\\bscroll\\b" 
-					<< "\\bselect\\b" << "\\bselectLastBranch\\b" << "\\bselectLastImage\\b"
+					<< "\\bselect\\b" 
+					<< "\\bselectLastBranch\\b" 
+					<< "\\bselectLastImage\\b"
 					<< "\\bsetMapAuthor\\b" 
 					<< "\\bsetMapComment\\b" 
 					<< "\\bsetMapBackgroundColor\\b" 
@@ -60,6 +70,7 @@
 					<< "\\bsetURL\\b" 
 					<< "\\bsetVymLink\\b" 
 					<< "\\bsetFlag\\b" 
+					<< "\\btoggleFlag\\b" 
 					<< "\\bunscroll\\b" 
 					<< "\\bunsetFlag\\b" 
 					;
@@ -84,7 +95,7 @@
     rule.format = singleLineCommentFormat;
     highlightingRules.append(rule);
 
-	// Single line comments
+	// multiline comments
     multiLineCommentFormat.setForeground(Qt::red);
     commentStartExpression = QRegExp("/\\*");
     commentEndExpression = QRegExp("\\*/");
diff -r c56ce5d81cc3 -r 72afe12da1c8 mainwindow.cpp
--- a/mainwindow.cpp	Tue Apr 10 13:22:51 2007 +0000
+++ b/mainwindow.cpp	Tue Apr 10 13:22:52 2007 +0000
@@ -3634,10 +3634,25 @@
     if (action)
 	{
         i=action->data().toInt();
-		QString m=settings.value(QString("/macros/macro-%1").arg(i) ).toString();
+		QString mDir (settings.value ("macros/macroDir").toString() );
+
+		QString fn=mDir + QString("/macro-%1.vys").arg(i+1);
+		QFile f (fn);
+		if ( !f.open( QIODevice::ReadOnly ) )
+		{
+			QMessageBox::warning(0, 
+				tr("Warning"),
+				tr("Couldn't find a macro at  %1.\n").arg(fn)+
+				tr("Please use Settings->")+tr("Set directory for vym macros"));
+			return;
+		}	
+
+		QTextStream ts( &f );
+		QString m= ts.read();
+
 		if (! m.isEmpty())
 		{
-			cout <<"Main::callMacro  m="<<m.ascii()<<endl;
+			//cout <<"Main::callMacro  m="<<m.ascii()<<endl;
 			currentMapEditor()->runScript (m);
 		}	
 	}	
diff -r c56ce5d81cc3 -r 72afe12da1c8 mapeditor.cpp
--- a/mapeditor.cpp	Tue Apr 10 13:22:51 2007 +0000
+++ b/mapeditor.cpp	Tue Apr 10 13:22:52 2007 +0000
@@ -434,7 +434,7 @@
 
 	// Split string s into command and parameters
 	parser.parseAtom (atom);
-	QString com=parser.command();
+	QString com=parser.getCommand();
 	
 	// External commands
 	if (com=="addBranch")
@@ -508,6 +508,19 @@
 				addMapInsertInt(t,y);	
 			}
 		}
+	} else if (com=="clearFlags")
+	{
+		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))
+		{
+			selb->clearStandardFlags();	
+			selb->updateFlagsToolbar();
+		}
 	} else if (com=="colorBranch")
 	{
 		if (xelection.isEmpty())
@@ -957,6 +970,23 @@
 			if (ok) 
 				setFrameType (s);
 		}
+	} else if (com=="toggleFlag")
+	{
+		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) 
+			{
+				selb->toggleStandardFlag(s);	
+				selb->updateFlagsToolbar();
+			}	
+		}
 	} else if (com=="unscroll")
 	{
 		if (xelection.isEmpty() )
@@ -1006,11 +1036,10 @@
 
 void MapEditor::runScript (QString script)
 {
-	// FIXME "atomize" script, currently each line holds one atom
-
 	parser.setScript (script);
 	parser.runScript();
-
+	while (parser.next() ) 
+		parseAtom(parser.getAtom());
 }
 
 bool MapEditor::isDefault()
diff -r c56ce5d81cc3 -r 72afe12da1c8 ornamentedobj.cpp
--- a/ornamentedobj.cpp	Tue Apr 10 13:22:51 2007 +0000
+++ b/ornamentedobj.cpp	Tue Apr 10 13:22:52 2007 +0000
@@ -305,6 +305,15 @@
 }
 
 
+void OrnamentedObj::clearStandardFlags()
+{
+	standardFlags->deactivateAll();
+	calcBBoxSize();
+	positionBBox();
+	move (absPos.x(), absPos.y() );
+	forceReposition();
+}
+
 void OrnamentedObj::toggleStandardFlag(QString f, bool exclusive)
 {
 	standardFlags->toggle(f,exclusive);
diff -r c56ce5d81cc3 -r 72afe12da1c8 ornamentedobj.h
--- a/ornamentedobj.h	Tue Apr 10 13:22:51 2007 +0000
+++ b/ornamentedobj.h	Tue Apr 10 13:22:52 2007 +0000
@@ -43,7 +43,8 @@
     virtual void setVymLink (QString);
     virtual QString getVymLink ();
 
-	virtual void toggleStandardFlag(QString, bool);
+	virtual void clearStandardFlags();
+	virtual void toggleStandardFlag(QString, bool exclusive=false);
 	virtual void activateStandardFlag(QString);
 	virtual void deactivateStandardFlag(QString);
 	virtual bool isSetStandardFlag(QString);
diff -r c56ce5d81cc3 -r 72afe12da1c8 parser.cpp
--- a/parser.cpp	Tue Apr 10 13:22:51 2007 +0000
+++ b/parser.cpp	Tue Apr 10 13:22:52 2007 +0000
@@ -7,26 +7,39 @@
 
 Parser::Parser()
 {
-	initCommand();
+	initParser();
 }
 
-void Parser::initCommand()
+void Parser::initParser()
 {
+	initAtom();
+	current=-1;
+}
+
+void Parser::initAtom()
+{
+	atom="";
 	com="";
 	paramList.clear();
 	resetError();
 }
 
-void Parser::parseAtom (const QString &s)
+void Parser::parseAtom (QString s)
 {
-	initCommand();
-	input=s;
+	initAtom();
+	atom=s;
 	QRegExp re;
 	int pos;
 
+	// Strip WS at beginning
+	re.setPattern ("\\w");
+	re.setMinimal (true);
+	pos=re.search (atom);
+	if (pos>=0)
+		s=s.right(s.length()-pos);
+
 	// Get command
 	re.setPattern ("\\b(.*)(\\s|\\()");
-	re.setMinimal (true);
 	pos=re.search (s);
 	if (pos>=0)
 		com=re.cap(1);
@@ -70,12 +83,17 @@
 	}	
 }
 
-QString Parser::command()
+QString Parser::getAtom()
+{
+	return atom;
+}
+
+QString Parser::getCommand()
 {
 	return com;
 }
 
-QStringList Parser::parameters()
+QStringList Parser::getParameters()
 {
 	return paramList;
 }
@@ -240,9 +258,63 @@
 
 void Parser::runScript()
 {
+	current=0;
 }	
 
-bool Parser::scriptNextAtom()
+bool Parser::next()
 {
+	int start=current;
+	if (current<0) runScript();
+	if (current>=script.length()-1) return false;
+
+	bool inBracket=false;
+	while (true)
+	{
+		//cout <<"current="<<current<< "   start="<<start<<"  length="<<script.length()<<endl;
+
+		// Check if we are inside a string
+		if (script.at(current)=='"')
+		{
+			if (inBracket)
+				inBracket=false;
+			else	
+				inBracket=true;
+		}
+
+		// Check if we are in a comment
+		if (!inBracket && script.at(current)=='#')
+		{
+			while (script.at(current)!='\n')
+			{
+				current++;
+				if (current>=script.length()) 
+					return false;
+			}
+			start=current;
+		}
+
+		// Check for end of atom
+		if (!inBracket && script.at(current)==';')
+		{
+			atom=script.mid(start,current-start);
+			current++;
+			return true;
+		}
+		
+		// Check for end of script
+		if (current==script.length() )
+		{
+			if (inBracket)
+			{
+				setError (Aborted,"Runaway string");
+				return false;
+			} else
+			{
+				atom=script.mid(start);
+				return true;
+			}
+		}
+		current++;
+	}
 }	
 
diff -r c56ce5d81cc3 -r 72afe12da1c8 parser.h
--- a/parser.h	Tue Apr 10 13:22:51 2007 +0000
+++ b/parser.h	Tue Apr 10 13:22:52 2007 +0000
@@ -10,9 +10,10 @@
 {
 public:
 	Parser();
-	void parseAtom (const QString &input);
-	QString command();
-	QStringList parameters();
+	void parseAtom (QString input);
+	QString getAtom();
+	QString getCommand();
+	QStringList getParameters();
 	int paramCount();
 	QString errorMessage();
 	QString errorDescription();
@@ -30,15 +31,18 @@
 	void setScript (const QString &);
 	QString getScript();
 	void runScript();
-	bool scriptNextAtom();
+	bool next();
 
 
 private:
-	void initCommand();
+	void initParser();
+	void initAtom();
 
 	QString input;
+	QString atom;
 	QString com;
 	QStringList paramList;
+	int current;
 	QString script;
 
 	QString errMessage;
diff -r c56ce5d81cc3 -r 72afe12da1c8 version.h
--- a/version.h	Tue Apr 10 13:22:51 2007 +0000
+++ b/version.h	Tue Apr 10 13:22:52 2007 +0000
@@ -4,8 +4,8 @@
 #include <QString>
 
 #define __VYM_NAME "VYM"
-#define __VYM_VERSION "1.8.70"
-#define __VYM_BUILD_DATE "April 9, 2007"
+#define __VYM_VERSION "1.8.71"
+#define __VYM_BUILD_DATE "April 10, 2007"
 
 
 bool checkVersion(const QString &);
diff -r c56ce5d81cc3 -r 72afe12da1c8 vym.pro
--- a/vym.pro	Tue Apr 10 13:22:51 2007 +0000
+++ b/vym.pro	Tue Apr 10 13:22:52 2007 +0000
@@ -125,7 +125,7 @@
 target.path = $${INSTALLDIR}/bin
 INSTALLS += target
 
-support.files = styles/ scripts/ icons/ flags/ lang/
+support.files = styles/ scripts/ icons/ flags/ lang/ macros/ exports/
 support.path = $${INSTALLDIR}/share/vym
 INSTALLS += support 
 
@@ -137,8 +137,3 @@
 demo.path = $${INSTALLDIR}/share/doc/packages/vym
 INSTALLS += demo
 
-exports.files = exports/
-exports.path =$${INSTALLDIR}/share/vym
-INSTALLS += exports
-
-