
! script name: misc.d/addbutton
! topic: add button to utility kit

!A
!A NAME:
!A
!A 	Add Button
!A
!A DESCRIPTION:
!A
!A 	Create new buttons to add to Utility Kit.
!A
!B INSTRUCTIONS:
!B
!B 	BUTTON LABEL: Label of button in the menu.
!B
!B	SELECT EXISTING SCRIPT NAME: Select the
!B 		script to be called by the button.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: addbutton ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Sname$[256]
DIM Lname$[256]
DIM Bname$[256]
DIM Output$[256]

DIM Dir$[256]
DIM D_label$[256]
DIM Sub_label$[256]
DIM F_label$[256]
DIM Choice$[256]
DIM Mask$[32]
DIM Header$[4096]
DIM Tmp$[256]
DIM Jobname$[256]
DIM Jobs$(20,2)[256]
DIM Startup$[256]
DIM Setconstants$[256]

Start:!

Stat=SetInputFormat("a99","")
Stat=GetValue("BUTTON LABEL",Answer$)
IF (ExitScript(Destination$)) OR (LEN(Answer$)<1) THEN Leave
Lname$=Answer$

Bname$=Lname$
RemoveSpaces: p=pos(Bname$," ")
if(p) then
Bname$[p]=Bname$[p+1]
goto RemoveSpaces
end if

FOR i=1 to len(Bname$)
	t$=Bname$[i;1]
	replace=1
	if pos("ABCDEFGHIJKLMNOPQRSTUVWXYZ",t$) then replace=0
	if pos("abcdefghijklmnopqrstuvwxyz",t$) then replace=0
	if pos("01234567890",t$) then replace=0
	if replace=1 then t$="_"
	Bname$[i;1]=t$
next i

Dir$="/usr/weber/ascrpt/"
D_label$="DIRECTORY"
Sub_label$="SUB DIRS."
F_label$="SCRIPTS"
Choice$="SCRIPT NAME"
Mask$="[A-Za-z0-9]*"

Stat=UserFileBox(Dir$,Mask$,D_label$,Sub_label$,F_label$,Choice$)
Stat=SetInputFormat("a99","")
Stat=GetValue("SELECT EXISTING SCRIPT NAME",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$= "CANCEL" THEN Leave
LowerFileBox

Sname$=Answer$
! Add line for NT to remove C: from getcwd()
if len(Sname$)>2 and Sname$[2,2]=":" then Sname$=Sname$[3]
if len(Sname$)>0 and Sname$[1,1]<>"\" then Sname$="\E"&Sname$

Stat=MapWidget("AddWidgetShell")

stat=ChangeLabelStr("ButtonLabelInput",Lname$)
stat=ChangeLabelStr("ButtonNameInput","UK0"&Bname$)
stat=ChangeLabelStr("ScriptNameInput",Sname$)

Leave:!
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
