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 heliosClass
  323. !
  324. getChildrenOf: aClass
  325. ^ self items select: [ :each | each superclass = aClass ]
  326. !
  327. getRootClassesOf: aCollection
  328. ^ aCollection select: [ :each |
  329. (aCollection includes: each superclass) not ]
  330. !
  331. label
  332. ^ 'Classes'
  333. ! !
  334. !HLClassesListWidget methodsFor: 'actions'!
  335. focus
  336. super focus.
  337. self selectedItem
  338. ifNil: [ self model showClassTemplate ]
  339. !
  340. focusMethodsListWidget
  341. self model announcer announce: HLMethodsListFocus new
  342. !
  343. focusProtocolsListWidget
  344. self model announcer announce: HLProtocolsListFocus new
  345. !
  346. observeModel
  347. self model announcer
  348. on: HLPackageSelected
  349. send: #onPackageSelected:
  350. to: self;
  351. on: HLShowInstanceToggled
  352. send: #onShowInstanceToggled
  353. to: self;
  354. on: HLShowCommentToggled
  355. send: #onShowCommentToggled
  356. to: self;
  357. on: HLClassSelected
  358. send: #onClassSelected:
  359. to: self;
  360. on: HLClassesFocusRequested
  361. send: #onClassesFocusRequested
  362. to: self
  363. !
  364. observeSystem
  365. self model systemAnnouncer
  366. on: ClassAdded
  367. send: #onClassAdded:
  368. to: self;
  369. on: ClassRemoved
  370. send: #onClassRemoved:
  371. to: self;
  372. on: ClassMoved
  373. send: #onClassMoved:
  374. to: self;
  375. on: ClassRenamed
  376. send: #onClassRenamed:
  377. to: self;
  378. on: ClassMigrated
  379. send: #onClassMigrated:
  380. to: self;
  381. on: ClassCommentChanged
  382. send: #onClassCommentChanged:
  383. to: self
  384. !
  385. selectItem: aClass
  386. self model selectedClass: aClass
  387. !
  388. showComment: aBoolean
  389. self model showComment: aBoolean
  390. !
  391. showInstance: aBoolean
  392. self model showInstance: aBoolean
  393. !
  394. toggleShowComment
  395. self model showComment: self showComment not
  396. ! !
  397. !HLClassesListWidget methodsFor: 'private'!
  398. setItemsForPackage: aPackage
  399. self items: (aPackage
  400. ifNil: [ #() ]
  401. ifNotNil: [ (aPackage classes
  402. collect: [ :each | each theNonMetaClass ])
  403. sort: [ :a :b | a name < b name ] ]).
  404. !
  405. setItemsForSelectedPackage
  406. self setItemsForPackage: self model selectedPackage
  407. ! !
  408. !HLClassesListWidget methodsFor: 'reactions'!
  409. onClassAdded: anAnnouncement
  410. | class |
  411. class := anAnnouncement theClass.
  412. (class package = self model selectedPackage or: [
  413. self items includes: class ]) ifFalse: [ ^ self ].
  414. self setItemsForSelectedPackage.
  415. self refresh
  416. !
  417. onClassCommentChanged: anAnnouncement
  418. | class |
  419. class := anAnnouncement theClass.
  420. class package = self model selectedPackage ifFalse: [ ^ self ].
  421. self refresh
  422. !
  423. onClassMigrated: anAnnouncement
  424. | class oldClass |
  425. class := anAnnouncement theClass.
  426. oldClass := anAnnouncement oldClass.
  427. (self items includes: oldClass) ifFalse: [ ^ self ].
  428. self model selectedClass = oldClass ifTrue: [
  429. self model selectedClass: class ].
  430. self setItemsForSelectedPackage.
  431. self refresh
  432. !
  433. onClassMoved: anAnnouncement
  434. | class oldPackage |
  435. class := anAnnouncement theClass.
  436. oldPackage := anAnnouncement oldPackage.
  437. (oldPackage = self model selectedPackage or: [
  438. class package = self model selectedPackage ])
  439. ifFalse: [ ^ self ].
  440. oldPackage = self model selectedPackage ifTrue: [
  441. self
  442. selectedItem: nil;
  443. selectItem: nil ].
  444. self setItemsForSelectedPackage.
  445. self refresh
  446. !
  447. onClassRemoved: anAnnouncement
  448. | class |
  449. class := anAnnouncement theClass.
  450. class package = self model selectedPackage ifFalse: [ ^ self ].
  451. self selectItem: nil.
  452. self setItemsForSelectedPackage.
  453. self refresh
  454. !
  455. onClassRenamed: anAnnouncement
  456. anAnnouncement theClass package = self model selectedPackage ifFalse: [ ^ self ].
  457. self setItemsForSelectedPackage.
  458. self refresh
  459. !
  460. onClassSelected: anAnnouncement
  461. | selectedClass |
  462. anAnnouncement item ifNil: [ ^ self ].
  463. selectedClass := anAnnouncement item theNonMetaClass.
  464. self selectedItem: selectedClass.
  465. self hasFocus ifFalse: [
  466. self
  467. activateItem: selectedClass;
  468. focus ]
  469. !
  470. onClassesFocusRequested
  471. self focus
  472. !
  473. onPackageSelected: anAnnouncement
  474. self selectedItem: nil.
  475. self setItemsForSelectedPackage.
  476. self refresh
  477. !
  478. onShowCommentToggled
  479. self refresh
  480. !
  481. onShowInstanceToggled
  482. self refresh
  483. ! !
  484. !HLClassesListWidget methodsFor: 'rendering'!
  485. renderButtonsOn: html
  486. | checkbox |
  487. html div
  488. class: 'btn-group';
  489. with: [
  490. html button
  491. class: (String streamContents: [ :str |
  492. str nextPutAll: 'btn'.
  493. self showInstance ifTrue: [
  494. str nextPutAll: ' active' ] ]);
  495. with: 'Instance';
  496. onClick: [ self showInstance: true ].
  497. html button
  498. class: (String streamContents: [ :str |
  499. str nextPutAll: 'btn'.
  500. self showClass ifTrue: [
  501. str nextPutAll: ' active' ] ]);
  502. with: 'Class';
  503. onClick: [ self showInstance: false ] ].
  504. html label
  505. class: 'checkbox';
  506. with: [
  507. checkbox := html input
  508. type: 'checkbox';
  509. onClick: [ self toggleShowComment ].
  510. html with: 'Doc' ].
  511. self showComment ifTrue: [
  512. checkbox at: 'checked' put: 'checked' ]
  513. !
  514. renderItem: aClass level: anInteger on: html
  515. | li |
  516. li := html li.
  517. li asJQuery data: 'item' put: aClass.
  518. li
  519. class: (self listCssClassForItem: aClass);
  520. with: [
  521. html a
  522. with: [
  523. (html tag: 'i') class: (self cssClassForItem: aClass).
  524. self renderItemLabel: aClass level: anInteger on: html ];
  525. onClick: [
  526. self activateListItem: li asJQuery ] ].
  527. (self getChildrenOf: aClass) do: [ :each |
  528. self renderItem: each level: anInteger + 1 on: html ]
  529. !
  530. renderItem: aClass on: html
  531. super renderItem: aClass on: html.
  532. (self getChildrenOf: aClass) do: [ :each |
  533. self renderItem: each level: 1 on: html ]
  534. !
  535. renderItemLabel: aClass level: anInteger on: html
  536. html span asJQuery html: (String streamContents: [ :str |
  537. anInteger timesRepeat: [
  538. str nextPutAll: '&nbsp;&nbsp;&nbsp;&nbsp;' ].
  539. str nextPutAll: aClass name ])
  540. !
  541. renderItemLabel: aClass on: html
  542. self renderItemLabel: aClass level: 0 on: html
  543. !
  544. renderListOn: html
  545. (self getRootClassesOf: self items)
  546. do: [ :each | self renderItem: each on: html ]
  547. ! !
  548. !HLClassesListWidget methodsFor: 'testing'!
  549. showClass
  550. ^ self model showInstance not
  551. !
  552. showComment
  553. ^ self model showComment
  554. !
  555. showInstance
  556. ^ self model showInstance
  557. ! !
  558. HLFocusableWidget subclass: #HLDocumentationWidget
  559. instanceVariableNames: 'model'
  560. package: 'Helios-Browser'!
  561. !HLDocumentationWidget commentStamp!
  562. I render the documentation for the selected class!
  563. !HLDocumentationWidget methodsFor: 'accessing'!
  564. documentation
  565. ^ self selectedItem
  566. ifNil: [ '' ]
  567. ifNotNil: [ :item | item comment ifEmpty: [ self defaultDocumentation ] ]
  568. !
  569. head
  570. ^ self selectedItem
  571. ifNil: [ self defaultHead ]
  572. ifNotNil: [ :item | item name ]
  573. !
  574. model
  575. ^ model
  576. !
  577. model: aModel
  578. model := aModel.
  579. self
  580. observeSystem;
  581. observeModel
  582. !
  583. selectedItem
  584. ^ self model selectedClass ifNotNil: [ :class | class theNonMetaClass ]
  585. ! !
  586. !HLDocumentationWidget methodsFor: 'actions'!
  587. editDocumentation
  588. self model editComment
  589. !
  590. observeModel
  591. self model announcer
  592. on: HLClassSelected
  593. send: #onClassSelected:
  594. to: self;
  595. on: HLEditComment
  596. send: #onEditDocumentation
  597. to: self
  598. !
  599. observeSystem
  600. self model systemAnnouncer
  601. on: ClassCommentChanged
  602. send: #onClassCommentChanged:
  603. to: self
  604. !
  605. selectClass: aClass
  606. self model selectedClass: aClass
  607. !
  608. unregister
  609. super unregister.
  610. self model announcer unregister: self
  611. ! !
  612. !HLDocumentationWidget methodsFor: 'defaults'!
  613. defaultDocumentation
  614. ^ 'No documentation is available for this class.'
  615. !
  616. defaultHead
  617. ^ 'No class selected'
  618. ! !
  619. !HLDocumentationWidget methodsFor: 'reactions'!
  620. onClassCommentChanged: anAnnouncement
  621. self model selectedClass ifNil: [ ^ self ].
  622. anAnnouncement theClass = self model selectedClass theNonMetaClass
  623. ifTrue: [ self refresh ]
  624. !
  625. onClassSelected: anAnnouncement
  626. self refresh
  627. !
  628. onEditDocumentation
  629. self
  630. request: self model selectedClass theNonMetaClass name, ' comment'
  631. value: self model selectedClass theNonMetaClass comment
  632. do: [ :comment | self setClassComment: comment ]
  633. !
  634. setClassComment: aString
  635. self model setClassComment: aString
  636. ! !
  637. !HLDocumentationWidget methodsFor: 'rendering'!
  638. renderContentOn: html
  639. html div
  640. class: 'doc';
  641. with: [
  642. self
  643. renderHeadOn: html;
  644. renderDocOn: html ]
  645. !
  646. renderDocOn: html
  647. self selectedItem ifNotNil: [
  648. self renderInheritanceOn: html.
  649. html h1
  650. with: 'Overview';
  651. with: [
  652. html button
  653. class: 'button default';
  654. with: 'Edit';
  655. onClick: [ self editDocumentation ] ].
  656. (html div
  657. class: 'markdown';
  658. asJQuery) html: ((Showdown at: 'converter') new makeHtml: self documentation) ]
  659. !
  660. renderHeadOn: html
  661. html div
  662. class: 'head';
  663. with: self head
  664. !
  665. renderInheritanceOn: html
  666. html div
  667. class: 'inheritance';
  668. with: [
  669. html with: 'Subclass of '.
  670. self selectedItem superclass
  671. ifNil: [ html em with: 'nil' ]
  672. ifNotNil: [
  673. html a
  674. with: self selectedItem superclass name;
  675. onClick: [ self selectClass: self selectedItem superclass ] ] ]
  676. ! !
  677. HLToolListWidget subclass: #HLMethodsListWidget
  678. instanceVariableNames: 'selectorsCache'
  679. package: 'Helios-Browser'!
  680. !HLMethodsListWidget commentStamp!
  681. I render a list of methods for the selected protocol.!
  682. !HLMethodsListWidget methodsFor: 'accessing'!
  683. allProtocol
  684. ^ self model allProtocol
  685. !
  686. cssClassForItem: aSelector
  687. | override overriden method |
  688. method := self methodForSelector: aSelector.
  689. override := self isOverride: method.
  690. overriden := self isOverridden: method.
  691. ^ override
  692. ifTrue: [ overriden
  693. ifTrue: [ 'override-overridden' ]
  694. ifFalse: [ 'override' ] ]
  695. ifFalse: [
  696. overriden
  697. ifTrue: [ 'overridden' ]
  698. ifFalse: [ '' ] ]
  699. !
  700. label
  701. ^ 'Methods'
  702. !
  703. methodForSelector: aSelector
  704. ^ self model selectedClass
  705. methodDictionary at: aSelector
  706. !
  707. methodsInProtocol: aString
  708. self model selectedClass ifNil: [ ^ #() ].
  709. ^ aString = self allProtocol
  710. ifTrue: [ self model selectedClass methods ]
  711. ifFalse: [ self model selectedClass methodsInProtocol: aString ]
  712. !
  713. overrideSelectors
  714. ^ self selectorsCache
  715. at: 'override'
  716. ifAbsentPut: [
  717. self model selectedClass allSuperclasses
  718. inject: Set new into: [ :acc :each | acc addAll: each selectors; yourself ] ]
  719. !
  720. overridenSelectors
  721. ^ self selectorsCache
  722. at: 'overriden'
  723. ifAbsentPut: [
  724. self model selectedClass allSubclasses
  725. inject: Set new into: [ :acc :each | acc addAll: each selectors; yourself ] ]
  726. !
  727. selectorsCache
  728. ^ self class selectorsCache
  729. !
  730. selectorsInProtocol: aString
  731. ^ ((self methodsInProtocol: aString)
  732. collect: [ :each | each selector ]) sorted
  733. ! !
  734. !HLMethodsListWidget methodsFor: 'actions'!
  735. focus
  736. super focus.
  737. self selectedItem ifNil: [
  738. self model showMethodTemplate ]
  739. !
  740. observeModel
  741. self model announcer
  742. on: HLProtocolSelected
  743. send: #onProtocolSelected:
  744. to: self;
  745. on: HLShowInstanceToggled
  746. send: #onShowInstanceToggled
  747. to: self;
  748. on: HLMethodSelected
  749. send: #onMethodSelected:
  750. to: self;
  751. on: HLMethodsFocusRequested
  752. send: #onMethodsFocusRequested
  753. to: self
  754. !
  755. observeSystem
  756. self model systemAnnouncer
  757. on: ProtocolAdded
  758. send: #onProtocolAdded:
  759. to: self;
  760. on: ProtocolRemoved
  761. send: #onProtocolRemoved:
  762. to: self;
  763. on: MethodAdded
  764. send: #onMethodAdded:
  765. to: self;
  766. on: MethodRemoved
  767. send: #onMethodRemoved:
  768. to: self;
  769. on: MethodMoved
  770. send: #onMethodMoved:
  771. to: self
  772. !
  773. selectItem: aSelector
  774. aSelector ifNil: [ ^ self model selectedMethod: nil ].
  775. self model selectedMethod: (self methodForSelector: aSelector)
  776. ! !
  777. !HLMethodsListWidget methodsFor: 'private'!
  778. setItemsForProtocol: aString
  779. ^ self items: (aString
  780. ifNil: [ #() ]
  781. ifNotNil: [ self selectorsInProtocol: aString ])
  782. !
  783. setItemsForSelectedProtocol
  784. self setItemsForProtocol: self model selectedProtocol
  785. ! !
  786. !HLMethodsListWidget methodsFor: 'reactions'!
  787. onMethodAdded: anAnnouncement
  788. self model selectedClass = anAnnouncement method methodClass ifFalse: [ ^ self ].
  789. self setItemsForSelectedProtocol.
  790. self refresh
  791. !
  792. onMethodMoved: anAnnouncement
  793. self model selectedMethod = anAnnouncement method ifFalse: [ ^ self ].
  794. self model selectedProtocol = self model allProtocol ifFalse: [
  795. self
  796. selectedItem: nil;
  797. selectItem: nil;
  798. setItemsForSelectedProtocol;
  799. refresh ]
  800. !
  801. onMethodRemoved: anAnnouncement
  802. | method |
  803. method := anAnnouncement method.
  804. self items detect: [ :each | each = method selector ] ifNone: [ ^ self ].
  805. self selectedItem ifNotNil: [
  806. (method methodClass = self model selectedClass and: [ method selector = self selectedItem ])
  807. ifTrue: [
  808. self selectedItem: nil;
  809. selectItem: nil ] ].
  810. self setItemsForSelectedProtocol.
  811. self refresh
  812. !
  813. onMethodSelected: anAnnouncement
  814. | selector method |
  815. method := anAnnouncement item.
  816. selector := method isCompiledMethod
  817. ifTrue: [ method selector ]
  818. ifFalse: [ nil ].
  819. self
  820. selectedItem: selector;
  821. activateItem: selector
  822. !
  823. onMethodsFocusRequested
  824. self focus
  825. !
  826. onProtocolAdded: anAnnouncement
  827. self model selectedClass = anAnnouncement theClass ifFalse: [ ^ self ].
  828. self setItemsForSelectedProtocol.
  829. self refresh.
  830. self focus
  831. !
  832. onProtocolRemoved: anAnnouncement
  833. self model selectedClass = anAnnouncement theClass ifFalse: [ ^ self ].
  834. self setItemsForSelectedProtocol.
  835. self refresh.
  836. self focus
  837. !
  838. onProtocolSelected: anAnnouncement
  839. self selectedItem: nil.
  840. self setItemsForSelectedProtocol.
  841. self refresh
  842. !
  843. onShowInstanceToggled
  844. self onProtocolSelected: nil
  845. ! !
  846. !HLMethodsListWidget methodsFor: 'rendering'!
  847. renderContentOn: html
  848. self model showInstance
  849. ifFalse: [ html div
  850. class: 'class_side';
  851. with: [ super renderContentOn: html ] ]
  852. ifTrue: [ super renderContentOn: html ]
  853. !
  854. renderItemLabel: aSelector on: html
  855. html with: aSelector
  856. ! !
  857. !HLMethodsListWidget methodsFor: 'testing'!
  858. isOverridden: aMethod
  859. ^ self selectorsCache isOverridden: aMethod
  860. !
  861. isOverride: aMethod
  862. ^ self selectorsCache isOverride: aMethod
  863. ! !
  864. HLMethodsListWidget class instanceVariableNames: 'selectorsCache'!
  865. !HLMethodsListWidget class methodsFor: 'accessing'!
  866. selectorsCache
  867. ^ HLSelectorsCache current
  868. ! !
  869. HLToolListWidget subclass: #HLPackagesListWidget
  870. instanceVariableNames: ''
  871. package: 'Helios-Browser'!
  872. !HLPackagesListWidget commentStamp!
  873. I render a list of the system packages.!
  874. !HLPackagesListWidget methodsFor: 'accessing'!
  875. cssClassForItem: anItem
  876. ^ 'package'
  877. !
  878. items
  879. ^ items ifNil: [ self initializeItems ]
  880. !
  881. label
  882. ^ 'Packages'
  883. ! !
  884. !HLPackagesListWidget methodsFor: 'actions'!
  885. commitPackage
  886. self model commitPackage
  887. !
  888. focusClassesListWidget
  889. self model announcer announce: HLClassesListFocus new
  890. !
  891. observeModel
  892. self model announcer
  893. on: HLPackageSelected
  894. send: #onPackageSelected:
  895. to: self;
  896. on: HLPackagesFocusRequested
  897. send: #onPackagesFocusRequested
  898. to: self
  899. !
  900. observeSystem
  901. self model systemAnnouncer
  902. on: ClassAdded
  903. send: #onClassAdded:
  904. to: self.
  905. self model systemAnnouncer
  906. on: PackageAdded
  907. send: #onPackageAdded:
  908. to: self
  909. !
  910. selectItem: aPackage
  911. super selectItem: aPackage.
  912. self model selectedPackage: aPackage
  913. ! !
  914. !HLPackagesListWidget methodsFor: 'initialization'!
  915. initializeItems
  916. ^ items := self model packages
  917. sort: [ :a :b | a name < b name ]
  918. ! !
  919. !HLPackagesListWidget methodsFor: 'reactions'!
  920. onClassAdded: anAnnouncement
  921. "Amber doesn't have yet a global organizer for packages"
  922. (self items includes: anAnnouncement theClass package) ifFalse: [
  923. self
  924. initializeItems;
  925. refresh ]
  926. !
  927. onPackageAdded: anAnnouncement
  928. self
  929. initializeItems;
  930. refresh
  931. !
  932. onPackageSelected: anAnnouncement
  933. | package |
  934. package := anAnnouncement item.
  935. self selectedItem: package.
  936. self hasFocus ifFalse: [
  937. self
  938. activateItem: package;
  939. focus ]
  940. !
  941. onPackagesFocusRequested
  942. self focus
  943. ! !
  944. !HLPackagesListWidget methodsFor: 'rendering'!
  945. renderItemLabel: aPackage on: html
  946. html with: aPackage name
  947. ! !
  948. HLToolListWidget subclass: #HLProtocolsListWidget
  949. instanceVariableNames: ''
  950. package: 'Helios-Browser'!
  951. !HLProtocolsListWidget commentStamp!
  952. I render a list of protocols for the selected class.!
  953. !HLProtocolsListWidget methodsFor: 'accessing'!
  954. allProtocol
  955. ^ self model allProtocol
  956. !
  957. cssClassForItem: anItem
  958. anItem = self allProtocol ifTrue: [ ^ '' ].
  959. anItem = 'private' ifTrue: [ ^ 'private' ].
  960. anItem = 'initialization' ifTrue: [ ^ 'initialization' ].
  961. (anItem match: '^\*') ifTrue: [ ^ 'extension' ].
  962. ^ ''
  963. !
  964. label
  965. ^ 'Protocols'
  966. !
  967. selectedItem
  968. ^ super selectedItem" ifNil: [ self allProtocol ]"
  969. ! !
  970. !HLProtocolsListWidget methodsFor: 'actions'!
  971. observeModel
  972. self model announcer
  973. on: HLClassSelected
  974. send: #onClassSelected:
  975. to: self;
  976. on: HLShowInstanceToggled
  977. send: #onClassSelected:
  978. to: self;
  979. on: HLProtocolSelected
  980. send: #onProtocolSelected:
  981. to: self;
  982. on: HLProtocolsFocusRequested
  983. send: #onProtocolsFocusRequested
  984. to: self
  985. !
  986. observeSystem
  987. self model systemAnnouncer
  988. on: ProtocolAdded
  989. send: #onProtocolAdded:
  990. to: self;
  991. on: ProtocolRemoved
  992. send: #onProtocolRemoved:
  993. to: self
  994. !
  995. selectItem: aString
  996. self model selectedProtocol: aString
  997. ! !
  998. !HLProtocolsListWidget methodsFor: 'private'!
  999. setItemsForClass: aClass
  1000. self items: (aClass
  1001. ifNil: [ Array with: self allProtocol ]
  1002. ifNotNil: [
  1003. (Array with: self allProtocol)
  1004. addAll: aClass protocols;
  1005. yourself ])
  1006. !
  1007. setItemsForSelectedClass
  1008. self setItemsForClass: self model selectedClass
  1009. ! !
  1010. !HLProtocolsListWidget methodsFor: 'reactions'!
  1011. onClassSelected: anAnnouncement
  1012. self selectedItem: nil.
  1013. self setItemsForSelectedClass.
  1014. self refresh
  1015. !
  1016. onProtocolAdded: anAnnouncement
  1017. | class |
  1018. class := anAnnouncement theClass.
  1019. class = self model selectedClass ifFalse: [ ^ self ].
  1020. self setItemsForSelectedClass.
  1021. self refresh
  1022. !
  1023. onProtocolRemoved: anAnnouncement
  1024. | class protocol |
  1025. class := anAnnouncement theClass.
  1026. protocol := anAnnouncement protocol.
  1027. class = self model selectedClass ifFalse: [ ^ self ].
  1028. self model selectedProtocol = protocol
  1029. ifTrue: [
  1030. self
  1031. selectedItem: nil;
  1032. selectItem: nil ].
  1033. self setItemsForSelectedClass.
  1034. self refresh
  1035. !
  1036. onProtocolSelected: anAnnouncement
  1037. | protocol |
  1038. protocol := anAnnouncement item.
  1039. self selectedItem: protocol.
  1040. protocol ifNil: [ ^ self ].
  1041. self hasFocus ifFalse: [
  1042. self
  1043. activateItem: protocol;
  1044. focus ]
  1045. !
  1046. onProtocolsFocusRequested
  1047. self focus
  1048. ! !
  1049. !HLProtocolsListWidget methodsFor: 'rendering'!
  1050. renderContentOn: html
  1051. self model showInstance
  1052. ifFalse: [ html div
  1053. class: 'class_side';
  1054. with: [ super renderContentOn: html ] ]
  1055. ifTrue: [ super renderContentOn: html ]
  1056. ! !
  1057. Object subclass: #HLSelectorsCache
  1058. instanceVariableNames: 'classesCache'
  1059. package: 'Helios-Browser'!
  1060. !HLSelectorsCache methodsFor: 'accessing'!
  1061. cacheFor: aClass
  1062. aClass ifNil: [ ^ nil ].
  1063. ^ self classesCache
  1064. at: aClass name
  1065. ifAbsentPut: [ self newCacheFor: aClass ]
  1066. !
  1067. classesCache
  1068. ^ classesCache ifNil: [ classesCache := HashedCollection new ]
  1069. ! !
  1070. !HLSelectorsCache methodsFor: 'actions'!
  1071. observeSystem
  1072. SystemAnnouncer current
  1073. on: MethodAdded
  1074. send: #onMethodAdded:
  1075. to: self;
  1076. on: MethodRemoved
  1077. send: #onMethodRemoved:
  1078. to: self
  1079. ! !
  1080. !HLSelectorsCache methodsFor: 'factory'!
  1081. newCacheFor: aClass
  1082. ^ HLClassCache
  1083. on: aClass
  1084. selectorsCache: self
  1085. ! !
  1086. !HLSelectorsCache methodsFor: 'initialization'!
  1087. initialize
  1088. super initialize.
  1089. self observeSystem
  1090. ! !
  1091. !HLSelectorsCache methodsFor: 'private'!
  1092. invalidateCacheFor: aMethod
  1093. (self cacheFor: aMethod methodClass)
  1094. invalidateSelector: aMethod selector
  1095. ! !
  1096. !HLSelectorsCache methodsFor: 'reactions'!
  1097. onMethodAdded: anAnnouncement
  1098. self invalidateCacheFor: anAnnouncement method
  1099. !
  1100. onMethodRemoved: anAnnouncement
  1101. self invalidateCacheFor: anAnnouncement method
  1102. ! !
  1103. !HLSelectorsCache methodsFor: 'testing'!
  1104. isOverridden: aMethod
  1105. ^ (self cacheFor: aMethod methodClass)
  1106. isOverridden: aMethod
  1107. !
  1108. isOverride: aMethod
  1109. ^ (self cacheFor: aMethod methodClass)
  1110. isOverride: aMethod
  1111. ! !
  1112. HLSelectorsCache class instanceVariableNames: 'current'!
  1113. !HLSelectorsCache class methodsFor: 'accessing'!
  1114. current
  1115. ^ current ifNil: [ current := super new ]
  1116. !
  1117. flush
  1118. current := nil
  1119. ! !
  1120. !HLSelectorsCache class methodsFor: 'instance creation'!
  1121. new
  1122. self shouldNotImplement
  1123. ! !