template "CtrlLib app with main window + Custom" main;

id     "Main window class name" classname = PACKAGE;
id	   "File extention" file_ext;

select("No layouts", "Generate layout file", "Main window has layout", "Main window has OK/Cancel")
       "Layout" lay = 2;
option "Imagelist file" iml;
option "Multithreaded" mt;

@@<:PACKAGE:>.h
#ifndef _<:PACKAGE:>_<:PACKAGE:>_h
#define _<:PACKAGE:>_<:PACKAGE:>_h

#include <CtrlLib/CtrlLib.h>

using namespace Upp;<:?lay:>

#define LAYOUTFILE <<:PACKAGE:>/<:PACKAGE:>.lay>
#include <CtrlCore/lay.h><:.:><:?iml:>

#define IMAGEFILE <<:PACKAGE:>/<:PACKAGE:>.iml>
#include <Draw/iml_header.h><:.:>

class <:classname:> : public <:lay > 1 ? "With" + classname + "Layout<TopWindow>" : "TopWindow":> {
public:
	typedef <:classname:> CLASSNAME;
	<:classname:>();
	void OpenFile();
	void OpenFile0(String FilePath);
	void Serialize ( Stream& s );
	virtual void DragAndDrop ( Point p, PasteClip& d );
	Vector<String> files;
	
	FileSel fs1;
	StatusBar status;	
};

#endif
@@<:PACKAGE:>.cpp
#include "<:PACKAGE:>.h"<:?iml:>

#define IMAGEFILE <<:PACKAGE:>/<:PACKAGE:>.iml>
#include <Draw/iml_source.h><:.:>

<:classname:>::<:classname:>()
{<:?lay > 1:>
	CtrlLayout<:(lay == 3 ? "OKCancel" : ""):>(*this, "Window title");<:.:>
	AddFrame ( status );
	Sizeable().Zoomable();
}


void <:classname:>::DragAndDrop ( Point p, PasteClip& d )
{
	int FileCnt, idnd1 ;
	String fName1;

	if ( AcceptFiles ( d ) )
	{
		files = GetFiles ( d );

		FileCnt = files.GetCount();

		if ( FileCnt > 0 )
		{
			fName1 =  files[0] ;
			String fExt = GetFileExt ( fName1 );
			fExt = ToUpper ( fExt );
			if ( fExt == ".<:file_ext:>" )
				OpenFile0 ( fName1 );
		}
	}
}

void <:classname:>::OpenFile0 ( String FilePath )
{
	//Add your code
}

void <:classname:>::OpenFile()
{
	fs1.Type ( "//Your file Description//", "*.<:file_ext:>" );  //Change Description
	if ( !fs1.ExecuteOpen ( t_ ( "//Your file Description//" ) ) )
	{
		Exclamation ( t_ ( "File not opened" ) );
		return;
	}
	OpenFile0 ( ~fs1 );
}

void <:classname:>::Serialize ( Stream& s )
{
	int version = 0;
	s / version;
	fs1.Serialize ( s );
}

GUI_APP_MAIN
{
	<:classname:> x;
	LoadFromFile ( x );
	x.Run();
	StoreToFile ( x );
}
@@<:PACKAGE:>.lay
??lay

LAYOUT(<:classname:>Layout, 200, 100)<:?lay == 3:>
	ITEM(Button, ok, SetLabel("OK").RightPosZ(90, 80).BottomPosZ(4, 22))
	ITEM(Button, cancel, SetLabel("Cancel").RightPosZ(4, 80).BottomPosZ(4, 22))<:.:>
END_LAYOUT
@@<:PACKAGE:>.iml
??iml

@@<:PACKAGE:>.upp
uses
	CtrlLib;

file
	<:PACKAGE:>.h,
	<:PACKAGE:>.cpp<:?lay:>,
	<:PACKAGE:>.lay<:.:><:?iml:>,
	<:PACKAGE:>.iml<:.:>;

mainconfig
	"" = "GUI<:?mt:> MT<:.:>";
