1
0

Helios-Browser.st 28 KB

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