Skip to content

Instantly share code, notes, and snippets.

@DideC
Last active January 25, 2017 21:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DideC/61138fe905a6950359087a07a374e0d4 to your computer and use it in GitHub Desktop.
Save DideC/61138fe905a6950359087a07a374e0d4 to your computer and use it in GitHub Desktop.
A very basic text editor in VID. Handling only load and save of a file. Needs `call` to handle compilation and test of script
Red [
title: "Red basic Editor"
author: "Didier Cadieu"
version: 0.1.1
date: "25-01-2017"
]
script: make string! 10000
saved?: true
f-file: f-script: file: none
new-file: does [
unless any [empty? script saved?] [
view/flags [Text "Do you want to save your script first ?" button "Yes, for sure" [save-file unview] button "No, discard it" [saved?: true unview]] 'modal
]
if saved? [
file: none
append clear f-file/text "(new file)"
clear head script
]
]
load-file: has [f] [
if f: request-file/title/filter "Select a Red file to load" [{Red or Red/system file (*.red *.reds)} "*.red;*.reds" {All files (*.*)} "*.*"] [
append clear f-file/text file: f
append clear script read file
saved?: true
]
]
save-as-file: has [f] [
if f: request-file/save/title/filter "Chosse a folder and name for your file to save" [{Red file (*.red)} "*.red" {Red/system file (*.reds)} "*.reds" {All files (*.*)} "*.*"] [
unless suffix? f [append f %.red] ; Not good enough : request-file/save must add suffix itself if missing regarding the selected filter IMO
file: f
save-file
]
]
save-file: does [
unless file [save-as-file exit]
write file head script
saved?: true
]
view/no-wait/flags main: layout [
title "Red basic editor"
origin 2x2 space 2x2
style btn: button 80x20
btn "New" [new-file]
btn "Load..." [load-file]
btn "Save" [save-file]
btn "Save as..." [save-as-file]
return
text 30x20 "File :" f-file: text "(new file)" bold 568x20
return
f-script: area script 600x600 on-change [saved?: false]
] 'resize
insert-event-func [
if all [event/window = main event/type = 'resize] [
f-file/size/y: event/window/size/y - 2 - f-file/offset/y
f-script/size: event/window/size - 2x2 - f-script/offset
'done
]
]
do-events
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment