#include "designer.h"

const char* Designer::type="Designer";

Designer::Designer(Ptr<TclInterp>& interp,Ptr<TkGui>& gui,ModuleManager* manager):gui(gui),manager(manager)
{
	this->interp=interp;
	this->active=true;

	appWindow=new AppWindow(interp,this);
	propEditor=new PropertyEditor(interp,this);
	frmList=new FrmList(interp,this);
}


Ptr<AppWindow>& Designer::getAppWindow()
{
	return appWindow;
}

Ptr<PropertyEditor>& Designer::getPropertyEditor()
{
	return propEditor;
}

Ptr<FrmList>& Designer::getFrmList()
{
	return frmList;
}

Ptr<TkGui>& Designer::getGui()
{
	return gui;
}

ModuleManager* Designer::getManager()
{
	return manager;
}

void Designer::saveAll()
{
	propEditor->beforeSave();
	gui->save();
	propEditor->afterSave();
}

void Designer::onExit()
{
	MBoxButton result=TkDialogs::createMBox(interp,"Question","Save before exit ?",mbox_yesnocancel,mico_question,mbut_yes);
	if (result==mbut_yes)
	{
		saveAll();
	}
	if (result==mbut_no||result==mbut_yes)
	{
		frmList->setVisible(false);
		propEditor->setVisible(false);
		appWindow->setVisible(false);
		active=false;
		gui->destroy();
		gui->load();
	}
}

void Designer::onReactivate()
{
	if (active==true) return;

	frmList->setVisible(true);
	propEditor->setVisible(true);
	appWindow->setVisible(true);

	frmList->reloadList();

	active=true;
}
