2
0

Helios-Browser.st 29 KB

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