Helios-Browser.st 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297
  1. Smalltalk current createPackage: 'Helios-Browser'!
  2. HLWidget subclass: #HLBrowser
  3. instanceVariableNames: 'model built 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: 'initialization'!
  19. initialize
  20. super initialize.
  21. built := false
  22. ! !
  23. !HLBrowser methodsFor: 'keybindings'!
  24. registerBindingsOn: aBindingGroup
  25. HLBrowserCommand registerConcreteClassesOn: aBindingGroup for: self model
  26. "aBindingGroup
  27. addGroupKey: 66 labelled: 'Browse';
  28. addGroupKey: 71 labelled: 'Go to';
  29. addGroupKey: 84 labelled: 'Toggle';
  30. addGroupKey: 77 labelled: 'Move'.
  31. (aBindingGroup at: 'Move')
  32. addGroupKey: 77 labelled: 'Method';
  33. addGroupKey: 67 labelled: 'Class';
  34. addGroupKey: 80 labelled: 'Protocol'.
  35. HLMoveMethodToCommand concreteClasses do: [ :each |
  36. (aBindingGroup at: 'Move')
  37. at: each bindingGroup
  38. add: (each on: self model) asBinding ].
  39. HLBrowserCommand concreteClasses do: [ :each |
  40. aBindingGroup
  41. at: each bindingGroup
  42. add: (each on: self model) asBinding ]"
  43. ! !
  44. !HLBrowser methodsFor: 'rendering'!
  45. renderContentOn: html
  46. html with: (HLContainer with: (HLHorizontalSplitter
  47. with: (HLVerticalSplitter
  48. with: (HLVerticalSplitter
  49. with: self packagesListWidget
  50. with: self classesListWidget)
  51. with: (HLVerticalSplitter
  52. with: self protocolsListWidget
  53. with: self methodsListWidget))
  54. with: self sourceWidget)).
  55. built ifFalse: [
  56. self packagesListWidget focus.
  57. built := true ]
  58. ! !
  59. !HLBrowser methodsFor: 'widgets'!
  60. classesListWidget
  61. ^ classesListWidget ifNil: [
  62. classesListWidget := HLClassesListWidget on: self model.
  63. classesListWidget next: self protocolsListWidget ]
  64. !
  65. methodsListWidget
  66. ^ methodsListWidget ifNil: [
  67. methodsListWidget := HLMethodsListWidget on: self model ]
  68. !
  69. packagesListWidget
  70. ^ packagesListWidget ifNil: [
  71. packagesListWidget := HLPackagesListWidget on: self model.
  72. packagesListWidget next: self classesListWidget ]
  73. !
  74. protocolsListWidget
  75. ^ protocolsListWidget ifNil: [
  76. protocolsListWidget := HLProtocolsListWidget on: self model.
  77. protocolsListWidget next: self methodsListWidget ]
  78. !
  79. sourceWidget
  80. ^ sourceWidget ifNil: [
  81. sourceWidget := HLBrowserSourceWidget on: self model ]
  82. ! !
  83. HLBrowser class instanceVariableNames: 'nextId'!
  84. !HLBrowser class methodsFor: 'accessing'!
  85. nextId
  86. nextId ifNil: [ nextId := 0 ].
  87. ^ 'browser_', (nextId + 1) asString
  88. !
  89. tabLabel
  90. ^ 'Browser'
  91. !
  92. tabPriority
  93. ^ 0
  94. ! !
  95. !HLBrowser class methodsFor: 'testing'!
  96. canBeOpenAsTab
  97. ^ true
  98. ! !
  99. HLNavigationListWidget subclass: #HLBrowserListWidget
  100. instanceVariableNames: 'model'
  101. package: 'Helios-Browser'!
  102. !HLBrowserListWidget methodsFor: 'accessing'!
  103. model
  104. ^ model
  105. !
  106. model: aBrowserModel
  107. model := aBrowserModel.
  108. self observeModel
  109. ! !
  110. !HLBrowserListWidget methodsFor: 'actions'!
  111. observeModel
  112. !
  113. observeSystem
  114. ! !
  115. !HLBrowserListWidget methodsFor: 'initialization'!
  116. initialize
  117. super initialize.
  118. self observeSystem
  119. ! !
  120. !HLBrowserListWidget class methodsFor: 'instance creation'!
  121. on: aModel
  122. ^ self new
  123. model: aModel;
  124. yourself
  125. ! !
  126. HLBrowserListWidget subclass: #HLClassesListWidget
  127. instanceVariableNames: ''
  128. package: 'Helios-Browser'!
  129. !HLClassesListWidget methodsFor: 'accessing'!
  130. getChildrenOf: aClass
  131. ^ self items select: [ :each | each superclass = aClass ]
  132. !
  133. getRootClassesOf: aCollection
  134. ^ aCollection select: [ :each |
  135. (aCollection includes: each superclass) not ]
  136. !
  137. iconForItem: aClass
  138. ^ aClass theNonMetaClass comment isEmpty
  139. ifFalse: [ 'icon-none' ]
  140. ifTrue: [ 'icon-question-sign' ]
  141. !
  142. showInstance
  143. ^ self model showInstance
  144. ! !
  145. !HLClassesListWidget methodsFor: 'actions'!
  146. focusMethodsListWidget
  147. self model announcer announce: HLMethodsListFocus new
  148. !
  149. focusProtocolsListWidget
  150. self model announcer announce: HLProtocolsListFocus new
  151. !
  152. observeModel
  153. self model announcer
  154. on: HLPackageSelected do: [ :ann | self onPackageSelected: ann item ];
  155. on: HLShowInstanceToggled do: [ :ann | self onShowInstanceToggled ];
  156. on: HLClassSelected do: [ :ann | self onClassSelected: ann item ];
  157. on: HLClassesFocusRequested do: [ :ann | self onClassesFocusRequested ]
  158. !
  159. observeSystem
  160. SystemAnnouncer current
  161. on: ClassAdded
  162. do: [ :ann | self onClassAdded: ann theClass ];
  163. on: ClassRemoved
  164. do: [ :ann | self onClassRemoved: ann theClass ]
  165. !
  166. selectItem: aClass
  167. self model selectedClass: aClass
  168. !
  169. showInstance: aBoolean
  170. self model showInstance: aBoolean
  171. ! !
  172. !HLClassesListWidget methodsFor: 'private'!
  173. setItemsForPackage: aPackage
  174. self items: (aPackage
  175. ifNil: [ #() ]
  176. ifNotNil: [ ((aPackage classes
  177. collect: [ :each | each theNonMetaClass ]) asSet asArray)
  178. sort: [:a :b | a name < b name ] ]).
  179. !
  180. setItemsForSelectedPackage
  181. self setItemsForPackage: self model selectedPackage
  182. ! !
  183. !HLClassesListWidget methodsFor: 'reactions'!
  184. onClassAdded: aClass
  185. aClass package = self model selectedPackage ifFalse: [ ^ self ].
  186. self setItemsForSelectedPackage.
  187. self refresh
  188. !
  189. onClassRemoved: aClass
  190. aClass package = self model selectedPackage ifFalse: [ ^ self ].
  191. aClass = self model selectedClass ifTrue: [ self selectItem: nil ].
  192. self setItemsForSelectedPackage.
  193. self refresh
  194. !
  195. onClassSelected: aClass
  196. self selectedItem: aClass.
  197. aClass ifNil: [ ^ self ].
  198. self focus
  199. !
  200. onClassesFocusRequested
  201. self focus
  202. !
  203. onPackageSelected: aPackage
  204. self selectedItem: nil.
  205. self setItemsForSelectedPackage.
  206. self refresh
  207. !
  208. onShowInstanceToggled
  209. self refresh
  210. ! !
  211. !HLClassesListWidget methodsFor: 'rendering'!
  212. renderButtonsOn: html
  213. html div
  214. class: 'btn-group';
  215. at: 'data-toggle' put: 'buttons-radio';
  216. with: [
  217. html button
  218. class: (String streamContents: [ :str |
  219. str nextPutAll: 'btn'.
  220. self showInstance ifTrue: [
  221. str nextPutAll: ' active'] ]);
  222. with: 'Instance';
  223. onClick: [ self showInstance: true ].
  224. html button
  225. class: (String streamContents: [ :str |
  226. str nextPutAll: 'btn'.
  227. self model showInstance ifFalse: [
  228. str nextPutAll: ' active'] ]);
  229. with: 'Class';
  230. onClick: [ self model showInstance: false ] ].
  231. html button
  232. class: 'btn';
  233. at: 'data-toggle' put: 'button';
  234. with: 'Comment'
  235. !
  236. renderItem: aClass level: anInteger on: html
  237. | li |
  238. li := html li.
  239. li
  240. at: 'list-data' put: (self items indexOf: aClass);
  241. class: (self cssClassForItem: aClass);
  242. with: [
  243. html a
  244. with: [
  245. (html tag: 'i') class: (self iconForItem: aClass).
  246. self renderItemLabel: aClass level: anInteger on: html ];
  247. onClick: [
  248. self activateListItem: li asJQuery ] ].
  249. (self getChildrenOf: aClass) do: [ :each |
  250. self renderItem: each level: anInteger + 1 on: html ]
  251. !
  252. renderItem: aClass on: html
  253. super renderItem: aClass on: html.
  254. (self getChildrenOf: aClass) do: [ :each |
  255. self renderItem: each level: 1 on: html ]
  256. !
  257. renderItemLabel: aClass level: anInteger on: html
  258. html span asJQuery html: (String streamContents: [ :str |
  259. anInteger timesRepeat: [
  260. str nextPutAll: '&nbsp;&nbsp;&nbsp;&nbsp;'].
  261. str nextPutAll: aClass name ])
  262. !
  263. renderItemLabel: aClass on: html
  264. self renderItemLabel: aClass level: 0 on: html
  265. !
  266. renderListOn: html
  267. (self getRootClassesOf: self items)
  268. do: [ :each | self renderItem: each on: html ]
  269. ! !
  270. HLBrowserListWidget subclass: #HLMethodsListWidget
  271. instanceVariableNames: ''
  272. package: 'Helios-Browser'!
  273. !HLMethodsListWidget methodsFor: 'accessing'!
  274. allProtocol
  275. ^ self model allProtocol
  276. !
  277. iconForItem: aSelector
  278. | override overriden method |
  279. method := self methodForSelector: aSelector.
  280. override := self isOverride: method.
  281. overriden := self isOverridden: method.
  282. ^ override
  283. ifTrue: [ overriden
  284. ifTrue: [ 'icon-resize-vertical' ]
  285. ifFalse: [ 'icon-arrow-up' ] ]
  286. ifFalse: [
  287. overriden
  288. ifTrue: [ 'icon-arrow-down' ]
  289. ifFalse: [ 'icon-none' ] ]
  290. !
  291. methodForSelector: aSelector
  292. ^ self model selectedClass
  293. methodDictionary at: aSelector
  294. !
  295. methodsInProtocol: aString
  296. self model selectedClass ifNil: [ ^ #() ].
  297. ^ aString = self allProtocol
  298. ifTrue: [ self model selectedClass methods ]
  299. ifFalse: [ self model selectedClass methodsInProtocol: aString ]
  300. !
  301. overrideSelectors
  302. ^ self selectorsCache
  303. at: 'override'
  304. ifAbsentPut: [
  305. self model selectedClass allSuperclasses
  306. inject: Set new into: [ :acc :each | acc addAll: each selectors; yourself ] ]
  307. !
  308. overridenSelectors
  309. ^ self selectorsCache
  310. at: 'overriden'
  311. ifAbsentPut: [
  312. self model selectedClass allSubclasses
  313. inject: Set new into: [ :acc :each | acc addAll: each selectors; yourself ] ]
  314. !
  315. selectorsCache
  316. ^ self class selectorsCache
  317. !
  318. selectorsInProtocol: aString
  319. ^ (self methodsInProtocol: aString)
  320. collect: [ :each | each selector ]
  321. ! !
  322. !HLMethodsListWidget methodsFor: 'actions'!
  323. observeModel
  324. self model announcer
  325. on: HLProtocolSelected
  326. do: [ :ann | self onProtocolSelected: ann item ];
  327. on: HLShowInstanceToggled
  328. do: [ :ann | self onProtocolSelected: nil ];
  329. on: HLMethodSelected
  330. do: [ :ann | self onMethodSelected: ann item ];
  331. on: HLMethodsFocusRequested
  332. do: [ :ann | self onMethodsFocusRequested ]
  333. !
  334. observeSystem
  335. SystemAnnouncer current
  336. on: MethodAdded
  337. do: [ :ann | self onMethodAdded: ann method ];
  338. on: MethodRemoved
  339. do: [ :ann | self onMethodRemoved: ann method ]
  340. !
  341. selectItem: aSelector
  342. aSelector ifNil: [ ^ self model selectedMethod: nil ].
  343. self model selectedMethod: (self methodForSelector: aSelector)
  344. ! !
  345. !HLMethodsListWidget methodsFor: 'cache'!
  346. flushSelectorsCache
  347. selectorsCache := Dictionary new
  348. ! !
  349. !HLMethodsListWidget methodsFor: 'initialization'!
  350. initialize
  351. super initialize.
  352. self flushSelectorsCache
  353. ! !
  354. !HLMethodsListWidget methodsFor: 'private'!
  355. setItemsForProtocol: aString
  356. ^ self items: (aString
  357. ifNil: [ #() ]
  358. ifNotNil: [ self selectorsInProtocol: aString ])
  359. !
  360. setItemsForSelectedProtocol
  361. self setItemsForProtocol: self model selectedProtocol
  362. ! !
  363. !HLMethodsListWidget methodsFor: 'reactions'!
  364. onMethodAdded: aMethod
  365. self model selectedClass = aMethod methodClass ifFalse: [ ^ self ].
  366. self setItemsForSelectedProtocol.
  367. self refresh
  368. !
  369. onMethodRemoved: aMethod
  370. self items detect: [ :each | each = aMethod selector ] ifNone: [ ^ self ].
  371. self selectedItem ifNotNil: [
  372. (aMethod methodClass = self model selectedClass and: [ aMethod selector = self selectedItem selector ])
  373. ifTrue: [ self selectItem: nil ] ].
  374. self setItemsForSelectedProtocol.
  375. self refresh
  376. !
  377. onMethodSelected: aMethod
  378. self selectedItem: aMethod.
  379. aMethod ifNil: [ ^ self ].
  380. self focus
  381. !
  382. onMethodsFocusRequested
  383. self focus
  384. !
  385. onProtocolSelected: aString
  386. self selectedItem: nil.
  387. self setItemsForSelectedProtocol.
  388. self refresh
  389. ! !
  390. !HLMethodsListWidget methodsFor: 'rendering'!
  391. renderContentOn: html
  392. self model showInstance
  393. ifFalse: [ html div
  394. class: 'class_side';
  395. with: [ super renderContentOn: html ] ]
  396. ifTrue: [ super renderContentOn: html ]
  397. !
  398. renderItemLabel: aSelector on: html
  399. html with: aSelector
  400. ! !
  401. !HLMethodsListWidget methodsFor: 'testing'!
  402. isOverridden: aMethod
  403. ^ self selectorsCache isOverridden: aMethod
  404. !
  405. isOverride: aMethod
  406. ^ self selectorsCache isOverride: aMethod
  407. ! !
  408. HLMethodsListWidget class instanceVariableNames: 'selectorsCache'!
  409. !HLMethodsListWidget class methodsFor: 'accessing'!
  410. selectorsCache
  411. ^ HLSelectorsCache current
  412. ! !
  413. HLBrowserListWidget subclass: #HLPackagesListWidget
  414. instanceVariableNames: ''
  415. package: 'Helios-Browser'!
  416. !HLPackagesListWidget methodsFor: 'accessing'!
  417. initializeItems
  418. ^ items := self model packages sort:[:a :b|
  419. a name < b name]
  420. !
  421. items
  422. ^ items ifNil: [self initializeItems]
  423. ! !
  424. !HLPackagesListWidget methodsFor: 'actions'!
  425. focusClassesListWidget
  426. self model announcer announce: HLClassesListFocus new
  427. !
  428. observeModel
  429. self model announcer
  430. on: HLPackageSelected
  431. do: [ :ann | self onPackageSelected: ann item ];
  432. on: HLPackagesFocusRequested
  433. do: [ :ann | self onPackagesFocusRequested ]
  434. !
  435. selectItem: aPackage
  436. self model selectedPackage: aPackage
  437. ! !
  438. !HLPackagesListWidget methodsFor: 'reactions'!
  439. onPackageSelected: aPackage
  440. self selectedItem: aPackage.
  441. self focus
  442. !
  443. onPackagesFocusRequested
  444. self focus
  445. ! !
  446. !HLPackagesListWidget methodsFor: 'rendering'!
  447. renderButtonsOn: html
  448. html span class: 'info'; with: 'Auto commit'.
  449. html div
  450. class: 'btn-group switch';
  451. at: 'data-toggle' put: 'buttons-radio';
  452. with: [
  453. html button
  454. class: (String streamContents: [ :str |
  455. str nextPutAll: 'btn' ]);
  456. with: 'On'.
  457. html button
  458. class: (String streamContents: [ :str |
  459. str nextPutAll: 'btn active' ]);
  460. with: 'Off' ].
  461. html a
  462. class: 'btn';
  463. with: 'Commit'.
  464. ! !
  465. HLBrowserListWidget subclass: #HLProtocolsListWidget
  466. instanceVariableNames: ''
  467. package: 'Helios-Browser'!
  468. !HLProtocolsListWidget methodsFor: 'accessing'!
  469. allProtocol
  470. ^ self model allProtocol
  471. !
  472. selectedItem
  473. ^ super selectedItem" ifNil: [ self allProtocol ]"
  474. ! !
  475. !HLProtocolsListWidget methodsFor: 'actions'!
  476. observeModel
  477. self model announcer
  478. on: HLClassSelected
  479. do: [ :ann | self onClassSelected: ann item ];
  480. on: HLShowInstanceToggled
  481. do: [ :ann | self onClassSelected: self model selectedClass ];
  482. on: HLProtocolSelected
  483. do: [ :ann | self onProtocolSelected: ann item ];
  484. on: HLProtocolsFocusRequested
  485. do: [ :ann | self onProtocolsFocusRequested ]
  486. !
  487. observeSystem
  488. SystemAnnouncer current
  489. on: ProtocolAdded
  490. do: [ :ann | self onProtocolAdded: ann protocol to: ann theClass ];
  491. on: ProtocolRemoved
  492. do: [ :ann | self onProtocolRemoved: ann protocol from: ann theClass ]
  493. !
  494. selectItem: aString
  495. self model selectedProtocol: aString
  496. ! !
  497. !HLProtocolsListWidget methodsFor: 'private'!
  498. setItemsForClass: aClass
  499. self items: (aClass
  500. ifNil: [ Array with: self allProtocol ]
  501. ifNotNil: [
  502. (Array with: self allProtocol)
  503. addAll: aClass protocols;
  504. yourself ])
  505. !
  506. setItemsForSelectedClass
  507. self setItemsForClass: self model selectedClass
  508. ! !
  509. !HLProtocolsListWidget methodsFor: 'reactions'!
  510. onClassSelected: aClass
  511. self selectedItem: nil.
  512. self setItemsForSelectedClass.
  513. self refresh
  514. !
  515. onProtocolAdded: aString to: aClass
  516. aClass = self model selectedClass ifFalse: [ ^ self ].
  517. self setItemsForSelectedClass.
  518. self refresh
  519. !
  520. onProtocolRemoved: aString from: aClass
  521. aClass = self model selectedClass ifFalse: [ ^ self ].
  522. self model selectedProtocol = aString
  523. ifTrue: [ self selectItem: nil ].
  524. self setItemsForSelectedClass.
  525. self refresh
  526. !
  527. onProtocolSelected: aString
  528. self selectedItem: aString.
  529. aString ifNil: [ ^ self ].
  530. self focus
  531. !
  532. onProtocolsFocusRequested
  533. self focus
  534. ! !
  535. !HLProtocolsListWidget methodsFor: 'rendering'!
  536. renderContentOn: html
  537. self model showInstance
  538. ifFalse: [ html div
  539. class: 'class_side';
  540. with: [ super renderContentOn: html ] ]
  541. ifTrue: [ super renderContentOn: html ]
  542. ! !
  543. Object subclass: #HLBrowserModel
  544. instanceVariableNames: 'announcer environment selectedPackage selectedClass selectedProtocol selectedSelector showInstance showComment'
  545. package: 'Helios-Browser'!
  546. !HLBrowserModel methodsFor: 'accessing'!
  547. announcer
  548. ^ announcer ifNil: [ announcer := Announcer new ]
  549. !
  550. environment
  551. ^ environment ifNil: [ HLManager current environment ]
  552. !
  553. environment: anEnvironment
  554. environment := anEnvironment
  555. !
  556. packages
  557. ^ self environment packages
  558. !
  559. selectedClass
  560. ^ selectedClass
  561. !
  562. selectedClass: aClass
  563. selectedClass = aClass ifTrue: [
  564. aClass ifNil: [ ^ self ].
  565. self selectedProtocol: nil ].
  566. aClass
  567. ifNil: [ selectedClass := nil ]
  568. ifNotNil: [
  569. self showInstance
  570. ifTrue: [ selectedClass := aClass theNonMetaClass ]
  571. ifFalse: [ selectedClass := aClass theMetaClass ] ].
  572. self selectedProtocol: nil.
  573. self announcer announce: (HLClassSelected on: self selectedClass)
  574. !
  575. selectedMethod
  576. ^ self selectedClass ifNotNil: [
  577. self selectedClass methodDictionary
  578. at: selectedSelector
  579. ifAbsent: [ nil ] ]
  580. !
  581. selectedMethod: aCompiledMethod
  582. selectedSelector = aCompiledMethod ifTrue: [ ^ self ].
  583. aCompiledMethod
  584. ifNil: [ selectedSelector := nil ]
  585. ifNotNil: [
  586. selectedSelector = aCompiledMethod selector ifTrue: [ ^ self ].
  587. selectedSelector := aCompiledMethod selector ].
  588. self announcer announce: (HLMethodSelected on: aCompiledMethod)
  589. !
  590. selectedPackage
  591. ^ selectedPackage
  592. !
  593. selectedPackage: aPackage
  594. selectedPackage = aPackage ifTrue: [ ^ self ].
  595. selectedPackage := aPackage.
  596. self selectedClass: nil.
  597. self announcer announce: (HLPackageSelected on: aPackage)
  598. !
  599. selectedProtocol
  600. ^ selectedProtocol
  601. !
  602. selectedProtocol: aString
  603. selectedProtocol = aString ifTrue: [ ^ self ].
  604. selectedProtocol := aString.
  605. self selectedMethod: nil.
  606. self announcer announce: (HLProtocolSelected on: aString)
  607. !
  608. showComment
  609. ^ showComment ifNil: [ false ]
  610. !
  611. showComment: aBoolean
  612. showComment := aBoolean.
  613. self announcer announce: HLShowCommentToggled new
  614. !
  615. showInstance
  616. ^ showInstance ifNil: [ true ]
  617. !
  618. showInstance: aBoolean
  619. showInstance := aBoolean.
  620. self selectedClass ifNotNil: [
  621. self selectedClass: (aBoolean
  622. ifTrue: [self selectedClass theNonMetaClass ]
  623. ifFalse: [ self selectedClass theMetaClass ]) ].
  624. self announcer announce: HLShowInstanceToggled new
  625. ! !
  626. !HLBrowserModel methodsFor: 'actions'!
  627. addInstVarNamed: aString
  628. self environment addInstVarNamed: aString to: self selectedClass.
  629. self announcer announce: (HLInstVarAdded new
  630. theClass: self selectedClass;
  631. variableName: aString;
  632. yourself)
  633. !
  634. focusOnClasses
  635. self announcer announce: HLClassesFocusRequested new
  636. !
  637. focusOnMethods
  638. self announcer announce: HLMethodsFocusRequested new
  639. !
  640. focusOnPackages
  641. self announcer announce: HLPackagesFocusRequested new
  642. !
  643. focusOnProtocols
  644. self announcer announce: HLProtocolsFocusRequested new
  645. !
  646. focusOnSourceCode
  647. self announcer announce: HLSourceCodeFocusRequested new
  648. !
  649. save: aString
  650. (self shouldCompileClassDefinition: aString)
  651. ifTrue: [ self compileClassDefinition: aString ]
  652. ifFalse: [ self compileMethod: aString ]
  653. !
  654. saveSourceCode
  655. self announcer announce: HLSaveSourceCode new
  656. ! !
  657. !HLBrowserModel methodsFor: 'compiling'!
  658. compileClassComment: aString
  659. self environment
  660. compileClassComment: aString
  661. for: self selectedClass
  662. !
  663. compileClassDefinition: aString
  664. self environment compileClassDefinition: aString
  665. !
  666. compileMethod: aString
  667. self withCompileErrorHandling: [ self environment
  668. compileMethod: aString
  669. for: self selectedClass
  670. protocol: self compilationProtocol ]
  671. ! !
  672. !HLBrowserModel methodsFor: 'defaults'!
  673. allProtocol
  674. ^ '-- all --'
  675. !
  676. unclassifiedProtocol
  677. ^ 'as yet unclassified'
  678. ! !
  679. !HLBrowserModel methodsFor: 'error handling'!
  680. handleCompileError: anError
  681. self announcer announce: (HLCompileErrorRaised new
  682. error: anError;
  683. yourself)
  684. !
  685. handleParseError: anError
  686. | split line column messageToInsert |
  687. split := anError messageText tokenize: ' : '.
  688. messageToInsert := split second.
  689. "21 = 'Parse error on line ' size + 1"
  690. split := split first copyFrom: 21 to: split first size.
  691. split := split tokenize: ' column '.
  692. line := split first.
  693. column := split second.
  694. self announcer announce: (HLParseErrorRaised new
  695. line: line asNumber;
  696. column: column asNumber;
  697. message: messageToInsert;
  698. error: anError;
  699. yourself)
  700. !
  701. handleUnkownVariableError: anError
  702. self announcer announce: (HLUnknownVariableErrorRaised new
  703. error: anError;
  704. yourself)
  705. !
  706. withCompileErrorHandling: aBlock
  707. [
  708. [
  709. aBlock
  710. on: ParseError
  711. do: [:ex | self handleParseError: ex ]
  712. ]
  713. on: UnknownVariableError
  714. do: [ :ex | self handleUnkownVariableError: ex ]
  715. ]
  716. on: CompilerError
  717. do: [ :ex | self handleCompileError: ex ]
  718. ! !
  719. !HLBrowserModel methodsFor: 'private'!
  720. compilationProtocol
  721. | currentProtocol |
  722. currentProtocol := self selectedProtocol.
  723. currentProtocol ifNil: [ currentProtocol := self unclassifiedProtocol ].
  724. self selectedMethod ifNotNil: [ currentProtocol := self selectedMethod protocol ].
  725. ^ currentProtocol = self allProtocol
  726. ifTrue: [ self unclassifiedProtocol ]
  727. ifFalse: [ currentProtocol ]
  728. ! !
  729. !HLBrowserModel methodsFor: 'testing'!
  730. shouldCompileClassDefinition: aString
  731. ^ self selectedClass isNil or: [
  732. aString first asUppercase = aString first ]
  733. ! !
  734. !HLBrowserModel class methodsFor: 'actions'!
  735. on: anEnvironment
  736. ^ self new
  737. environment: anEnvironment;
  738. yourself
  739. ! !
  740. HLWidget subclass: #HLBrowserSourceWidget
  741. instanceVariableNames: 'model methodContents codeWidget'
  742. package: 'Helios-Browser'!
  743. !HLBrowserSourceWidget methodsFor: 'accessing'!
  744. codeWidget
  745. ^ codeWidget ifNil: [ codeWidget := HLSourceCodeWidget on: self model ]
  746. !
  747. contents
  748. ^ self codeWidget contents
  749. !
  750. contents: aString
  751. self methodContents: aString.
  752. self codeWidget contents: aString
  753. !
  754. methodContents
  755. ^ methodContents ifNil: [ methodContents := '' ]
  756. !
  757. methodContents: aString
  758. methodContents := aString
  759. !
  760. model
  761. ^ model
  762. !
  763. model: aBrowserModel
  764. model := aBrowserModel.
  765. self observeModel
  766. ! !
  767. !HLBrowserSourceWidget methodsFor: 'actions'!
  768. focus
  769. self codeWidget focus
  770. !
  771. observeModel
  772. self model announcer
  773. on: HLMethodSelected
  774. do: [ :ann | self onMethodSelected: ann item ];
  775. on: HLClassSelected
  776. do: [ :ann | self onClassSelected: ann item ];
  777. on: HLProtocolSelected
  778. do: [ :ann | self onProtocolSelected: ann item ];
  779. on: HLSourceCodeFocusRequested
  780. do: [ :ann | self onSourceCodeFocusRequested ]
  781. !
  782. observeSystem
  783. SystemAnnouncer current
  784. on: MethodModified
  785. do: [ :ann | self onMethodModified: ann method ]
  786. ! !
  787. !HLBrowserSourceWidget methodsFor: 'initialization'!
  788. initialize
  789. super initialize.
  790. self observeSystem
  791. ! !
  792. !HLBrowserSourceWidget methodsFor: 'reactions'!
  793. onClassSelected: aClass
  794. aClass ifNil: [ ^ self contents: '' ].
  795. self contents: aClass definition
  796. !
  797. onMethodModified: aMethod
  798. self model selectedClass = aMethod methodClass ifFalse: [ ^ self ].
  799. self model selectedMethod ifNil: [ ^ self ].
  800. self model selectedMethod selector = aMethod selector ifFalse: [ ^ self ].
  801. self refresh
  802. !
  803. onMethodSelected: aCompiledMethod
  804. aCompiledMethod ifNil: [ ^ self contents: '' ].
  805. self contents: aCompiledMethod source
  806. !
  807. onProtocolSelected: aString
  808. self model selectedClass ifNil: [ ^ self contents: '' ].
  809. self contents: self model selectedClass definition
  810. !
  811. onSourceCodeFocusRequested
  812. self focus
  813. ! !
  814. !HLBrowserSourceWidget methodsFor: 'rendering'!
  815. renderContentOn: html
  816. self codeWidget renderOn: html
  817. ! !
  818. !HLBrowserSourceWidget methodsFor: 'testing'!
  819. hasFocus
  820. ^ self codeWidget hasFocus
  821. !
  822. hasModification
  823. ^ (self methodContents = self contents) not
  824. ! !
  825. !HLBrowserSourceWidget methodsFor: 'updating'!
  826. refresh
  827. self hasModification ifTrue: [ ^ self ].
  828. self hasFocus ifTrue: [ ^ self ].
  829. self contents: self model selectedMethod source
  830. ! !
  831. !HLBrowserSourceWidget class methodsFor: 'instance creation'!
  832. on: aBrowserModel
  833. ^ self new
  834. model: aBrowserModel;
  835. yourself
  836. ! !
  837. Object subclass: #HLClassCache
  838. instanceVariableNames: 'class selectorsCache overrideCache overriddenCache'
  839. package: 'Helios-Browser'!
  840. !HLClassCache methodsFor: 'accessing'!
  841. overriddenCache
  842. ^ overriddenCache ifNil: [ overriddenCache := HashedCollection new ]
  843. !
  844. overrideCache
  845. ^ overrideCache ifNil: [ overrideCache := HashedCollection new ]
  846. !
  847. selectorsCache
  848. ^ selectorsCache
  849. !
  850. selectorsCache: aCache
  851. selectorsCache := aCache
  852. !
  853. theClass
  854. ^ class
  855. !
  856. theClass: aClass
  857. class := aClass
  858. ! !
  859. !HLClassCache methodsFor: 'actions'!
  860. invalidateChildrenSelector: aSelector
  861. self theClass subclasses do: [ :each |
  862. (self selectorsCache cacheFor: each)
  863. removeSelector: aSelector;
  864. invalidateChildrenSelector: aSelector ]
  865. !
  866. invalidateParentSelector: aSelector
  867. self theClass superclass ifNotNil: [
  868. (self selectorsCache cacheFor: self theClass superclass)
  869. removeSelector: aSelector;
  870. invalidateParentSelector: aSelector ]
  871. !
  872. invalidateSelector: aSelector
  873. self
  874. invalidateParentSelector: aSelector;
  875. invalidateChildrenSelector: aSelector;
  876. removeSelector: aSelector
  877. ! !
  878. !HLClassCache methodsFor: 'private'!
  879. removeSelector: aSelector
  880. self overriddenCache
  881. removeKey: aSelector
  882. ifAbsent: [ ].
  883. self overrideCache
  884. removeKey: aSelector
  885. ifAbsent: [ ]
  886. ! !
  887. !HLClassCache methodsFor: 'testing'!
  888. isOverridden: aMethod
  889. ^ self overriddenCache
  890. at: aMethod selector
  891. ifAbsentPut: [ aMethod isOverridden ]
  892. !
  893. isOverride: aMethod
  894. ^ self overrideCache
  895. at: aMethod selector
  896. ifAbsentPut: [ aMethod isOverride ]
  897. ! !
  898. !HLClassCache class methodsFor: 'instance creation'!
  899. on: aClass selectorsCache: aSelectorsCache
  900. ^ self new
  901. theClass: aClass;
  902. selectorsCache: aSelectorsCache;
  903. yourself
  904. ! !
  905. Object subclass: #HLSelectorsCache
  906. instanceVariableNames: 'classesCache'
  907. package: 'Helios-Browser'!
  908. !HLSelectorsCache methodsFor: 'accessing'!
  909. cacheFor: aClass
  910. aClass ifNil: [ ^ nil ].
  911. ^ self classesCache
  912. at: aClass name
  913. ifAbsentPut: [ self newCacheFor: aClass ]
  914. !
  915. classesCache
  916. ^ classesCache ifNil: [ classesCache := HashedCollection new ]
  917. ! !
  918. !HLSelectorsCache methodsFor: 'actions'!
  919. observeSystem
  920. SystemAnnouncer current
  921. on: MethodAdded
  922. do: [ :ann | self onMethodAdded: ann method ];
  923. on: MethodRemoved
  924. do: [ :ann | self onMethodRemoved: ann method ]
  925. ! !
  926. !HLSelectorsCache methodsFor: 'factory'!
  927. newCacheFor: aClass
  928. ^ HLClassCache
  929. on: aClass
  930. selectorsCache: self
  931. ! !
  932. !HLSelectorsCache methodsFor: 'initialization'!
  933. initialize
  934. super initialize.
  935. self observeSystem
  936. ! !
  937. !HLSelectorsCache methodsFor: 'private'!
  938. invalidateCacheFor: aMethod
  939. (self cacheFor: aMethod methodClass)
  940. invalidateSelector: aMethod selector
  941. ! !
  942. !HLSelectorsCache methodsFor: 'reactions'!
  943. onMethodAdded: aMethod
  944. self invalidateCacheFor: aMethod
  945. !
  946. onMethodRemoved: aMethod
  947. self invalidateCacheFor: aMethod
  948. ! !
  949. !HLSelectorsCache methodsFor: 'testing'!
  950. isOverridden: aMethod
  951. ^ (self cacheFor: aMethod methodClass)
  952. isOverridden: aMethod
  953. !
  954. isOverride: aMethod
  955. ^ (self cacheFor: aMethod methodClass)
  956. isOverride: aMethod
  957. ! !
  958. HLSelectorsCache class instanceVariableNames: 'current'!
  959. !HLSelectorsCache class methodsFor: 'accessing'!
  960. current
  961. ^ current ifNil: [ current := super new ]
  962. !
  963. flush
  964. current := nil
  965. ! !
  966. !HLSelectorsCache class methodsFor: 'instance creation'!
  967. new
  968. self shouldNotImplement
  969. ! !
  970. !CompiledMethod methodsFor: '*Helios-Browser'!
  971. isOverridden
  972. | selector |
  973. selector := self selector.
  974. self methodClass allSubclassesDo: [ :each |
  975. (each includesSelector: selector)
  976. ifTrue: [ ^ true ] ].
  977. ^ false
  978. !
  979. isOverride
  980. | superclass |
  981. superclass := self methodClass superclass.
  982. superclass ifNil: [ ^ false ].
  983. ^ (self methodClass superclass lookupSelector: self selector) notNil
  984. ! !