1
0

Helios-Browser.st 26 KB

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