Helios-Browser.st 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348
  1. Smalltalk current createPackage: 'Helios-Browser'!
  2. HLWidget subclass: #HLBrowser
  3. instanceVariableNames: 'model packagesListWidget classesListWidget protocolsListWidget methodsListWidget sourceWidget'
  4. package: 'Helios-Browser'!
  5. !HLBrowser methodsFor: 'accessing'!
  6. announcer
  7. ^ self model announcer
  8. !
  9. environment
  10. ^ self model environment
  11. !
  12. model
  13. ^ model ifNil: [ model := HLBrowserModel new ]
  14. !
  15. model: aModel
  16. model := aModel
  17. ! !
  18. !HLBrowser methodsFor: 'actions'!
  19. focus
  20. ^ self packagesListWidget focus
  21. ! !
  22. !HLBrowser methodsFor: 'keybindings'!
  23. registerBindingsOn: aBindingGroup
  24. HLBrowserCommand
  25. registerConcreteClassesOn: aBindingGroup
  26. for: self model
  27. ! !
  28. !HLBrowser methodsFor: 'rendering'!
  29. renderContentOn: html
  30. html with: (HLContainer with: (HLHorizontalSplitter
  31. with: (HLVerticalSplitter
  32. with: (HLVerticalSplitter
  33. with: self packagesListWidget
  34. with: self classesListWidget)
  35. with: (HLVerticalSplitter
  36. with: self protocolsListWidget
  37. with: self methodsListWidget))
  38. with: self sourceWidget)).
  39. self packagesListWidget focus
  40. ! !
  41. !HLBrowser methodsFor: 'testing'!
  42. canHaveFocus
  43. ^ true
  44. ! !
  45. !HLBrowser methodsFor: 'widgets'!
  46. classesListWidget
  47. ^ classesListWidget ifNil: [
  48. classesListWidget := HLClassesListWidget on: self model.
  49. classesListWidget next: self protocolsListWidget ]
  50. !
  51. methodsListWidget
  52. ^ methodsListWidget ifNil: [
  53. methodsListWidget := HLMethodsListWidget on: self model.
  54. methodsListWidget next: self sourceWidget ]
  55. !
  56. packagesListWidget
  57. ^ packagesListWidget ifNil: [
  58. packagesListWidget := HLPackagesListWidget on: self model.
  59. packagesListWidget next: self classesListWidget ]
  60. !
  61. protocolsListWidget
  62. ^ protocolsListWidget ifNil: [
  63. protocolsListWidget := HLProtocolsListWidget on: self model.
  64. protocolsListWidget next: self methodsListWidget ]
  65. !
  66. sourceWidget
  67. ^ sourceWidget ifNil: [
  68. sourceWidget := HLSourceCodeWidget new
  69. browserModel: self model;
  70. yourself ]
  71. ! !
  72. HLBrowser class instanceVariableNames: 'nextId'!
  73. !HLBrowser class methodsFor: 'accessing'!
  74. nextId
  75. nextId ifNil: [ nextId := 0 ].
  76. ^ 'browser_', (nextId + 1) asString
  77. !
  78. tabLabel
  79. ^ 'Browser'
  80. !
  81. tabPriority
  82. ^ 0
  83. ! !
  84. !HLBrowser class methodsFor: 'testing'!
  85. canBeOpenAsTab
  86. ^ true
  87. ! !
  88. HLNavigationListWidget subclass: #HLBrowserListWidget
  89. instanceVariableNames: 'model'
  90. package: 'Helios-Browser'!
  91. !HLBrowserListWidget methodsFor: 'accessing'!
  92. label
  93. ^ 'List'
  94. !
  95. menuCommands
  96. "Answer a collection of commands to be put in the cog menu"
  97. ^ (HLBrowserCommand concreteClasses
  98. select: [ :each | each isValidFor: self selectedItem ])
  99. collect: [ :each | each for: self model ]
  100. !
  101. model
  102. ^ model
  103. !
  104. model: aBrowserModel
  105. model := aBrowserModel.
  106. self
  107. observeSystem;
  108. observeModel
  109. !
  110. selectedItem: anItem
  111. "Selection changed, update the cog menu"
  112. super selectedItem: anItem.
  113. self updateMenu
  114. ! !
  115. !HLBrowserListWidget methodsFor: 'actions'!
  116. observeModel
  117. !
  118. observeSystem
  119. ! !
  120. !HLBrowserListWidget methodsFor: 'rendering'!
  121. renderContentOn: html
  122. self renderHeadOn: html.
  123. super renderContentOn: html
  124. !
  125. renderHeadOn: html
  126. html div
  127. class: 'list-label';
  128. with: [
  129. html with: self label.
  130. self renderMenuOn: html ]
  131. !
  132. renderMenuOn: html
  133. | commands |
  134. commands := self menuCommands.
  135. commands isEmpty ifTrue: [ ^ self ].
  136. html div
  137. class: 'btn-group cog';
  138. with: [
  139. html a
  140. class: 'btn dropdown-toggle';
  141. at: 'data-toggle' put: 'dropdown';
  142. with: [ (html tag: 'i') class: 'icon-cog' ].
  143. html ul
  144. class: 'dropdown-menu pull-right';
  145. with: [
  146. self menuCommands do: [ :each |
  147. html li with: [ html a
  148. with: each menuLabel;
  149. onClick: [ self execute: each ] ] ] ] ]
  150. ! !
  151. !HLBrowserListWidget methodsFor: 'updating'!
  152. updateMenu
  153. (self wrapper asJQuery find: '.cog') remove.
  154. [ :html | self renderMenuOn: html ]
  155. appendToJQuery: (self wrapper asJQuery find: '.list-label')
  156. ! !
  157. !HLBrowserListWidget class methodsFor: 'instance creation'!
  158. on: aModel
  159. ^ self new
  160. model: aModel;
  161. yourself
  162. ! !
  163. HLBrowserListWidget subclass: #HLClassesListWidget
  164. instanceVariableNames: ''
  165. package: 'Helios-Browser'!
  166. !HLClassesListWidget methodsFor: 'accessing'!
  167. getChildrenOf: aClass
  168. ^ self items select: [ :each | each superclass = aClass ]
  169. !
  170. getRootClassesOf: aCollection
  171. ^ aCollection select: [ :each |
  172. (aCollection includes: each superclass) not ]
  173. !
  174. iconForItem: aClass
  175. ^ aClass theNonMetaClass comment isEmpty
  176. ifFalse: [ 'icon-none' ]
  177. ifTrue: [ 'icon-question-sign' ]
  178. !
  179. label
  180. ^ 'Classes'
  181. !
  182. showClass
  183. ^ self model showInstance not and: [
  184. self model showComment not ]
  185. !
  186. showComment
  187. ^ self model showComment
  188. !
  189. showInstance
  190. ^ self model showInstance and: [
  191. self model showComment not ]
  192. ! !
  193. !HLClassesListWidget methodsFor: 'actions'!
  194. focusMethodsListWidget
  195. self model announcer announce: HLMethodsListFocus new
  196. !
  197. focusProtocolsListWidget
  198. self model announcer announce: HLProtocolsListFocus new
  199. !
  200. observeModel
  201. self model announcer
  202. on: HLPackageSelected do: [ :ann | self onPackageSelected: ann item ];
  203. on: HLShowInstanceToggled do: [ :ann | self onShowInstanceToggled ];
  204. on: HLClassSelected do: [ :ann | self onClassSelected: ann item ];
  205. on: HLClassesFocusRequested do: [ :ann | self onClassesFocusRequested ]
  206. !
  207. observeSystem
  208. self model systemAnnouncer
  209. on: ClassAdded
  210. do: [ :ann | self onClassAdded: ann theClass ];
  211. on: ClassRemoved
  212. do: [ :ann | self onClassRemoved: ann theClass ]
  213. !
  214. selectItem: aClass
  215. self model selectedClass: aClass
  216. !
  217. showComment: aBoolean
  218. self model showComment: aBoolean
  219. !
  220. showInstance: aBoolean
  221. self model showInstance: aBoolean
  222. ! !
  223. !HLClassesListWidget methodsFor: 'private'!
  224. setItemsForPackage: aPackage
  225. self items: (aPackage
  226. ifNil: [ #() ]
  227. ifNotNil: [ ((aPackage classes
  228. collect: [ :each | each theNonMetaClass ]) asSet asArray)
  229. sort: [:a :b | a name < b name ] ]).
  230. !
  231. setItemsForSelectedPackage
  232. self setItemsForPackage: self model selectedPackage
  233. ! !
  234. !HLClassesListWidget methodsFor: 'reactions'!
  235. onClassAdded: aClass
  236. aClass package = self model selectedPackage ifFalse: [ ^ self ].
  237. self setItemsForSelectedPackage.
  238. self refresh
  239. !
  240. onClassRemoved: aClass
  241. aClass package = self model selectedPackage ifFalse: [ ^ self ].
  242. aClass = self model selectedClass ifTrue: [ self selectItem: nil ].
  243. self setItemsForSelectedPackage.
  244. self refresh
  245. !
  246. onClassSelected: aClass
  247. | selectedClass |
  248. aClass ifNil: [ ^ self ].
  249. selectedClass := aClass theNonMetaClass.
  250. self selectedItem: selectedClass.
  251. self hasFocus ifFalse: [
  252. self
  253. activateItem: selectedClass;
  254. focus ]
  255. !
  256. onClassesFocusRequested
  257. self focus
  258. !
  259. onPackageSelected: aPackage
  260. self selectedItem: nil.
  261. self setItemsForSelectedPackage.
  262. self refresh
  263. !
  264. onShowInstanceToggled
  265. self refresh
  266. ! !
  267. !HLClassesListWidget methodsFor: 'rendering'!
  268. renderButtonsOn: html
  269. html div
  270. class: 'btn-group';
  271. at: 'data-toggle' put: 'buttons-radio';
  272. with: [
  273. html button
  274. class: (String streamContents: [ :str |
  275. str nextPutAll: 'btn'.
  276. self showInstance ifTrue: [
  277. str nextPutAll: ' active' ] ]);
  278. with: 'Instance';
  279. onClick: [ self showInstance: true ].
  280. html button
  281. class: (String streamContents: [ :str |
  282. str nextPutAll: 'btn'.
  283. self showClass ifTrue: [
  284. str nextPutAll: ' active' ] ]);
  285. with: 'Class';
  286. onClick: [ self showInstance: false ].
  287. html button
  288. class: (String streamContents: [ :str |
  289. str nextPutAll: 'btn'.
  290. self showComment ifTrue: [
  291. str nextPutAll: ' active' ] ]);
  292. with: 'Doc';
  293. onClick: [ self showComment: true ] ]
  294. !
  295. renderItem: aClass level: anInteger on: html
  296. | li |
  297. li := html li.
  298. self registerMappingFrom: aClass to: li.
  299. li
  300. at: 'list-data' put: (self items indexOf: aClass);
  301. class: (self cssClassForItem: aClass);
  302. with: [
  303. html a
  304. with: [
  305. (html tag: 'i') class: (self iconForItem: aClass).
  306. self renderItemLabel: aClass level: anInteger on: html ];
  307. onClick: [
  308. self activateListItem: li asJQuery ] ].
  309. (self getChildrenOf: aClass) do: [ :each |
  310. self renderItem: each level: anInteger + 1 on: html ]
  311. !
  312. renderItem: aClass on: html
  313. super renderItem: aClass on: html.
  314. (self getChildrenOf: aClass) do: [ :each |
  315. self renderItem: each level: 1 on: html ]
  316. !
  317. renderItemLabel: aClass level: anInteger on: html
  318. html span asJQuery html: (String streamContents: [ :str |
  319. anInteger timesRepeat: [
  320. str nextPutAll: '&nbsp;&nbsp;&nbsp;&nbsp;'].
  321. str nextPutAll: aClass name ])
  322. !
  323. renderItemLabel: aClass on: html
  324. self renderItemLabel: aClass level: 0 on: html
  325. !
  326. renderListOn: html
  327. (self getRootClassesOf: self items)
  328. do: [ :each | self renderItem: each on: html ]
  329. ! !
  330. HLBrowserListWidget subclass: #HLMethodsListWidget
  331. instanceVariableNames: 'selectorsCache'
  332. package: 'Helios-Browser'!
  333. !HLMethodsListWidget methodsFor: 'accessing'!
  334. allProtocol
  335. ^ self model allProtocol
  336. !
  337. iconForItem: aSelector
  338. | override overriden method |
  339. method := self methodForSelector: aSelector.
  340. override := self isOverride: method.
  341. overriden := self isOverridden: method.
  342. ^ override
  343. ifTrue: [ overriden
  344. ifTrue: [ 'icon-resize-vertical' ]
  345. ifFalse: [ 'icon-arrow-up' ] ]
  346. ifFalse: [
  347. overriden
  348. ifTrue: [ 'icon-arrow-down' ]
  349. ifFalse: [ 'icon-none' ] ]
  350. !
  351. label
  352. ^ 'Methods'
  353. !
  354. methodForSelector: aSelector
  355. ^ self model selectedClass
  356. methodDictionary at: aSelector
  357. !
  358. methodsInProtocol: aString
  359. self model selectedClass ifNil: [ ^ #() ].
  360. ^ aString = self allProtocol
  361. ifTrue: [ self model selectedClass methods ]
  362. ifFalse: [ self model selectedClass methodsInProtocol: aString ]
  363. !
  364. overrideSelectors
  365. ^ self selectorsCache
  366. at: 'override'
  367. ifAbsentPut: [
  368. self model selectedClass allSuperclasses
  369. inject: Set new into: [ :acc :each | acc addAll: each selectors; yourself ] ]
  370. !
  371. overridenSelectors
  372. ^ self selectorsCache
  373. at: 'overriden'
  374. ifAbsentPut: [
  375. self model selectedClass allSubclasses
  376. inject: Set new into: [ :acc :each | acc addAll: each selectors; yourself ] ]
  377. !
  378. selectorsCache
  379. ^ self class selectorsCache
  380. !
  381. selectorsInProtocol: aString
  382. ^ (self methodsInProtocol: aString)
  383. collect: [ :each | each selector ]
  384. ! !
  385. !HLMethodsListWidget methodsFor: 'actions'!
  386. observeModel
  387. self model announcer
  388. on: HLProtocolSelected
  389. do: [ :ann | self onProtocolSelected: ann item ];
  390. on: HLShowInstanceToggled
  391. do: [ :ann | self onProtocolSelected: nil ];
  392. on: HLMethodSelected
  393. do: [ :ann | self onMethodSelected: ann item ];
  394. on: HLMethodsFocusRequested
  395. do: [ :ann | self onMethodsFocusRequested ]
  396. !
  397. observeSystem
  398. self model systemAnnouncer
  399. on: ProtocolAdded
  400. do: [ :ann | self onProtocolAdded: ann theClass ];
  401. on: ProtocolRemoved
  402. do: [ :ann | self onProtocolRemoved: ann theClass ];
  403. on: MethodAdded
  404. do: [ :ann | self onMethodAdded: ann method ];
  405. on: MethodRemoved
  406. do: [ :ann | self onMethodRemoved: ann method ]
  407. !
  408. selectItem: aSelector
  409. aSelector ifNil: [ ^ self model selectedMethod: nil ].
  410. self model selectedMethod: (self methodForSelector: aSelector)
  411. ! !
  412. !HLMethodsListWidget methodsFor: 'private'!
  413. setItemsForProtocol: aString
  414. ^ self items: (aString
  415. ifNil: [ #() ]
  416. ifNotNil: [ self selectorsInProtocol: aString ])
  417. !
  418. setItemsForSelectedProtocol
  419. self setItemsForProtocol: self model selectedProtocol
  420. ! !
  421. !HLMethodsListWidget methodsFor: 'reactions'!
  422. onMethodAdded: aMethod
  423. self model selectedClass = aMethod methodClass ifFalse: [ ^ self ].
  424. self setItemsForSelectedProtocol.
  425. self refresh
  426. !
  427. onMethodRemoved: aMethod
  428. self items detect: [ :each | each = aMethod selector ] ifNone: [ ^ self ].
  429. self selectedItem ifNotNil: [
  430. (aMethod methodClass = self model selectedClass and: [ aMethod selector = self selectedItem selector ])
  431. ifTrue: [ self selectItem: nil ] ].
  432. self setItemsForSelectedProtocol.
  433. self refresh
  434. !
  435. onMethodSelected: aMethod
  436. self selectedItem: aMethod.
  437. aMethod ifNil: [ ^ self ].
  438. self hasFocus ifFalse: [
  439. self
  440. activateItem: aMethod;
  441. focus ]
  442. !
  443. onMethodsFocusRequested
  444. self focus
  445. !
  446. onProtocolAdded: aClass
  447. self model selectedClass = aClass ifFalse: [ ^ self ].
  448. self setItemsForSelectedProtocol.
  449. self refresh.
  450. self focus
  451. !
  452. onProtocolRemoved: aClass
  453. self model selectedClass = aClass ifFalse: [ ^ self ].
  454. self setItemsForSelectedProtocol.
  455. self refresh.
  456. self focus
  457. !
  458. onProtocolSelected: aString
  459. self selectedItem: nil.
  460. self setItemsForSelectedProtocol.
  461. self refresh
  462. ! !
  463. !HLMethodsListWidget methodsFor: 'rendering'!
  464. renderContentOn: html
  465. self model showInstance
  466. ifFalse: [ html div
  467. class: 'class_side';
  468. with: [ super renderContentOn: html ] ]
  469. ifTrue: [ super renderContentOn: html ]
  470. !
  471. renderItemLabel: aSelector on: html
  472. html with: aSelector
  473. ! !
  474. !HLMethodsListWidget methodsFor: 'testing'!
  475. isOverridden: aMethod
  476. ^ self selectorsCache isOverridden: aMethod
  477. !
  478. isOverride: aMethod
  479. ^ self selectorsCache isOverride: aMethod
  480. ! !
  481. HLMethodsListWidget class instanceVariableNames: 'selectorsCache'!
  482. !HLMethodsListWidget class methodsFor: 'accessing'!
  483. selectorsCache
  484. ^ HLSelectorsCache current
  485. ! !
  486. HLBrowserListWidget subclass: #HLPackagesListWidget
  487. instanceVariableNames: ''
  488. package: 'Helios-Browser'!
  489. !HLPackagesListWidget methodsFor: 'accessing'!
  490. items
  491. ^ items ifNil: [self initializeItems]
  492. !
  493. label
  494. ^ 'Packages'
  495. ! !
  496. !HLPackagesListWidget methodsFor: 'actions'!
  497. commitPackage
  498. self model commitPackage
  499. !
  500. focusClassesListWidget
  501. self model announcer announce: HLClassesListFocus new
  502. !
  503. observeModel
  504. self model announcer
  505. on: HLPackageSelected
  506. do: [ :ann | self onPackageSelected: ann item ];
  507. on: HLPackagesFocusRequested
  508. do: [ :ann | self onPackagesFocusRequested ]
  509. !
  510. selectItem: aPackage
  511. self model selectedPackage: aPackage
  512. ! !
  513. !HLPackagesListWidget methodsFor: 'initialization'!
  514. initializeItems
  515. ^ items := self model packages
  516. sort: [ :a :b | a name < b name ]
  517. ! !
  518. !HLPackagesListWidget methodsFor: 'reactions'!
  519. onPackageSelected: aPackage
  520. self selectedItem: aPackage.
  521. self hasFocus ifFalse: [
  522. self
  523. activateItem: aPackage;
  524. focus ]
  525. !
  526. onPackagesFocusRequested
  527. self focus
  528. ! !
  529. !HLPackagesListWidget methodsFor: 'rendering'!
  530. renderButtonsOn: html
  531. html div
  532. class: 'buttons';
  533. with: [
  534. html button
  535. class: 'btn';
  536. with: 'Commit';
  537. onClick: [ self commitPackage ] ]
  538. !
  539. renderItemLabel: aPackage on: html
  540. html with: aPackage name
  541. ! !
  542. HLBrowserListWidget subclass: #HLProtocolsListWidget
  543. instanceVariableNames: ''
  544. package: 'Helios-Browser'!
  545. !HLProtocolsListWidget methodsFor: 'accessing'!
  546. allProtocol
  547. ^ self model allProtocol
  548. !
  549. label
  550. ^ 'Protocols'
  551. !
  552. selectedItem
  553. ^ super selectedItem" ifNil: [ self allProtocol ]"
  554. ! !
  555. !HLProtocolsListWidget methodsFor: 'actions'!
  556. observeModel
  557. self model announcer
  558. on: HLClassSelected
  559. do: [ :ann | self onClassSelected: ann item ];
  560. on: HLShowInstanceToggled
  561. do: [ :ann | self onClassSelected: self model selectedClass ];
  562. on: HLProtocolSelected
  563. do: [ :ann | self onProtocolSelected: ann item ];
  564. on: HLProtocolsFocusRequested
  565. do: [ :ann | self onProtocolsFocusRequested ]
  566. !
  567. observeSystem
  568. self model systemAnnouncer
  569. on: ProtocolAdded
  570. do: [ :ann | self onProtocolAdded: ann protocol to: ann theClass ];
  571. on: ProtocolRemoved
  572. do: [ :ann | self onProtocolRemoved: ann protocol from: ann theClass ]
  573. !
  574. selectItem: aString
  575. self model selectedProtocol: aString
  576. ! !
  577. !HLProtocolsListWidget methodsFor: 'private'!
  578. setItemsForClass: aClass
  579. self items: (aClass
  580. ifNil: [ Array with: self allProtocol ]
  581. ifNotNil: [
  582. (Array with: self allProtocol)
  583. addAll: aClass protocols;
  584. yourself ])
  585. !
  586. setItemsForSelectedClass
  587. self setItemsForClass: self model selectedClass
  588. ! !
  589. !HLProtocolsListWidget methodsFor: 'reactions'!
  590. onClassSelected: aClass
  591. self selectedItem: nil.
  592. self setItemsForSelectedClass.
  593. self refresh
  594. !
  595. onProtocolAdded: aString to: aClass
  596. aClass = self model selectedClass ifFalse: [ ^ self ].
  597. self setItemsForSelectedClass.
  598. self refresh
  599. !
  600. onProtocolRemoved: aString from: aClass
  601. aClass = self model selectedClass ifFalse: [ ^ self ].
  602. self model selectedProtocol = aString
  603. ifTrue: [ self selectItem: nil ].
  604. self setItemsForSelectedClass.
  605. self refresh
  606. !
  607. onProtocolSelected: aString
  608. self selectedItem: aString.
  609. aString ifNil: [ ^ self ].
  610. self hasFocus ifFalse: [
  611. self
  612. activateItem: aString;
  613. focus ]
  614. !
  615. onProtocolsFocusRequested
  616. self focus
  617. ! !
  618. !HLProtocolsListWidget methodsFor: 'rendering'!
  619. renderContentOn: html
  620. self model showInstance
  621. ifFalse: [ html div
  622. class: 'class_side';
  623. with: [ super renderContentOn: html ] ]
  624. ifTrue: [ super renderContentOn: html ]
  625. ! !
  626. Object subclass: #HLBrowserModel
  627. instanceVariableNames: 'announcer environment selectedPackage selectedClass selectedProtocol selectedSelector showInstance showComment'
  628. package: 'Helios-Browser'!
  629. !HLBrowserModel methodsFor: 'accessing'!
  630. announcer
  631. ^ announcer ifNil: [ announcer := Announcer new ]
  632. !
  633. availableClassNames
  634. ^ self environment availableClassNames
  635. !
  636. availablePackageNames
  637. ^ self environment availablePackageNames
  638. !
  639. availablePackages
  640. ^ self environment availablePackageNames
  641. !
  642. availableProtocols
  643. ^ self environment availableProtocolsFor: self selectedClass
  644. !
  645. environment
  646. ^ environment ifNil: [ HLManager current environment ]
  647. !
  648. environment: anEnvironment
  649. environment := anEnvironment
  650. !
  651. handleUnkownVariableError: anError
  652. self announcer announce: (HLUnknownVariableErrorRaised new
  653. error: anError;
  654. yourself)
  655. !
  656. manager
  657. ^ HLManager current
  658. !
  659. packages
  660. ^ self environment packages
  661. !
  662. selectedClass
  663. ^ selectedClass
  664. !
  665. selectedClass: aClass
  666. selectedClass = aClass ifTrue: [
  667. aClass ifNil: [ ^ self ].
  668. self selectedProtocol: nil ].
  669. aClass
  670. ifNil: [ selectedClass := nil ]
  671. ifNotNil: [
  672. self showInstance
  673. ifTrue: [ selectedClass := aClass theNonMetaClass ]
  674. ifFalse: [ selectedClass := aClass theMetaClass ] ].
  675. self selectedProtocol: nil.
  676. self announcer announce: (HLClassSelected on: self selectedClass)
  677. !
  678. selectedMethod
  679. ^ self selectedClass ifNotNil: [
  680. self selectedClass methodDictionary
  681. at: selectedSelector
  682. ifAbsent: [ nil ] ]
  683. !
  684. selectedMethod: aCompiledMethod
  685. selectedSelector = aCompiledMethod ifTrue: [ ^ self ].
  686. aCompiledMethod
  687. ifNil: [ selectedSelector := nil ]
  688. ifNotNil: [
  689. selectedSelector = aCompiledMethod selector ifTrue: [ ^ self ].
  690. selectedSelector := aCompiledMethod selector ].
  691. self announcer announce: (HLMethodSelected on: aCompiledMethod)
  692. !
  693. selectedPackage
  694. ^ selectedPackage
  695. !
  696. selectedPackage: aPackage
  697. selectedPackage = aPackage ifTrue: [ ^ self ].
  698. selectedPackage := aPackage.
  699. self selectedClass: nil.
  700. self announcer announce: (HLPackageSelected on: aPackage)
  701. !
  702. selectedProtocol
  703. ^ selectedProtocol
  704. !
  705. selectedProtocol: aString
  706. selectedProtocol = aString ifTrue: [ ^ self ].
  707. selectedProtocol := aString.
  708. self selectedMethod: nil.
  709. self announcer announce: (HLProtocolSelected on: aString)
  710. !
  711. showComment
  712. ^ showComment ifNil: [ false ]
  713. !
  714. showComment: aBoolean
  715. showComment := aBoolean.
  716. self announcer announce: HLShowCommentToggled new
  717. !
  718. showInstance
  719. ^ showInstance ifNil: [ true ]
  720. !
  721. showInstance: aBoolean
  722. showInstance := aBoolean.
  723. showComment := false.
  724. self selectedClass ifNotNil: [
  725. self selectedClass: (aBoolean
  726. ifTrue: [self selectedClass theNonMetaClass ]
  727. ifFalse: [ self selectedClass theMetaClass ]) ].
  728. self announcer announce: HLShowInstanceToggled new
  729. !
  730. systemAnnouncer
  731. ^ self environment systemAnnouncer
  732. ! !
  733. !HLBrowserModel methodsFor: 'actions'!
  734. addInstVarNamed: aString
  735. self environment addInstVarNamed: aString to: self selectedClass.
  736. self announcer announce: (HLInstVarAdded new
  737. theClass: self selectedClass;
  738. variableName: aString;
  739. yourself)
  740. !
  741. focusOnClasses
  742. self announcer announce: HLClassesFocusRequested new
  743. !
  744. focusOnMethods
  745. self announcer announce: HLMethodsFocusRequested new
  746. !
  747. focusOnPackages
  748. self announcer announce: HLPackagesFocusRequested new
  749. !
  750. focusOnProtocols
  751. self announcer announce: HLProtocolsFocusRequested new
  752. !
  753. focusOnSourceCode
  754. self announcer announce: HLSourceCodeFocusRequested new
  755. !
  756. save: aString
  757. (self shouldCompileClassDefinition: aString)
  758. ifTrue: [ self compileClassDefinition: aString ]
  759. ifFalse: [ self compileMethod: aString ]
  760. !
  761. saveSourceCode
  762. self announcer announce: HLSaveSourceCode new
  763. ! !
  764. !HLBrowserModel methodsFor: 'commands actions'!
  765. commitPackage
  766. self
  767. withHelperLabelled: 'Committing package ', self selectedPackage name, '...'
  768. do: [ self environment commitPackage: self selectedPackage ]
  769. !
  770. moveClassToPackage: aPackageName
  771. self environment
  772. moveClass: self selectedClass theNonMetaClass
  773. toPackage: aPackageName
  774. !
  775. moveMethodToClass: aClassName
  776. self environment
  777. moveMethod: self selectedMethod
  778. toClass: aClassName
  779. !
  780. moveMethodToProtocol: aProtocol
  781. self environment moveMethod: self selectedMethod toProtocol: aProtocol
  782. !
  783. openClassNamed: aString
  784. | class |
  785. class := self environment classNamed: aString.
  786. self selectedPackage: class package.
  787. self selectedClass: class
  788. !
  789. removeClass
  790. (self manager confirm: 'Do you REALLY want to remove class ', self selectedClass name)
  791. ifTrue: [ self environment removeClass: self selectedClass ]
  792. !
  793. removeMethod
  794. (self manager confirm: 'Do you REALLY want to remove method ', self selectedMethod methodClass name,' >> #', self selectedMethod selector)
  795. ifTrue: [ self environment removeMethod: self selectedMethod ]
  796. ! !
  797. !HLBrowserModel methodsFor: 'compiling'!
  798. compileClassComment: aString
  799. self environment
  800. compileClassComment: aString
  801. for: self selectedClass
  802. !
  803. compileClassDefinition: aString
  804. self environment compileClassDefinition: aString
  805. !
  806. compileMethod: aString
  807. self withCompileErrorHandling: [ self environment
  808. compileMethod: aString
  809. for: self selectedClass
  810. protocol: self compilationProtocol ]
  811. ! !
  812. !HLBrowserModel methodsFor: 'defaults'!
  813. allProtocol
  814. ^ '-- all --'
  815. !
  816. unclassifiedProtocol
  817. ^ 'as yet unclassified'
  818. ! !
  819. !HLBrowserModel methodsFor: 'error handling'!
  820. handleCompileError: anError
  821. self announcer announce: (HLCompileErrorRaised new
  822. error: anError;
  823. yourself)
  824. !
  825. handleParseError: anError
  826. | split line column messageToInsert |
  827. split := anError messageText tokenize: ' : '.
  828. messageToInsert := split second.
  829. "21 = 'Parse error on line ' size + 1"
  830. split := split first copyFrom: 21 to: split first size.
  831. split := split tokenize: ' column '.
  832. line := split first.
  833. column := split second.
  834. self announcer announce: (HLParseErrorRaised new
  835. line: line asNumber;
  836. column: column asNumber;
  837. message: messageToInsert;
  838. error: anError;
  839. yourself)
  840. !
  841. withCompileErrorHandling: aBlock
  842. [
  843. [
  844. aBlock
  845. on: ParseError
  846. do: [:ex | self handleParseError: ex ]
  847. ]
  848. on: UnknownVariableError
  849. do: [ :ex | self handleUnkownVariableError: ex ]
  850. ]
  851. on: CompilerError
  852. do: [ :ex | self handleCompileError: ex ]
  853. ! !
  854. !HLBrowserModel methodsFor: 'private'!
  855. compilationProtocol
  856. | currentProtocol |
  857. currentProtocol := self selectedProtocol.
  858. currentProtocol ifNil: [ currentProtocol := self unclassifiedProtocol ].
  859. self selectedMethod ifNotNil: [ currentProtocol := self selectedMethod protocol ].
  860. ^ currentProtocol = self allProtocol
  861. ifTrue: [ self unclassifiedProtocol ]
  862. ifFalse: [ currentProtocol ]
  863. !
  864. withHelperLabelled: aString do: aBlock
  865. "TODO: doesn't belong here"
  866. (window jQuery: '#helper') remove.
  867. [ :html |
  868. html div
  869. id: 'helper';
  870. with: aString ] appendToJQuery: 'body' asJQuery.
  871. [
  872. aBlock value.
  873. (window jQuery: '#helper') remove
  874. ]
  875. valueWithTimeout: 10
  876. ! !
  877. !HLBrowserModel methodsFor: 'testing'!
  878. shouldCompileClassDefinition: aString
  879. ^ self selectedClass isNil or: [
  880. aString first asUppercase = aString first ]
  881. ! !
  882. !HLBrowserModel class methodsFor: 'actions'!
  883. on: anEnvironment
  884. ^ self new
  885. environment: anEnvironment;
  886. yourself
  887. ! !
  888. Object subclass: #HLClassCache
  889. instanceVariableNames: 'class selectorsCache overrideCache overriddenCache'
  890. package: 'Helios-Browser'!
  891. !HLClassCache methodsFor: 'accessing'!
  892. overriddenCache
  893. ^ overriddenCache ifNil: [ overriddenCache := HashedCollection new ]
  894. !
  895. overrideCache
  896. ^ overrideCache ifNil: [ overrideCache := HashedCollection new ]
  897. !
  898. selectorsCache
  899. ^ selectorsCache
  900. !
  901. selectorsCache: aCache
  902. selectorsCache := aCache
  903. !
  904. theClass
  905. ^ class
  906. !
  907. theClass: aClass
  908. class := aClass
  909. ! !
  910. !HLClassCache methodsFor: 'actions'!
  911. invalidateChildrenSelector: aSelector
  912. self theClass subclasses do: [ :each |
  913. (self selectorsCache cacheFor: each)
  914. removeSelector: aSelector;
  915. invalidateChildrenSelector: aSelector ]
  916. !
  917. invalidateParentSelector: aSelector
  918. self theClass superclass ifNotNil: [
  919. (self selectorsCache cacheFor: self theClass superclass)
  920. removeSelector: aSelector;
  921. invalidateParentSelector: aSelector ]
  922. !
  923. invalidateSelector: aSelector
  924. self
  925. invalidateParentSelector: aSelector;
  926. invalidateChildrenSelector: aSelector;
  927. removeSelector: aSelector
  928. ! !
  929. !HLClassCache methodsFor: 'private'!
  930. removeSelector: aSelector
  931. self overriddenCache
  932. removeKey: aSelector
  933. ifAbsent: [ ].
  934. self overrideCache
  935. removeKey: aSelector
  936. ifAbsent: [ ]
  937. ! !
  938. !HLClassCache methodsFor: 'testing'!
  939. isOverridden: aMethod
  940. ^ self overriddenCache
  941. at: aMethod selector
  942. ifAbsentPut: [ aMethod isOverridden ]
  943. !
  944. isOverride: aMethod
  945. ^ self overrideCache
  946. at: aMethod selector
  947. ifAbsentPut: [ aMethod isOverride ]
  948. ! !
  949. !HLClassCache class methodsFor: 'instance creation'!
  950. on: aClass selectorsCache: aSelectorsCache
  951. ^ self new
  952. theClass: aClass;
  953. selectorsCache: aSelectorsCache;
  954. yourself
  955. ! !
  956. Object subclass: #HLSelectorsCache
  957. instanceVariableNames: 'classesCache'
  958. package: 'Helios-Browser'!
  959. !HLSelectorsCache methodsFor: 'accessing'!
  960. cacheFor: aClass
  961. aClass ifNil: [ ^ nil ].
  962. ^ self classesCache
  963. at: aClass name
  964. ifAbsentPut: [ self newCacheFor: aClass ]
  965. !
  966. classesCache
  967. ^ classesCache ifNil: [ classesCache := HashedCollection new ]
  968. ! !
  969. !HLSelectorsCache methodsFor: 'actions'!
  970. observeSystem
  971. SystemAnnouncer current
  972. on: MethodAdded
  973. do: [ :ann | self onMethodAdded: ann method ];
  974. on: MethodRemoved
  975. do: [ :ann | self onMethodRemoved: ann method ]
  976. ! !
  977. !HLSelectorsCache methodsFor: 'factory'!
  978. newCacheFor: aClass
  979. ^ HLClassCache
  980. on: aClass
  981. selectorsCache: self
  982. ! !
  983. !HLSelectorsCache methodsFor: 'initialization'!
  984. initialize
  985. super initialize.
  986. self observeSystem
  987. ! !
  988. !HLSelectorsCache methodsFor: 'private'!
  989. invalidateCacheFor: aMethod
  990. (self cacheFor: aMethod methodClass)
  991. invalidateSelector: aMethod selector
  992. ! !
  993. !HLSelectorsCache methodsFor: 'reactions'!
  994. onMethodAdded: aMethod
  995. self invalidateCacheFor: aMethod
  996. !
  997. onMethodRemoved: aMethod
  998. self invalidateCacheFor: aMethod
  999. ! !
  1000. !HLSelectorsCache methodsFor: 'testing'!
  1001. isOverridden: aMethod
  1002. ^ (self cacheFor: aMethod methodClass)
  1003. isOverridden: aMethod
  1004. !
  1005. isOverride: aMethod
  1006. ^ (self cacheFor: aMethod methodClass)
  1007. isOverride: aMethod
  1008. ! !
  1009. HLSelectorsCache class instanceVariableNames: 'current'!
  1010. !HLSelectorsCache class methodsFor: 'accessing'!
  1011. current
  1012. ^ current ifNil: [ current := super new ]
  1013. !
  1014. flush
  1015. current := nil
  1016. ! !
  1017. !HLSelectorsCache class methodsFor: 'instance creation'!
  1018. new
  1019. self shouldNotImplement
  1020. ! !
  1021. !CompiledMethod methodsFor: '*Helios-Browser'!
  1022. isOverridden
  1023. | selector |
  1024. selector := self selector.
  1025. self methodClass allSubclassesDo: [ :each |
  1026. (each includesSelector: selector)
  1027. ifTrue: [ ^ true ] ].
  1028. ^ false
  1029. !
  1030. isOverride
  1031. | superclass |
  1032. superclass := self methodClass superclass.
  1033. superclass ifNil: [ ^ false ].
  1034. ^ (self methodClass superclass lookupSelector: self selector) notNil
  1035. ! !