Helios-Browser.st 30 KB

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