# HG changeset patch
# User insilmaril
# Date 1176133341 0
# Node ID 0796c5592f00a01e0fd5eb7501a4f0f95dfb4e82
# Parent  fb97757e06c0cbbaf89581c419b6f1f85a8f6cae
Started implementation of macros

diff -r fb97757e06c0 -r 0796c5592f00 demos/todo.vym
Binary file demos/todo.vym has changed
diff -r fb97757e06c0 -r 0796c5592f00 mainwindow.cpp
--- a/mainwindow.cpp	Sat Mar 31 09:28:30 2007 +0000
+++ b/mainwindow.cpp	Mon Apr 09 15:42:21 2007 +0000
@@ -154,6 +154,7 @@
 	setupFlagActions();
     setupSettingsActions();
 	setupContextMenus();
+	setupMacros();
     if (settings.value( "/mainwindow/showTestMenu",false).toBool()) setupTestActions();
     setupHelpActions();
     
@@ -446,7 +447,7 @@
 	actionEditHeading=a;
     a = new QAction( tr( "Edit heading","Edit menu" ), this);
 	a->setStatusTip (tr( "edit Heading" ));
-	a->setShortcut ( Qt::Key_F2 );					//Edit heading
+	//a->setShortcut ( Qt::Key_F2 );					//Edit heading
 	a->setShortcutContext (Qt::WindowShortcut);
 	addAction (a);
     connect( a, SIGNAL( triggered() ), this, SLOT( editHeading() ) );
@@ -1427,12 +1428,12 @@
     QAction *a;
     a = new QAction( "Test function" , this);
     a->setStatusTip( "Call test function" );
-	a->setShortcut (Qt::Key_F4 );
+	//a->setShortcut (Qt::Key_F4 );
     connect( a, SIGNAL( triggered() ), this, SLOT( testFunction() ) );
 	testMenu->addAction (a);
     a = new QAction( "Command" , this);
     a->setStatusTip( "Enter command to call in editor" );
-	a->setShortcut (Qt::Key_F5 );
+	//a->setShortcut (Qt::Key_F5 );
     connect( a, SIGNAL( triggered() ), this, SLOT( testCommand() ) );
 	testMenu->addAction (a);
 }
@@ -1556,10 +1557,10 @@
 	// Create actions
 	for (int i = 0; i < MaxRecentFiles; ++i) 
 	{
-        recentFileActs[i] = new QAction(this);
-        recentFileActs[i]->setVisible(false);
-        fileLastMapsMenu->addAction(recentFileActs[i]);
-        connect(recentFileActs[i], SIGNAL(triggered()),
+        recentFileActions[i] = new QAction(this);
+        recentFileActions[i]->setVisible(false);
+        fileLastMapsMenu->addAction(recentFileActions[i]);
+        connect(recentFileActions[i], SIGNAL(triggered()),
                 this, SLOT(fileLoadRecent()));
     }
 	setupRecentMapsMenu();
@@ -1572,14 +1573,37 @@
     int numRecentFiles = qMin(files.size(), (int)MaxRecentFiles);
 
     for (int i = 0; i < numRecentFiles; ++i) {
-        //QString text = tr("&%1 %2").arg(i + 1).arg(strippedName(files[i]));
         QString text = tr("&%1 %2").arg(i + 1).arg(files[i]);
-        recentFileActs[i]->setText(text);
-        recentFileActs[i]->setData(files[i]);
-        recentFileActs[i]->setVisible(true);
+        recentFileActions[i]->setText(text);
+        recentFileActions[i]->setData(files[i]);
+        recentFileActions[i]->setVisible(true);
     }
     for (int j = numRecentFiles; j < MaxRecentFiles; ++j)
-        recentFileActs[j]->setVisible(false);
+        recentFileActions[j]->setVisible(false);
+}
+
+void Main::setupMacros()
+{
+    for (int i = 0; i <= 11; i++) 
+	{
+        macroActions[i] = new QAction(this);
+        macroActions[i]->setData(i);
+        addAction (macroActions[i]);
+        connect(macroActions[i], SIGNAL(triggered()),
+                this, SLOT(callMacro()));
+	}			
+	macroActions[0]->setShortcut ( Qt::Key_F1 );
+	macroActions[1]->setShortcut ( Qt::Key_F2 );
+	macroActions[2]->setShortcut ( Qt::Key_F3 );
+	macroActions[3]->setShortcut ( Qt::Key_F4 );
+	macroActions[4]->setShortcut ( Qt::Key_F5 );
+	macroActions[5]->setShortcut ( Qt::Key_F6 );
+	macroActions[6]->setShortcut ( Qt::Key_F7 );
+	macroActions[7]->setShortcut ( Qt::Key_F8 );
+	macroActions[8]->setShortcut ( Qt::Key_F9 );
+	macroActions[9]->setShortcut ( Qt::Key_F10 );
+	macroActions[10]->setShortcut ( Qt::Key_F11 );
+	macroActions[11]->setShortcut ( Qt::Key_F12 );
 }
 
 void Main::hideEvent (QHideEvent * )
@@ -2257,9 +2281,9 @@
 		QStringList fl;
 		QFileDialog *fd=new QFileDialog (this);
 		fd->setCaption (tr("Export map as image"));
+		fd->setDirectory (lastImageDir);
 		fd->setFileMode(QFileDialog::AnyFile);
 		fd->setFilters  (imageIO.getFilters() );
-		fd->setDirectory (lastImageDir);
 		if (fd->exec())
 		{
 			fl=fd->selectedFiles();
@@ -3603,3 +3627,19 @@
 	QMessageBox::aboutQt( this, "Qt Application Example" );
 }
 
+void Main::callMacro ()
+{
+    QAction *action = qobject_cast<QAction *>(sender());
+	int i=-1;
+    if (action)
+	{
+        i=action->data().toInt();
+		QString m=settings.value(QString("/macros/macro-%1").arg(i) ).toString();
+		if (! m.isEmpty())
+		{
+			cout <<"Main::callMacro  m="<<m.ascii()<<endl;
+			currentMapEditor()->runScript (m);
+		}	
+	}	
+}
+
diff -r fb97757e06c0 -r 0796c5592f00 mainwindow.h
--- a/mainwindow.h	Sat Mar 31 09:28:30 2007 +0000
+++ b/mainwindow.h	Mon Apr 09 15:42:21 2007 +0000
@@ -43,6 +43,7 @@
     void setupHelpActions();
     void setupContextMenus();
 	void setupRecentMapsMenu();
+    void setupMacros();
 	void hideEvent (QHideEvent * );
 	void showEvent (QShowEvent * );
 	bool reallyWriteDirectory(const QString&);
@@ -193,6 +194,7 @@
     void helpAbout();
     void helpAboutQT();
 
+	void callMacro ();
 private:
 	QTabWidget *tabWidget;
 	FindWindow *findWindow;
@@ -214,7 +216,10 @@
 
 	QMenu *recentFilesMenu;
 	enum { MaxRecentFiles = 9 };
-    QAction *recentFileActs[MaxRecentFiles];
+    QAction *recentFileActions[MaxRecentFiles];
+
+    QAction *macroActions[12];
+	QStringList macro;
 
 	QAction* actionFileSave;
 	QAction* actionFilePrint;
diff -r fb97757e06c0 -r 0796c5592f00 mapeditor.cpp
--- a/mapeditor.cpp	Sat Mar 31 09:28:30 2007 +0000
+++ b/mapeditor.cpp	Mon Apr 09 15:42:21 2007 +0000
@@ -523,6 +523,7 @@
 		}	
 	} else if (com=="colorSubtree")
 	{
+		cout << "atom="<< atom.ascii()<<endl;
 		if (xelection.isEmpty())
 		{
 			parser.setError (Aborted,"Nothing selected");
@@ -942,6 +943,20 @@
 				selb->updateFlagsToolbar();
 			}	
 		}
+	} else if (com=="setFrameType")
+	{
+		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) 
+				setFrameType (s);
+		}
 	} else if (com=="unscroll")
 	{
 		if (xelection.isEmpty() )
@@ -991,23 +1006,10 @@
 
 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<list.size(); i++)
-	{
-		l=list.at(i);
-
-		// Ignore comments
-		pos=l.indexOf ("#");
-		if (pos>=0) l.truncate (pos);
-
-		// Try to ignore empty lines
-		if (l.contains (QRegExp ("\\w")))
-			parseAtom (l);
-	}
+	// FIXME "atomize" script, currently each line holds one atom
+
+	parser.setScript (script);
+	parser.runScript();
 
 }
 
@@ -2513,9 +2515,9 @@
 	QColor oldcol=mapScene->backgroundBrush().color();
 	saveState(
 		mapCenter,
-		QString ("setMapBackgroundColor (%1)").arg(oldcol.name()),
+		QString ("setMapBackgroundColor (\"%1\")").arg(oldcol.name()),
 		mapCenter,
-		QString ("setMapBackgroundColor (%1)").arg(col.name()),
+		QString ("setMapBackgroundColor (\"%1\")").arg(col.name()),
 		QString("Set background color of map to %1").arg(col.name()));
 	mapScene->setBackgroundBrush(col);
 }
@@ -2541,9 +2543,9 @@
 	{
 		saveState(
 			bo, 
-			QString ("colorBranch (%1)").arg(bo->getColor().name()),
+			QString ("colorBranch (\"%1\")").arg(bo->getColor().name()),
 			bo,
-			QString ("colorBranch (%1)").arg(c.name()),
+			QString ("colorBranch (\"%1\")").arg(c.name()),
 			QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name())
 		);	
 		bo->setColor(c); // color branch
@@ -2558,7 +2560,7 @@
 		saveStateChangingPart(
 			bo, 
 			bo,
-			QString ("colorSubtree (%1)").arg(c.name()),
+			QString ("colorSubtree (\"%1\")").arg(c.name()),
 			QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name())
 		);	
 		bo->setColorSubtree (c); // color links, color childs
@@ -3336,6 +3338,17 @@
 	}
 }
 
+void MapEditor::setFrameType(const QString &s)	// FIXME missing saveState
+{
+	BranchObj *bo=xelection.getBranch();
+	if (bo)
+	{
+		bo->setFrameType (s);
+		mapCenter->reposition();
+		bo->updateLink();
+	}
+}
+
 void MapEditor::setFramePenColor(const QColor &c)	// FIXME missing saveState
 {
 	BranchObj *bo=xelection.getBranch();
diff -r fb97757e06c0 -r 0796c5592f00 mapeditor.h
--- a/mapeditor.h	Sat Mar 31 09:28:30 2007 +0000
+++ b/mapeditor.h	Mon Apr 09 15:42:21 2007 +0000
@@ -183,6 +183,7 @@
 public:	
 	void saveFloatImage ();
 	void setFrameType(const FrameType &);
+	void setFrameType(const QString &);
 	void setFramePenColor (const QColor &);
 	void setFrameBrushColor (const QColor &);
 	void setIncludeImagesVer(bool);
diff -r fb97757e06c0 -r 0796c5592f00 parser.cpp
--- a/parser.cpp	Sat Mar 31 09:28:30 2007 +0000
+++ b/parser.cpp	Mon Apr 09 15:42:21 2007 +0000
@@ -214,8 +214,18 @@
 QColor Parser::parColor(bool &ok,const int &index)
 {
 	// return the QColor at index
-	ok=true;
-	return QColor (paramList[index]);
+	ok=false;
+	QString r;
+	QColor c;
+	QRegExp re("\"(.*)\"");
+	int pos=re.search (paramList[index]);
+	if (pos>=0)
+	{
+		r=re.cap (1);
+		c.setNamedColor(r);
+		ok=c.isValid();
+	}	
+	return c;
 }
 
 void Parser::setScript(const QString &s)
@@ -228,7 +238,11 @@
 	return script;
 }	
 
-void Parser::startScript()
+void Parser::runScript()
 {
 }	
 
+bool Parser::scriptNextAtom()
+{
+}	
+
diff -r fb97757e06c0 -r 0796c5592f00 parser.h
--- a/parser.h	Sat Mar 31 09:28:30 2007 +0000
+++ b/parser.h	Mon Apr 09 15:42:21 2007 +0000
@@ -29,8 +29,8 @@
 
 	void setScript (const QString &);
 	QString getScript();
-	void startScript();
-	bool next();
+	void runScript();
+	bool scriptNextAtom();
 
 
 private:
diff -r fb97757e06c0 -r 0796c5592f00 version.h
--- a/version.h	Sat Mar 31 09:28:30 2007 +0000
+++ b/version.h	Mon Apr 09 15:42:21 2007 +0000
@@ -5,7 +5,7 @@
 
 #define __VYM_NAME "VYM"
 #define __VYM_VERSION "1.8.70"
-#define __VYM_BUILD_DATE "March 31, 2007"
+#define __VYM_BUILD_DATE "April 9, 2007"
 
 
 bool checkVersion(const QString &);