Helios-Browser.st 29 KB

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