Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] text-editor/word-processer

From: izkata::aol::com at: 27-Apr-2002 10:40

Sorry about that empty E-mail, I accidentally pressed the Send hotkey. I've seen and used a type of text editor: ctx-edit: [ prefs: view-root/edit-prefs.r dirty-edit: false this-file: none this-app: none t1: s1: h1: f1: none edit-prefs: context [ offset: 40x40 size: 640x480 wrap: on ] ed-lo: layout/offset [ style tx vtext bold 40x22 font [colors: [255.255.255 200.200.200]] middle center size 640x320 origin 0 space 0 across tx "Open" [open-as] tx "New" [new-file] tx "Find" [find-text] tx "Save" [save-file] tx "Save-As" 60 [save-as] tx "Do" [if error? try [do t1/text] [alert "There was an error somewhere."]] tx "Print" [write %printer.html rejoin [{<HTML> <HEAD> <TITLE> AutoPrinter </TITLE> </HEAD> <BODY> <PRE> } t1/text { </PRE> <SCRIPT LANGUAGE="JavaScript"> self.print(); self.close(); </SCRIPT> </BODY> </HTML>}] browse %printer.html] tx "Quit" [quit-edit] pad 8 text "File:" bold black right middle 30x22 h1: at f1: info 300x22 base-color + 40.40.40 return t1: area 624x320 font [name: font-fixed] para [tabs: 28 origin: 4x4] [dirty-edit: any [dirty-edit face/dirty?]] with [color: snow feel: make feel [redraw: none]] s1: slider 16x320 [scroll-para t1 s1] ] 0x0 ed-lo/color: base-color t1/flags: [] save-lo: layout [ origin 10x10 space 8x4 style btn button 140 vtext bold "Edit Save Options" 140 center pad 0x4 btn "Save" [hide-popup save-file result: true] btn "Save As..." [hide-popup result: save-as] btn "Quit - No Save" [hide-popup quit-now] btn "Cancel" [hide-popup] ] save-lo/color: base-color ff: fb: fc: fp: none find-lo: layout [ space 4x4 across origin 16x16 label "Find:" ff: field [search ff/text fc/data false] pad 4 fb: button 80 "Find" [search ff/text fc/data false] return at ff/offset + 0x32 fc: check vtext "Match case" at fb/offset + 0x32 button 80 "Cancel" [unview/only find-lo] ] find-lo/color: base-color deflag-face ff tabbed resize: func [size] [ ed-lo/size: size t1/size: size - (s1/size * 1x0) - (f1/size * 0x1) s1/offset/x: t1/offset/x + t1/size/x s1/size/y: t1/size/y f1/size/x: size/x - h1/x t1/line-list: none ] refresh: does [ show ed-lo s1/redrag t1/size/y / max 1 second size-text t1 ] save-prefs: has [str] [ str: copy "" edit-prefs/offset: ed-lo/offset edit-prefs/size: ed-lo/size foreach w next first edit-prefs [ append str rejoin [w ": " edit-prefs/:w newline] ] write prefs str ] open-as: has [file] [ if not save-edit [exit] file: request-file/keep/file/title this-file "Select a file to open:" Open if not all [file file: pick file 1] [return false] open-file file ] new-file: does [ if not save-edit [exit] open-file none ] save-as: has [file] [ file: any [this-file %temp.txt] file: request-file/keep/file/title file "Select a file or enter a file name:" "Save" if not all [file file: pick file 1] [return false] this-file: file save-file true ] save-file: has [file] [ if not this-file [save-as exit] f1/text: this-file f1/color: gold show f1 write this-file t1/text wait 0.2 f1/color: base-color + 40.40.40 show f1 dirty-edit: t1/dirty?: false true ] open-file: func [file /local txt] [ if file = 'same [file: this-file] either f1/text: this-file: file [ if error? try [txt: read file] [ request/ok reform ["Cannot read file:" file] f1/text: this-file: none txt: "" ] ] [ txt: "" ] dirty-edit: false t1/dirty?: false s1/data: 0 t1/para/scroll: 0x0 t1/text: t1/data: copy txt t1/line-list: none unfocus refresh focus t1 system/view/caret: t1/text ] result: none ask-save: does [result: none inform save-lo result] save-edit: does [either any [dirty-edit t1/dirty?] [ask-save] [true]] do-file: does [save-edit launch/secure-cmd this-file] quit-edit: does [if save-edit [quit-now]] quit-now: does [ if viewed? find-lo [unview/only find-lo] unview/only ed-lo dirty-edit: false t1/dirty?: false ] caret: none start: none last-str: last-case: last-pat: none find-text: does [ caret: system/view/caret view/new/title find-lo "Find" find-lo/changes: 'activate show find-lo focus ff ] search: func [str case pat] [ unview/only find-lo start: any [caret t1/text] last-str: str last-case: case last-pat: pat find-str str case pat ] find-str: func [str case pat] [ if not find-next str case pat [ start: none if not find-next str case pat [system/view/caret: caret] ] ] find-again: does [ start: any [system/view/caret t1/text] if last-str [find-str last-str last-case last-pat] ] find-next: func [str case pat /local txt] [ if txt: find' any [start t1/text] str case pat none [ focus t1 system/view/caret: txt if not pat [ system/view/highlight-start: txt system/view/caret: system/view/highlight-end: start: find' txt str case pat true ] scroll-to txt true ] ] find': func [txt str case pat tal /local code p] [ code: copy [find txt str] if any [case pat tal] [ change/only code p: make path! [find] if case [insert tail :p 'case] if pat [insert tail :p 'any] if tal [insert tail :p 'tail] ] do code ] scroll-to: func [txt /local xy] [ xy: (caret-to-offset t1 txt) - t1/para/scroll t1/para/scroll: min 0x0 t1/size / 2 - xy s1/data: (second xy) / max 1 second size-text t1 show [s1 t1] ] keymap: [ #"^S" [save-file] #"^W" [quit-edit] #"^Q" [quit-edit] #"^O" [open-as] #"^N" [new-file] #"^E" [do-file] #"^F" [find-text] #"^G" [find-again] F3 [find-text] F5 [do-edit] page-up [scroll-edit true -1] page-down [scroll-edit true 1] ] scroll-edit: func [page n] [ s1/data: s1/data + (n * (either page [t1/size/y] [t1/font/size]) / max 1 second size-text t1 ) show s1 scroll-para t1 s1 ] init: does [ ed-lo/feel: make ed-lo/feel [ detect: func [face event] [ switch event/type [ offset [save-prefs] scroll-line [scroll-edit false event/offset/y] scroll-page [scroll-edit true event/offset/y] resize [ resize max 100x64 ed-lo/size refresh save-prefs return true ] key [switch event/key keymap] close [quit-edit] ] event ] ] ] view-file: func [file] [ if not save-edit [exit] t1/text: none t1/line-list: none either viewed? ed-lo [ ed-lo/changes: 'activate show ed-lo ] [ if exists? prefs [edit-prefs: make edit-prefs load/all prefs] t1/para/wrap?: edit-prefs/wrap ed-lo/offset: edit-prefs/offset if outside? system/view/screen-face/size ed-lo/offset + 20x20 [ ed-lo/offset: 40x40 save-prefs ] resize edit-prefs/size view/new/title/options ed-lo "Editor" [resize] init center-face/with save-lo ed-lo center-face/with find-lo ed-lo ] open-file file if 1 = length? system/view/screen-face/pane [do-events] ] ] editor: func [file /local tmp][ either exists? tmp: view-root/desktop/scripts/edit.r [do/args tmp file] [ if block? ctx-edit [ctx-edit: context ctx-edit] ctx-edit/view-file file ] ] editor none But, I've never seen a word processor for REBOL. As long as it uses rebol script in the save file, I'll use it. I don't have any idea on how to make one myself, because I'm only 14, and can't even do simple parsing very easily. Daniel S.