/* CMD: ½ConfigPlugIns                                                  */
/* By Brett Evan Hester      13032 Copenhill Rd. Dallas, Tx. 75240-5302 */
	MacrosName = "ConfigPlugIns"
/* Macro Type:                                                          */
/* SPECIAL     * REMEMBERS                                              */
/* Description:                                                         */

Info1A = "!Config Plug Ins ©             Information 1 of 2"
Info1B = ""
Info1C = "@This macro changes general settings across all  "
Info1D = '@of the "Plug-Ins and Go!" macros.               '
Info1E = ""
Info1F = "þ The DEFAULT FILE PATH is for when a macro has "
Info1G = "  a file requester of it's own.                 "
Info1H = "þ SAVE SETTINGS is a directory for recording and"
Info1I = "  recalling each and every macro setting.       "
Info1J = "þ SPEECH AND/OR AUDIO is for the possiblity if a"
Info1K = "  macro does have audio; the question is does   "
Info1L = "  the user wants it or not.                     "
Info1M = ""
Info1N = '@þ The "ConfigVT3D" macro may also be of intrest.'

Info2A = "!Config Plug Ins ©             Information 2 of 2"
Info2B = "@               Plug-Ins and Go! ©               "
Info2C = "                           Hester and associates"
Info2D = "                           13032 Copenhill Road "
Info2E = "                           Dallas, Texas 75240  "
Info2F = "@Special Thanks to:                              "
Info2G = "Arnie Cachelin  Henry Ribron    Mark J. Holland "
Info2H = "J. Phil Kelso   Terry Wester    Steven K. Simms "
Info2I = "Kevin DeRita    Greg Glaser     William S. Hawes"
Info2J = "NewTek ©        Commodore ©     INOVAtronics ©  "
Info2K = ""
Info2L = "@This macro represents a lot of time & hard work."
Info2M = "@Encourage people to create new ones and not kill"
Info2N = "@that possibility by stealing those that are out."

/* -------------------------------------------------------------------- */
                                     /* Start Error Detection (See End) */
SIGNAL ON ERROR
SIGNAL ON SYNTAX
                                                   /* Address LightWave */
VT3DLib = ADDLIB("LWModelerARexx.port",0)
ADDRESS "LWModelerARexx.port"
                                               /* Add Support Functions */
SupportLib = "rexxsupport.library"
IF POS(SupportLib , SHOW('L')) = 0 THEN
	IF ~ADDLIB(SupportLib , 0 , -30 , 0) THEN DO
		CALL Notify(1,"!Can't find "SupportLib)
		IF (VT3DLib) THEN CALL REMLIB("LWModelerARexx.port")
		EXIT
	END

/* -------------------------------------------------------------------- */
                                    /* Reading Global Macro Preferences */
BEHDefaultFilePath = "Sys:"
BEHSettingsSavedTo = "T:"
BEHSpeechAndSound = "1"

IF (EXISTS("S:PlugInPrefs")) THEN DO
	IF (~OPEN(PlugInPrefs, "S:PlugInPrefs", 'R')) THEN BREAK
	IF (READLN(PlugInPrefs) ~= "PlugInPrefs") THEN BREAK
	BEHDefaultFilePath = READLN(PlugInPrefs)
	BEHSettingsSavedTo = READLN(PlugInPrefs)
	BEHSpeechAndSound = READLN(PlugInPrefs)
	CALL CLOSE PlugInPrefs
END

/* ******************************************************************** */
                                                   /* Main Body Of Code */
CALL StartupWindow

CALL DefaultArea  ; BEHDefaultFilePath = FilePathPlus
CALL SettingsArea ; BEHSettingsSavedTo = FilePathPlus

CALL MenuRequester

FileReq = BEHDefaultFilePath
CALL ExtractName
CALL VerifyInput
IF OKorCancel = 0 THEN DO
	DO UNTIL OKorCancel = 1
		CALL DefaultArea
		CALL VerifyInput
	END
END
BEHDefaultFilePath = FilePathPlus

FileReq = BEHSettingsSavedTo
CALL ExtractName
CALL VerifyInput
IF OKorCancel = 0 THEN DO
	DO UNTIL OKorCancel = 1
		CALL SettingsArea
		CALL VerifyInput
	END
END
BEHSettingsSavedTo = FilePathPlus

CALL SaveSettings
CALL Exiting

/* ******************************************************************** */

StartupWindow:

	CALL Req_Begin("Config Plug-Ins ©           by Brett Hester")

	CALL Req_AddControl("","T"," Two file requesters will appear, asking for: ")
	CALL Req_AddControl("","T","")
	CALL Req_AddControl("","T","þ The default file path for when a macro has  ")
	CALL Req_AddControl("","T","  a file requester of it's own.               ")
	CALL Req_AddControl("","T","")
	CALL Req_AddControl("","T","þ The file path for recording and recalling   ")
	CALL Req_AddControl("","T",'  any "Plug-Ins and Go!" macro setting.       ')
	CALL Req_AddControl("","T","")

	OKorCancel = Req_Post() ; IF OKorCancel = 0 THEN CALL Exiting

	CALL Req_End()

RETURN

/* -------------------------------------------------------------------- */
                                                   /* Default File Path */
DefaultArea:

	FileReq = GetFileName("-- Default File Path --", BEHDefaultFilePath)
	IF FileReq = "(none)" THEN CALL Exiting
	CALL ExtractName

RETURN

/* -------------------------------------------------------------------- */
                                                /* Settings Saved To... */
SettingsArea:

	FileReq = GetFileName("-- Settings Saved To --", BEHSettingsSavedTo)
	IF FileReq = "(none)" THEN CALL Exiting
	CALL ExtractName

RETURN

/* -------------------------------------------------------------------- */
                                                      /* User Interface */
MenuRequester:

	CALL Req_Begin("Config Plug Ins ©                  by Brett Hester")

	CALL Req_AddControl("These settings will","T",'be saved as "S:PlugInPrefs"')
	ReqA = Req_AddControl("Default File Path",'S',33)
	ReqB = Req_AddControl("Save Settings To",'S',33)
	ReqC = Req_AddControl("Speech and/or Audio",'B')
	BEHInfo = Req_AddControl("",'CH',"Information")

	CALL Req_SetVal(ReqA, BEHDefaultFilePath)
	CALL Req_SetVal(ReqB, BEHSettingsSavedTo)
	CALL Req_SetVal(ReqC, BEHSpeechAndSound)
	CALL Req_SetVal(BEHInfo, 0)

	IF Req_Post() = 0 THEN CALL Exiting

	BEHDefaultFilePath = Req_GetVal(ReqA)
	BEHSettingsSavedTo = Req_GetVal(ReqB)
	BEHSpeechAndSound = Req_GetVal(ReqC)
	BEHInfo = Req_GetVal(BEHInfo)

	CALL Req_End()

	IF BEHInfo = 1 THEN CALL InformationWindows

RETURN

/* -------------------------------------------------------------------- */
                        /* Extracting File Name and Path from Requester */
ExtractName:

	FileReqLength = LENGTH(FileReq)
	FileDivider = LASTPOS("/",FileReq)
	IF FileDivider = 0 THEN FileDivider = LASTPOS(":",FileReq)
	FileNameLength = FileReqLength - FileDivider

	FilePath = STRIP(LEFT(FileReq, FileDivider),"T","/")

	FilePathPlus = FilePath
	IF RIGHT(FilePath,1) ~= ":" THEN FilePathPlus = FilePath||"/"

	FileName = RIGHT(FileReq, FileNameLength)

RETURN

/* -------------------------------------------------------------------- */
                                                        /* Verify Input */
VerifyInput:

	IF EXISTS(FilePath) = 0 THEN DO
		ReqA = "!Sorry!"
		ReqB = ""
		ReqC = '@Path "'||FilePath||'" not found.'
		ReqD = ""
		ReqE = "Select OK to create the new path / directory.   "
		ReqF = "Select CANCEL to display another file requester."
		OKorCancel = Notify(2, ReqA, ReqB, ReqC, ReqD, ReqE, ReqF)
		IF OKorCancel = 1 THEN CALL MAKEDIR(FilePath)
	END

	IF EXISTS(FilePath) = 1 THEN DO
		PARSE VALUE STATEF(FilePath) WITH DirOrFile .
		IF DirOrFile = "DIR" THEN OKorCancel = 1
		IF DirOrFile ~= "DIR" THEN OKorCancel = 0
	END

RETURN

/* -------------------------------------------------------------------- */
                                    /* Writing Global Macro Preferences */
SaveSettings:

	IF (OPEN(PlugInPrefs, "S:PlugInPrefs", 'W')) THEN DO
		CALL WRITELN(PlugInPrefs,"PlugInPrefs")
		CALL WRITELN(PlugInPrefs, BEHDefaultFilePath)
		CALL WRITELN(PlugInPrefs, BEHSettingsSavedTo)
		CALL WRITELN(PlugInPrefs, BEHSpeechAndSound)
		CALL CLOSE PlugInPrefs
	END

RETURN

/* -------------------------------------------------------------------- */
                                                              /* Ending */
Exiting:

	IF (VT3DLib) THEN CALL REMLIB("LWModelerARexx.port")
	EXIT

RETURN

/* -------------------------------------------------------------------- */
                                                 /* Information Windows */
InformationWindows:

	OKorCancel = Notify(2, Info1A, Info1B, Info1C, Info1D, Info1E, Info1F, Info1G, Info1H, Info1I, Info1J, Info1K, Info1L, Info1M, Info1N)
	IF OKorCancel = 1 THEN CALL Notify(1, Info2A, Info2B, Info2C, Info2D, Info2E, Info2F, Info2G, Info2H, Info2I, Info2J, Info2K, Info2L, Info2M, Info2N)
	CALL MenuRequester

RETURN

/* -------------------------------------------------------------------- */
                                                      /* Error Handling */
SYNTAX:
ERROR:

	ErrCode = RC
	ErrLine = SIGL
	ErrInfo = ERRORTEXT(ErrCode)

	Err1 = "!Sorry!"
	Err2 = "An Error has been detected"
	Err3 = "@þ Macro -            "
	Err4 = "@þ Line Number -      "
	Err5 = "@þ Error Code -       "
	Err6 = "@þ Error Description -"
	Err7 = "@¤ Please Inform -    "
	Err8 = '  "Error Notice"     '
	Err9 = "  13032 Copenhill Rd."
	Err10 = "  Dallas, TX. 75240  "

	Call Notify(1,Err1,Err2,Err3,MacrosName,Err4,ErrLine,Err5,ErrCode,Err6,ErrInfo,Err7,Err8,Err9,Err10)

/* -------------------------------------------------------------------- */
                                             /* Advanced Error Handling */
	CALL SETCLIP("ErrorMacro",MacrosName)
	CALL SETCLIP("ErrorLine",ErrLine)
	CALL SETCLIP("ErrorCode",ErrCode)
	CALL SETCLIP("ErrorDesc",ErrInfo)

	PARSE SOURCE TempA TempB ErrFile TempC TempD TempE

	CALL SETCLIP("ErrorFile",ErrFile)

/* -------------------------------------------------------------------- */

	IF (VT3DLib) THEN CALL REMLIB("LWModelerARexx.port")
	EXIT
