Helios-Browser.st 29 KB

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