1
0

Helios-Transcript.st 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. Smalltalk current createPackage: 'Helios-Transcript'!
  2. HLWidget subclass: #HLTranscript
  3. instanceVariableNames: 'textarea'
  4. package: 'Helios-Transcript'!
  5. !HLTranscript commentStamp!
  6. I am a widget responsible for displaying transcript contents.
  7. ## Transcript API
  8. Transcript
  9. show: 'hello world';
  10. cr;
  11. show: anObject.
  12. Transcript clear.
  13. See the `Transcript` class.!
  14. !HLTranscript methodsFor: 'actions'!
  15. clear
  16. textarea asJQuery text: ''
  17. !
  18. show: aString
  19. textarea asJQuery append: aString asString
  20. ! !
  21. !HLTranscript methodsFor: 'initialization'!
  22. initialize
  23. super initialize.
  24. self register
  25. ! !
  26. !HLTranscript methodsFor: 'registration'!
  27. register
  28. HLTranscriptHandler register: self
  29. !
  30. unregister
  31. super unregister.
  32. HLTranscriptHandler unregister: self
  33. ! !
  34. !HLTranscript methodsFor: 'rendering'!
  35. renderOn: html
  36. html div
  37. class: 'transcript';
  38. with: [ textarea := html textarea ]
  39. ! !
  40. Object subclass: #HLTranscriptHandler
  41. instanceVariableNames: ''
  42. package: 'Helios-Transcript'!
  43. !HLTranscriptHandler commentStamp!
  44. I handle transcript events, dispatching them to all instances of `HLTranscript`.
  45. ## API
  46. On class initialization I am automatically registered as the current transcript.!
  47. HLTranscriptHandler class instanceVariableNames: 'transcripts'!
  48. !HLTranscriptHandler class methodsFor: 'accessing'!
  49. transcripts
  50. ^ transcripts ifNil: [ transcripts := OrderedCollection new ]
  51. ! !
  52. !HLTranscriptHandler class methodsFor: 'initialization'!
  53. initialize
  54. Transcript register: self
  55. ! !
  56. !HLTranscriptHandler class methodsFor: 'registration'!
  57. clear
  58. self transcripts do: [ :each |
  59. each clear ]
  60. !
  61. register: aTranscript
  62. self transcripts add: aTranscript
  63. !
  64. show: aString
  65. self transcripts do: [ :each |
  66. each show: aString ]
  67. !
  68. unregister: aTranscript
  69. self transcripts remove: aTranscript
  70. ! !