NB. built from project: ~Source\packages\wizard\wizard

script_z_ '~system\main\compare.ijs'
script_z_ '~system\main\convert.ijs'
script_z_ '~system\main\dir.ijs'
script_z_ '~system\main\files.ijs'
script_z_ '~system\main\strings.ijs'

coclass 'jwizard'


coclass 'jwizard'

runcount=: 0 

wizseq=: 'start';'prefix';'suffix';'filename';'form';'template'

message=: 3 : 0
wd'mb "Class Wizard" *',y.
)

START=: 0 : 0
pc start;pn "New Class Wizard";
xywh 272 8 38 12;cc next button;cn "&Next";
xywh 272 23 38 12;cc back button;cn "&Back";
xywh 272 40 38 12;cc cancel button;cn "Cancel";
xywh 8 5 245 85;cc static static;cn "";
xywh 311 184 1 1;cc sizer static;cn "";
pas 6 6;pcenter;
rem form end;
)

PREFIX=: 0 : 0
pc prefix;pn "Set Class Name Prefix";
xywh 8 5 245 85;cc static static;cn "";
xywh 8 96 26 11;cc label static;cn "Prefix:";
xywh 38 95 52 11;cc prefix edit ws_border es_autohscroll;
xywh 272 8 38 12;cc next button;cn "&Next";
xywh 272 23 38 12;cc back button;cn "&Back";
xywh 272 40 38 12;cc cancel button;cn "Cancel";
xywh 311 184 1 1;cc sizer static;cn "";
pas 6 6;pcenter;
rem form end;
)

SUFFIX=: 0 : 0
pc suffix;pn "Set Class Name Suffix";
xywh 8 7 245 12;cc static static;cn "";
xywh 10 26 26 11;cc label static;cn "Suffix:";
xywh 39 25 52 11;cc suffix edit ws_border es_autohscroll;
xywh 272 8 38 12;cc next button;cn "&Next";
xywh 272 24 38 12;cc back button;cn "&Back";
xywh 272 40 38 12;cc cancel button;cn "Cancel";
xywh 311 184 1 1;cc sizer static;cn "";
pas 6 6;pcenter;
rem form end;
)

FORM=: 0 : 0
pc form;pn "Set Class";
xywh 8 5 245 39;cc static static;cn "";
xywh 8 50 173 11;cc formclass checkbox;cn "Form Class";
xywh 272 8 38 12;cc next button;cn "&Next";
xywh 272 23 38 12;cc back button;cn "&Back";
xywh 272 40 38 12;cc cancel button;cn "Cancel";
xywh 311 184 1 1;cc sizer static;cn "";
pas 6 6;pcenter;
rem form end;
)

FILENAME=: 0 : 0
pc filename;pn "Class Filename";
xywh 5 7 253 88;cc filenametext static;cn "";
xywh 5 97 39 11;cc static static;cn "Class name:";
xywh 47 97 67 11;cc classname static;cn "";
xywh 5 109 39 11;cc ccstatic static;cn "Filename:";
xywh 5 120 261 12;cc filename edit ws_border es_autohscroll;
xywh 272 8 38 12;cc next button;cn "&Next";
xywh 272 24 38 12;cc back button;cn "&Back";
xywh 272 40 38 12;cc cancel button;cn "Cancel";
xywh 272 61 38 12;cc browse button;cn "Browse...";
xywh 311 184 1 1;cc sizer static;cn "";
pas 6 6;pcenter;
rem form end;
)

TEMPLATE=: 0 : 0
pc template;pn "Form Class Template";
xywh 6 8 208 68;cc templatetext static;cn "static";
xywh 219 6 50 50;cc templates listbox;
xywh 272 9 38 12;cc next button;cn "&Next";
xywh 272 25 38 12;cc back button;cn "&Back";
xywh 272 40 38 12;cc cancel button;cn "Cancel";
xywh 12 83 50 11;cc static static;cn "Template file name:";
xywh 64 83 211 11;cc templatefilename static;cn "";
xywh 6 96 305 84;cc editm editm ws_border ws_hscroll ws_vscroll es_readonly rightmove bottommove;
xywh 311 184 1 1;cc sizer static;cn "";
pas 6 6;pcenter;
rem form end;
)
prefix_run=: 3 : 0
wd PREFIX
wizindex=: wizseq i. <'prefix'
wd'set prefix *',newprefix
wd'setselect prefix ',": 0,(<:#newprefix),0
wd 'setfocus prefix'
wd'set static *',prefixtext
wd'setenable next ',":wizindex<<:#wizseq
wd'setenable back ',":0<wizindex
wd'setfocus prefix'
wd 'pshow;'
)

prefixtext=: 0 : 0
A class name starts with a prefix.

p indicates a personal class that will not be distributed.

j indicates the class is part of the distributed J system.

Other prefixes (perhaps your initials, or company acronym) are for classes that you will distribute to others.
)

exit=: 3 : 0
wd'pclose'
runcount=: 0
)

close=: 3 :0
wd 'pclose;'
runcount=: 0
)

prefix_cancel_button=: prefix_cancel=: prefix_close=: exit

prefix_next_button=: 3 : 0
newprefix=: prefix
close''
wizindex=: >:wizindex
".(>wizindex{wizseq),'_run 0'
)

prefix_back_button=: 3 : 0
close''
wizindex=: <:wizindex
".(>wizindex{wizseq),'_run 0'
)

prefix_prefix_button=: prefix_next_button
suffix_run=: 3 : 0
wd SUFFIX
wizindex=: wizseq i. <'suffix'
wd'set suffix *',newsuffix
wd'set static *',suffixtext
wd'setenable next ',":wizindex<<:#wizseq
wd'setenable back ',":0<wizindex
wd'setfocus suffix'
wd 'pshow;'
)

suffixtext=: 0 : 0
Set the suffix you want to use in the class name.
)

suffix_cancel_button=: suffix_cancel=: suffix_close=: exit

suffix_next_button=: 3 : 0
if. 0=#suffix-.' ' do.
  wd'mb "Class Wizard" "Must not be blank."'
  wd'setfocus suffix'
  return. end.
newsuffix=: suffix
close''
wizindex=: >:wizindex
".(>wizindex{wizseq),'_run 0'
)

suffix_back_button=: 3 : 0
close''
wizindex=: <:wizindex
".(>wizindex{wizseq),'_run 0'
)
filenametext=: 0 : 0
Class definitions are stored in a class file.

Usually the file name is the same as the classname.

By default class files are stored in directory user\classes.

Browse to change the directory.
)

filename_run=: 3 : 0
wd FILENAME
wizindex=: wizseq i. <'filename'
wd'set filenametext *',filenametext
wd'set classname *',newprefix,newsuffix
wd'set filename *',jpath '~user\classes\',newprefix,newsuffix,'.ijs'
wd'setenable next ',":wizindex<<:#wizseq
wd'setenable back ',":0<wizindex
wd 'pshow;'
)

filename_browse_button=: 3 : 0
name=. newprefix,newsuffix,'.ijs'
fn=. wd'mbopen "Path for new class Definition File" "user\classes" "',name,'" "Script(*.ijs)|*.ijs"'
if. #fn do.
  wd'set filename *',fn end.
)

filename_next_button=: 3 : 0
newfilename=: filename
if. fexist newfilename do.
  if. 'OK'-:wd'mb "Class Wizard" "File already exists. Do you want to replace it?" mb_okcancel mb_defbutton2' do.

    ferase newfilename
    if. #id=. name2id_jijs_ newfilename do.
      smsel_jijs_ id
      smclose_jijs_ id
    end.
    coerase <prefix,suffix
  else.
    return.
  end.
end.
close''
wizindex=: >:wizindex
".(>wizindex{wizseq),'_run 0'
)

filename_cancel_button=: filename_cancel=: filename_close=: exit

templatetext=: 0 : 0
Select a template from the list of files at the right.

Chose the template that is closest to the type of new class you are building.

The box below has a complete listing of the template file.
)
template_run=: 3 : 0
wd TEMPLATE
wizindex=: wizseq i. <'filename'
wd'set templatetext *',templatetext
p=. jpath '~system\classes\template\'
f=. 1 dir p
b=. '.ijs'&-: @ (_4&{.) &> f
files=: b#f
t=. }. ; LF&, each (#p)&}. each files
wd'set templates ',,t
wd'setselect templates 0'
wd'setfocus templates'
templates_select=: '0'
template_templates_select''
wd'setenable next ',":wizindex<<:#wizseq
wd'setenable back ',":0<wizindex
wd 'pshow;'
)

template_templates_select=: 3 : 0
wd'set templatefilename *',>(".templates_select){files
wd'set editm *',fread (".templates_select){files
)

jxprompt=: 0 : 0
   object =: '' conew 'CLASS'
)

jxclassprompt=: 0 : 0
   object =: '' conew 'CLASS'
   test__object 23
)

finished=: 3 : 0
wd'mb "Finished" "The new class file has been created and will be opened for editing."'
)

template_next_button=: 3 : 0
class=. newprefix,newsuffix
templatefile=. >(".templates_select){files
d=. fread templatefile
d=. d rplc 'myclass';class
d=. d rplc 'MYCLASS';toupper class
d fwrite newfilename
finished''
close''
load newfilename
open newfilename
txt=. (jxprompt rplc 'CLASS';class) rplc 'NEWFILENAME';newfilename
smselout_jijs_''
smappend_jijs_ txt
)

template_cancel_button=: template_cancel=: template_close=: exit
template_templates_button=: template_next_button

filename_back_button=: 3 : 0
close''
suffix_run''
)

template_back_button=: 3 : 0
close''
form_run''
)

classwizard=: 3 : 0
newprefix=: 'p'
newsuffix=: ''
start_run''
)

suffix_suffix_button=: suffix_next_button

start_text=: 0 : 0
This wizard helps you create a new class script.

A class script is a script file that defines a class.

When you finish, the new class script will be open and ready for editing.
)

start_run=: 3 : 0
wd START
wizindex=: wizseq i. <'start'
wd'set static *',start_text
wd'setenable next ',":wizindex<<:#wizseq
wd'setenable back ',":0<wizindex
wd 'pshow;'
if. runcount do.
  message '"Class Wizard is already running."'
  close''
  empty''
  return.
end.
runcount=: 1
empty''
)

start_next_button=: 3 : 0
close''
wizindex=: >:wizindex
".(>wizindex{wizseq),'_run 0'
)

start_back_button=: 3 : 0
close''
wizindex=: <:wizindex
".(>wizindex{wizseq),'_run 0'
)

start_cancel_button=: start_cancel=: start_close=: exit

form_text=: 0 : 0
A class that is associated with a GUI form is a form class.

Click the checkbox if you want this class to be a form class.
)

form_run=: 3 : 0
wd FORM
wizindex=: wizseq i. <'form'
wd'set static *',form_text
wd'setenable next ',":wizindex<<:#wizseq
wd'setenable back ',":0<wizindex
wd 'pshow;'
)

form_next_button=: 3 : 0

if. ".formclass do.
  close''
  wizindex=: >:wizindex
  ".(>wizindex{wizseq),'_run 0'
else.
  form_finish''
end.
)

form_finish=: 3 : 0
class=. newprefix,newsuffix
d=. fread jpath '~system\classes\template\class.ijs'
d=. d rplc 'myclass';class
d fwrite newfilename
finished''
exit''
load newfilename
open newfilename
txt=. (jxclassprompt rplc 'CLASS';class) rplc 'NEWFILENAME';newfilename
smselout_jijs_''
smappend_jijs_ txt
)

form_back_button=: 3 : 0
close''
wizindex=: <:wizindex
".(>wizindex{wizseq),'_run 0'
)

form_cancel_button=: form_cancel=: form_close=: exit
