Helios-Browser.st 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294
  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: 'commands actions'!
  651. moveMethodToClass: aClassName
  652. console log: 'moveMethodToClass ', aClassName
  653. ! !
  654. !HLBrowserModel methodsFor: 'compiling'!
  655. compileClassComment: aString
  656. self environment
  657. compileClassComment: aString
  658. for: self selectedClass
  659. !
  660. compileClassDefinition: aString
  661. self environment compileClassDefinition: aString
  662. !
  663. compileMethod: aString
  664. self withCompileErrorHandling: [ self environment
  665. compileMethod: aString
  666. for: self selectedClass
  667. protocol: self compilationProtocol ]
  668. ! !
  669. !HLBrowserModel methodsFor: 'defaults'!
  670. allProtocol
  671. ^ '-- all --'
  672. !
  673. unclassifiedProtocol
  674. ^ 'as yet unclassified'
  675. ! !
  676. !HLBrowserModel methodsFor: 'error handling'!
  677. handleCompileError: anError
  678. self announcer announce: (HLCompileErrorRaised new
  679. error: anError;
  680. yourself)
  681. !
  682. handleParseError: anError
  683. | split line column messageToInsert |
  684. split := anError messageText tokenize: ' : '.
  685. messageToInsert := split second.
  686. "21 = 'Parse error on line ' size + 1"
  687. split := split first copyFrom: 21 to: split first size.
  688. split := split tokenize: ' column '.
  689. line := split first.
  690. column := split second.
  691. self announcer announce: (HLParseErrorRaised new
  692. line: line asNumber;
  693. column: column asNumber;
  694. message: messageToInsert;
  695. error: anError;
  696. yourself)
  697. !
  698. handleUnkownVariableError: anError
  699. self announcer announce: (HLUnknownVariableErrorRaised new
  700. error: anError;
  701. yourself)
  702. !
  703. withCompileErrorHandling: aBlock
  704. [
  705. [
  706. aBlock
  707. on: ParseError
  708. do: [:ex | self handleParseError: ex ]
  709. ]
  710. on: UnknownVariableError
  711. do: [ :ex | self handleUnkownVariableError: ex ]
  712. ]
  713. on: CompilerError
  714. do: [ :ex | self handleCompileError: ex ]
  715. ! !
  716. !HLBrowserModel methodsFor: 'private'!
  717. compilationProtocol
  718. | currentProtocol |
  719. currentProtocol := self selectedProtocol.
  720. currentProtocol ifNil: [ currentProtocol := self unclassifiedProtocol ].
  721. self selectedMethod ifNotNil: [ currentProtocol := self selectedMethod protocol ].
  722. ^ currentProtocol = self allProtocol
  723. ifTrue: [ self unclassifiedProtocol ]
  724. ifFalse: [ currentProtocol ]
  725. ! !
  726. !HLBrowserModel methodsFor: 'testing'!
  727. shouldCompileClassDefinition: aString
  728. ^ self selectedClass isNil or: [
  729. aString first asUppercase = aString first ]
  730. ! !
  731. !HLBrowserModel class methodsFor: 'actions'!
  732. on: anEnvironment
  733. ^ self new
  734. environment: anEnvironment;
  735. yourself
  736. ! !
  737. HLWidget subclass: #HLBrowserSourceWidget
  738. instanceVariableNames: 'model methodContents codeWidget'
  739. package: 'Helios-Browser'!
  740. !HLBrowserSourceWidget methodsFor: 'accessing'!
  741. codeWidget
  742. ^ codeWidget ifNil: [ codeWidget := HLSourceCodeWidget on: self model ]
  743. !
  744. contents
  745. ^ self codeWidget contents
  746. !
  747. contents: aString
  748. self methodContents: aString.
  749. self codeWidget contents: aString
  750. !
  751. methodContents
  752. ^ methodContents ifNil: [ methodContents := '' ]
  753. !
  754. methodContents: aString
  755. methodContents := aString
  756. !
  757. model
  758. ^ model
  759. !
  760. model: aBrowserModel
  761. model := aBrowserModel.
  762. self observeModel
  763. ! !
  764. !HLBrowserSourceWidget methodsFor: 'actions'!
  765. focus
  766. self codeWidget focus
  767. !
  768. observeModel
  769. self model announcer
  770. on: HLMethodSelected
  771. do: [ :ann | self onMethodSelected: ann item ];
  772. on: HLClassSelected
  773. do: [ :ann | self onClassSelected: ann item ];
  774. on: HLProtocolSelected
  775. do: [ :ann | self onProtocolSelected: ann item ];
  776. on: HLSourceCodeFocusRequested
  777. do: [ :ann | self onSourceCodeFocusRequested ]
  778. !
  779. observeSystem
  780. SystemAnnouncer current
  781. on: MethodModified
  782. do: [ :ann | self onMethodModified: ann method ]
  783. ! !
  784. !HLBrowserSourceWidget methodsFor: 'initialization'!
  785. initialize
  786. super initialize.
  787. self observeSystem
  788. ! !
  789. !HLBrowserSourceWidget methodsFor: 'reactions'!
  790. onClassSelected: aClass
  791. aClass ifNil: [ ^ self contents: '' ].
  792. self contents: aClass definition
  793. !
  794. onMethodModified: aMethod
  795. self model selectedClass = aMethod methodClass ifFalse: [ ^ self ].
  796. self model selectedMethod ifNil: [ ^ self ].
  797. self model selectedMethod selector = aMethod selector ifFalse: [ ^ self ].
  798. self refresh
  799. !
  800. onMethodSelected: aCompiledMethod
  801. aCompiledMethod ifNil: [ ^ self contents: '' ].
  802. self contents: aCompiledMethod source
  803. !
  804. onProtocolSelected: aString
  805. self model selectedClass ifNil: [ ^ self contents: '' ].
  806. self contents: self model selectedClass definition
  807. !
  808. onSourceCodeFocusRequested
  809. self focus
  810. ! !
  811. !HLBrowserSourceWidget methodsFor: 'rendering'!
  812. renderContentOn: html
  813. self codeWidget renderOn: html
  814. ! !
  815. !HLBrowserSourceWidget methodsFor: 'testing'!
  816. hasFocus
  817. ^ self codeWidget hasFocus
  818. !
  819. hasModification
  820. ^ (self methodContents = self contents) not
  821. ! !
  822. !HLBrowserSourceWidget methodsFor: 'updating'!
  823. refresh
  824. self hasModification ifTrue: [ ^ self ].
  825. self hasFocus ifTrue: [ ^ self ].
  826. self contents: self model selectedMethod source
  827. ! !
  828. !HLBrowserSourceWidget class methodsFor: 'instance creation'!
  829. on: aBrowserModel
  830. ^ self new
  831. model: aBrowserModel;
  832. yourself
  833. ! !
  834. Object subclass: #HLClassCache
  835. instanceVariableNames: 'class selectorsCache overrideCache overriddenCache'
  836. package: 'Helios-Browser'!
  837. !HLClassCache methodsFor: 'accessing'!
  838. overriddenCache
  839. ^ overriddenCache ifNil: [ overriddenCache := HashedCollection new ]
  840. !
  841. overrideCache
  842. ^ overrideCache ifNil: [ overrideCache := HashedCollection new ]
  843. !
  844. selectorsCache
  845. ^ selectorsCache
  846. !
  847. selectorsCache: aCache
  848. selectorsCache := aCache
  849. !
  850. theClass
  851. ^ class
  852. !
  853. theClass: aClass
  854. class := aClass
  855. ! !
  856. !HLClassCache methodsFor: 'actions'!
  857. invalidateChildrenSelector: aSelector
  858. self theClass subclasses do: [ :each |
  859. (self selectorsCache cacheFor: each)
  860. removeSelector: aSelector;
  861. invalidateChildrenSelector: aSelector ]
  862. !
  863. invalidateParentSelector: aSelector
  864. self theClass superclass ifNotNil: [
  865. (self selectorsCache cacheFor: self theClass superclass)
  866. removeSelector: aSelector;
  867. invalidateParentSelector: aSelector ]
  868. !
  869. invalidateSelector: aSelector
  870. self
  871. invalidateParentSelector: aSelector;
  872. invalidateChildrenSelector: aSelector;
  873. removeSelector: aSelector
  874. ! !
  875. !HLClassCache methodsFor: 'private'!
  876. removeSelector: aSelector
  877. self overriddenCache
  878. removeKey: aSelector
  879. ifAbsent: [ ].
  880. self overrideCache
  881. removeKey: aSelector
  882. ifAbsent: [ ]
  883. ! !
  884. !HLClassCache methodsFor: 'testing'!
  885. isOverridden: aMethod
  886. ^ self overriddenCache
  887. at: aMethod selector
  888. ifAbsentPut: [ aMethod isOverridden ]
  889. !
  890. isOverride: aMethod
  891. ^ self overrideCache
  892. at: aMethod selector
  893. ifAbsentPut: [ aMethod isOverride ]
  894. ! !
  895. !HLClassCache class methodsFor: 'instance creation'!
  896. on: aClass selectorsCache: aSelectorsCache
  897. ^ self new
  898. theClass: aClass;
  899. selectorsCache: aSelectorsCache;
  900. yourself
  901. ! !
  902. Object subclass: #HLSelectorsCache
  903. instanceVariableNames: 'classesCache'
  904. package: 'Helios-Browser'!
  905. !HLSelectorsCache methodsFor: 'accessing'!
  906. cacheFor: aClass
  907. aClass ifNil: [ ^ nil ].
  908. ^ self classesCache
  909. at: aClass name
  910. ifAbsentPut: [ self newCacheFor: aClass ]
  911. !
  912. classesCache
  913. ^ classesCache ifNil: [ classesCache := HashedCollection new ]
  914. ! !
  915. !HLSelectorsCache methodsFor: 'actions'!
  916. observeSystem
  917. SystemAnnouncer current
  918. on: MethodAdded
  919. do: [ :ann | self onMethodAdded: ann method ];
  920. on: MethodRemoved
  921. do: [ :ann | self onMethodRemoved: ann method ]
  922. ! !
  923. !HLSelectorsCache methodsFor: 'factory'!
  924. newCacheFor: aClass
  925. ^ HLClassCache
  926. on: aClass
  927. selectorsCache: self
  928. ! !
  929. !HLSelectorsCache methodsFor: 'initialization'!
  930. initialize
  931. super initialize.
  932. self observeSystem
  933. ! !
  934. !HLSelectorsCache methodsFor: 'private'!
  935. invalidateCacheFor: aMethod
  936. (self cacheFor: aMethod methodClass)
  937. invalidateSelector: aMethod selector
  938. ! !
  939. !HLSelectorsCache methodsFor: 'reactions'!
  940. onMethodAdded: aMethod
  941. self invalidateCacheFor: aMethod
  942. !
  943. onMethodRemoved: aMethod
  944. self invalidateCacheFor: aMethod
  945. ! !
  946. !HLSelectorsCache methodsFor: 'testing'!
  947. isOverridden: aMethod
  948. ^ (self cacheFor: aMethod methodClass)
  949. isOverridden: aMethod
  950. !
  951. isOverride: aMethod
  952. ^ (self cacheFor: aMethod methodClass)
  953. isOverride: aMethod
  954. ! !
  955. HLSelectorsCache class instanceVariableNames: 'current'!
  956. !HLSelectorsCache class methodsFor: 'accessing'!
  957. current
  958. ^ current ifNil: [ current := super new ]
  959. !
  960. flush
  961. current := nil
  962. ! !
  963. !HLSelectorsCache class methodsFor: 'instance creation'!
  964. new
  965. self shouldNotImplement
  966. ! !
  967. !CompiledMethod methodsFor: '*Helios-Browser'!
  968. isOverridden
  969. | selector |
  970. selector := self selector.
  971. self methodClass allSubclassesDo: [ :each |
  972. (each includesSelector: selector)
  973. ifTrue: [ ^ true ] ].
  974. ^ false
  975. !
  976. isOverride
  977. | superclass |
  978. superclass := self methodClass superclass.
  979. superclass ifNil: [ ^ false ].
  980. ^ (self methodClass superclass lookupSelector: self selector) notNil
  981. ! !