1
0

Helios-Transcript.st 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 ifNotNil: [
  20. textarea asJQuery append: aString asString ]
  21. ! !
  22. !HLTranscript methodsFor: 'initialization'!
  23. initialize
  24. super initialize.
  25. self register
  26. ! !
  27. !HLTranscript methodsFor: 'registration'!
  28. register
  29. HLTranscriptHandler register: self
  30. !
  31. unregister
  32. super unregister.
  33. HLTranscriptHandler unregister: self
  34. ! !
  35. !HLTranscript methodsFor: 'rendering'!
  36. renderOn: html
  37. html div
  38. class: 'transcript';
  39. with: [ textarea := html textarea ]
  40. ! !
  41. Object subclass: #HLTranscriptHandler
  42. instanceVariableNames: ''
  43. package: 'Helios-Transcript'!
  44. !HLTranscriptHandler commentStamp!
  45. I handle transcript events, dispatching them to all instances of `HLTranscript`.
  46. ## API
  47. On class initialization I am automatically registered as the current transcript.!
  48. HLTranscriptHandler class instanceVariableNames: 'transcripts'!
  49. !HLTranscriptHandler class methodsFor: 'accessing'!
  50. transcripts
  51. ^ transcripts ifNil: [ transcripts := OrderedCollection new ]
  52. ! !
  53. !HLTranscriptHandler class methodsFor: 'initialization'!
  54. initialize
  55. Transcript register: self
  56. ! !
  57. !HLTranscriptHandler class methodsFor: 'registration'!
  58. clear
  59. self transcripts do: [ :each |
  60. each clear ]
  61. !
  62. register: aTranscript
  63. self transcripts add: aTranscript
  64. !
  65. show: aString
  66. self transcripts do: [ :each |
  67. each show: aString ]
  68. !
  69. unregister: aTranscript
  70. self transcripts remove: aTranscript
  71. ! !