Helios-Browser.st 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573
  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: false ]
  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 ]) asArray
  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. at: 'role' put: 'group';
  542. with: [
  543. html button
  544. class: (String streamContents: [ :str |
  545. str nextPutAll: 'btn btn-default'.
  546. self showInstance ifTrue: [
  547. str nextPutAll: ' active' ] ]);
  548. with: 'Instance';
  549. onClick: [ self showInstance: true ].
  550. html button
  551. class: (String streamContents: [ :str |
  552. str nextPutAll: 'btn btn-default'.
  553. self showClass ifTrue: [
  554. str nextPutAll: ' active' ] ]);
  555. with: 'Class';
  556. onClick: [ self showInstance: false ] ].
  557. html label
  558. class: 'checkbox';
  559. with: [
  560. checkbox := html input
  561. type: 'checkbox';
  562. onClick: [ self toggleShowComment ].
  563. html with: 'Doc' ].
  564. self showComment ifTrue: [
  565. checkbox at: 'checked' put: 'checked' ]
  566. !
  567. renderItem: aClass level: anInteger on: html
  568. | li |
  569. li := html li.
  570. li asJQuery data: 'item' put: aClass.
  571. li
  572. class: (self listCssClassForItem: aClass);
  573. with: [
  574. html a
  575. with: [
  576. (html tag: 'i') class: (self cssClassForItem: aClass).
  577. self renderItemLabel: aClass level: anInteger on: html ];
  578. onClick: [
  579. self reactivateListItem: li asJQuery ] ].
  580. (self getChildrenOf: aClass) do: [ :each |
  581. self renderItem: each level: anInteger + 1 on: html ]
  582. !
  583. renderItem: aClass on: html
  584. super renderItem: aClass on: html.
  585. (self getChildrenOf: aClass) do: [ :each |
  586. self renderItem: each level: 1 on: html ]
  587. !
  588. renderItemLabel: aClass level: anInteger on: html
  589. | indent |
  590. indent := String fromCharCode: 160.
  591. indent := indent, indent, indent, indent.
  592. html span with: (String streamContents: [ :str |
  593. anInteger timesRepeat: [
  594. str nextPutAll: indent ].
  595. str nextPutAll: aClass name ])
  596. !
  597. renderItemLabel: aClass on: html
  598. self renderItemLabel: aClass level: 0 on: html
  599. !
  600. renderListOn: html
  601. (self getRootClassesOf: self items)
  602. do: [ :each | self renderItem: each on: html ]
  603. ! !
  604. !HLClassesListWidget methodsFor: 'testing'!
  605. showClass
  606. ^ self model showInstance not
  607. !
  608. showComment
  609. ^ self model showComment
  610. !
  611. showInstance
  612. ^ self model showInstance
  613. ! !
  614. HLFocusableWidget subclass: #HLDocumentationWidget
  615. instanceVariableNames: 'model'
  616. package: 'Helios-Browser'!
  617. !HLDocumentationWidget commentStamp!
  618. I render the documentation for the selected class!
  619. !HLDocumentationWidget methodsFor: 'accessing'!
  620. documentation
  621. ^ self selectedItem
  622. ifNil: [ '' ]
  623. ifNotNil: [ :item | item comment ifEmpty: [ self defaultDocumentation ] ]
  624. !
  625. head
  626. ^ self selectedItem
  627. ifNil: [ self defaultHead ]
  628. ifNotNil: [ :item | item name ]
  629. !
  630. model
  631. ^ model
  632. !
  633. model: aModel
  634. model := aModel.
  635. self
  636. observeSystem;
  637. observeModel
  638. !
  639. selectedItem
  640. ^ self model selectedClass ifNotNil: [ :class | class theNonMetaClass ]
  641. ! !
  642. !HLDocumentationWidget methodsFor: 'actions'!
  643. editDocumentation
  644. self model editComment
  645. !
  646. observeModel
  647. self model announcer
  648. on: HLClassSelected
  649. send: #onClassSelected:
  650. to: self;
  651. on: HLEditComment
  652. send: #onEditDocumentation
  653. to: self;
  654. on: HLDocumentationFocusRequested
  655. send: #onDocumentationFocusRequested
  656. to: self
  657. !
  658. observeSystem
  659. self model systemAnnouncer
  660. on: ClassCommentChanged
  661. send: #onClassCommentChanged:
  662. to: self
  663. !
  664. selectClass: aClass
  665. self model selectedClass: aClass
  666. !
  667. unregister
  668. super unregister.
  669. self model announcer unregister: self
  670. ! !
  671. !HLDocumentationWidget methodsFor: 'defaults'!
  672. defaultDocumentation
  673. ^ 'No documentation is available for this class.'
  674. !
  675. defaultHead
  676. ^ 'No class selected'
  677. ! !
  678. !HLDocumentationWidget methodsFor: 'reactions'!
  679. onClassCommentChanged: anAnnouncement
  680. self model selectedClass ifNil: [ ^ self ].
  681. anAnnouncement theClass = self model selectedClass theNonMetaClass
  682. ifTrue: [ self refresh ]
  683. !
  684. onClassSelected: anAnnouncement
  685. self refresh
  686. !
  687. onDocumentationFocusRequested
  688. self focus
  689. !
  690. onEditDocumentation
  691. self
  692. request: self model selectedClass theNonMetaClass name, ' comment'
  693. value: self model selectedClass theNonMetaClass comment
  694. do: [ :comment | self setClassComment: comment ]
  695. !
  696. setClassComment: aString
  697. self model setClassComment: aString
  698. ! !
  699. !HLDocumentationWidget methodsFor: 'rendering'!
  700. renderContentOn: html
  701. html div
  702. class: 'doc';
  703. with: [
  704. self
  705. renderHeadOn: html;
  706. renderDocOn: html ]
  707. !
  708. renderDocOn: html
  709. self selectedItem ifNotNil: [
  710. self renderInheritanceOn: html.
  711. html h1
  712. with: 'Overview';
  713. with: [
  714. html button
  715. class: 'button default';
  716. with: 'Edit';
  717. onClick: [ self editDocumentation ] ].
  718. (html div
  719. class: 'markdown';
  720. asJQuery) html: ((Showdown at: 'converter') new makeHtml: self documentation) ]
  721. !
  722. renderHeadOn: html
  723. html div
  724. class: 'head';
  725. with: self head
  726. !
  727. renderInheritanceOn: html
  728. html div
  729. class: 'inheritance';
  730. with: [
  731. html with: 'Subclass of '.
  732. self selectedItem superclass
  733. ifNil: [ html em with: 'nil' ]
  734. ifNotNil: [
  735. html a
  736. with: self selectedItem superclass name;
  737. onClick: [ self selectClass: self selectedItem superclass ] ] ]
  738. ! !
  739. HLToolListWidget subclass: #HLMethodsListWidget
  740. instanceVariableNames: 'selectorsCache'
  741. package: 'Helios-Browser'!
  742. !HLMethodsListWidget commentStamp!
  743. I render a list of methods for the selected protocol.!
  744. !HLMethodsListWidget methodsFor: 'accessing'!
  745. allProtocol
  746. ^ self model allProtocol
  747. !
  748. cssClassForItem: aSelector
  749. | override overriden method |
  750. method := self methodForSelector: aSelector.
  751. override := self isOverride: method.
  752. overriden := self isOverridden: method.
  753. ^ override
  754. ifTrue: [ overriden
  755. ifTrue: [ 'override-overridden' ]
  756. ifFalse: [ 'override' ] ]
  757. ifFalse: [
  758. overriden
  759. ifTrue: [ 'overridden' ]
  760. ifFalse: [ '' ] ]
  761. !
  762. label
  763. ^ 'Methods'
  764. !
  765. methodForSelector: aSelector
  766. ^ self model selectedClass
  767. methodDictionary at: aSelector
  768. !
  769. methodsInProtocol: aString
  770. self model selectedClass ifNil: [ ^ #() ].
  771. ^ aString = self allProtocol
  772. ifTrue: [ self model selectedClass methods ]
  773. ifFalse: [ self model selectedClass methodsInProtocol: aString ]
  774. !
  775. overrideSelectors
  776. ^ self selectorsCache
  777. at: 'override'
  778. ifAbsentPut: [
  779. self model selectedClass allSuperclasses
  780. inject: Set new into: [ :acc :each | acc addAll: each selectors; yourself ] ]
  781. !
  782. overridenSelectors
  783. ^ self selectorsCache
  784. at: 'overriden'
  785. ifAbsentPut: [
  786. self model selectedClass allSubclasses
  787. inject: Set new into: [ :acc :each | acc addAll: each selectors; yourself ] ]
  788. !
  789. selectorsCache
  790. ^ self class selectorsCache
  791. !
  792. selectorsInProtocol: aString
  793. ^ ((self methodsInProtocol: aString)
  794. collect: [ :each | each selector ]) sorted
  795. ! !
  796. !HLMethodsListWidget methodsFor: 'actions'!
  797. focus
  798. super focus.
  799. self selectedItem ifNil: [
  800. self model showMethodTemplate ]
  801. !
  802. observeModel
  803. self model announcer
  804. on: HLProtocolSelected
  805. send: #onProtocolSelected:
  806. to: self;
  807. on: HLShowInstanceToggled
  808. send: #onShowInstanceToggled
  809. to: self;
  810. on: HLMethodSelected
  811. send: #onMethodSelected:
  812. to: self;
  813. on: HLMethodsFocusRequested
  814. send: #onMethodsFocusRequested
  815. to: self
  816. !
  817. observeSystem
  818. self model systemAnnouncer
  819. on: ProtocolAdded
  820. send: #onProtocolAdded:
  821. to: self;
  822. on: ProtocolRemoved
  823. send: #onProtocolRemoved:
  824. to: self;
  825. on: MethodAdded
  826. send: #onMethodAdded:
  827. to: self;
  828. on: MethodRemoved
  829. send: #onMethodRemoved:
  830. to: self;
  831. on: MethodMoved
  832. send: #onMethodMoved:
  833. to: self
  834. !
  835. reselectItem: aSelector
  836. self model forceSelectedMethod: (self methodForSelector: aSelector)
  837. !
  838. selectItem: aSelector
  839. aSelector ifNil: [ ^ self model selectedMethod: nil ].
  840. self model selectedMethod: (self methodForSelector: aSelector)
  841. ! !
  842. !HLMethodsListWidget methodsFor: 'private'!
  843. setItemsForProtocol: aString
  844. ^ self items: (aString
  845. ifNil: [ #() ]
  846. ifNotNil: [ self selectorsInProtocol: aString ])
  847. !
  848. setItemsForSelectedProtocol
  849. self setItemsForProtocol: self model selectedProtocol
  850. ! !
  851. !HLMethodsListWidget methodsFor: 'reactions'!
  852. onMethodAdded: anAnnouncement
  853. self model selectedClass = anAnnouncement method methodClass ifFalse: [ ^ self ].
  854. self setItemsForSelectedProtocol.
  855. self refresh
  856. !
  857. onMethodMoved: anAnnouncement
  858. self model selectedMethod = anAnnouncement method ifFalse: [ ^ self ].
  859. self model selectedProtocol = self model allProtocol ifFalse: [
  860. self
  861. selectedItem: nil;
  862. selectItem: nil;
  863. setItemsForSelectedProtocol;
  864. refresh ]
  865. !
  866. onMethodRemoved: anAnnouncement
  867. | method |
  868. method := anAnnouncement method.
  869. self items detect: [ :each | each = method selector ] ifNone: [ ^ self ].
  870. self selectedItem ifNotNil: [
  871. (method methodClass = self model selectedClass and: [ method selector = self selectedItem ])
  872. ifTrue: [
  873. self selectedItem: nil;
  874. selectItem: nil ] ].
  875. self setItemsForSelectedProtocol.
  876. self
  877. refresh;
  878. focus
  879. !
  880. onMethodSelected: anAnnouncement
  881. | selector method |
  882. method := anAnnouncement item.
  883. selector := method isCompiledMethod
  884. ifTrue: [ method selector ]
  885. ifFalse: [ nil ].
  886. self
  887. selectedItem: selector;
  888. activateItem: selector
  889. !
  890. onMethodsFocusRequested
  891. self focus
  892. !
  893. onProtocolAdded: anAnnouncement
  894. self model selectedClass = anAnnouncement theClass ifFalse: [ ^ self ].
  895. self setItemsForSelectedProtocol.
  896. self refresh.
  897. self focus
  898. !
  899. onProtocolRemoved: anAnnouncement
  900. self model selectedClass = anAnnouncement theClass ifFalse: [ ^ self ].
  901. self setItemsForSelectedProtocol.
  902. self refresh.
  903. self focus
  904. !
  905. onProtocolSelected: anAnnouncement
  906. self selectedItem: nil.
  907. self setItemsForSelectedProtocol.
  908. self refresh
  909. !
  910. onShowInstanceToggled
  911. self onProtocolSelected: nil
  912. ! !
  913. !HLMethodsListWidget methodsFor: 'rendering'!
  914. renderContentOn: html
  915. self model showInstance
  916. ifFalse: [ html div
  917. class: 'class_side';
  918. with: [ super renderContentOn: html ] ]
  919. ifTrue: [ super renderContentOn: html ]
  920. !
  921. renderItemLabel: aSelector on: html
  922. | methodClass |
  923. methodClass := (self methodForSelector: aSelector) methodClass.
  924. self model selectedClass = methodClass
  925. ifTrue: [ html with: aSelector ]
  926. ifFalse: [ html with: aSelector; with: ' '; with: '(', methodClass name, ')' ]
  927. ! !
  928. !HLMethodsListWidget methodsFor: 'testing'!
  929. isOverridden: aMethod
  930. ^ self selectorsCache isOverridden: aMethod
  931. !
  932. isOverride: aMethod
  933. ^ self selectorsCache isOverride: aMethod
  934. ! !
  935. HLMethodsListWidget class instanceVariableNames: 'selectorsCache'!
  936. !HLMethodsListWidget class methodsFor: 'accessing'!
  937. selectorsCache
  938. ^ HLSelectorsCache current
  939. ! !
  940. HLToolListWidget subclass: #HLPackagesListWidget
  941. instanceVariableNames: ''
  942. package: 'Helios-Browser'!
  943. !HLPackagesListWidget commentStamp!
  944. I render a list of the system packages.!
  945. !HLPackagesListWidget methodsFor: 'accessing'!
  946. cssClassForItem: anItem
  947. ^ anItem isDirty
  948. ifTrue: [ 'package_dirty' ]
  949. ifFalse: [ 'package' ]
  950. !
  951. items
  952. ^ items ifNil: [ self initializeItems ]
  953. !
  954. label
  955. ^ 'Packages'
  956. ! !
  957. !HLPackagesListWidget methodsFor: 'actions'!
  958. focusClassesListWidget
  959. self model announcer announce: HLClassesListFocus new
  960. !
  961. observeModel
  962. self model announcer
  963. on: HLPackageSelected
  964. send: #onPackageSelected:
  965. to: self;
  966. on: HLPackagesFocusRequested
  967. send: #onPackagesFocusRequested
  968. to: self
  969. !
  970. observeSystem
  971. self model systemAnnouncer
  972. on: ClassAdded
  973. send: #onClassAdded:
  974. to: self.
  975. self model systemAnnouncer
  976. on: PackageAdded
  977. send: #onPackageAdded:
  978. to: self.
  979. self model systemAnnouncer
  980. on: PackageClean
  981. send: #onPackageStateChanged
  982. to: self.
  983. self model systemAnnouncer
  984. on: PackageDirty
  985. send: #onPackageStateChanged
  986. to: self.
  987. !
  988. reselectItem: anItem
  989. self model forceSelectedPackage: anItem
  990. !
  991. selectItem: aPackage
  992. super selectItem: aPackage.
  993. self model selectedPackage: aPackage
  994. ! !
  995. !HLPackagesListWidget methodsFor: 'initialization'!
  996. initializeItems
  997. ^ items := self model packages
  998. sort: [ :a :b | a name < b name ]
  999. ! !
  1000. !HLPackagesListWidget methodsFor: 'reactions'!
  1001. onClassAdded: anAnnouncement
  1002. "Amber doesn't have yet a global organizer for packages"
  1003. (self items includes: anAnnouncement theClass package) ifFalse: [
  1004. self
  1005. initializeItems;
  1006. refresh ]
  1007. !
  1008. onPackageAdded: anAnnouncement
  1009. self
  1010. initializeItems;
  1011. refresh
  1012. !
  1013. onPackageSelected: anAnnouncement
  1014. | package |
  1015. package := anAnnouncement item.
  1016. self selectedItem: package.
  1017. self hasFocus ifFalse: [
  1018. self
  1019. activateItem: package;
  1020. focus ]
  1021. !
  1022. onPackageStateChanged
  1023. self refresh
  1024. !
  1025. onPackagesFocusRequested
  1026. self focus
  1027. ! !
  1028. !HLPackagesListWidget methodsFor: 'rendering'!
  1029. renderItemLabel: aPackage on: html
  1030. html with: aPackage name
  1031. ! !
  1032. HLToolListWidget subclass: #HLProtocolsListWidget
  1033. instanceVariableNames: ''
  1034. package: 'Helios-Browser'!
  1035. !HLProtocolsListWidget commentStamp!
  1036. I render a list of protocols for the selected class.!
  1037. !HLProtocolsListWidget methodsFor: 'accessing'!
  1038. allProtocol
  1039. ^ self model allProtocol
  1040. !
  1041. cssClassForItem: anItem
  1042. anItem = self allProtocol ifTrue: [ ^ '' ].
  1043. anItem = 'private' ifTrue: [ ^ 'private' ].
  1044. anItem = 'initialization' ifTrue: [ ^ 'initialization' ].
  1045. (anItem match: '^\*') ifTrue: [ ^ 'extension' ].
  1046. ^ ''
  1047. !
  1048. label
  1049. ^ 'Protocols'
  1050. !
  1051. selectedItem
  1052. ^ super selectedItem" ifNil: [ self allProtocol ]"
  1053. ! !
  1054. !HLProtocolsListWidget methodsFor: 'actions'!
  1055. observeModel
  1056. self model announcer
  1057. on: HLClassSelected
  1058. send: #onClassSelected:
  1059. to: self;
  1060. on: HLShowInstanceToggled
  1061. send: #onClassSelected:
  1062. to: self;
  1063. on: HLProtocolSelected
  1064. send: #onProtocolSelected:
  1065. to: self;
  1066. on: HLProtocolsFocusRequested
  1067. send: #onProtocolsFocusRequested
  1068. to: self
  1069. !
  1070. observeSystem
  1071. self model systemAnnouncer
  1072. on: ProtocolAdded
  1073. send: #onProtocolAdded:
  1074. to: self;
  1075. on: ProtocolRemoved
  1076. send: #onProtocolRemoved:
  1077. to: self
  1078. !
  1079. reselectItem: anItem
  1080. self model forceSelectedProtocol: anItem
  1081. !
  1082. selectItem: aString
  1083. self model selectedProtocol: aString
  1084. ! !
  1085. !HLProtocolsListWidget methodsFor: 'private'!
  1086. setItemsForClass: aClass
  1087. self items: (aClass
  1088. ifNil: [ Array with: self allProtocol ]
  1089. ifNotNil: [
  1090. (Array with: self allProtocol)
  1091. addAll: aClass protocols;
  1092. yourself ])
  1093. !
  1094. setItemsForSelectedClass
  1095. self setItemsForClass: self model selectedClass
  1096. ! !
  1097. !HLProtocolsListWidget methodsFor: 'reactions'!
  1098. onClassSelected: anAnnouncement
  1099. self selectedItem: nil.
  1100. self setItemsForSelectedClass.
  1101. self refresh
  1102. !
  1103. onProtocolAdded: anAnnouncement
  1104. | class |
  1105. class := anAnnouncement theClass.
  1106. class = self model selectedClass ifFalse: [ ^ self ].
  1107. self setItemsForSelectedClass.
  1108. self refresh
  1109. !
  1110. onProtocolRemoved: anAnnouncement
  1111. | class protocol |
  1112. class := anAnnouncement theClass.
  1113. protocol := anAnnouncement protocol.
  1114. class = self model selectedClass ifFalse: [ ^ self ].
  1115. self model selectedProtocol = protocol
  1116. ifTrue: [
  1117. self
  1118. selectedItem: nil;
  1119. selectItem: nil ].
  1120. self setItemsForSelectedClass.
  1121. self refresh
  1122. !
  1123. onProtocolSelected: anAnnouncement
  1124. | protocol |
  1125. protocol := anAnnouncement item.
  1126. self selectedItem: protocol.
  1127. protocol ifNil: [ ^ self ].
  1128. self hasFocus ifFalse: [
  1129. self
  1130. activateItem: protocol;
  1131. focus ]
  1132. !
  1133. onProtocolsFocusRequested
  1134. self focus
  1135. ! !
  1136. !HLProtocolsListWidget methodsFor: 'rendering'!
  1137. renderContentOn: html
  1138. self model showInstance
  1139. ifFalse: [ html div
  1140. class: 'class_side';
  1141. with: [ super renderContentOn: html ] ]
  1142. ifTrue: [ super renderContentOn: html ]
  1143. ! !
  1144. Object subclass: #HLSelectorsCache
  1145. instanceVariableNames: 'classesCache'
  1146. package: 'Helios-Browser'!
  1147. !HLSelectorsCache methodsFor: 'accessing'!
  1148. cacheFor: aClass
  1149. aClass ifNil: [ ^ nil ].
  1150. ^ self classesCache
  1151. at: aClass name
  1152. ifAbsentPut: [ self newCacheFor: aClass ]
  1153. !
  1154. classesCache
  1155. ^ classesCache ifNil: [ classesCache := HashedCollection new ]
  1156. ! !
  1157. !HLSelectorsCache methodsFor: 'actions'!
  1158. observeSystem
  1159. SystemAnnouncer current
  1160. on: MethodAdded
  1161. send: #onMethodAdded:
  1162. to: self;
  1163. on: MethodRemoved
  1164. send: #onMethodRemoved:
  1165. to: self
  1166. ! !
  1167. !HLSelectorsCache methodsFor: 'factory'!
  1168. newCacheFor: aClass
  1169. ^ HLClassCache
  1170. on: aClass
  1171. selectorsCache: self
  1172. ! !
  1173. !HLSelectorsCache methodsFor: 'initialization'!
  1174. initialize
  1175. super initialize.
  1176. self observeSystem
  1177. ! !
  1178. !HLSelectorsCache methodsFor: 'private'!
  1179. invalidateCacheFor: aMethod
  1180. (self cacheFor: aMethod methodClass)
  1181. invalidateSelector: aMethod selector
  1182. ! !
  1183. !HLSelectorsCache methodsFor: 'reactions'!
  1184. onMethodAdded: anAnnouncement
  1185. self invalidateCacheFor: anAnnouncement method
  1186. !
  1187. onMethodRemoved: anAnnouncement
  1188. self invalidateCacheFor: anAnnouncement method
  1189. ! !
  1190. !HLSelectorsCache methodsFor: 'testing'!
  1191. isOverridden: aMethod
  1192. ^ (self cacheFor: aMethod methodClass)
  1193. isOverridden: aMethod
  1194. !
  1195. isOverride: aMethod
  1196. ^ (self cacheFor: aMethod methodClass)
  1197. isOverride: aMethod
  1198. ! !
  1199. HLSelectorsCache class instanceVariableNames: 'current'!
  1200. !HLSelectorsCache class methodsFor: 'accessing'!
  1201. current
  1202. ^ current ifNil: [ current := super new ]
  1203. !
  1204. flush
  1205. current := nil
  1206. ! !
  1207. !HLSelectorsCache class methodsFor: 'instance creation'!
  1208. new
  1209. self shouldNotImplement
  1210. ! !