]> gitweb.factorcode.org Git - factor.git/blob - basis/ui/gadgets/editors/editors-docs.factor
ui.gadgets.*: updated docs and new tests
[factor.git] / basis / ui / gadgets / editors / editors-docs.factor
1 USING: colors documents fonts help.markup help.syntax help.tips models
2 sequences strings ui.commands ui.gadgets ui.gadgets.line-support
3 ui.gadgets.scrollers ;
4 IN: ui.gadgets.editors
5
6 HELP: <multiline-editor>
7 { $values { "editor" multiline-editor } }
8 { $description "Creates a new multi-line editor gadget." } ;
9
10 HELP: editor
11 { $class-description "An editor is a control for editing a multi-line passage of text stored in a " { $link document } " model. Editors are crated by calling " { $link <editor> } "."
12 $nl
13 "Editors have the following slots:"
14 { $list
15     { { $snippet "caret-color" } " - a " { $link color } "." }
16     { { $snippet "caret" } " - a " { $link model } " storing a line/column pair." }
17     { { $snippet "mark" } " - a " { $link model } " storing a line/column pair. If there is no selection, the mark is equal to the caret, otherwise the mark is located at the opposite end of the selection from the caret." }
18     { { $snippet "focused?" } " - a boolean." }
19 } }
20 { $see-also line-gadget } ;
21
22 HELP: <editor>
23 { $values { "editor" "a new " { $link editor } } }
24 { $description "Creates a new " { $link editor } " with an empty document." } ;
25
26 { editor-caret editor-mark } related-words
27
28 HELP: editor-caret
29 { $values { "editor" editor } { "loc" "a pair of integers" } }
30 { $description "Outputs the current caret location as a line/column number pair." } ;
31
32 HELP: editor-mark
33 { $values { "editor" editor } { "loc" "a pair of integers" } }
34 { $description "Outputs the current mark location as a line/column number pair." } ;
35
36 HELP: change-caret
37 { $values { "editor" editor } { "quot" { $quotation ( loc document -- newloc ) } } }
38 { $description "Applies a quotation to the current caret location and moves the caret to the location output by the quotation." } ;
39
40 { change-caret change-caret&mark mark>caret } related-words
41
42 HELP: mark>caret
43 { $values { "editor" editor } }
44 { $description "Moves the mark to the caret location, effectively deselecting any selected text." } ;
45
46 HELP: change-caret&mark
47 { $values { "editor" editor } { "quot" { $quotation ( loc document -- newloc ) } } }
48 { $description "Applies a quotation to the current caret location and moves the caret and the mark to the location output by the quotation." } ;
49
50 HELP: point>loc
51 { $values { "point" "a pair of integers" } { "editor" editor } { "loc" "a pair of integers" } }
52 { $description "Converts a point to a line/column number pair." } ;
53
54 HELP: scroll>caret
55 { $values { "editor" editor } }
56 { $description "Ensures that the caret becomes visible in a " { $link scroller } " containing the editor. Does nothing if no parent of " { $snippet "gadget" } " is a " { $link scroller } "." } ;
57
58 HELP: remove-selection
59 { $values { "editor" editor } }
60 { $description "Removes currently selected text from the editor's " { $link document } "." } ;
61
62 HELP: <model-field>
63 { $values { "model" model } { "gadget" editor } }
64 { $description "Creates an editor gadget which targets the specified model. The model must contain a string, or another item with a defined " { $link length } ", as this will be checked during layout." } ;
65
66 HELP: <action-field>
67 { $values { "quot" { $quotation ( string -- ) } } { "gadget" editor } }
68 { $description "Creates an editor gadget with a blank model. Whenever a value is entered into the editor and Return pressed, the value is pushed on the stack as a string and the specified quotation is called. Note that the quotation cannot update the value in the field. " } ;
69
70
71 HELP: editor-string
72 { $values { "editor" editor } { "string" string } }
73 { $description "Outputs the contents of the editor's " { $link document } " as a string. Lines are separated by " { $snippet "\\n" } "." } ;
74
75
76
77 HELP: set-editor-string
78 { $values { "string" string } { "editor" editor } }
79 { $description "Sets the contents of the editor's " { $link document } " to a string,  which may use either " { $snippet "\\n" } ", " { $snippet "\\r\\n" } " or " { $snippet "\\r" } " line separators." } ;
80
81 ARTICLE: "gadgets-editors-selection" "The caret and mark"
82 "If there is no selection, the caret and the mark are at the same location; otherwise the mark delimits the end-point of the selection opposite the caret."
83 { $subsections
84     editor-caret
85     editor-mark
86     change-caret
87     change-caret&mark
88     mark>caret
89 }
90 "Getting the selected text:"
91 { $subsections
92     gadget-selection?
93     gadget-selection
94 }
95 "Removing selected text:"
96 { $subsections remove-selection }
97 "Scrolling to the caret location:"
98 { $subsections scroll>caret }
99 "Use " { $link user-input* } " to change selected text." ;
100
101 ARTICLE: "gadgets-editors-contents" "Getting and setting editor contents"
102 { $subsections
103     editor-string
104     set-editor-string
105     clear-editor
106 } ;
107
108 ARTICLE: "gadgets-editors-commands" "Editor gadget commands"
109 { $command-map editor "editing" }
110 { $command-map editor "caret-motion" }
111 { $command-map editor "selection" }
112 { $command-map editor "clipboard" }
113 { $command-map multiline-editor "multiline" } ;
114
115 ARTICLE: "ui.gadgets.editors" "Editor gadgets"
116 "The " { $vocab-link "ui.gadgets.editors" } " vocabulary implements editor gadgets. An editor edits a passage of text. Editors display a " { $link document } ". Editors are built from and inherit all features of " { $link "ui.gadgets.line-support" } "."
117 { $subsections "gadgets-editors-commands" }
118 "Editors:"
119 { $subsections
120     editor
121     <editor>
122     "gadgets-editors-contents"
123     "gadgets-editors-selection"
124 }
125 "Multiline editors:"
126 { $subsections <multiline-editor> }
127 "Fields:"
128 { $subsections
129     <model-field>
130     <action-field>
131 }
132 "Editors edit " { $emphasis "documents" } ":"
133 { $subsections "documents" } ;
134
135 TIP: "Editor gadgets support undo and redo; press " { $command editor "editing" com-undo } " and " { $command editor "editing" com-redo } "." ;
136
137 TIP: "Learn the keyboard shortcuts used in " { $link "ui.gadgets.editors" } "." ;
138
139 ABOUT: "ui.gadgets.editors"