Helios-Browser.st 23 KB

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