2
0

Helios-Browser.st 26 KB

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