/***************************************************************************
 *   Copyright (C) 2005 by Juergen Thies                                   *
 *   layout@juergenthies.de                                                *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "macromenuentry.h"
#include "layout.h"
#include "macro/macro.h"
#include "general/errorreport.h"
#include "defines.h"
#include "general/guiworkthread.h"

macroMenuEntry::macroMenuEntry(QString *f,macroMenuEntry **first, mainWindow *d,QString *n,QString *h,menus *p)
 : QObject(0)
{
next=*first;
*first=this;
fileName=(*f);
name=(*n);
help=(*h);
mainwindow=d;
menu=p;
action=NULL;
//menuId=0;
}


macroMenuEntry::~macroMenuEntry()
{
}


void macroMenuEntry::start(){
mainwindow->macroStart(fileName,name);
/*
#ifndef multithread
    if (mainWindow->drawing->mutexChangeGuiTryLock()) {
	mainWindow->drawing->autorepaint=false;
	bool macrorecord=mainWindow->drawing->record;
	mainWindow->drawing->record=false;
	macro m;
	errorreport error;
	QString s="Executing Macro \""+name+"\" ("+fileName+").";
	error.setTitle(s);
	m.load(&fileName);
	m.setLayout(mainWindow);
	int ret=1;
	ret=m.execute(&error);
	if (ret!=0) {error.addItem(tr("main function exit code: ")+s.setNum(ret),2);}
	error.showReport();
	mainWindow->drawing->autorepaint=true;
	mainWindow->setWindowTitle( mainWindow->filename );
	if (macrorecord) mainWindow->drawing->record=true;
	//mainWindow->drawing->macroAdd("// Execute of macro \""+name+"\" ("+fileName+"). A macro cannot start another macro.");
	mainWindow->drawing->macroAdd("layout->executeMacro(\""+fileName+"\");");
	mainWindow->drawing->recountSelect();
	mainWindow->drawing->mutexChangeUnlock();
	mainWindow->drawing->firstCell->paintInfoClear();
	mainWindow->updateSetupLayerbutton();
	mainWindow->cellsUpdate();
	mainWindow->updateGrid();
	mainWindow->drawing->setModifyChanged();
	mainWindow->drawing->paint();
#ifdef USE_3d
	//mainWindow->trigger3dProcess();
#endif
	}
#else
	mainWindow->workThread->startOperation("macro",fileName);
#endif
*/
}
