Helios-Browser.st 28 KB

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