Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. Red [
  2. title: "Red basic Editor"
  3. author: "Didier Cadieu"
  4. version: 0.1.0
  5. date: "24-01-2017"
  6. ]
  7.  
  8. script: make string! 10000
  9. saved?: true
  10.  
  11. f-file: f-script: file: none
  12.  
  13. new-file: has [stop?] [
  14. unless any [empty? script saved?] [
  15. 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
  16. ]
  17. if saved? [
  18. file: none
  19. append clear f-file/text "(new file)"
  20. clear head script
  21. ]
  22. ]
  23.  
  24. load-file: has [f] [
  25. if f: request-file/title/filter "Select a Red file to load" [{Red or Red/system file (*.red *.reds)} "*.red;*.reds" {All files (*.*)} "*.*"] [
  26. append clear f-file/text file: f
  27. append clear script read file
  28. saved?: true
  29. ]
  30. ]
  31.  
  32.  
  33. save-as-file: has [f] [
  34. 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 (*.*)} "*.*"] [
  35. unless suffix? f [append f %.red] ; Not good enough : request-file/save must add suffix itself if missing regarding the selected filter IMO
  36. file: f
  37. save-file
  38. ]
  39. ]
  40.  
  41. save-file: does [
  42. unless file [save-as-file exit]
  43. write file head script
  44. saved?: true
  45. ]
  46.  
  47. view/no-wait/flags main: layout [
  48. title "Red basic editor"
  49. origin 2x2 space 2x2
  50.  
  51. style btn: button 80x20
  52.  
  53. btn "New" [new-file]
  54. btn "Load..." [load-file]
  55. btn "Save" [save-file]
  56. btn "Save as..." [save-as-file]
  57. return
  58. text 30x20 "File :" f-file: text "(new file)" bold 568x20
  59. return
  60. f-script: area script 600x600 on-change [saved?: false]
  61. ] 'resize
  62.  
  63. insert-event-func [
  64. if event/type = 'resize [
  65. f-file/size/y: event/window/size/y - 2 - f-file/offset/y
  66. f-script/size: event/window/size - 2x2 - f-script/offset
  67. 'done
  68. ]
  69. ]
  70.  
  71. do-events
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement