2018-12-01 21:06:12 +00:00
|
|
|
#lang racket/gui
|
|
|
|
|
2018-12-02 17:05:50 +00:00
|
|
|
(require "interpreter.rkt"
|
|
|
|
framework)
|
2018-12-01 21:06:12 +00:00
|
|
|
|
|
|
|
; The editor width in pixels
|
|
|
|
(define EDITOR-WIDTH 600)
|
|
|
|
(define EDITOR-HEIGHT 600)
|
|
|
|
|
|
|
|
; The frame racket/gui base object for the editor
|
|
|
|
(define f (new frame%
|
|
|
|
[label "DrBrainf*ck"]
|
|
|
|
[width EDITOR-WIDTH]
|
|
|
|
[height EDITOR-HEIGHT]))
|
|
|
|
|
2018-12-02 17:05:50 +00:00
|
|
|
; execute-content: -> ProgState
|
2018-12-01 21:06:12 +00:00
|
|
|
; Returns the last state of execution of the program loaded in the editor
|
|
|
|
(define (execute-content)
|
|
|
|
(execute
|
2018-12-02 17:05:50 +00:00
|
|
|
(program->prog-state
|
2018-12-01 21:06:12 +00:00
|
|
|
(string->program
|
2018-12-02 17:05:50 +00:00
|
|
|
(send editor get-flattened-text)))))
|
2018-12-01 21:06:12 +00:00
|
|
|
|
|
|
|
; The run button
|
2018-12-02 17:05:50 +00:00
|
|
|
(define run-btn (new button% [parent f]
|
|
|
|
[label "Run"]
|
|
|
|
; Callback procedure for a button click:
|
|
|
|
[callback
|
|
|
|
(lambda (button event)
|
|
|
|
; empty output text and set color to running
|
|
|
|
(send run-output set-value "")
|
|
|
|
(send run-output set-field-background run-col)
|
|
|
|
|
|
|
|
; run the program
|
|
|
|
(define out (prog-state-output (execute-content)))
|
|
|
|
|
|
|
|
; set output and change color to ended
|
|
|
|
(send run-output set-value out)
|
|
|
|
(send run-output set-field-background end-col))]))
|
2018-12-01 21:06:12 +00:00
|
|
|
|
|
|
|
(define c (new editor-canvas% [parent f]))
|
|
|
|
|
|
|
|
; The editor text object
|
2018-12-02 17:05:50 +00:00
|
|
|
(define text-ln% (text:line-numbers-mixin
|
|
|
|
(editor:standard-style-list-mixin text%)))
|
|
|
|
(define editor (new text-ln%))
|
|
|
|
|
|
|
|
; Show line numbers in editor
|
|
|
|
(send editor show-line-numbers! #t)
|
|
|
|
|
|
|
|
; Change font to monospace 16
|
|
|
|
(send editor change-style (make-object style-delta% 'change-size 16))
|
|
|
|
(send editor change-style (make-object style-delta% 'change-family 'modern))
|
|
|
|
|
|
|
|
; Running output color
|
|
|
|
(define run-col (make-object color% 250 250 200))
|
|
|
|
|
|
|
|
; Output completed color
|
|
|
|
(define end-col (make-object color% 200 250 200))
|
2018-12-01 21:06:12 +00:00
|
|
|
|
|
|
|
(define mb (new menu-bar% [parent f]))
|
|
|
|
(define m-file (new menu% [label "File"] [parent mb]))
|
|
|
|
(define m-edit (new menu% [label "Edit"] [parent mb]))
|
|
|
|
|
2018-12-02 17:05:50 +00:00
|
|
|
; The run output text object
|
|
|
|
(define run-output (new text-field%
|
|
|
|
[style (list 'multiple 'vertical-label)]
|
|
|
|
[label "Execution output:"]
|
|
|
|
[parent f]))
|
2018-12-01 21:06:12 +00:00
|
|
|
|
|
|
|
(define mi-open
|
|
|
|
(new menu-item%
|
|
|
|
[label "Open"]
|
|
|
|
[parent m-file]
|
|
|
|
[callback
|
|
|
|
(lambda (i e)
|
|
|
|
(define path (get-file #f f))
|
|
|
|
(when path
|
2018-12-02 17:05:50 +00:00
|
|
|
(send editor load-file path 'text)))]
|
2018-12-01 21:06:12 +00:00
|
|
|
[shortcut #\o]
|
|
|
|
[shortcut-prefix '(ctl)]))
|
|
|
|
|
|
|
|
(define mi-save
|
|
|
|
(new menu-item%
|
|
|
|
[label "Save"]
|
|
|
|
[parent m-file]
|
|
|
|
[callback
|
|
|
|
(lambda (i e)
|
2018-12-02 17:05:50 +00:00
|
|
|
(send editor save-file #f 'text))]
|
2018-12-01 21:06:12 +00:00
|
|
|
[shortcut #\s]
|
|
|
|
[shortcut-prefix '(ctl)]))
|
|
|
|
|
|
|
|
(append-editor-operation-menu-items m-edit #f)
|
2018-12-02 17:05:50 +00:00
|
|
|
(send editor set-max-undo-history 100)
|
|
|
|
(send c set-editor editor)
|
2018-12-01 21:06:12 +00:00
|
|
|
(send f show #t)
|