From: John Benediktsson Date: Tue, 24 Oct 2017 17:05:09 +0000 (-0700) Subject: ui.gadgets.editors: allow all editors to have default text. X-Git-Tag: 0.98~640 X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=02d6c8df1ff2f1c2604b5301010ea923a23cd1e2 ui.gadgets.editors: allow all editors to have default text. --- diff --git a/basis/ui/gadgets/editors/editors.factor b/basis/ui/gadgets/editors/editors.factor index 7243a5ebc6..74ffbd4695 100644 --- a/basis/ui/gadgets/editors/editors.factor +++ b/basis/ui/gadgets/editors/editors.factor @@ -13,7 +13,8 @@ IN: ui.gadgets.editors TUPLE: editor < line-gadget caret-color caret mark - focused? blink blink-timer ; + focused? blink blink-timer + default-text ; > ] [ model>> doc-string empty? ] } 1&& ; + +: draw-default-text ( editor -- ) + [ font>> clone line-color >>foreground ] + [ default-text>> ] bi draw-text ; + PRIVATE> M: editor draw-line ( line index editor -- ) @@ -206,13 +214,19 @@ M: editor draw-line ( line index editor -- ) [ draw-selected-line ] [ nip draw-unselected-line ] if ; M: editor draw-gadget* - dup compute-selection selected-lines [ - [ draw-lines ] [ draw-caret ] bi - ] with-variable ; + dup draw-default-text? [ + [ draw-default-text ] [ draw-caret ] bi + ] [ + dup compute-selection selected-lines [ + [ draw-lines ] [ draw-caret ] bi + ] with-variable + ] if ; M: editor pref-dim* ! Add some space for the caret. - [ font>> ] [ control-value ] bi text-dim { 1 0 } v+ ; + [ font>> ] keep dup draw-default-text? + [ default-text>> ] [ control-value ] if + text-dim { 1 0 } v+ ; M: editor baseline font>> font-metrics ascent>> ; @@ -627,6 +641,10 @@ M: field pref-dim* [ [ line-gadget-width ] [ drop second ] 2bi 2array ] tri border-pref-dim ; +M: field default-text>> editor>> default-text>> ; + +M: field default-text<< editor>> default-text<< ; + TUPLE: model-field < field field-model ; : ( model -- gadget ) @@ -644,48 +662,14 @@ M: model-field ungraft* M: model-field model-changed nip [ editor>> editor-string ] [ field-model>> ] bi set-model ; -TUPLE: action-editor < editor default-text ; - -: ( -- editor ) - action-editor new-editor ; - -> ] [ model>> doc-string empty? ] } 1&& ; - -: draw-default-text ( editor -- ) - [ font>> clone line-color >>foreground ] - [ default-text>> ] bi draw-text ; - -PRIVATE> - -M: action-editor draw-gadget* - dup draw-default-text? [ - [ draw-default-text ] [ draw-caret ] bi - ] [ - call-next-method - ] if ; - -M: action-editor pref-dim* - dup draw-default-text? [ - [ font>> ] [ default-text>> ] bi text-dim { 1 0 } v+ - ] [ - call-next-method - ] if ; - TUPLE: action-field < field quot ; : ( quot: ( string -- ) -- gadget ) - action-field [ ] dip new-border + action-field [ ] dip new-border dup gadget-child >>editor field-theme swap >>quot ; -M: action-field default-text>> editor>> default-text>> ; - -M: action-field default-text<< editor>> default-text<< ; - : invoke-action-field ( field -- ) [ editor>> editor-string ] [ editor>> clear-editor ]