

    'This new version of grafdemo.bas takes advantage of the
    'new !contents and !contents? commands, and it also uses
    'an empty edit menu to place the default edit menu after
    'File on the menu bar (a new LB feature).

    nomainwin

    texteditor #main.text, 10, 10, 175, 200
    menu #main, "&File", "&Open File", [load], "&Save File", [save], "&Print Text", [print], |, "E&xit Grafdemo", [quit]
    menu #main, "edit"
    menu #main, "&Action", "&Draw Graphic", [go]
    WindowWidth = 500 : WindowHeight = 265
    open "Graf Demo" for graphics_nsb as #main
    print #main, "when leftButtonDown [getPoint]"
    print #main, "when rightButtonDown [menu]"
    print #main, "trapclose [quit]"

[inputLoop]

    input r$ 
    goto [inputLoop]

[go]

    print #main.text, "!lines" ;
    input #main.text, lines
    print #main, "cls" ;
    for x = 1 to lines
    print #main.text, "!line " ; x ;
    input #main.text, line$ 

    if word$( line$, 1 ) = "times" and x < lines then
        i = val(word$(line$, 2))
        x = x + 1
        print #main.text, "!line "; x ;
        input #main.text, line$
        for x = 1 to i
            print #main, line$
        next x
    else
        print #main, line$ ;
    end if

    next x
    print #main, "flush" ;
    goto [inputLoop]

[getPoint]

    print #main.text, "place " ; MouseX ; " " ; MouseY
    goto [inputLoop]

[load]

    filedialog "Load GrafDemo Text", "*.gdt", fname$
    if fname$ = "" then [inputLoop]
    open fname$ for input as #1
    line$ = input$(#1, lof(#1))
    print #main.text, "!contents line$";
    close #1
    goto [inputLoop]

[save]

    filedialog "Save GrafDemo Text", "*.gdt", fname$ 
    if fname$ = "" then [inputLoop]
    open fname$ for output as #1
        print #main.text, "!contents?";
        input #main.text, line$
        print #1, line$
    close #1
    goto [inputLoop]

[print]

    print #main.text, "!lines";
    input #main.text, lineCount
    for x = 1 to lineCount
        print #main.text, "!line "; x ;
        input #main.text, lineOfText$
        lprint lineOfText$
    next x
    dump

    goto [inputLoop]

[menu]

    popupmenu "&Draw Graphic", [go]
    goto [inputLoop]


[quit]   'exit grafdemo.bas

    close #main
    end
