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