'===========================================================================
' Subject: DAVE'S EDITOR V1.2                 Date: 10-16-99 (19:56)       
'  Author: David P. Mosley                    Code: LB                     
'  Origin: pmosley@infoway.lib.nm.us        Packet: LIBERTY.ABC
'===========================================================================
'Dave's Editor  V1.2
'David P.Mosley
'E-Mail  pmosley@infoway.lib.nm.us


[main.BeforeLoad]
NOMAINWIN 'Turn off main window
'*********** Load Arrarys ************
Dim x(6000)
Dim q(6000)
    Dim branch$(6000)

    Dim line1$(6000)

    Dim line3$(6000)
' *************************************



    '** Set Window Attributes
    UpperLeftX = int((DisplayWidth- 562)/2) 'Center window horizontally on screen
    UpperLeftY = int((DisplayHeight- 432)/2) 'Center window vertically on screen
    WindowWidth = 562
    WindowHeight = 432

    '** Add Window Controls
    texteditor #main.te1,  7,  35,  546,  350
    combobox #main.branch , branch$(, [main.Combobox2Click] ,  112,  7,  308,  308


    Menu #main, "&File", "&New", [main.newfile], "&Load", [main.loadfile], "&Save", [main.savefile], "&Print", [main.printfile], "&Exit", [main.exit]
    Menu #main, "&Edit"
    Menu #main, "&Run", "&Run Program", [main.run.test]
    Menu #main, "&Ext Programs", "&Explorer", [main.run.explorer], "&Enhancer Pro", [main.run.enh], "&Paint", [main.run.paint], "&Liberty Basic", [main.run.lb]
    Menu #main, "&Help", "&LB Help", [main.help.lb], "&About", [main.about]    '** Display window
    OPEN "Dave's Notepad" For graphics_nsb AS #main
    Print #main, "TRAPCLOSE [main.CloseWindow]"

    Print #main.te1, "!font Arial 0 14"; '** Set the font
    Print #main, "fill cyan";

[main.Graphic3DSetup] 'Draw 3D controls
    print #main, "down";
    Print #main, "color darkgray ; line  5  33  553  33 ; line  5  33  5  385"; 'Render #main.te1 3D.
    Print #main, "color white ; line  5  384  553  384 ; line  552  384  552  33"; 'Render #main.te1 3D.
    Print #main, "color darkgray ; line  110  5  420  5 ; line  110  5  110  30"; 'Render #main.branch  3D.
    Print #main, "color white ; line  110  29  420  29 ; line  419  29  419  5"; 'Render #main.branch  3D.

[main.SpecialGraphicWindow] 'Ensure that the graphics window attributes stick
    Print #main, "flush";

[main.AUTORESIZESetup] 'Enable Graphic Boxes and Text Editors can automatically resize
    Print #main.te1, "!AUTORESIZE";

[main.InputLoop]
Input eventCheck$ 'Check for events


[main.CloseWindow]
'** CONFIRM on exit routine
    CONFIRM " Do you want to exit? "; ANSWER$
    If ANSWER$="no" Then GoTo [main.InputLoop] 'Modify branch label
    CLOSE #main 'change window handle TO the current window(s)
    'CLOSE #user
    'KILL "temp.bas" 'this TO delete the temp file no longer needed.
    'KILL "temp.bak" 'same here.

    END

CLOSE #main
END

[main.Combobox2Click]  'Insert code for the Combo Box called branch
'************* Get useer Input **********
Print #main.branch,"selection?"
Input #main.branch,sel$ 

branchLength=len(sel$)

Print #main.te1,"!lines";
     Input #main.te1,count
For t = 1 TO count
  Print #main.te1,"!line ";t;
   Input #main.te1,fline$
    line3$(t)=fline$
  If left$(fline$, branchLength)= sel$ Then
    Print #main.te1, "!origin ";t;" ,0";
    t=count
  END If
Next t

Goto [main.InputLoop]


[main.newfile]  'Insert code for the menu item "&New"
Print #main.te1,"!cls"
Print #main.te1, "!origin 1 1";

Goto [main.InputLoop] 'Check for more user events

[main.loadfile]  'Insert code for the menu item "&Load"
Print #main.te1,"!cls"
for t = 1 to x
  branch$(t)=""
next t
FileDialog "Open text file", "*.bas", fileName$
If fileName$= "" Then [main.InputLoop]
'********* Title Bar ****************
ht=hwnd(#main)
OPEN "USER" For dll AS #user
CallDLL #user, "GetParent", _
ht AS word, _
hParent AS word

title$="Dave's Editor - "+fileName$
CallDLL #user, "SetWindowText", _
hParent AS word, _
title$ AS ptr, _
result AS void
CLOSE #user
'**************************************


Print #main.te1,"!cls"

OPEN fileName$ For Input AS #1
     Print #main.te1, "!Contents #1";
      Print #main.te1, "!origin 1 1";

CLOSE #1
' ************* Load file into memory *****
OPEN fileName$ For Input AS #1

[loop]
TRACE 2
  If eof(#1) <> 0 Then [quit]
  x=x+1
  Input #1, fake$
    line1$(x)=fake$          ' Read File into the array For latter use
    line1$(x)=trim$(line1$(x))
    If left$(line1$(x),1)="[" Then branch$(x) = left$(line1$(x), instr(line1$(x),"]",1))

  GoTo [loop]
[quit]
  Print #main.branch,"reload"        ' Load the combox
  CLOSE #1
'**********************************************************************
'************ Cleanup Array ***************
For q = 1 TO x
   line1$(q)=""

Next q

Goto [main.InputLoop] 'Check for more user events

[main.savefile]  'Insert code for the menu item "&Save"
FileDialog "Save file", "*.bas", fileName$
If fileName$= "" Then [main.InputLoop]
OPEN fileName$ For Output AS #1

   Print #main.te1, "!Contents? #1";
   Input #main.te1,text$
   Print #1,text$
   Print #main.te1, "!origin 1 1";
MESSAGE$="Your File has been saved."

'OPEN "user" For dll AS #user
h=hwnd(#main)
wtype =  _MB_ICONINFORMATION OR _MB_OK OR _MB_DEFBUTTON1
CallDLL #user, "Messagebox", _
    h AS word, _
    MESSAGE$ AS ptr, _
    "File Saved" AS ptr, _
    wtype AS word, _
    result AS short
CLOSE #user

'** User responses are stored in the variable "result"
'Possible responses are:

'    result = 1 ('OK' Button pushed)

CLOSE #1


Goto [main.InputLoop] 'Check for more user events

[main.printfile]  'Insert code for the menu item "&Print"

Goto [main.InputLoop] 'Check for more user events

[main.exit]  'Insert code for the menu item "&Exit"
'** CONFIRM on exit routine
    CONFIRM " Do you want to exit? "; ANSWER$
    If ANSWER$="no" Then GoTo [main.InputLoop] 'Modify branch label
    CLOSE #main 'change window handle TO the current window(s)
    'CLOSE #user
    'KILL "temp.bas" 'this TO delete the temp file no longer needed.
    'KILL "temp.bak" 'same here.

    END


Goto [main.InputLoop] 'Check for more user events

[main.run.test]  'Insert code for the menu item "&Run Program"
Print #main.te1, "!contents?";
    Input #main.te1, entry$
    OPEN "temp.bas" For output AS #sf
    Print #sf, entry$
    CLOSE #sf
    RUN  "liberty -r -m -a "+"temp.bas"

Goto [main.InputLoop] 'Check for more user events

[main.run.explorer]  'Insert code for the menu item "&Explorer"
run "Explorer.exe"
Goto [main.InputLoop] 'Check for more user events

[main.run.enh]  'Insert code for the menu item "&Enhancer Pro"
run "c:\enhancer\enh.exe"
Goto [main.InputLoop] 'Check for more user events

[main.run.paint]  'Insert code for the menu item "&Paint"
run "C:\windows\pbrush.exe"
Goto [main.InputLoop] 'Check for more user events

[main.run.lb]  'Insert code for the menu item "&Liberty Basic"
RUN "c:\Liberty142\liberty.exe"
Goto [main.InputLoop] 'Check for more user events

[main.help.lb]  'Insert code for the menu item "&LB Help"
'Another alternative (Rather than an API) is:
DefaultDir$="C:\Liberty142"
RUN "WINHELP.EXE " + DefaultDir$+"\Liberty.hlp"

Goto [main.InputLoop] 'Check for more user events

[main.about]  'Insert code for the menu item "&About"
MESSAGE$="David P.Mosley" + CHR$(13) + _
    "E-Mail pmosley@infoway.lib.nm.us" + CHR$(13) + _
    "Version # 1.2" + CHR$(13) + _
    "" + CHR$(13) + _
    "This program was made with the " + CHR$(13) + _
    "help of Enhancer Pro."

Open "user" for dll as #user
h=hwnd(#main)
wtype =  _MB_ICONINFORMATION or _MB_OK or _MB_DEFBUTTON1
calldll #user, "Messagebox", _
    h as word, _
    MESSAGE$ as ptr, _
    "About" as ptr, _
    wtype as word, _
    result as short
Close #user

'** User responses are stored in the variable "result"
'Possible responses are:

'    result = 1 ('OK' Button pushed)


Goto [main.InputLoop] 'Check for more user events
