
! script name: edit.d/edittoolent
! topic: edit tool entity

!A
!A NAME:
!A
!A 	Edit Tool Entity
!A
!A DESCRIPTION:
!A
!A	This script allows the user to edit the contents of a tool entity's
!A	user data string.
!A
!# see also - htdocs/help.d/vdminfo.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: edit tool entity")

DIM Destination$[256],Answer$[256]
DIM Data$[32000],Name$[256]
DIM Descr$[512],File$[512]
DIM Editor$[256]

File$= "tempdata"
Stat= NamedVarStr("file editor",WsSystemVars,"notepad.exe",Editor$)
Flip_file= NamedVarVal("flip crlf",WsSystemVars,0)

ActivateUndo
Start:!
No_tools=ToolSelectBox("TOOLS","selected tool")
IF No_tools THEN Leave

Stat=SetInputFormat("a99","")
Stat=GetValue("TOOL TO BE EDITED",Name$)
IF ExitScript(Destination$) OR Name$="CANCEL" THEN Leave
Tool=FindUserData(Name$,WsToolData)

Stat= UserDataString(Tool,Data$)

Stat= OutputString(File$,Data$,WsNewFile)
Stat=EditFile(Editor$,File$,Flip_file)

LowerSelectBox
Stat=SetInputFormat("a1",",R,C,")
Stat=GetValue("TOOL DATA: Replace, Cancel",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$= "R" THEN
	ActivateUndo
	Stat= AdvanceUndoNumber("edit tool data")
	Stat= AddItemToUndo(WsUBModifyMode,Tool)

	New_tool= ReadUserData(WsToolData,Name$,File$)
	Stat= UserDataString(New_tool,Data$)
        Stat= ReplaceUserData(Tool,Data$)
	Stat= DeleteEntity(New_tool)
END IF
GOTO Start

Leave:!
LowerSelectBox
Stat=SetInputFormat("n4","")
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
