Helios-Browser.st 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480
  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: [ false ]
  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. ifNotNil: [ :class |
  342. self model announcer announce: (HLClassSelected on: class) ]
  343. !
  344. focusMethodsListWidget
  345. self model announcer announce: HLMethodsListFocus new
  346. !
  347. focusProtocolsListWidget
  348. self model announcer announce: HLProtocolsListFocus new
  349. !
  350. observeModel
  351. self model announcer
  352. on: HLPackageSelected
  353. send: #onPackageSelected:
  354. to: self;
  355. on: HLShowInstanceToggled
  356. send: #onShowInstanceToggled
  357. to: self;
  358. on: HLShowCommentToggled
  359. send: #onShowCommentToggled
  360. to: self;
  361. on: HLClassSelected
  362. send: #onClassSelected:
  363. to: self;
  364. on: HLClassesFocusRequested
  365. send: #onClassesFocusRequested
  366. to: self
  367. !
  368. observeSystem
  369. self model systemAnnouncer
  370. on: ClassAdded
  371. send: #onClassAdded:
  372. to: self;
  373. on: ClassRemoved
  374. send: #onClassRemoved:
  375. to: self;
  376. on: ClassMoved
  377. send: #onClassMoved:
  378. to: self;
  379. on: ClassRenamed
  380. send: #onClassRenamed:
  381. to: self;
  382. on: ClassMigrated
  383. send: #onClassMigrated:
  384. to: self;
  385. on: ClassCommentChanged
  386. send: #onClassCommentChanged:
  387. to: self
  388. !
  389. selectItem: aClass
  390. self model selectedClass: aClass
  391. !
  392. showComment: aBoolean
  393. self model showComment: aBoolean
  394. !
  395. showInstance: aBoolean
  396. self model showInstance: aBoolean
  397. !
  398. toggleShowComment
  399. self model showComment: self showComment not
  400. ! !
  401. !HLClassesListWidget methodsFor: 'private'!
  402. setItemsForPackage: aPackage
  403. self items: (aPackage
  404. ifNil: [ #() ]
  405. ifNotNil: [ (aPackage classes
  406. collect: [ :each | each theNonMetaClass ])
  407. sort: [ :a :b | a name < b name ] ]).
  408. !
  409. setItemsForSelectedPackage
  410. self setItemsForPackage: self model selectedPackage
  411. ! !
  412. !HLClassesListWidget methodsFor: 'reactions'!
  413. onClassAdded: anAnnouncement
  414. | class |
  415. class := anAnnouncement theClass.
  416. (class package = self model selectedPackage or: [
  417. self items includes: class ]) ifFalse: [ ^ self ].
  418. self setItemsForSelectedPackage.
  419. self refresh
  420. !
  421. onClassCommentChanged: anAnnouncement
  422. | class |
  423. class := anAnnouncement theClass.
  424. class package = self model selectedPackage ifFalse: [ ^ self ].
  425. self refresh
  426. !
  427. onClassMigrated: anAnnouncement
  428. | class oldClass |
  429. class := anAnnouncement theClass.
  430. oldClass := anAnnouncement oldClass.
  431. (self items includes: oldClass) ifFalse: [ ^ self ].
  432. self model selectedClass = oldClass ifTrue: [
  433. self model selectedClass: class ].
  434. self setItemsForSelectedPackage.
  435. self refresh
  436. !
  437. onClassMoved: anAnnouncement
  438. | class oldPackage |
  439. class := anAnnouncement theClass.
  440. oldPackage := anAnnouncement oldPackage.
  441. (oldPackage = self model selectedPackage or: [
  442. class package = self model selectedPackage ])
  443. ifFalse: [ ^ self ].
  444. oldPackage = self model selectedPackage ifTrue: [
  445. self
  446. selectedItem: nil;
  447. selectItem: nil ].
  448. self setItemsForSelectedPackage.
  449. self refresh
  450. !
  451. onClassRemoved: anAnnouncement
  452. | class |
  453. class := anAnnouncement theClass.
  454. class package = self model selectedPackage ifFalse: [ ^ self ].
  455. self selectItem: nil.
  456. self setItemsForSelectedPackage.
  457. self refresh
  458. !
  459. onClassRenamed: anAnnouncement
  460. anAnnouncement theClass package = self model selectedPackage ifFalse: [ ^ self ].
  461. self setItemsForSelectedPackage.
  462. self refresh
  463. !
  464. onClassSelected: anAnnouncement
  465. | selectedClass |
  466. anAnnouncement item ifNil: [ ^ self ].
  467. selectedClass := anAnnouncement item theNonMetaClass.
  468. self selectedItem: selectedClass.
  469. self hasFocus ifFalse: [
  470. self
  471. activateItem: selectedClass;
  472. focus ]
  473. !
  474. onClassesFocusRequested
  475. self focus
  476. !
  477. onPackageSelected: anAnnouncement
  478. self selectedItem: nil.
  479. self setItemsForSelectedPackage.
  480. self refresh
  481. !
  482. onShowCommentToggled
  483. self refresh
  484. !
  485. onShowInstanceToggled
  486. self refresh
  487. ! !
  488. !HLClassesListWidget methodsFor: 'rendering'!
  489. renderButtonsOn: html
  490. | checkbox |
  491. html div
  492. class: 'btn-group';
  493. with: [
  494. html button
  495. class: (String streamContents: [ :str |
  496. str nextPutAll: 'btn'.
  497. self showInstance ifTrue: [
  498. str nextPutAll: ' active' ] ]);
  499. with: 'Instance';
  500. onClick: [ self showInstance: true ].
  501. html button
  502. class: (String streamContents: [ :str |
  503. str nextPutAll: 'btn'.
  504. self showClass ifTrue: [
  505. str nextPutAll: ' active' ] ]);
  506. with: 'Class';
  507. onClick: [ self showInstance: false ] ].
  508. html label
  509. class: 'checkbox';
  510. with: [
  511. checkbox := html input
  512. type: 'checkbox';
  513. onClick: [ self toggleShowComment ].
  514. html with: 'Doc' ].
  515. self showComment ifTrue: [
  516. checkbox at: 'checked' put: 'checked' ]
  517. !
  518. renderItem: aClass level: anInteger on: html
  519. | li |
  520. li := html li.
  521. li asJQuery data: 'item' put: aClass.
  522. li
  523. class: (self listCssClassForItem: aClass);
  524. with: [
  525. html a
  526. with: [
  527. (html tag: 'i') class: (self cssClassForItem: aClass).
  528. self renderItemLabel: aClass level: anInteger on: html ];
  529. onClick: [
  530. self activateListItem: li asJQuery ] ].
  531. (self getChildrenOf: aClass) do: [ :each |
  532. self renderItem: each level: anInteger + 1 on: html ]
  533. !
  534. renderItem: aClass on: html
  535. super renderItem: aClass on: html.
  536. (self getChildrenOf: aClass) do: [ :each |
  537. self renderItem: each level: 1 on: html ]
  538. !
  539. renderItemLabel: aClass level: anInteger on: html
  540. html span asJQuery html: (String streamContents: [ :str |
  541. anInteger timesRepeat: [
  542. str nextPutAll: '&nbsp;&nbsp;&nbsp;&nbsp;' ].
  543. str nextPutAll: aClass name ])
  544. !
  545. renderItemLabel: aClass on: html
  546. self renderItemLabel: aClass level: 0 on: html
  547. !
  548. renderListOn: html
  549. (self getRootClassesOf: self items)
  550. do: [ :each | self renderItem: each on: html ]
  551. ! !
  552. !HLClassesListWidget methodsFor: 'testing'!
  553. showClass
  554. ^ self model showInstance not
  555. !
  556. showComment
  557. ^ self model showComment
  558. !
  559. showInstance
  560. ^ self model showInstance
  561. ! !
  562. HLFocusableWidget subclass: #HLDocumentationWidget
  563. instanceVariableNames: 'model'
  564. package: 'Helios-Browser'!
  565. !HLDocumentationWidget commentStamp!
  566. I render the documentation for the selected class!
  567. !HLDocumentationWidget methodsFor: 'accessing'!
  568. documentation
  569. ^ self selectedItem
  570. ifNil: [ '' ]
  571. ifNotNil: [ :item | item comment ifEmpty: [ self defaultDocumentation ] ]
  572. !
  573. head
  574. ^ self selectedItem
  575. ifNil: [ self defaultHead ]
  576. ifNotNil: [ :item | item name ]
  577. !
  578. model
  579. ^ model
  580. !
  581. model: aModel
  582. model := aModel.
  583. self
  584. observeSystem;
  585. observeModel
  586. !
  587. selectedItem
  588. ^ self model selectedClass ifNotNil: [ :class | class theNonMetaClass ]
  589. ! !
  590. !HLDocumentationWidget methodsFor: 'actions'!
  591. editDocumentation
  592. self model editComment
  593. !
  594. observeModel
  595. self model announcer
  596. on: HLClassSelected
  597. send: #onClassSelected:
  598. to: self;
  599. on: HLEditComment
  600. send: #onEditDocumentation
  601. to: self
  602. !
  603. observeSystem
  604. self model systemAnnouncer
  605. on: ClassCommentChanged
  606. send: #onClassCommentChanged:
  607. to: self
  608. !
  609. selectClass: aClass
  610. self model selectedClass: aClass
  611. !
  612. unregister
  613. super unregister.
  614. self model announcer unregister: self
  615. ! !
  616. !HLDocumentationWidget methodsFor: 'defaults'!
  617. defaultDocumentation
  618. ^ 'No documentation available.
  619. **That''s bad. Seriously.**'
  620. !
  621. defaultHead
  622. ^ 'No class selected'
  623. ! !
  624. !HLDocumentationWidget methodsFor: 'reactions'!
  625. onClassCommentChanged: anAnnouncement
  626. anAnnouncement theClass = self model selectedClass theNonMetaClass
  627. ifTrue: [ self refresh ]
  628. !
  629. onClassSelected: anAnnouncement
  630. self refresh
  631. !
  632. onEditDocumentation
  633. self
  634. request: self model selectedClass theNonMetaClass name, ' comment'
  635. value: self model selectedClass theNonMetaClass comment
  636. do: [ :comment | self setClassComment: comment ]
  637. !
  638. setClassComment: aString
  639. self model setClassComment: aString
  640. ! !
  641. !HLDocumentationWidget methodsFor: 'rendering'!
  642. renderContentOn: html
  643. html div
  644. class: 'doc';
  645. with: [
  646. self
  647. renderHeadOn: html;
  648. renderDocOn: html ]
  649. !
  650. renderDocOn: html
  651. self selectedItem ifNotNil: [
  652. self renderInheritanceOn: html.
  653. html h1
  654. with: 'Overview';
  655. with: [
  656. html button
  657. class: 'button default';
  658. with: 'Edit';
  659. onClick: [ self editDocumentation ] ].
  660. (html div
  661. class: 'markdown';
  662. asJQuery) html: ((Showdown at: 'converter') new makeHtml: self documentation) ]
  663. !
  664. renderHeadOn: html
  665. html div
  666. class: 'head';
  667. with: self head
  668. !
  669. renderInheritanceOn: html
  670. html div
  671. class: 'inheritance';
  672. with: [
  673. html with: 'Subclass of '.
  674. self selectedItem superclass
  675. ifNil: [ html em with: 'nil' ]
  676. ifNotNil: [
  677. html a
  678. with: self selectedItem superclass name;
  679. onClick: [ self selectClass: self selectedItem superclass ] ] ]
  680. ! !
  681. HLToolListWidget subclass: #HLMethodsListWidget
  682. instanceVariableNames: 'selectorsCache'
  683. package: 'Helios-Browser'!
  684. !HLMethodsListWidget commentStamp!
  685. I render a list of methods for the selected protocol.!
  686. !HLMethodsListWidget methodsFor: 'accessing'!
  687. allProtocol
  688. ^ self model allProtocol
  689. !
  690. cssClassForItem: aSelector
  691. | override overriden method |
  692. method := self methodForSelector: aSelector.
  693. override := self isOverride: method.
  694. overriden := self isOverridden: method.
  695. ^ override
  696. ifTrue: [ overriden
  697. ifTrue: [ 'override-overridden' ]
  698. ifFalse: [ 'override' ] ]
  699. ifFalse: [
  700. overriden
  701. ifTrue: [ 'overridden' ]
  702. ifFalse: [ '' ] ]
  703. !
  704. label
  705. ^ 'Methods'
  706. !
  707. methodForSelector: aSelector
  708. ^ self model selectedClass
  709. methodDictionary at: aSelector
  710. !
  711. methodsInProtocol: aString
  712. self model selectedClass ifNil: [ ^ #() ].
  713. ^ aString = self allProtocol
  714. ifTrue: [ self model selectedClass methods ]
  715. ifFalse: [ self model selectedClass methodsInProtocol: aString ]
  716. !
  717. overrideSelectors
  718. ^ self selectorsCache
  719. at: 'override'
  720. ifAbsentPut: [
  721. self model selectedClass allSuperclasses
  722. inject: Set new into: [ :acc :each | acc addAll: each selectors; yourself ] ]
  723. !
  724. overridenSelectors
  725. ^ self selectorsCache
  726. at: 'overriden'
  727. ifAbsentPut: [
  728. self model selectedClass allSubclasses
  729. inject: Set new into: [ :acc :each | acc addAll: each selectors; yourself ] ]
  730. !
  731. selectorsCache
  732. ^ self class selectorsCache
  733. !
  734. selectorsInProtocol: aString
  735. ^ ((self methodsInProtocol: aString)
  736. collect: [ :each | each selector ]) sorted
  737. ! !
  738. !HLMethodsListWidget methodsFor: 'actions'!
  739. focus
  740. super focus.
  741. self selectedItem ifNil: [
  742. self model showMethodTemplate ]
  743. !
  744. observeModel
  745. self model announcer
  746. on: HLProtocolSelected
  747. send: #onProtocolSelected:
  748. to: self;
  749. on: HLShowInstanceToggled
  750. send: #onShowInstanceToggled
  751. to: self;
  752. on: HLMethodSelected
  753. send: #onMethodSelected:
  754. to: self;
  755. on: HLMethodsFocusRequested
  756. send: #onMethodsFocusRequested
  757. to: self
  758. !
  759. observeSystem
  760. self model systemAnnouncer
  761. on: ProtocolAdded
  762. send: #onProtocolAdded:
  763. to: self;
  764. on: ProtocolRemoved
  765. send: #onProtocolRemoved:
  766. to: self;
  767. on: MethodAdded
  768. send: #onMethodAdded:
  769. to: self;
  770. on: MethodRemoved
  771. send: #onMethodRemoved:
  772. to: self;
  773. on: MethodMoved
  774. send: #onMethodMoved:
  775. to: self
  776. !
  777. selectItem: aSelector
  778. aSelector ifNil: [ ^ self model selectedMethod: nil ].
  779. self model selectedMethod: (self methodForSelector: aSelector)
  780. ! !
  781. !HLMethodsListWidget methodsFor: 'private'!
  782. setItemsForProtocol: aString
  783. ^ self items: (aString
  784. ifNil: [ #() ]
  785. ifNotNil: [ self selectorsInProtocol: aString ])
  786. !
  787. setItemsForSelectedProtocol
  788. self setItemsForProtocol: self model selectedProtocol
  789. ! !
  790. !HLMethodsListWidget methodsFor: 'reactions'!
  791. onMethodAdded: anAnnouncement
  792. self model selectedClass = anAnnouncement method methodClass ifFalse: [ ^ self ].
  793. self setItemsForSelectedProtocol.
  794. self refresh
  795. !
  796. onMethodMoved: anAnnouncement
  797. self model selectedMethod = anAnnouncement method ifFalse: [ ^ self ].
  798. self model selectedProtocol = self model allProtocol ifFalse: [
  799. self
  800. selectedItem: nil;
  801. selectItem: nil;
  802. setItemsForSelectedProtocol;
  803. refresh ]
  804. !
  805. onMethodRemoved: anAnnouncement
  806. | method |
  807. method := anAnnouncement method.
  808. self items detect: [ :each | each = method selector ] ifNone: [ ^ self ].
  809. self selectedItem ifNotNil: [
  810. (method methodClass = self model selectedClass and: [ method selector = self selectedItem ])
  811. ifTrue: [
  812. self selectedItem: nil;
  813. selectItem: nil ] ].
  814. self setItemsForSelectedProtocol.
  815. self refresh
  816. !
  817. onMethodSelected: anAnnouncement
  818. | selector method |
  819. method := anAnnouncement item.
  820. selector := method isCompiledMethod
  821. ifTrue: [ method selector ]
  822. ifFalse: [ nil ].
  823. self
  824. selectedItem: selector;
  825. activateItem: selector
  826. !
  827. onMethodsFocusRequested
  828. self focus
  829. !
  830. onProtocolAdded: anAnnouncement
  831. self model selectedClass = anAnnouncement theClass ifFalse: [ ^ self ].
  832. self setItemsForSelectedProtocol.
  833. self refresh.
  834. self focus
  835. !
  836. onProtocolRemoved: anAnnouncement
  837. self model selectedClass = anAnnouncement theClass ifFalse: [ ^ self ].
  838. self setItemsForSelectedProtocol.
  839. self refresh.
  840. self focus
  841. !
  842. onProtocolSelected: anAnnouncement
  843. self selectedItem: nil.
  844. self setItemsForSelectedProtocol.
  845. self refresh
  846. !
  847. onShowInstanceToggled
  848. self onProtocolSelected: nil
  849. ! !
  850. !HLMethodsListWidget methodsFor: 'rendering'!
  851. renderContentOn: html
  852. self model showInstance
  853. ifFalse: [ html div
  854. class: 'class_side';
  855. with: [ super renderContentOn: html ] ]
  856. ifTrue: [ super renderContentOn: html ]
  857. !
  858. renderItemLabel: aSelector on: html
  859. html with: aSelector
  860. ! !
  861. !HLMethodsListWidget methodsFor: 'testing'!
  862. isOverridden: aMethod
  863. ^ self selectorsCache isOverridden: aMethod
  864. !
  865. isOverride: aMethod
  866. ^ self selectorsCache isOverride: aMethod
  867. ! !
  868. HLMethodsListWidget class instanceVariableNames: 'selectorsCache'!
  869. !HLMethodsListWidget class methodsFor: 'accessing'!
  870. selectorsCache
  871. ^ HLSelectorsCache current
  872. ! !
  873. HLToolListWidget subclass: #HLPackagesListWidget
  874. instanceVariableNames: ''
  875. package: 'Helios-Browser'!
  876. !HLPackagesListWidget commentStamp!
  877. I render a list of the system packages.!
  878. !HLPackagesListWidget methodsFor: 'accessing'!
  879. cssClassForItem: anItem
  880. ^ 'package'
  881. !
  882. items
  883. ^ items ifNil: [ self initializeItems ]
  884. !
  885. label
  886. ^ 'Packages'
  887. ! !
  888. !HLPackagesListWidget methodsFor: 'actions'!
  889. commitPackage
  890. self model commitPackage
  891. !
  892. focus
  893. super focus.
  894. self selectedItem ifNotNil: [ :package |
  895. self model announcer announce: (HLPackageSelected on: package) ]
  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. ! !