I think someone else was asking about something similar composite snips problem a couple of weeks ago for a grid. I don't know if they were successful?<br><br>Have you tried using the 'File->search in files' menu item to search the collects/ dir to see how the XML box works? (though if I remember correctly- it is just one snip - not two)<br>
<br>Cheers, <br><br>Stephen<br><br><br><div class="gmail_quote">On Sat, Apr 11, 2009 at 7:40 AM, Jordan Johnson <span dir="ltr"><<a href="mailto:jmj@fellowhuman.com">jmj@fellowhuman.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi all,<br>
<br>
I'm trying to implement a snip similar to DrScheme's comment and XML boxes, but containing two distinct text boxes rather than one. Before I invest more time searching for the right way -- I've put in enough time that my this-*must*-be-easier alarm bells are going off -- I need to ask which classes/methods are the ones I'm after, or, at very least, if there's a relevant tutorial out there.<br>
<br>
Here's what I want to accomplish:<br>
1) When both parts are visible, the user should be able to click into either one to edit its text; the contents will be independent, but the boxes should remain stacked (i.e., one should display above the other, in fixed order).<br>
2) When the snip does not have focus, only one of the two text boxes should be visible.<br>
3) Ultimately I want to hook into DrScheme and be able to create these snips by highlighting text in another editor and selecting a menu item, much like "Comment Out with a Box", to populate one of the snip's two fields with the selection.<br>
<br>
Currently I'm just trying a simple precursor to (1): getting DrScheme to draw the snip with both areas visible. Code is below; it does not successfully draw the snip.<br>
<br>
What is an appropriate way to manage the two editors the snip contains?<br>
<br>
Thanks,<br>
Jordan<br>
<br>
=== code ===<br>
#lang scheme/gui<br>
<br>
<br>
(define PAD 4)<br>
<br>
(define my-snip%<br>
(class snip%<br>
(init-field [has-focus? #f]<br>
[area1-text (new editor-snip%<br>
[editor (new text%)]<br>
[min-width 20]<br>
[max-width 600])]<br>
[area2-text (new editor-snip%<br>
[editor (new text%)]<br>
[min-width 20]<br>
[max-width 600])])<br>
<br>
(define/override get-extent<br>
(lambda (dc x y w h descent space lspace rspace)<br>
(when (box? w)<br>
(let ([area2-w (box #f)]<br>
[area1-w (box #f)]<br>
[area1-h (box #f)])<br>
(send area1-text get-extent dc x y area1-w area1-h)<br>
(send area2-text get-extent dc x (+ y area1-h PAD) area2-w)<br>
(set-box! w (max (unbox area2-w area1-w)))))<br>
(when (box? h)<br>
(let ([area2-h (box #f)]<br>
[area1-h (box #f)])<br>
(send area1-text get-extent dc x y #f area1-h)<br>
(send area2-text get-extent dc x (+ y area1-h PAD) #f area2-h)<br>
(set-box! h (+ area2-h area1-h PAD))))<br>
))<br>
<br>
(define/override (draw dc x y left top right bottom<br>
dx dy draw-caret?)<br>
(let ([area1-bottom (box #f)])<br>
(send area1-text get-extent dc x y #f area1-bottom)<br>
(send area1-text draw dc<br>
x y left top right area1-bottom<br>
dx dy draw-caret?)<br>
(send area2-text draw dc<br>
x (+ area1-bottom PAD)<br>
left (+ area1-bottom PAD)<br>
dx dy draw-caret?)))<br>
(super-new)<br>
))<br>
<br>
(define s (new my-snip%)) ;; s doesn't render.<br>
<br>
_________________________________________________<br>
For list-related administrative tasks:<br>
<a href="http://list.cs.brown.edu/mailman/listinfo/plt-scheme" target="_blank">http://list.cs.brown.edu/mailman/listinfo/plt-scheme</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Cheers,<br><br>Stephen<br><br>--<br>Stephen De Gabrielle<br><a href="mailto:s.degabrielle@cs.ucl.ac.uk">s.degabrielle@cs.ucl.ac.uk</a><br>Telephone +44 (0)20 7679 0693 (x30693)<br>
Mobile 079 851 890 45<br>Project: Making Sense of Information (MaSI)<br>Work:<a href="http://www.uclic.ucl.ac.uk/annb/MaSI.html">http://www.uclic.ucl.ac.uk/annb/MaSI.html</a><br>Home:<a href="http://www.degabrielle.name/stephen">http://www.degabrielle.name/stephen</a><br>
<br><br>UCL Interaction Centre<br>MPEB 8th floor<br>University College London<br>Gower Street<br>London WC1E 6BT<br>