Helios-Browser.st 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297
  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 ifAbsent: aBlock
  652. self environment
  653. moveMethod: self selectedMethod
  654. toClass: aClassName
  655. ifAbsent: aBlock
  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. ! !