add content-gadget hook for inspector

Allow objects such as images, strings, and audio clips to display rich representations of themselves in the inspector by providing methods for a content-gadget generic.
db4
Joe Groff 2012-02-21 15:06:27 -08:00
parent ff990717f8
commit 273b5115bf
6 changed files with 52 additions and 18 deletions

View File

@ -47,6 +47,10 @@ HELP: <pane-stream>
{ with-pane make-pane } related-words { with-pane make-pane } related-words
HELP: content-gadget
{ $values { "object" object } { "gadget/f" { $maybe gadget } } }
{ $description "This generic function may be implemented for objects in order to display a rich representation of the object in the " { $link "ui-inspector" } ". If " { $snippet "content-gadget" } " returns a gadget for an inspected object, the returned gadget is displayed under the \"Content\" heading in the inspector window. If " { $snippet "content-gadget" } " returns " { $link POSTPONE: f } ", no content section is included in the given object's inspector." } ;
ARTICLE: "ui.gadgets.panes" "Pane gadgets" ARTICLE: "ui.gadgets.panes" "Pane gadgets"
"The " { $vocab-link "ui.gadgets.panes" } " vocabulary implements panes, which display formatted text." "The " { $vocab-link "ui.gadgets.panes" } " vocabulary implements panes, which display formatted text."
{ $subsections { $subsections

View File

@ -12,6 +12,7 @@ ui.text ui.gadgets.presentations ui.gadgets.grids ui.gadgets.tracks
ui.gadgets.icons ui.gadgets.grid-lines ui.baseline-alignment ui.gadgets.icons ui.gadgets.grid-lines ui.baseline-alignment
colors io.styles classes ; colors io.styles classes ;
FROM: io.styles => foreground background ; FROM: io.styles => foreground background ;
FROM: ui.gadgets.wrappers => <wrapper> ;
IN: ui.gadgets.panes IN: ui.gadgets.panes
TUPLE: pane < track TUPLE: pane < track
@ -436,3 +437,12 @@ pane H{
{ copy-action [ com-copy ] } { copy-action [ com-copy ] }
{ T{ button-down f f 3 } [ pane-menu ] } { T{ button-down f f 3 } [ pane-menu ] }
} set-gestures } set-gestures
GENERIC: content-gadget ( object -- gadget/f )
M: object content-gadget drop f ;
M: string content-gadget
'[ _ write ] make-pane <scroller>
{ 450 100 } >>pref-dim
<wrapper> ;

View File

@ -1,5 +1,5 @@
USING: help.markup help.syntax ui.commands ui.gadgets.slots USING: help.markup help.syntax ui.commands ui.gadgets.slots
ui.gadgets.editors kernel ; ui.gadgets.panes ui.gadgets.editors kernel ;
IN: ui.tools.inspector IN: ui.tools.inspector
ARTICLE: "ui-inspector-edit" "Editing slot values in the inspector" ARTICLE: "ui-inspector-edit" "Editing slot values in the inspector"
@ -15,6 +15,8 @@ ARTICLE: "ui-inspector" "UI inspector"
$nl $nl
"To display an object in the UI inspector, right-click a presentation and choose " { $strong "Inspector" } " from the menu that appears. The inspector can also be opened from the listener using a word:" "To display an object in the UI inspector, right-click a presentation and choose " { $strong "Inspector" } " from the menu that appears. The inspector can also be opened from the listener using a word:"
{ $subsections inspector } { $subsections inspector }
"Objects may extend the inspector window with a content gadget, in order to provide a rich representation of the object's content in the inspector."
{ $subsections content-gadget }
"The inspector embeds a table gadget, which supports keyboard navigation; see " { $link "ui.gadgets.tables" } ". It also provides a few other commands:" "The inspector embeds a table gadget, which supports keyboard navigation; see " { $link "ui.gadgets.tables" } ". It also provides a few other commands:"
{ $command-map inspector-gadget "toolbar" } { $command-map inspector-gadget "toolbar" }
{ $command-map inspector-gadget "multi-touch" } { $command-map inspector-gadget "multi-touch" }

View File

@ -6,7 +6,7 @@ classes io io.styles arrays hashtables math.order sorting refs fonts
ui.tools.browser ui.commands ui.operations ui.gadgets ui.gadgets.panes ui.tools.browser ui.commands ui.operations ui.gadgets ui.gadgets.panes
ui.gadgets.scrollers ui.gadgets.slots ui.gadgets.tracks ui.gestures ui.gadgets.scrollers ui.gadgets.slots ui.gadgets.tracks ui.gestures
ui.gadgets.buttons ui.gadgets.tables ui.gadgets.status-bar ui.gadgets.buttons ui.gadgets.tables ui.gadgets.status-bar
ui.gadgets.labeled ui.tools.common ui ; ui.gadgets.labeled ui.tools.common ui combinators ;
IN: ui.tools.inspector IN: ui.tools.inspector
TUPLE: inspector-gadget < tool table ; TUPLE: inspector-gadget < tool table ;
@ -30,6 +30,7 @@ M: inspector-renderer column-titles
: <summary-gadget> ( model -- gadget ) : <summary-gadget> ( model -- gadget )
[ [
standard-table-style [ standard-table-style [
{
[ [
[ [
[ "Class:" write ] with-cell [ "Class:" write ] with-cell
@ -47,7 +48,16 @@ M: inspector-renderer column-titles
[ "Summary:" write ] with-cell [ "Summary:" write ] with-cell
[ print-summary ] with-cell [ print-summary ] with-cell
] with-row ] with-row
] tri ]
[
content-gadget [
[
[ "Content:" write ] with-cell
[ output-stream get write-gadget ] with-cell
] with-row
] when*
]
} cleave
] tabular-output ] tabular-output
] <pane-control> ; ] <pane-control> ;
@ -123,3 +133,5 @@ inspector-gadget "multi-touch" f {
: inspector ( obj -- ) : inspector ( obj -- )
<model> inspect-model ; <model> inspect-model ;
{ 550 400 } inspector-gadget set-tool-dim

View File

@ -72,3 +72,6 @@ PRIVATE>
: audio. ( audio -- ) : audio. ( audio -- )
<audio-gadget> gadget. ; <audio-gadget> gadget. ;
M: audio content-gadget
<audio-gadget> ;

View File

@ -109,3 +109,6 @@ M: model set-image [ value>> >>image drop ] [ >>model ] 2bi ;
M: image-control graft* start-control ; M: image-control graft* start-control ;
M: image-control ungraft* [ stop-control ] [ call-next-method ] bi ; M: image-control ungraft* [ stop-control ] [ call-next-method ] bi ;
PRIVATE> PRIVATE>
M: image content-gadget
<image-gadget> ;