Helios-Browser.st 28 KB

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