Helios-Browser.st 30 KB

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