]> gitweb.factorcode.org Git - factor.git/blob - basis/ui/gadgets/editors/editors-docs.factor
make the caret color themeable
[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 created by calling " { $link <editor> } "."
12 $nl
13 "Editors have the following slots:"
14 { $list
15     { { $snippet "caret" } " - a " { $link model } " storing a line/column pair." }
16     { { $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." }
17     { { $snippet "focused?" } " - a boolean." }
18 } }
19 { $see-also line-gadget } ;
20
21 HELP: <editor>
22 { $values { "editor" "a new " { $link editor } } }
23 { $description "Creates a new " { $link editor } " with an empty document." } ;
24
25 { editor-caret editor-mark } related-words
26
27 HELP: editor-caret
28 { $values { "editor" editor } { "loc" "a pair of integers" } }
29 { $description "Outputs the current caret location as a line/column number pair." } ;
30
31 HELP: editor-mark
32 { $values { "editor" editor } { "loc" "a pair of integers" } }
33 { $description "Outputs the current mark location as a line/column number pair." } ;
34
35 HELP: change-caret
36 { $values { "editor" editor } { "quot" { $quotation ( loc document -- newloc ) } } }
37 { $description "Applies a quotation to the current caret location and moves the caret to the location output by the quotation." } ;
38
39 { change-caret change-caret&mark mark>caret } related-words
40
41 HELP: mark>caret
42 { $values { "editor" editor } }
43 { $description "Moves the mark to the caret location, effectively deselecting any selected text." } ;
44
45 HELP: change-caret&mark
46 { $values { "editor" editor } { "quot" { $quotation ( loc document -- newloc ) } } }
47 { $description "Applies a quotation to the current caret location and moves the caret and the mark to the location output by the quotation." } ;
48
49 HELP: point>loc
50 { $values { "point" "a pair of integers" } { "editor" editor } { "loc" "a pair of integers" } }
51 { $description "Converts a point to a line/column number pair." } ;
52
53 HELP: scroll>caret
54 { $values { "editor" editor } }
55 { $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 } "." } ;
56
57 HELP: remove-selection
58 { $values { "editor" editor } }
59 { $description "Removes currently selected text from the editor's " { $link document } "." } ;
60
61 HELP: <model-field>
62 { $values { "model" model } { "gadget" editor } }
63 { $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." } ;
64
65 HELP: <action-field>
66 { $values { "quot" { $quotation ( string -- ) } } { "gadget" editor } }
67 { $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." } ;
68
69
70 HELP: editor-string
71 { $values { "editor" editor } { "string" string } }
72 { $description "Outputs the contents of the editor's " { $link document } " as a string. Lines are separated by " { $snippet "\\n" } "." } ;
73
74
75
76 HELP: set-editor-string
77 { $values { "string" string } { "editor" editor } }
78 { $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." } ;
79
80 ARTICLE: "gadgets-editors-selection" "The caret and mark"
81 "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."
82 { $subsections
83     editor-caret
84     editor-mark
85     change-caret
86     change-caret&mark
87     mark>caret
88 }
89 "Getting the selected text:"
90 { $subsections
91     gadget-selection?
92     gadget-selection
93 }
94 "Removing selected text:"
95 { $subsections remove-selection }
96 "Scrolling to the caret location:"
97 { $subsections scroll>caret }
98 "Use " { $link user-input* } " to change selected text." ;
99
100 ARTICLE: "gadgets-editors-contents" "Getting and setting editor contents"
101 { $subsections
102     editor-string
103     set-editor-string
104     clear-editor
105 } ;
106
107 ARTICLE: "gadgets-editors-commands" "Editor gadget commands"
108 { $command-map editor "editing" }
109 { $command-map editor "caret-motion" }
110 { $command-map editor "selection" }
111 { $command-map editor "clipboard" }
112 { $command-map multiline-editor "multiline" } ;
113
114 ARTICLE: "ui.gadgets.editors" "Editor gadgets"
115 "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" } "."
116 { $subsections "gadgets-editors-commands" }
117 "Editors:"
118 { $subsections
119     editor
120     <editor>
121     "gadgets-editors-contents"
122     "gadgets-editors-selection"
123 }
124 "Multiline editors:"
125 { $subsections <multiline-editor> }
126 "Fields:"
127 { $subsections
128     <model-field>
129     <action-field>
130 }
131 "Editors edit " { $emphasis "documents" } ":"
132 { $subsections "documents" } ;
133
134 TIP: "Editor gadgets support undo and redo; press " { $command editor "editing" com-undo } " and " { $command editor "editing" com-redo } "." ;
135
136 TIP: "Learn the keyboard shortcuts used in " { $link "ui.gadgets.editors" } "." ;
137
138 ABOUT: "ui.gadgets.editors"