#include <origin.h>
#include <GetNBox.h>
#include <xfutils.h>
//put additional include files here
//----- Modification log ----------
//CPY 5/28/09 ADD_OUTPUT_RESULT_PATH
//CPY 8/16/08 ALLOW_ALREADY_EXISTED rewrite code so chk will mean to use existing if not set to 1
//put your own support static functions here



void pe_mkdir(const string& folder, const int& chk, const int& cd, string& path)
{
	if(folder.IsEmpty())
	{
		///Cheney 2007-7-2 UPDATE_XF_ERR_THROW
		//printf("Error!!! Can't Create new subfolder without name!\n");
		//return;
		XF_THROW(XFERR_PE_MKDIR_CAN_NOT_CREATE_NEW_SUBFOLDER_NO_NAME);
		///end UPDATE_XF_ERR_THROW
	}
		
	Folder fld = Project.ActiveFolder();
	string strsub = fld.GetPath() + folder;
	//Folder subfld = fld.GetFolder(strsub);
	Folder subfld(strsub);
	//----- CPY 8/16/08 ALLOW_ALREADY_EXISTED
	/*
	/// EJP 2006-06-19 v8.0431 QA70-8766 NEW_PROJECT_FOLDER_BUTTON
	///if(subfld)
	if( subfld && chk )
	/// end NEW_PROJECT_FOLDER_BUTTON
	{
		///Cheney 2007-7-2 UPDATE_XF_ERR_THROW
		//printf("A sub folder %s already exist!\n", folder);
		warning_msg_box(XFERR_PE_MKDIR_SUBFOLDER_EXIST, folder, false, 'E');
		///end UPDATE_XF_ERR_THROW
		return;
	}
	subfld = fld.AddSubfolder(folder);
	*/
	if(!subfld || chk == 0)
		subfld = fld.AddSubfolder(folder);
	//----- end ALLOW_ALREADY_EXISTED
	
	if( !subfld.IsValid() )
	{
		///-----Kit 10/22/2010 CLEANUP_XFS_ERROR_CODE
		/////Cheney 2007-7-2 UPDATE_XF_ERR_THROW
		////printf("Error!!! Can't Create new subfolder %s !\n", folder);
		//warning_msg_box(XFERR_PE_MKDIR_CAN_NOT_CREATE_NEW_SUBFOLDER, folder, false, 'E');
		/////end UPDATE_XF_ERR_THROW
		XF_THROW_EX(XFERR_PE_MKDIR_CAN_NOT_CREATE_NEW_SUBFOLDER, folder);
		///-----End CLEANUP_XFS_ERROR_CODE
	}
	/// EJP 2006-06-19 v8.0431 QA70-8766 NEW_PROJECT_FOLDER_BUTTON
	else if( cd )
		subfld.Activate();
	/// end NEW_PROJECT_FOLDER_BUTTON
	//----- CPY 5/28/09 ADD_OUTPUT_RESULT_PATH
	if(path != NULL)
	{
		if(subfld.IsValid())
			path = subfld.GetPath();
		else
			path.Empty();
	}
	//-----
	
}

//nEventID < 0 on event, like GETNE_ON_INIT, GETNE_ON_OK etc, >0 on change from control
//return 0 to do nothing, return PEVENT_GETN_RET_TO_CLOSE to close dialog
//dwEnables = bOKEnable, bBTN1Enable, bBTN2Enable, bBTN3Enable, , can set to false to disable OK/Apply buttons
//lpcszNodeName = the trGetN TreeNode tag name that generates the event, or is  if GETNE_ON_OK etc
//strAux = optional string for XF Wizard Bar, like DLG_NEED_CHANGE_GRID etc, it will be invalid if from internal node value change event
//strErrMsg = allowing messages to be shown
int pe_mkdir_event1(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	if( xf_is_extended_event(nEventID) )
		return pe_mkdir_event1_ex(trGetN, nRow, nEventID, dwEnables, lpcszNodeName, DynaCntrlContainer, strAux, strErrMsg);
	DECLARE_BUTTON_ENABLES
	return false;

}

int pe_mkdir_make_tree(TreeNode& tr, LPCSTR lpcszVarName)
{
	return false;
}
//nGetNDialog = 0,1,2, corresponding to the XF GetN dropdown, 0 = dialog is not used
//you can change nRet to be one of XFEVT_PROCEED (defualt), XFEVT_ABORT, XFEVT_PROCEED_NO_DLG or XFEVT_PROCEED_WITH_DLG(when nGetNDialog = 0)
//nGetNDialog = -1 when Ok on GetN dialog to allow handler to preocess <auto> etc variables
//dwCntrl is combination of bits
//LTXF_FROM_GUI_MENU, LTXF_FROM_GUI_PROMPT, LTXF_FROM_AUTO_UPDATE, LTXF_FROM_FUNCTION, LTXF_THEME_USED, LTXF_CHANGE_PARAM
void pe_mkdir_before_execute(TreeNode& trGetN, int nGetNDialog, int& nRet, int dwCntrl)
{

}
//nEventID < 0 on event, like GETNE_ON_INIT, GETNE_ON_OK etc, >0 on change from control
//return 0 to do nothing, return PEVENT_GETN_RET_TO_CLOSE to close dialog
//dwEnables = bOKEnable, bBTN1Enable, bBTN2Enable, bBTN3Enable, , can set to false to disable OK/Apply buttons
//lpcszNodeName = the trGetN TreeNode tag name that generates the event, or is  if GETNE_ON_OK etc
//strAux = optional string for XF Wizard Bar, like DLG_NEED_CHANGE_GRID etc, it will be invalid if from internal node value change event
//strErrMsg = allowing messages to be shown
int pe_mkdir_event1_ex(TreeNode& trGetN, int nRow, int nEventID, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& DynaCntrlContainer, string& strAux, string& strErrMsg)
{
	return false;
}
