//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "FDLGSelDir.h"
#include "FDLGProjectOptions.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TDLGProjectOptions *DLGProjectOptions;
//---------------------------------------------------------------------------
__fastcall TDLGProjectOptions::TDLGProjectOptions(TComponent* Owner) : TForm(Owner)
{
}
//---------------------------------------------------------------------------
bool dlg_bSetupProjectOptions(TProjectOptions& _roPrjOpts)
{
    bool bRes;
    Application->CreateForm(__classid(TDLGProjectOptions), &DLGProjectOptions);

	DLGProjectOptions->mem_EGroupPRE->Text 	    = _roPrjOpts.m_asEGroupPRE;
	DLGProjectOptions->mem_EGroupPOST->Text     = _roPrjOpts.m_asEGroupPOST;
	DLGProjectOptions->mem_EntryPRE->Text 	    = _roPrjOpts.m_asEntryPRE;
	DLGProjectOptions->mem_EntryPOST->Text 	    = _roPrjOpts.m_asEntryPOST;
	DLGProjectOptions->ed_TAG->Text    		    = _roPrjOpts.m_asDateTAG;
	DLGProjectOptions->ed_ShowImageScript->Text = _roPrjOpts.m_asShowImageScript;

	if (_roPrjOpts.m_asFileType == "php")
		DLGProjectOptions->cb_OutputFile->ItemIndex = 1;
	else
		DLGProjectOptions->cb_OutputFile->ItemIndex = 0;

	DLGProjectOptions->ed_SiteDir->Text    		= _roPrjOpts.m_asSiteDir;
    DLGProjectOptions->ed_EntriesDir->Text  	= _roPrjOpts.m_asEntriesDir;

    DLGProjectOptions->ShowModal();

    bRes = (DLGProjectOptions->ModalResult == mrOk);
	if (bRes)
    {
		_roPrjOpts.m_asEGroupPRE   	= DLGProjectOptions->mem_EGroupPRE ->Text;
		_roPrjOpts.m_asEGroupPOST  	= DLGProjectOptions->mem_EGroupPOST->Text;
		_roPrjOpts.m_asEntryPRE    	= DLGProjectOptions->mem_EntryPRE ->Text;
		_roPrjOpts.m_asEntryPOST   	= DLGProjectOptions->mem_EntryPOST->Text;
		_roPrjOpts.m_asDateTAG		= DLGProjectOptions->ed_TAG->Text;
		_roPrjOpts.m_asShowImageScript = DLGProjectOptions->ed_ShowImageScript->Text;

		_roPrjOpts.m_asFileType 	= DLGProjectOptions->cb_OutputFile->Text;
        _roPrjOpts.m_asSiteDir  	= DLGProjectOptions->ed_SiteDir->Text;
        _roPrjOpts.m_asEntriesDir  	= DLGProjectOptions->ed_EntriesDir->Text;
    }

    delete DLGProjectOptions;
    return(bRes);
}
//---------------------------------------------------------------------------
void __fastcall TDLGProjectOptions::Button4Click(TObject *Sender)
{
	AnsiString asRootDir = ed_EntriesDir->Text;

	if (dlg_bSelectDirectory("Select the root directory for the entries",asRootDir))
        ed_EntriesDir->Text = asRootDir;
}
//---------------------------------------------------------------------------
void __fastcall TDLGProjectOptions::Button1Click(TObject *Sender)
{
	AnsiString asRootDir = ed_SiteDir->Text;

	if (dlg_bSelectDirectory("Select the root directory of the site",asRootDir))
        ed_SiteDir->Text = asRootDir;
}
//---------------------------------------------------------------------------
void __fastcall TDLGProjectOptions::Button5Click(TObject *Sender)
{
    dlg_SelectShowImageScript->FileName = ed_ShowImageScript->Text;

    if (dlg_SelectShowImageScript->Execute())
    	ed_ShowImageScript->Text = dlg_SelectShowImageScript->FileName;
}
//---------------------------------------------------------------------------
void __fastcall TDLGProjectOptions::FormKeyDown(TObject *Sender, WORD &Key,      TShiftState Shift)
{
	if (Key == VK_ESCAPE) ModalResult = mrCancel;
}
//---------------------------------------------------------------------------

