Helios-Browser.st 27 KB

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