module gedo.gui.dialog;



public import gedo.gui.table;
public import gedo.gui.cursor;
public import gedo.gui.component;



alias void delegate(bool isOk) OnQuit;



public class Dialog : Table
{
public:
	this(int colCount, int rowCount)
	{
		super(colCount, rowCount);
	}


	void show(OnQuit dg, Cursor cursor)
	{
		if(!parent)
		{
			_backup.focus = cursor.focus;

			_onQuit = dg;

			_cursor = cursor;

			cursor.focus.add(this);

			cursor.focus = rows[0];
		}
	}


	void close(bool isOk = true)
	{
		if(parent)
		{
			_onQuit(isOk);

			_cursor.focus = _backup.focus;

			parent.remove(this);
		}
	}


	void closeOk()
	{
		close(true);
	}


	void closeCancel()
	{
		close(false);
	}


private:
	struct Backup
	{
		Component focus;
	}


	OnQuit _onQuit;
	Cursor _cursor;
	Backup _backup;
}
