Helios-Transcript.st 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. Smalltalk 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` service 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. Use the class-side method `#register:` to add transcript instances.!
  48. HLTranscriptHandler class instanceVariableNames: 'transcripts'!
  49. !HLTranscriptHandler class methodsFor: 'accessing'!
  50. transcripts
  51. ^ transcripts ifNil: [ transcripts := OrderedCollection new ]
  52. ! !
  53. !HLTranscriptHandler class methodsFor: 'printing'!
  54. clear
  55. self transcripts do: [ :each |
  56. each clear ]
  57. !
  58. cr
  59. self transcripts do: [ :each | each cr ]
  60. !
  61. show: aString
  62. self transcripts do: [ :each |
  63. each show: aString ]
  64. ! !
  65. !HLTranscriptHandler class methodsFor: 'registration'!
  66. register: aTranscript
  67. self transcripts add: aTranscript
  68. !
  69. unregister: aTranscript
  70. self transcripts remove: aTranscript
  71. ! !