Helios-Browser.st 22 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057
  1. Smalltalk current createPackage: 'Helios-Browser'!
  2. HLWidget subclass: #HLBrowser
  3. instanceVariableNames: 'model packagesListWidget classesListWidget protocolsListWidget methodsListWidget sourceWidget'
  4. package: 'Helios-Browser'!
  5. !HLBrowser methodsFor: 'accessing'!
  6. announcer
  7. ^ self model announcer
  8. !
  9. environment
  10. ^ self model environment
  11. !
  12. model
  13. ^ model ifNil: [ model := HLBrowserModel new ]
  14. !
  15. model: aModel
  16. model := aModel
  17. ! !
  18. !HLBrowser methodsFor: 'keybindings'!
  19. registerBindingsOn: aBindingGroup
  20. aBindingGroup
  21. addGroupKey: 66 labelled: 'Browse';
  22. addGroupKey: 71 labelled: 'Go to';
  23. addGroupKey: 84 labelled: 'Toggle'.
  24. HLBrowserCommand withAllSubclasses do: [ :each |
  25. each key ifNotNil: [
  26. (aBindingGroup at: each bindingGroup)
  27. add: (each on: self model) asBinding ] ]
  28. ! !
  29. !HLBrowser methodsFor: 'rendering'!
  30. renderContentOn: html
  31. html with: (HLContainer with: (HLHorizontalSplitter
  32. with: (HLVerticalSplitter
  33. with: (HLVerticalSplitter
  34. with: self packagesListWidget
  35. with: self classesListWidget)
  36. with: (HLVerticalSplitter
  37. with: self protocolsListWidget
  38. with: self methodsListWidget))
  39. with: self sourceWidget))
  40. ! !
  41. !HLBrowser methodsFor: 'widgets'!
  42. classesListWidget
  43. ^ classesListWidget ifNil: [
  44. classesListWidget := HLClassesListWidget on: self model.
  45. classesListWidget next: self protocolsListWidget ]
  46. !
  47. methodsListWidget
  48. ^ methodsListWidget ifNil: [
  49. methodsListWidget := HLMethodsListWidget on: self model ]
  50. !
  51. packagesListWidget
  52. ^ packagesListWidget ifNil: [
  53. packagesListWidget := HLPackagesListWidget on: self model.
  54. packagesListWidget next: self classesListWidget ]
  55. !
  56. protocolsListWidget
  57. ^ protocolsListWidget ifNil: [
  58. protocolsListWidget := HLProtocolsListWidget on: self model.
  59. protocolsListWidget next: self methodsListWidget ]
  60. !
  61. sourceWidget
  62. ^ sourceWidget ifNil: [
  63. sourceWidget := HLBrowserSourceWidget on: self model ]
  64. ! !
  65. HLBrowser class instanceVariableNames: 'nextId'!
  66. !HLBrowser class methodsFor: 'accessing'!
  67. nextId
  68. nextId ifNil: [ nextId := 0 ].
  69. ^ 'browser_', (nextId + 1) asString
  70. !
  71. tabLabel
  72. ^ 'Browser'
  73. !
  74. tabPriority
  75. ^ 0
  76. ! !
  77. !HLBrowser class methodsFor: 'testing'!
  78. canBeOpenAsTab
  79. ^ true
  80. ! !
  81. HLNavigationListWidget subclass: #HLBrowserListWidget
  82. instanceVariableNames: 'model'
  83. package: 'Helios-Browser'!
  84. !HLBrowserListWidget methodsFor: 'accessing'!
  85. model
  86. ^ model
  87. !
  88. model: aBrowserModel
  89. model := aBrowserModel.
  90. self observeModel
  91. ! !
  92. !HLBrowserListWidget methodsFor: 'actions'!
  93. observeModel
  94. !
  95. observeSystem
  96. ! !
  97. !HLBrowserListWidget methodsFor: 'initialization'!
  98. initialize
  99. super initialize.
  100. self observeSystem
  101. ! !
  102. !HLBrowserListWidget class methodsFor: 'instance creation'!
  103. on: aModel
  104. ^ self new
  105. model: aModel;
  106. yourself
  107. ! !
  108. HLBrowserListWidget subclass: #HLClassesListWidget
  109. instanceVariableNames: ''
  110. package: 'Helios-Browser'!
  111. !HLClassesListWidget methodsFor: 'accessing'!
  112. getChildrenOf: aClass
  113. ^ self items select: [ :each | each superclass = aClass ]
  114. !
  115. getRootClassesOf: aCollection
  116. ^ aCollection select: [ :each |
  117. (aCollection includes: each superclass) not ]
  118. !
  119. iconForItem: aClass
  120. ^ aClass theNonMetaClass comment isEmpty
  121. ifFalse: [ 'icon-none' ]
  122. ifTrue: [ 'icon-question-sign' ]
  123. !
  124. showInstance
  125. ^ self model showInstance
  126. ! !
  127. !HLClassesListWidget methodsFor: 'actions'!
  128. focusMethodsListWidget
  129. self model announcer announce: HLMethodsListFocus new
  130. !
  131. focusProtocolsListWidget
  132. self model announcer announce: HLProtocolsListFocus new
  133. !
  134. observeModel
  135. self model announcer
  136. on: HLPackageSelected do: [ :ann | self onPackageSelected: ann item ];
  137. on: HLShowInstanceToggled do: [ :ann | self onShowInstanceToggled ];
  138. on: HLClassSelected do: [ :ann | self onClassSelected: ann item ]
  139. !
  140. observeSystem
  141. SystemAnnouncer current
  142. on: ClassAdded
  143. do: [ :ann | self onClassAdded: ann theClass ];
  144. on: ClassRemoved
  145. do: [ :ann | self onClassRemoved: ann theClass ]
  146. !
  147. selectItem: aClass
  148. self model selectedClass: aClass
  149. !
  150. showInstance: aBoolean
  151. self model showInstance: aBoolean
  152. ! !
  153. !HLClassesListWidget methodsFor: 'private'!
  154. setItemsForPackage: aPackage
  155. self items: (aPackage
  156. ifNil: [ #() ]
  157. ifNotNil: [ ((aPackage classes
  158. collect: [ :each | each theNonMetaClass ]) asSet asArray)
  159. sort: [:a :b | a name < b name ] ]).
  160. !
  161. setItemsForSelectedPackage
  162. self setItemsForPackage: self model selectedPackage
  163. ! !
  164. !HLClassesListWidget methodsFor: 'reactions'!
  165. onClassAdded: aClass
  166. aClass package = self model selectedPackage ifFalse: [ ^ self ].
  167. self setItemsForSelectedPackage.
  168. self refresh
  169. !
  170. onClassRemoved: aClass
  171. aClass package = self model selectedPackage ifFalse: [ ^ self ].
  172. aClass = self model selectedClass ifTrue: [ self selectItem: nil ].
  173. self setItemsForSelectedPackage.
  174. self refresh
  175. !
  176. onClassSelected: aClass
  177. self selectedItem: aClass.
  178. aClass ifNil: [ ^ self ].
  179. self focus
  180. !
  181. onPackageSelected: aPackage
  182. self selectedItem: nil.
  183. self setItemsForSelectedPackage.
  184. self refresh
  185. !
  186. onShowInstanceToggled
  187. self refresh
  188. ! !
  189. !HLClassesListWidget methodsFor: 'rendering'!
  190. renderButtonsOn: html
  191. html div
  192. class: 'btn-group';
  193. at: 'data-toggle' put: 'buttons-radio';
  194. with: [
  195. html button
  196. class: (String streamContents: [ :str |
  197. str nextPutAll: 'btn'.
  198. self showInstance ifTrue: [
  199. str nextPutAll: ' active'] ]);
  200. with: 'Instance';
  201. onClick: [ self showInstance: true ].
  202. html button
  203. class: (String streamContents: [ :str |
  204. str nextPutAll: 'btn'.
  205. self model showInstance ifFalse: [
  206. str nextPutAll: ' active'] ]);
  207. with: 'Class';
  208. onClick: [ self model showInstance: false ] ].
  209. html button
  210. class: 'btn';
  211. at: 'data-toggle' put: 'button';
  212. with: 'Comment'
  213. !
  214. renderItem: aClass level: anInteger on: html
  215. | li |
  216. li := html li.
  217. li
  218. at: 'list-data' put: (self items indexOf: aClass);
  219. class: (self cssClassForItem: aClass);
  220. with: [
  221. html a
  222. with: [
  223. (html tag: 'i') class: (self iconForItem: aClass).
  224. self renderItemLabel: aClass level: anInteger on: html ];
  225. onClick: [
  226. self activateListItem: li asJQuery ] ].
  227. (self getChildrenOf: aClass) do: [ :each |
  228. self renderItem: each level: anInteger + 1 on: html ]
  229. !
  230. renderItem: aClass on: html
  231. super renderItem: aClass on: html.
  232. (self getChildrenOf: aClass) do: [ :each |
  233. self renderItem: each level: 1 on: html ]
  234. !
  235. renderItemLabel: aClass level: anInteger on: html
  236. html span asJQuery html: (String streamContents: [ :str |
  237. anInteger timesRepeat: [
  238. str nextPutAll: '&nbsp;&nbsp;&nbsp;&nbsp;'].
  239. str nextPutAll: aClass name ])
  240. !
  241. renderItemLabel: aClass on: html
  242. self renderItemLabel: aClass level: 0 on: html
  243. !
  244. renderListOn: html
  245. (self getRootClassesOf: self items)
  246. do: [ :each | self renderItem: each on: html ]
  247. ! !
  248. HLBrowserListWidget subclass: #HLMethodsListWidget
  249. instanceVariableNames: ''
  250. package: 'Helios-Browser'!
  251. !HLMethodsListWidget methodsFor: 'accessing'!
  252. allProtocol
  253. ^ self model allProtocol
  254. !
  255. iconForItem: aSelector
  256. | override overriden method |
  257. method := self methodForSelector: aSelector.
  258. override := self isOverride: method.
  259. overriden := self isOverridden: method.
  260. ^ override
  261. ifTrue: [ overriden
  262. ifTrue: [ 'icon-resize-vertical' ]
  263. ifFalse: [ 'icon-arrow-up' ] ]
  264. ifFalse: [
  265. overriden
  266. ifTrue: [ 'icon-arrow-down' ]
  267. ifFalse: [ 'icon-none' ] ]
  268. !
  269. methodForSelector: aSelector
  270. ^ self model selectedClass
  271. methodDictionary at: aSelector
  272. !
  273. methodsInProtocol: aString
  274. self model selectedClass ifNil: [ ^ #() ].
  275. ^ aString = self allProtocol
  276. ifTrue: [ self model selectedClass methods ]
  277. ifFalse: [ self model selectedClass methodsInProtocol: aString ]
  278. !
  279. overrideSelectors
  280. ^ self selectorsCache
  281. at: 'override'
  282. ifAbsentPut: [
  283. self model selectedClass allSuperclasses
  284. inject: Set new into: [ :acc :each | acc addAll: each selectors; yourself ] ]
  285. !
  286. overridenSelectors
  287. ^ self selectorsCache
  288. at: 'overriden'
  289. ifAbsentPut: [
  290. self model selectedClass allSubclasses
  291. inject: Set new into: [ :acc :each | acc addAll: each selectors; yourself ] ]
  292. !
  293. selectorsCache
  294. ^ self class selectorsCache
  295. !
  296. selectorsInProtocol: aString
  297. ^ (self methodsInProtocol: aString)
  298. collect: [ :each | each selector ]
  299. ! !
  300. !HLMethodsListWidget methodsFor: 'actions'!
  301. observeModel
  302. self model announcer on: HLProtocolSelected do: [ :ann |
  303. self onProtocolSelected: ann item ].
  304. self model announcer on: HLShowInstanceToggled do: [ :ann |
  305. self onProtocolSelected: nil ].
  306. self model announcer on: HLMethodSelected do: [ :ann |
  307. self onMethodSelected: ann item ]
  308. !
  309. observeSystem
  310. SystemAnnouncer current
  311. on: MethodAdded
  312. do: [ :ann | self onMethodAdded: ann method ];
  313. on: MethodRemoved
  314. do: [ :ann | self onMethodRemoved: ann method ]
  315. !
  316. selectItem: aSelector
  317. aSelector ifNil: [ ^ self model selectedMethod: nil ].
  318. self model selectedMethod: (self methodForSelector: aSelector)
  319. ! !
  320. !HLMethodsListWidget methodsFor: 'cache'!
  321. flushSelectorsCache
  322. selectorsCache := Dictionary new
  323. ! !
  324. !HLMethodsListWidget methodsFor: 'initialization'!
  325. initialize
  326. super initialize.
  327. self flushSelectorsCache
  328. ! !
  329. !HLMethodsListWidget methodsFor: 'private'!
  330. setItemsForProtocol: aString
  331. ^ self items: (aString
  332. ifNil: [ #() ]
  333. ifNotNil: [ self selectorsInProtocol: aString ])
  334. !
  335. setItemsForSelectedProtocol
  336. self setItemsForProtocol: self model selectedProtocol
  337. ! !
  338. !HLMethodsListWidget methodsFor: 'reactions'!
  339. onMethodAdded: aMethod
  340. self model selectedClass = aMethod methodClass ifFalse: [ ^ self ].
  341. self setItemsForSelectedProtocol.
  342. self refresh
  343. !
  344. onMethodRemoved: aMethod
  345. self items detect: [ :each | each = aMethod selector ] ifNone: [ ^ self ].
  346. self selectedItem ifNotNil: [
  347. (aMethod methodClass = self model selectedClass and: [ aMethod selector = self selectedItem selector ])
  348. ifTrue: [ self selectItem: nil ] ].
  349. self setItemsForSelectedProtocol.
  350. self refresh
  351. !
  352. onMethodSelected: aMethod
  353. self selectedItem: aMethod.
  354. aMethod ifNil: [ ^ self ].
  355. self focus
  356. !
  357. onProtocolSelected: aString
  358. self selectedItem: nil.
  359. self setItemsForSelectedProtocol.
  360. self refresh
  361. ! !
  362. !HLMethodsListWidget methodsFor: 'rendering'!
  363. renderContentOn: html
  364. self model showInstance
  365. ifFalse: [ html div
  366. class: 'class_side';
  367. with: [ super renderContentOn: html ] ]
  368. ifTrue: [ super renderContentOn: html ]
  369. !
  370. renderItemLabel: aSelector on: html
  371. html with: aSelector
  372. ! !
  373. !HLMethodsListWidget methodsFor: 'testing'!
  374. isOverridden: aMethod
  375. ^ self selectorsCache isOverridden: aMethod
  376. !
  377. isOverride: aMethod
  378. ^ self selectorsCache isOverride: aMethod
  379. ! !
  380. HLMethodsListWidget class instanceVariableNames: 'selectorsCache'!
  381. !HLMethodsListWidget class methodsFor: 'accessing'!
  382. selectorsCache
  383. ^ HLSelectorsCache current
  384. ! !
  385. HLBrowserListWidget subclass: #HLPackagesListWidget
  386. instanceVariableNames: ''
  387. package: 'Helios-Browser'!
  388. !HLPackagesListWidget methodsFor: 'accessing'!
  389. initializeItems
  390. ^ items := self model packages sort:[:a :b|
  391. a name < b name]
  392. !
  393. items
  394. ^ items ifNil: [self initializeItems]
  395. ! !
  396. !HLPackagesListWidget methodsFor: 'actions'!
  397. focusClassesListWidget
  398. self model announcer announce: HLClassesListFocus new
  399. !
  400. observeModel
  401. self model announcer on: HLPackageSelected do: [ :ann |
  402. self onPackageSelected: ann item ]
  403. !
  404. selectItem: aPackage
  405. self model selectedPackage: aPackage
  406. ! !
  407. !HLPackagesListWidget methodsFor: 'reactions'!
  408. onPackageSelected: aPackage
  409. self selectedItem: aPackage.
  410. self focus
  411. ! !
  412. !HLPackagesListWidget methodsFor: 'rendering'!
  413. renderButtonsOn: html
  414. html span class: 'info'; with: 'Auto commit'.
  415. html div
  416. class: 'btn-group switch';
  417. at: 'data-toggle' put: 'buttons-radio';
  418. with: [
  419. html button
  420. class: (String streamContents: [ :str |
  421. str nextPutAll: 'btn' ]);
  422. with: 'On'.
  423. html button
  424. class: (String streamContents: [ :str |
  425. str nextPutAll: 'btn active' ]);
  426. with: 'Off' ].
  427. html a
  428. class: 'btn';
  429. with: 'Commit'.
  430. ! !
  431. HLBrowserListWidget subclass: #HLProtocolsListWidget
  432. instanceVariableNames: ''
  433. package: 'Helios-Browser'!
  434. !HLProtocolsListWidget methodsFor: 'accessing'!
  435. allProtocol
  436. ^ self model allProtocol
  437. !
  438. selectedItem
  439. ^ super selectedItem" ifNil: [ self allProtocol ]"
  440. ! !
  441. !HLProtocolsListWidget methodsFor: 'actions'!
  442. observeModel
  443. self model announcer on: HLClassSelected do: [ :ann |
  444. self onClassSelected: ann item ].
  445. self model announcer on: HLShowInstanceToggled do: [ :ann |
  446. self onClassSelected: self model selectedClass ].
  447. self model announcer on: HLProtocolSelected do: [ :ann |
  448. self onProtocolSelected: ann item ]
  449. !
  450. selectItem: aString
  451. self model selectedProtocol: aString
  452. ! !
  453. !HLProtocolsListWidget methodsFor: 'reactions'!
  454. onClassSelected: aClass
  455. self selectedItem: nil.
  456. self items: (aClass
  457. ifNil: [ Array with: self allProtocol ]
  458. ifNotNil: [
  459. (Array with: self allProtocol)
  460. addAll: aClass protocols;
  461. yourself ]).
  462. self refresh
  463. !
  464. onProtocolSelected: aString
  465. self selectedItem: aString.
  466. aString ifNil: [ ^ self ].
  467. self focus
  468. ! !
  469. !HLProtocolsListWidget methodsFor: 'rendering'!
  470. renderContentOn: html
  471. self model showInstance
  472. ifFalse: [ html div
  473. class: 'class_side';
  474. with: [ super renderContentOn: html ] ]
  475. ifTrue: [ super renderContentOn: html ]
  476. ! !
  477. Object subclass: #HLBrowserModel
  478. instanceVariableNames: 'announcer environment selectedPackage selectedClass selectedProtocol selectedSelector showInstance showComment'
  479. package: 'Helios-Browser'!
  480. !HLBrowserModel methodsFor: 'accessing'!
  481. allProtocol
  482. ^ '-- All --'
  483. !
  484. announcer
  485. ^ announcer ifNil: [ announcer := Announcer new ]
  486. !
  487. environment
  488. ^ environment ifNil: [ HLManager current environment ]
  489. !
  490. environment: anEnvironment
  491. environment := anEnvironment
  492. !
  493. packages
  494. ^ self environment packages
  495. !
  496. selectedClass
  497. ^ selectedClass
  498. !
  499. selectedClass: aClass
  500. selectedClass = aClass ifTrue: [ ^ self ].
  501. aClass
  502. ifNil: [ selectedClass := nil ]
  503. ifNotNil: [
  504. self showInstance
  505. ifTrue: [ selectedClass := aClass theNonMetaClass ]
  506. ifFalse: [ selectedClass := aClass theMetaClass ] ].
  507. self selectedProtocol: nil.
  508. self announcer announce: (HLClassSelected on: self selectedClass)
  509. !
  510. selectedMethod
  511. ^ self selectedClass
  512. ifNotNil: [ self selectedClass methodDictionary at: selectedSelector ]
  513. !
  514. selectedMethod: aCompiledMethod
  515. selectedSelector = aCompiledMethod ifTrue: [ ^ self ].
  516. aCompiledMethod
  517. ifNil: [ selectedSelector := nil ]
  518. ifNotNil: [
  519. selectedSelector = aCompiledMethod selector ifTrue: [ ^ self ].
  520. selectedSelector := aCompiledMethod selector ].
  521. self announcer announce: (HLMethodSelected on: aCompiledMethod)
  522. !
  523. selectedPackage
  524. ^ selectedPackage
  525. !
  526. selectedPackage: aPackage
  527. selectedPackage = aPackage ifTrue: [ ^ self ].
  528. selectedPackage := aPackage.
  529. self selectedClass: nil.
  530. self announcer announce: (HLPackageSelected on: aPackage)
  531. !
  532. selectedProtocol
  533. ^ selectedProtocol
  534. !
  535. selectedProtocol: aString
  536. selectedProtocol = aString ifTrue: [ ^ self ].
  537. selectedProtocol := aString.
  538. self selectedMethod: nil.
  539. self announcer announce: (HLProtocolSelected on: aString)
  540. !
  541. showComment
  542. ^ showComment ifNil: [ false ]
  543. !
  544. showComment: aBoolean
  545. showComment := aBoolean.
  546. self announcer announce: HLShowCommentToggled new
  547. !
  548. showInstance
  549. ^ showInstance ifNil: [ true ]
  550. !
  551. showInstance: aBoolean
  552. showInstance := aBoolean.
  553. self selectedClass ifNotNil: [
  554. self selectedClass: (aBoolean
  555. ifTrue: [self selectedClass theNonMetaClass ]
  556. ifFalse: [ self selectedClass theMetaClass ]) ].
  557. self announcer announce: HLShowInstanceToggled new
  558. ! !
  559. !HLBrowserModel class methodsFor: 'actions'!
  560. on: anEnvironment
  561. ^ self new
  562. environment: anEnvironment;
  563. yourself
  564. ! !
  565. HLWidget subclass: #HLBrowserSourceWidget
  566. instanceVariableNames: 'model methodContents codeWidget'
  567. package: 'Helios-Browser'!
  568. !HLBrowserSourceWidget methodsFor: 'accessing'!
  569. codeWidget
  570. ^ codeWidget ifNil: [ codeWidget := HLCodeWidget new ]
  571. !
  572. contents
  573. ^ self codeWidget contents
  574. !
  575. contents: aString
  576. self methodContents: aString.
  577. self codeWidget contents: aString
  578. !
  579. methodContents
  580. ^ methodContents ifNil: [ methodContents := '' ]
  581. !
  582. methodContents: aString
  583. methodContents := aString
  584. !
  585. model
  586. ^ model
  587. !
  588. model: aBrowserModel
  589. model := aBrowserModel.
  590. self observeModel
  591. ! !
  592. !HLBrowserSourceWidget methodsFor: 'actions'!
  593. observeModel
  594. self model announcer on: HLMethodSelected do: [ :ann |
  595. self onMethodSelected: ann item ].
  596. self model announcer on: HLClassSelected do: [ :ann |
  597. self onClassSelected: ann item ].
  598. self model announcer on: HLProtocolSelected do: [ :ann |
  599. self onProtocolSelected: ann item ]
  600. !
  601. observeSystem
  602. SystemAnnouncer current
  603. on: MethodModified
  604. do: [ :ann | self onMethodModified: ann method ]
  605. ! !
  606. !HLBrowserSourceWidget methodsFor: 'initialization'!
  607. initialize
  608. super initialize.
  609. self observeSystem
  610. ! !
  611. !HLBrowserSourceWidget methodsFor: 'reactions'!
  612. onClassSelected: aClass
  613. aClass ifNil: [ ^ self contents: '' ].
  614. self contents: aClass definition
  615. !
  616. onMethodModified: aMethod
  617. self model selectedClass = aMethod methodClass ifFalse: [ ^ self ].
  618. self model selectedMethod selector = aMethod selector ifFalse: [ ^ self ].
  619. self refresh
  620. !
  621. onMethodSelected: aCompiledMethod
  622. aCompiledMethod ifNil: [ ^ self contents: '' ].
  623. self contents: aCompiledMethod source
  624. !
  625. onProtocolSelected: aString
  626. self model selectedClass ifNil: [ ^ self contents: '' ].
  627. self contents: self model selectedClass definition
  628. ! !
  629. !HLBrowserSourceWidget methodsFor: 'rendering'!
  630. renderContentOn: html
  631. self codeWidget renderOn: html
  632. ! !
  633. !HLBrowserSourceWidget methodsFor: 'testing'!
  634. hasModification
  635. ^ (self methodContents = self contents) not
  636. ! !
  637. !HLBrowserSourceWidget methodsFor: 'updating'!
  638. refresh
  639. self hasModification ifTrue: [ ^ self ].
  640. self contents: self model selectedMethod source.
  641. super refresh
  642. ! !
  643. !HLBrowserSourceWidget class methodsFor: 'instance creation'!
  644. on: aBrowserModel
  645. ^ self new
  646. model: aBrowserModel;
  647. yourself
  648. ! !
  649. Object subclass: #HLClassCache
  650. instanceVariableNames: 'class selectorsCache overrideCache overriddenCache'
  651. package: 'Helios-Browser'!
  652. !HLClassCache methodsFor: 'accessing'!
  653. overriddenCache
  654. ^ overriddenCache ifNil: [ overriddenCache := HashedCollection new ]
  655. !
  656. overrideCache
  657. ^ overrideCache ifNil: [ overrideCache := HashedCollection new ]
  658. !
  659. selectorsCache
  660. ^ selectorsCache
  661. !
  662. selectorsCache: aCache
  663. selectorsCache := aCache
  664. !
  665. theClass
  666. ^ class
  667. !
  668. theClass: aClass
  669. class := aClass
  670. ! !
  671. !HLClassCache methodsFor: 'actions'!
  672. invalidateChildrenSelector: aSelector
  673. self theClass subclasses do: [ :each |
  674. (self selectorsCache cacheFor: each)
  675. removeSelector: aSelector;
  676. invalidateChildrenSelector: aSelector ]
  677. !
  678. invalidateParentSelector: aSelector
  679. self theClass superclass ifNotNil: [
  680. (self selectorsCache cacheFor: self theClass superclass)
  681. removeSelector: aSelector;
  682. invalidateParentSelector: aSelector ]
  683. !
  684. invalidateSelector: aSelector
  685. self
  686. invalidateParentSelector: aSelector;
  687. invalidateChildrenSelector: aSelector;
  688. removeSelector: aSelector
  689. ! !
  690. !HLClassCache methodsFor: 'private'!
  691. removeSelector: aSelector
  692. self overriddenCache
  693. removeKey: aSelector
  694. ifAbsent: [ ].
  695. self overrideCache
  696. removeKey: aSelector
  697. ifAbsent: [ ]
  698. ! !
  699. !HLClassCache methodsFor: 'testing'!
  700. isOverridden: aMethod
  701. ^ self overriddenCache
  702. at: aMethod selector
  703. ifAbsentPut: [ aMethod isOverridden ]
  704. !
  705. isOverride: aMethod
  706. ^ self overrideCache
  707. at: aMethod selector
  708. ifAbsentPut: [ aMethod isOverride ]
  709. ! !
  710. !HLClassCache class methodsFor: 'instance creation'!
  711. on: aClass selectorsCache: aSelectorsCache
  712. ^ self new
  713. theClass: aClass;
  714. selectorsCache: aSelectorsCache;
  715. yourself
  716. ! !
  717. Object subclass: #HLSelectorsCache
  718. instanceVariableNames: 'classesCache'
  719. package: 'Helios-Browser'!
  720. !HLSelectorsCache methodsFor: 'accessing'!
  721. cacheFor: aClass
  722. aClass ifNil: [ ^ nil ].
  723. ^ self classesCache
  724. at: aClass name
  725. ifAbsentPut: [ self newCacheFor: aClass ]
  726. !
  727. classesCache
  728. ^ classesCache ifNil: [ classesCache := HashedCollection new ]
  729. ! !
  730. !HLSelectorsCache methodsFor: 'actions'!
  731. observeSystem
  732. SystemAnnouncer current
  733. on: MethodAdded
  734. do: [ :ann | self onMethodAdded: ann method ];
  735. on: MethodRemoved
  736. do: [ :ann | self onMethodRemoved: ann method ]
  737. ! !
  738. !HLSelectorsCache methodsFor: 'factory'!
  739. newCacheFor: aClass
  740. ^ HLClassCache
  741. on: aClass
  742. selectorsCache: self
  743. ! !
  744. !HLSelectorsCache methodsFor: 'initialization'!
  745. initialize
  746. super initialize.
  747. self observeSystem
  748. ! !
  749. !HLSelectorsCache methodsFor: 'private'!
  750. invalidateCacheFor: aMethod
  751. (self cacheFor: aMethod methodClass)
  752. invalidateSelector: aMethod selector
  753. ! !
  754. !HLSelectorsCache methodsFor: 'reactions'!
  755. onMethodAdded: aMethod
  756. self invalidateCacheFor: aMethod
  757. !
  758. onMethodRemoved: aMethod
  759. self invalidateCacheFor: aMethod
  760. ! !
  761. !HLSelectorsCache methodsFor: 'testing'!
  762. isOverridden: aMethod
  763. ^ (self cacheFor: aMethod methodClass)
  764. isOverridden: aMethod
  765. !
  766. isOverride: aMethod
  767. ^ (self cacheFor: aMethod methodClass)
  768. isOverride: aMethod
  769. ! !
  770. HLSelectorsCache class instanceVariableNames: 'current'!
  771. !HLSelectorsCache class methodsFor: 'accessing'!
  772. current
  773. ^ current ifNil: [ current := super new ]
  774. !
  775. flush
  776. current := nil
  777. ! !
  778. !HLSelectorsCache class methodsFor: 'instance creation'!
  779. new
  780. self shouldNotImplement
  781. ! !
  782. !CompiledMethod methodsFor: '*Helios-Browser'!
  783. isOverridden
  784. | selector |
  785. selector := self selector.
  786. self methodClass allSubclassesDo: [ :each |
  787. (each includesSelector: selector)
  788. ifTrue: [ ^ true ] ].
  789. ^ false
  790. !
  791. isOverride
  792. | superclass |
  793. superclass := self methodClass superclass.
  794. superclass ifNil: [ ^ false ].
  795. ^ (self methodClass superclass lookupSelector: self selector) notNil
  796. ! !