Helios-Browser.st 27 KB

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