Helios-Browser.st 26 KB

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