Helios-Browser.st 28 KB

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