Helios-Browser.st 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363
  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. on: ClassMoved
  214. do: [ :ann | self onClassMoved: ann theClass from: ann oldPackage ]
  215. !
  216. selectItem: aClass
  217. self model selectedClass: aClass
  218. !
  219. showComment: aBoolean
  220. self model showComment: aBoolean
  221. !
  222. showInstance: aBoolean
  223. self model showInstance: aBoolean
  224. ! !
  225. !HLClassesListWidget methodsFor: 'private'!
  226. setItemsForPackage: aPackage
  227. self items: (aPackage
  228. ifNil: [ #() ]
  229. ifNotNil: [ ((aPackage classes
  230. collect: [ :each | each theNonMetaClass ]) asSet asArray)
  231. sort: [:a :b | a name < b name ] ]).
  232. !
  233. setItemsForSelectedPackage
  234. self setItemsForPackage: self model selectedPackage
  235. ! !
  236. !HLClassesListWidget methodsFor: 'reactions'!
  237. onClassAdded: aClass
  238. aClass package = self model selectedPackage ifFalse: [ ^ self ].
  239. self setItemsForSelectedPackage.
  240. self refresh
  241. !
  242. onClassMoved: aClass from: aPackage
  243. (aPackage = self model selectedPackage or: [
  244. aClass package = self model selectedPackage ])
  245. ifFalse: [ ^ self ].
  246. (self model selectedClass == aClass and: [
  247. aPackage = self model selectedPackage])
  248. ifTrue: [ self selectItem: nil ].
  249. self setItemsForSelectedPackage.
  250. self refresh
  251. !
  252. onClassRemoved: aClass
  253. aClass package = self model selectedPackage ifFalse: [ ^ self ].
  254. aClass = self model selectedClass ifTrue: [ self selectItem: nil ].
  255. self setItemsForSelectedPackage.
  256. self refresh
  257. !
  258. onClassSelected: aClass
  259. | selectedClass |
  260. aClass ifNil: [ ^ self ].
  261. selectedClass := aClass theNonMetaClass.
  262. self selectedItem: selectedClass.
  263. self hasFocus ifFalse: [
  264. self
  265. activateItem: selectedClass;
  266. focus ]
  267. !
  268. onClassesFocusRequested
  269. self focus
  270. !
  271. onPackageSelected: aPackage
  272. self selectedItem: nil.
  273. self setItemsForSelectedPackage.
  274. self refresh
  275. !
  276. onShowInstanceToggled
  277. self refresh
  278. ! !
  279. !HLClassesListWidget methodsFor: 'rendering'!
  280. renderButtonsOn: html
  281. html div
  282. class: 'btn-group';
  283. at: 'data-toggle' put: 'buttons-radio';
  284. with: [
  285. html button
  286. class: (String streamContents: [ :str |
  287. str nextPutAll: 'btn'.
  288. self showInstance ifTrue: [
  289. str nextPutAll: ' active' ] ]);
  290. with: 'Instance';
  291. onClick: [ self showInstance: true ].
  292. html button
  293. class: (String streamContents: [ :str |
  294. str nextPutAll: 'btn'.
  295. self showClass ifTrue: [
  296. str nextPutAll: ' active' ] ]);
  297. with: 'Class';
  298. onClick: [ self showInstance: false ].
  299. html button
  300. class: (String streamContents: [ :str |
  301. str nextPutAll: 'btn'.
  302. self showComment ifTrue: [
  303. str nextPutAll: ' active' ] ]);
  304. with: 'Doc';
  305. onClick: [ self showComment: true ] ]
  306. !
  307. renderItem: aClass level: anInteger on: html
  308. | li |
  309. li := html li.
  310. self registerMappingFrom: aClass to: li.
  311. li
  312. at: 'list-data' put: (self items indexOf: aClass);
  313. class: (self cssClassForItem: aClass);
  314. with: [
  315. html a
  316. with: [
  317. (html tag: 'i') class: (self iconForItem: aClass).
  318. self renderItemLabel: aClass level: anInteger on: html ];
  319. onClick: [
  320. self activateListItem: li asJQuery ] ].
  321. (self getChildrenOf: aClass) do: [ :each |
  322. self renderItem: each level: anInteger + 1 on: html ]
  323. !
  324. renderItem: aClass on: html
  325. super renderItem: aClass on: html.
  326. (self getChildrenOf: aClass) do: [ :each |
  327. self renderItem: each level: 1 on: html ]
  328. !
  329. renderItemLabel: aClass level: anInteger on: html
  330. html span asJQuery html: (String streamContents: [ :str |
  331. anInteger timesRepeat: [
  332. str nextPutAll: '&nbsp;&nbsp;&nbsp;&nbsp;'].
  333. str nextPutAll: aClass name ])
  334. !
  335. renderItemLabel: aClass on: html
  336. self renderItemLabel: aClass level: 0 on: html
  337. !
  338. renderListOn: html
  339. (self getRootClassesOf: self items)
  340. do: [ :each | self renderItem: each on: html ]
  341. ! !
  342. HLBrowserListWidget subclass: #HLMethodsListWidget
  343. instanceVariableNames: 'selectorsCache'
  344. package: 'Helios-Browser'!
  345. !HLMethodsListWidget methodsFor: 'accessing'!
  346. allProtocol
  347. ^ self model allProtocol
  348. !
  349. iconForItem: aSelector
  350. | override overriden method |
  351. method := self methodForSelector: aSelector.
  352. override := self isOverride: method.
  353. overriden := self isOverridden: method.
  354. ^ override
  355. ifTrue: [ overriden
  356. ifTrue: [ 'icon-resize-vertical' ]
  357. ifFalse: [ 'icon-arrow-up' ] ]
  358. ifFalse: [
  359. overriden
  360. ifTrue: [ 'icon-arrow-down' ]
  361. ifFalse: [ 'icon-none' ] ]
  362. !
  363. label
  364. ^ 'Methods'
  365. !
  366. methodForSelector: aSelector
  367. ^ self model selectedClass
  368. methodDictionary at: aSelector
  369. !
  370. methodsInProtocol: aString
  371. self model selectedClass ifNil: [ ^ #() ].
  372. ^ aString = self allProtocol
  373. ifTrue: [ self model selectedClass methods ]
  374. ifFalse: [ self model selectedClass methodsInProtocol: aString ]
  375. !
  376. overrideSelectors
  377. ^ self selectorsCache
  378. at: 'override'
  379. ifAbsentPut: [
  380. self model selectedClass allSuperclasses
  381. inject: Set new into: [ :acc :each | acc addAll: each selectors; yourself ] ]
  382. !
  383. overridenSelectors
  384. ^ self selectorsCache
  385. at: 'overriden'
  386. ifAbsentPut: [
  387. self model selectedClass allSubclasses
  388. inject: Set new into: [ :acc :each | acc addAll: each selectors; yourself ] ]
  389. !
  390. selectorsCache
  391. ^ self class selectorsCache
  392. !
  393. selectorsInProtocol: aString
  394. ^ (self methodsInProtocol: aString)
  395. collect: [ :each | each selector ]
  396. ! !
  397. !HLMethodsListWidget methodsFor: 'actions'!
  398. observeModel
  399. self model announcer
  400. on: HLProtocolSelected
  401. do: [ :ann | self onProtocolSelected: ann item ];
  402. on: HLShowInstanceToggled
  403. do: [ :ann | self onProtocolSelected: nil ];
  404. on: HLMethodSelected
  405. do: [ :ann | self onMethodSelected: ann item ];
  406. on: HLMethodsFocusRequested
  407. do: [ :ann | self onMethodsFocusRequested ]
  408. !
  409. observeSystem
  410. self model systemAnnouncer
  411. on: ProtocolAdded
  412. do: [ :ann | self onProtocolAdded: ann theClass ];
  413. on: ProtocolRemoved
  414. do: [ :ann | self onProtocolRemoved: ann theClass ];
  415. on: MethodAdded
  416. do: [ :ann | self onMethodAdded: ann method ];
  417. on: MethodRemoved
  418. do: [ :ann | self onMethodRemoved: ann method ]
  419. !
  420. selectItem: aSelector
  421. aSelector ifNil: [ ^ self model selectedMethod: nil ].
  422. self model selectedMethod: (self methodForSelector: aSelector)
  423. ! !
  424. !HLMethodsListWidget methodsFor: 'private'!
  425. setItemsForProtocol: aString
  426. ^ self items: (aString
  427. ifNil: [ #() ]
  428. ifNotNil: [ self selectorsInProtocol: aString ])
  429. !
  430. setItemsForSelectedProtocol
  431. self setItemsForProtocol: self model selectedProtocol
  432. ! !
  433. !HLMethodsListWidget methodsFor: 'reactions'!
  434. onMethodAdded: aMethod
  435. self model selectedClass = aMethod methodClass ifFalse: [ ^ self ].
  436. self setItemsForSelectedProtocol.
  437. self refresh
  438. !
  439. onMethodRemoved: aMethod
  440. self items detect: [ :each | each = aMethod selector ] ifNone: [ ^ self ].
  441. self selectedItem ifNotNil: [
  442. (aMethod methodClass = self model selectedClass and: [ aMethod selector = self selectedItem selector ])
  443. ifTrue: [ self selectItem: nil ] ].
  444. self setItemsForSelectedProtocol.
  445. self refresh
  446. !
  447. onMethodSelected: aMethod
  448. self selectedItem: aMethod.
  449. aMethod ifNil: [ ^ self ].
  450. self hasFocus ifFalse: [
  451. self
  452. activateItem: aMethod;
  453. focus ]
  454. !
  455. onMethodsFocusRequested
  456. self focus
  457. !
  458. onProtocolAdded: aClass
  459. self model selectedClass = aClass ifFalse: [ ^ self ].
  460. self setItemsForSelectedProtocol.
  461. self refresh.
  462. self focus
  463. !
  464. onProtocolRemoved: aClass
  465. self model selectedClass = aClass ifFalse: [ ^ self ].
  466. self setItemsForSelectedProtocol.
  467. self refresh.
  468. self focus
  469. !
  470. onProtocolSelected: aString
  471. self selectedItem: nil.
  472. self setItemsForSelectedProtocol.
  473. self refresh
  474. ! !
  475. !HLMethodsListWidget methodsFor: 'rendering'!
  476. renderContentOn: html
  477. self model showInstance
  478. ifFalse: [ html div
  479. class: 'class_side';
  480. with: [ super renderContentOn: html ] ]
  481. ifTrue: [ super renderContentOn: html ]
  482. !
  483. renderItemLabel: aSelector on: html
  484. html with: aSelector
  485. ! !
  486. !HLMethodsListWidget methodsFor: 'testing'!
  487. isOverridden: aMethod
  488. ^ self selectorsCache isOverridden: aMethod
  489. !
  490. isOverride: aMethod
  491. ^ self selectorsCache isOverride: aMethod
  492. ! !
  493. HLMethodsListWidget class instanceVariableNames: 'selectorsCache'!
  494. !HLMethodsListWidget class methodsFor: 'accessing'!
  495. selectorsCache
  496. ^ HLSelectorsCache current
  497. ! !
  498. HLBrowserListWidget subclass: #HLPackagesListWidget
  499. instanceVariableNames: ''
  500. package: 'Helios-Browser'!
  501. !HLPackagesListWidget methodsFor: 'accessing'!
  502. items
  503. ^ items ifNil: [self initializeItems]
  504. !
  505. label
  506. ^ 'Packages'
  507. ! !
  508. !HLPackagesListWidget methodsFor: 'actions'!
  509. commitPackage
  510. self model commitPackage
  511. !
  512. focusClassesListWidget
  513. self model announcer announce: HLClassesListFocus new
  514. !
  515. observeModel
  516. self model announcer
  517. on: HLPackageSelected
  518. do: [ :ann | self onPackageSelected: ann item ];
  519. on: HLPackagesFocusRequested
  520. do: [ :ann | self onPackagesFocusRequested ]
  521. !
  522. selectItem: aPackage
  523. self model selectedPackage: aPackage
  524. ! !
  525. !HLPackagesListWidget methodsFor: 'initialization'!
  526. initializeItems
  527. ^ items := self model packages
  528. sort: [ :a :b | a name < b name ]
  529. ! !
  530. !HLPackagesListWidget methodsFor: 'reactions'!
  531. onPackageSelected: aPackage
  532. self selectedItem: aPackage.
  533. self hasFocus ifFalse: [
  534. self
  535. activateItem: aPackage;
  536. focus ]
  537. !
  538. onPackagesFocusRequested
  539. self focus
  540. ! !
  541. !HLPackagesListWidget methodsFor: 'rendering'!
  542. renderButtonsOn: html
  543. html div
  544. class: 'buttons';
  545. with: [
  546. html button
  547. class: 'btn';
  548. with: 'Commit';
  549. onClick: [ self commitPackage ] ]
  550. !
  551. renderItemLabel: aPackage on: html
  552. html with: aPackage name
  553. ! !
  554. HLBrowserListWidget subclass: #HLProtocolsListWidget
  555. instanceVariableNames: ''
  556. package: 'Helios-Browser'!
  557. !HLProtocolsListWidget methodsFor: 'accessing'!
  558. allProtocol
  559. ^ self model allProtocol
  560. !
  561. label
  562. ^ 'Protocols'
  563. !
  564. selectedItem
  565. ^ super selectedItem" ifNil: [ self allProtocol ]"
  566. ! !
  567. !HLProtocolsListWidget methodsFor: 'actions'!
  568. observeModel
  569. self model announcer
  570. on: HLClassSelected
  571. do: [ :ann | self onClassSelected: ann item ];
  572. on: HLShowInstanceToggled
  573. do: [ :ann | self onClassSelected: self model selectedClass ];
  574. on: HLProtocolSelected
  575. do: [ :ann | self onProtocolSelected: ann item ];
  576. on: HLProtocolsFocusRequested
  577. do: [ :ann | self onProtocolsFocusRequested ]
  578. !
  579. observeSystem
  580. self model systemAnnouncer
  581. on: ProtocolAdded
  582. do: [ :ann | self onProtocolAdded: ann protocol to: ann theClass ];
  583. on: ProtocolRemoved
  584. do: [ :ann | self onProtocolRemoved: ann protocol from: ann theClass ]
  585. !
  586. selectItem: aString
  587. self model selectedProtocol: aString
  588. ! !
  589. !HLProtocolsListWidget methodsFor: 'private'!
  590. setItemsForClass: aClass
  591. self items: (aClass
  592. ifNil: [ Array with: self allProtocol ]
  593. ifNotNil: [
  594. (Array with: self allProtocol)
  595. addAll: aClass protocols;
  596. yourself ])
  597. !
  598. setItemsForSelectedClass
  599. self setItemsForClass: self model selectedClass
  600. ! !
  601. !HLProtocolsListWidget methodsFor: 'reactions'!
  602. onClassSelected: aClass
  603. self selectedItem: nil.
  604. self setItemsForSelectedClass.
  605. self refresh
  606. !
  607. onProtocolAdded: aString to: aClass
  608. aClass = self model selectedClass ifFalse: [ ^ self ].
  609. self setItemsForSelectedClass.
  610. self refresh
  611. !
  612. onProtocolRemoved: aString from: aClass
  613. aClass = self model selectedClass ifFalse: [ ^ self ].
  614. self model selectedProtocol = aString
  615. ifTrue: [ self selectItem: nil ].
  616. self setItemsForSelectedClass.
  617. self refresh
  618. !
  619. onProtocolSelected: aString
  620. self selectedItem: aString.
  621. aString ifNil: [ ^ self ].
  622. self hasFocus ifFalse: [
  623. self
  624. activateItem: aString;
  625. focus ]
  626. !
  627. onProtocolsFocusRequested
  628. self focus
  629. ! !
  630. !HLProtocolsListWidget methodsFor: 'rendering'!
  631. renderContentOn: html
  632. self model showInstance
  633. ifFalse: [ html div
  634. class: 'class_side';
  635. with: [ super renderContentOn: html ] ]
  636. ifTrue: [ super renderContentOn: html ]
  637. ! !
  638. Object subclass: #HLBrowserModel
  639. instanceVariableNames: 'announcer environment selectedPackage selectedClass selectedProtocol selectedSelector showInstance showComment'
  640. package: 'Helios-Browser'!
  641. !HLBrowserModel methodsFor: 'accessing'!
  642. announcer
  643. ^ announcer ifNil: [ announcer := Announcer new ]
  644. !
  645. availableClassNames
  646. ^ self environment availableClassNames
  647. !
  648. availablePackageNames
  649. ^ self environment availablePackageNames
  650. !
  651. availablePackages
  652. ^ self environment availablePackageNames
  653. !
  654. availableProtocols
  655. ^ self environment availableProtocolsFor: self selectedClass
  656. !
  657. environment
  658. ^ environment ifNil: [ HLManager current environment ]
  659. !
  660. environment: anEnvironment
  661. environment := anEnvironment
  662. !
  663. handleUnkownVariableError: anError
  664. self announcer announce: (HLUnknownVariableErrorRaised new
  665. error: anError;
  666. yourself)
  667. !
  668. manager
  669. ^ HLManager current
  670. !
  671. packages
  672. ^ self environment packages
  673. !
  674. selectedClass
  675. ^ selectedClass
  676. !
  677. selectedClass: aClass
  678. selectedClass = aClass ifTrue: [
  679. aClass ifNil: [ ^ self ].
  680. self selectedProtocol: nil ].
  681. aClass
  682. ifNil: [ selectedClass := nil ]
  683. ifNotNil: [
  684. self showInstance
  685. ifTrue: [ selectedClass := aClass theNonMetaClass ]
  686. ifFalse: [ selectedClass := aClass theMetaClass ] ].
  687. self selectedProtocol: nil.
  688. self announcer announce: (HLClassSelected on: self selectedClass)
  689. !
  690. selectedMethod
  691. ^ self selectedClass ifNotNil: [
  692. self selectedClass methodDictionary
  693. at: selectedSelector
  694. ifAbsent: [ nil ] ]
  695. !
  696. selectedMethod: aCompiledMethod
  697. selectedSelector = aCompiledMethod ifTrue: [ ^ self ].
  698. aCompiledMethod
  699. ifNil: [ selectedSelector := nil ]
  700. ifNotNil: [
  701. selectedSelector = aCompiledMethod selector ifTrue: [ ^ self ].
  702. selectedSelector := aCompiledMethod selector ].
  703. self announcer announce: (HLMethodSelected on: aCompiledMethod)
  704. !
  705. selectedPackage
  706. ^ selectedPackage
  707. !
  708. selectedPackage: aPackage
  709. selectedPackage = aPackage ifTrue: [ ^ self ].
  710. selectedPackage := aPackage.
  711. self selectedClass: nil.
  712. self announcer announce: (HLPackageSelected on: aPackage)
  713. !
  714. selectedProtocol
  715. ^ selectedProtocol
  716. !
  717. selectedProtocol: aString
  718. selectedProtocol = aString ifTrue: [ ^ self ].
  719. selectedProtocol := aString.
  720. self selectedMethod: nil.
  721. self announcer announce: (HLProtocolSelected on: aString)
  722. !
  723. showComment
  724. ^ showComment ifNil: [ false ]
  725. !
  726. showComment: aBoolean
  727. showComment := aBoolean.
  728. self announcer announce: HLShowCommentToggled new
  729. !
  730. showInstance
  731. ^ showInstance ifNil: [ true ]
  732. !
  733. showInstance: aBoolean
  734. showInstance := aBoolean.
  735. showComment := false.
  736. self selectedClass ifNotNil: [
  737. self selectedClass: (aBoolean
  738. ifTrue: [self selectedClass theNonMetaClass ]
  739. ifFalse: [ self selectedClass theMetaClass ]) ].
  740. self announcer announce: HLShowInstanceToggled new
  741. !
  742. systemAnnouncer
  743. ^ self environment systemAnnouncer
  744. ! !
  745. !HLBrowserModel methodsFor: 'actions'!
  746. addInstVarNamed: aString
  747. self environment addInstVarNamed: aString to: self selectedClass.
  748. self announcer announce: (HLInstVarAdded new
  749. theClass: self selectedClass;
  750. variableName: aString;
  751. yourself)
  752. !
  753. focusOnClasses
  754. self announcer announce: HLClassesFocusRequested new
  755. !
  756. focusOnMethods
  757. self announcer announce: HLMethodsFocusRequested new
  758. !
  759. focusOnPackages
  760. self announcer announce: HLPackagesFocusRequested new
  761. !
  762. focusOnProtocols
  763. self announcer announce: HLProtocolsFocusRequested new
  764. !
  765. focusOnSourceCode
  766. self announcer announce: HLSourceCodeFocusRequested new
  767. !
  768. save: aString
  769. (self shouldCompileClassDefinition: aString)
  770. ifTrue: [ self compileClassDefinition: aString ]
  771. ifFalse: [ self compileMethod: aString ]
  772. !
  773. saveSourceCode
  774. self announcer announce: HLSaveSourceCode new
  775. ! !
  776. !HLBrowserModel methodsFor: 'commands actions'!
  777. commitPackage
  778. self
  779. withHelperLabelled: 'Committing package ', self selectedPackage name, '...'
  780. do: [ self environment commitPackage: self selectedPackage ]
  781. !
  782. moveClassToPackage: aPackageName
  783. self environment
  784. moveClass: self selectedClass theNonMetaClass
  785. toPackage: aPackageName
  786. !
  787. moveMethodToClass: aClassName
  788. self environment
  789. moveMethod: self selectedMethod
  790. toClass: aClassName
  791. !
  792. moveMethodToProtocol: aProtocol
  793. self environment moveMethod: self selectedMethod toProtocol: aProtocol
  794. !
  795. openClassNamed: aString
  796. | class |
  797. class := self environment classNamed: aString.
  798. self selectedPackage: class package.
  799. self selectedClass: class
  800. !
  801. removeClass
  802. (self manager confirm: 'Do you REALLY want to remove class ', self selectedClass name)
  803. ifTrue: [ self environment removeClass: self selectedClass ]
  804. !
  805. removeMethod
  806. (self manager confirm: 'Do you REALLY want to remove method ', self selectedMethod methodClass name,' >> #', self selectedMethod selector)
  807. ifTrue: [ self environment removeMethod: self selectedMethod ]
  808. ! !
  809. !HLBrowserModel methodsFor: 'compiling'!
  810. compileClassComment: aString
  811. self environment
  812. compileClassComment: aString
  813. for: self selectedClass
  814. !
  815. compileClassDefinition: aString
  816. self environment compileClassDefinition: aString
  817. !
  818. compileMethod: aString
  819. self withCompileErrorHandling: [ self environment
  820. compileMethod: aString
  821. for: self selectedClass
  822. protocol: self compilationProtocol ]
  823. ! !
  824. !HLBrowserModel methodsFor: 'defaults'!
  825. allProtocol
  826. ^ '-- all --'
  827. !
  828. unclassifiedProtocol
  829. ^ 'as yet unclassified'
  830. ! !
  831. !HLBrowserModel methodsFor: 'error handling'!
  832. handleCompileError: anError
  833. self announcer announce: (HLCompileErrorRaised new
  834. error: anError;
  835. yourself)
  836. !
  837. handleParseError: anError
  838. | split line column messageToInsert |
  839. split := anError messageText tokenize: ' : '.
  840. messageToInsert := split second.
  841. "21 = 'Parse error on line ' size + 1"
  842. split := split first copyFrom: 21 to: split first size.
  843. split := split tokenize: ' column '.
  844. line := split first.
  845. column := split second.
  846. self announcer announce: (HLParseErrorRaised new
  847. line: line asNumber;
  848. column: column asNumber;
  849. message: messageToInsert;
  850. error: anError;
  851. yourself)
  852. !
  853. withCompileErrorHandling: aBlock
  854. [
  855. [
  856. aBlock
  857. on: ParseError
  858. do: [:ex | self handleParseError: ex ]
  859. ]
  860. on: UnknownVariableError
  861. do: [ :ex | self handleUnkownVariableError: ex ]
  862. ]
  863. on: CompilerError
  864. do: [ :ex | self handleCompileError: ex ]
  865. ! !
  866. !HLBrowserModel methodsFor: 'private'!
  867. compilationProtocol
  868. | currentProtocol |
  869. currentProtocol := self selectedProtocol.
  870. currentProtocol ifNil: [ currentProtocol := self unclassifiedProtocol ].
  871. self selectedMethod ifNotNil: [ currentProtocol := self selectedMethod protocol ].
  872. ^ currentProtocol = self allProtocol
  873. ifTrue: [ self unclassifiedProtocol ]
  874. ifFalse: [ currentProtocol ]
  875. !
  876. withHelperLabelled: aString do: aBlock
  877. "TODO: doesn't belong here"
  878. (window jQuery: '#helper') remove.
  879. [ :html |
  880. html div
  881. id: 'helper';
  882. with: aString ] appendToJQuery: 'body' asJQuery.
  883. [
  884. aBlock value.
  885. (window jQuery: '#helper') remove
  886. ]
  887. valueWithTimeout: 10
  888. ! !
  889. !HLBrowserModel methodsFor: 'testing'!
  890. shouldCompileClassDefinition: aString
  891. ^ self selectedClass isNil or: [
  892. aString first asUppercase = aString first ]
  893. ! !
  894. !HLBrowserModel class methodsFor: 'actions'!
  895. on: anEnvironment
  896. ^ self new
  897. environment: anEnvironment;
  898. yourself
  899. ! !
  900. Object subclass: #HLClassCache
  901. instanceVariableNames: 'class selectorsCache overrideCache overriddenCache'
  902. package: 'Helios-Browser'!
  903. !HLClassCache methodsFor: 'accessing'!
  904. overriddenCache
  905. ^ overriddenCache ifNil: [ overriddenCache := HashedCollection new ]
  906. !
  907. overrideCache
  908. ^ overrideCache ifNil: [ overrideCache := HashedCollection new ]
  909. !
  910. selectorsCache
  911. ^ selectorsCache
  912. !
  913. selectorsCache: aCache
  914. selectorsCache := aCache
  915. !
  916. theClass
  917. ^ class
  918. !
  919. theClass: aClass
  920. class := aClass
  921. ! !
  922. !HLClassCache methodsFor: 'actions'!
  923. invalidateChildrenSelector: aSelector
  924. self theClass subclasses do: [ :each |
  925. (self selectorsCache cacheFor: each)
  926. removeSelector: aSelector;
  927. invalidateChildrenSelector: aSelector ]
  928. !
  929. invalidateParentSelector: aSelector
  930. self theClass superclass ifNotNil: [
  931. (self selectorsCache cacheFor: self theClass superclass)
  932. removeSelector: aSelector;
  933. invalidateParentSelector: aSelector ]
  934. !
  935. invalidateSelector: aSelector
  936. self
  937. invalidateParentSelector: aSelector;
  938. invalidateChildrenSelector: aSelector;
  939. removeSelector: aSelector
  940. ! !
  941. !HLClassCache methodsFor: 'private'!
  942. removeSelector: aSelector
  943. self overriddenCache
  944. removeKey: aSelector
  945. ifAbsent: [ ].
  946. self overrideCache
  947. removeKey: aSelector
  948. ifAbsent: [ ]
  949. ! !
  950. !HLClassCache methodsFor: 'testing'!
  951. isOverridden: aMethod
  952. ^ self overriddenCache
  953. at: aMethod selector
  954. ifAbsentPut: [ aMethod isOverridden ]
  955. !
  956. isOverride: aMethod
  957. ^ self overrideCache
  958. at: aMethod selector
  959. ifAbsentPut: [ aMethod isOverride ]
  960. ! !
  961. !HLClassCache class methodsFor: 'instance creation'!
  962. on: aClass selectorsCache: aSelectorsCache
  963. ^ self new
  964. theClass: aClass;
  965. selectorsCache: aSelectorsCache;
  966. yourself
  967. ! !
  968. Object subclass: #HLSelectorsCache
  969. instanceVariableNames: 'classesCache'
  970. package: 'Helios-Browser'!
  971. !HLSelectorsCache methodsFor: 'accessing'!
  972. cacheFor: aClass
  973. aClass ifNil: [ ^ nil ].
  974. ^ self classesCache
  975. at: aClass name
  976. ifAbsentPut: [ self newCacheFor: aClass ]
  977. !
  978. classesCache
  979. ^ classesCache ifNil: [ classesCache := HashedCollection new ]
  980. ! !
  981. !HLSelectorsCache methodsFor: 'actions'!
  982. observeSystem
  983. SystemAnnouncer current
  984. on: MethodAdded
  985. do: [ :ann | self onMethodAdded: ann method ];
  986. on: MethodRemoved
  987. do: [ :ann | self onMethodRemoved: ann method ]
  988. ! !
  989. !HLSelectorsCache methodsFor: 'factory'!
  990. newCacheFor: aClass
  991. ^ HLClassCache
  992. on: aClass
  993. selectorsCache: self
  994. ! !
  995. !HLSelectorsCache methodsFor: 'initialization'!
  996. initialize
  997. super initialize.
  998. self observeSystem
  999. ! !
  1000. !HLSelectorsCache methodsFor: 'private'!
  1001. invalidateCacheFor: aMethod
  1002. (self cacheFor: aMethod methodClass)
  1003. invalidateSelector: aMethod selector
  1004. ! !
  1005. !HLSelectorsCache methodsFor: 'reactions'!
  1006. onMethodAdded: aMethod
  1007. self invalidateCacheFor: aMethod
  1008. !
  1009. onMethodRemoved: aMethod
  1010. self invalidateCacheFor: aMethod
  1011. ! !
  1012. !HLSelectorsCache methodsFor: 'testing'!
  1013. isOverridden: aMethod
  1014. ^ (self cacheFor: aMethod methodClass)
  1015. isOverridden: aMethod
  1016. !
  1017. isOverride: aMethod
  1018. ^ (self cacheFor: aMethod methodClass)
  1019. isOverride: aMethod
  1020. ! !
  1021. HLSelectorsCache class instanceVariableNames: 'current'!
  1022. !HLSelectorsCache class methodsFor: 'accessing'!
  1023. current
  1024. ^ current ifNil: [ current := super new ]
  1025. !
  1026. flush
  1027. current := nil
  1028. ! !
  1029. !HLSelectorsCache class methodsFor: 'instance creation'!
  1030. new
  1031. self shouldNotImplement
  1032. ! !
  1033. !CompiledMethod methodsFor: '*Helios-Browser'!
  1034. isOverridden
  1035. | selector |
  1036. selector := self selector.
  1037. self methodClass allSubclassesDo: [ :each |
  1038. (each includesSelector: selector)
  1039. ifTrue: [ ^ true ] ].
  1040. ^ false
  1041. !
  1042. isOverride
  1043. | superclass |
  1044. superclass := self methodClass superclass.
  1045. superclass ifNil: [ ^ false ].
  1046. ^ (self methodClass superclass lookupSelector: self selector) notNil
  1047. ! !