Helios-Browser.st 27 KB

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