Helios-Browser.st 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341
  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: ProtocolAdded
  330. do: [ :ann | self onProtocolAdded: ann theClass ];
  331. on: ProtocolRemoved
  332. do: [ :ann | self onProtocolRemoved: ann theClass ];
  333. on: MethodAdded
  334. do: [ :ann | self onMethodAdded: ann method ];
  335. on: MethodRemoved
  336. do: [ :ann | self onMethodRemoved: ann method ]
  337. !
  338. selectItem: aSelector
  339. aSelector ifNil: [ ^ self model selectedMethod: nil ].
  340. self model selectedMethod: (self methodForSelector: aSelector)
  341. ! !
  342. !HLMethodsListWidget methodsFor: 'cache'!
  343. flushSelectorsCache
  344. selectorsCache := Dictionary new
  345. ! !
  346. !HLMethodsListWidget methodsFor: 'initialization'!
  347. initialize
  348. super initialize.
  349. self flushSelectorsCache
  350. ! !
  351. !HLMethodsListWidget methodsFor: 'private'!
  352. setItemsForProtocol: aString
  353. ^ self items: (aString
  354. ifNil: [ #() ]
  355. ifNotNil: [ self selectorsInProtocol: aString ])
  356. !
  357. setItemsForSelectedProtocol
  358. self setItemsForProtocol: self model selectedProtocol
  359. ! !
  360. !HLMethodsListWidget methodsFor: 'reactions'!
  361. onMethodAdded: aMethod
  362. self model selectedClass = aMethod methodClass ifFalse: [ ^ self ].
  363. self setItemsForSelectedProtocol.
  364. self refresh
  365. !
  366. onMethodRemoved: aMethod
  367. self items detect: [ :each | each = aMethod selector ] ifNone: [ ^ self ].
  368. self selectedItem ifNotNil: [
  369. (aMethod methodClass = self model selectedClass and: [ aMethod selector = self selectedItem selector ])
  370. ifTrue: [ self selectItem: nil ] ].
  371. self setItemsForSelectedProtocol.
  372. self refresh
  373. !
  374. onMethodSelected: aMethod
  375. self selectedItem: aMethod.
  376. aMethod ifNil: [ ^ self ].
  377. self focus
  378. !
  379. onMethodsFocusRequested
  380. self focus
  381. !
  382. onProtocolAdded: aClass
  383. self model selectedClass = aClass ifFalse: [ ^ self ].
  384. self setItemsForSelectedProtocol.
  385. self refresh.
  386. self focus
  387. !
  388. onProtocolRemoved: aClass
  389. self model selectedClass = aClass ifFalse: [ ^ self ].
  390. self setItemsForSelectedProtocol.
  391. self refresh.
  392. self focus
  393. !
  394. onProtocolSelected: aString
  395. self selectedItem: nil.
  396. self setItemsForSelectedProtocol.
  397. self refresh
  398. ! !
  399. !HLMethodsListWidget methodsFor: 'rendering'!
  400. renderContentOn: html
  401. self model showInstance
  402. ifFalse: [ html div
  403. class: 'class_side';
  404. with: [ super renderContentOn: html ] ]
  405. ifTrue: [ super renderContentOn: html ]
  406. !
  407. renderItemLabel: aSelector on: html
  408. html with: aSelector
  409. ! !
  410. !HLMethodsListWidget methodsFor: 'testing'!
  411. isOverridden: aMethod
  412. ^ self selectorsCache isOverridden: aMethod
  413. !
  414. isOverride: aMethod
  415. ^ self selectorsCache isOverride: aMethod
  416. ! !
  417. HLMethodsListWidget class instanceVariableNames: 'selectorsCache'!
  418. !HLMethodsListWidget class methodsFor: 'accessing'!
  419. selectorsCache
  420. ^ HLSelectorsCache current
  421. ! !
  422. HLBrowserListWidget subclass: #HLPackagesListWidget
  423. instanceVariableNames: ''
  424. package: 'Helios-Browser'!
  425. !HLPackagesListWidget methodsFor: 'accessing'!
  426. initializeItems
  427. ^ items := self model packages sort:[:a :b|
  428. a name < b name]
  429. !
  430. items
  431. ^ items ifNil: [self initializeItems]
  432. ! !
  433. !HLPackagesListWidget methodsFor: 'actions'!
  434. focusClassesListWidget
  435. self model announcer announce: HLClassesListFocus new
  436. !
  437. observeModel
  438. self model announcer
  439. on: HLPackageSelected
  440. do: [ :ann | self onPackageSelected: ann item ];
  441. on: HLPackagesFocusRequested
  442. do: [ :ann | self onPackagesFocusRequested ]
  443. !
  444. selectItem: aPackage
  445. self model selectedPackage: aPackage
  446. ! !
  447. !HLPackagesListWidget methodsFor: 'reactions'!
  448. onPackageSelected: aPackage
  449. self selectedItem: aPackage.
  450. self 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 focus
  540. !
  541. onProtocolsFocusRequested
  542. self focus
  543. ! !
  544. !HLProtocolsListWidget methodsFor: 'rendering'!
  545. renderContentOn: html
  546. self model showInstance
  547. ifFalse: [ html div
  548. class: 'class_side';
  549. with: [ super renderContentOn: html ] ]
  550. ifTrue: [ super renderContentOn: html ]
  551. ! !
  552. Object subclass: #HLBrowserModel
  553. instanceVariableNames: 'announcer environment selectedPackage selectedClass selectedProtocol selectedSelector showInstance showComment'
  554. package: 'Helios-Browser'!
  555. !HLBrowserModel methodsFor: 'accessing'!
  556. announcer
  557. ^ announcer ifNil: [ announcer := Announcer new ]
  558. !
  559. availableClassNames
  560. ^ self environment availableClassNames
  561. !
  562. availableProtocols
  563. ^ self environment availableProtocolsFor: self selectedClass
  564. !
  565. environment
  566. ^ environment ifNil: [ HLManager current environment ]
  567. !
  568. environment: anEnvironment
  569. environment := anEnvironment
  570. !
  571. handleUnkownVariableError: anError
  572. self announcer announce: (HLUnknownVariableErrorRaised new
  573. error: anError;
  574. yourself)
  575. !
  576. manager
  577. ^ HLManager current
  578. !
  579. packages
  580. ^ self environment packages
  581. !
  582. selectedClass
  583. ^ selectedClass
  584. !
  585. selectedClass: aClass
  586. selectedClass = aClass ifTrue: [
  587. aClass ifNil: [ ^ self ].
  588. self selectedProtocol: nil ].
  589. aClass
  590. ifNil: [ selectedClass := nil ]
  591. ifNotNil: [
  592. self showInstance
  593. ifTrue: [ selectedClass := aClass theNonMetaClass ]
  594. ifFalse: [ selectedClass := aClass theMetaClass ] ].
  595. self selectedProtocol: nil.
  596. self announcer announce: (HLClassSelected on: self selectedClass)
  597. !
  598. selectedMethod
  599. ^ self selectedClass ifNotNil: [
  600. self selectedClass methodDictionary
  601. at: selectedSelector
  602. ifAbsent: [ nil ] ]
  603. !
  604. selectedMethod: aCompiledMethod
  605. selectedSelector = aCompiledMethod ifTrue: [ ^ self ].
  606. aCompiledMethod
  607. ifNil: [ selectedSelector := nil ]
  608. ifNotNil: [
  609. selectedSelector = aCompiledMethod selector ifTrue: [ ^ self ].
  610. selectedSelector := aCompiledMethod selector ].
  611. self announcer announce: (HLMethodSelected on: aCompiledMethod)
  612. !
  613. selectedPackage
  614. ^ selectedPackage
  615. !
  616. selectedPackage: aPackage
  617. selectedPackage = aPackage ifTrue: [ ^ self ].
  618. selectedPackage := aPackage.
  619. self selectedClass: nil.
  620. self announcer announce: (HLPackageSelected on: aPackage)
  621. !
  622. selectedProtocol
  623. ^ selectedProtocol
  624. !
  625. selectedProtocol: aString
  626. selectedProtocol = aString ifTrue: [ ^ self ].
  627. selectedProtocol := aString.
  628. self selectedMethod: nil.
  629. self announcer announce: (HLProtocolSelected on: aString)
  630. !
  631. showComment
  632. ^ showComment ifNil: [ false ]
  633. !
  634. showComment: aBoolean
  635. showComment := aBoolean.
  636. self announcer announce: HLShowCommentToggled new
  637. !
  638. showInstance
  639. ^ showInstance ifNil: [ true ]
  640. !
  641. showInstance: aBoolean
  642. showInstance := aBoolean.
  643. self selectedClass ifNotNil: [
  644. self selectedClass: (aBoolean
  645. ifTrue: [self selectedClass theNonMetaClass ]
  646. ifFalse: [ self selectedClass theMetaClass ]) ].
  647. self announcer announce: HLShowInstanceToggled new
  648. ! !
  649. !HLBrowserModel methodsFor: 'actions'!
  650. addInstVarNamed: aString
  651. self environment addInstVarNamed: aString to: self selectedClass.
  652. self announcer announce: (HLInstVarAdded new
  653. theClass: self selectedClass;
  654. variableName: aString;
  655. yourself)
  656. !
  657. focusOnClasses
  658. self announcer announce: HLClassesFocusRequested new
  659. !
  660. focusOnMethods
  661. self announcer announce: HLMethodsFocusRequested new
  662. !
  663. focusOnPackages
  664. self announcer announce: HLPackagesFocusRequested new
  665. !
  666. focusOnProtocols
  667. self announcer announce: HLProtocolsFocusRequested new
  668. !
  669. focusOnSourceCode
  670. self announcer announce: HLSourceCodeFocusRequested new
  671. !
  672. save: aString
  673. (self shouldCompileClassDefinition: aString)
  674. ifTrue: [ self compileClassDefinition: aString ]
  675. ifFalse: [ self compileMethod: aString ]
  676. !
  677. saveSourceCode
  678. self announcer announce: HLSaveSourceCode new
  679. ! !
  680. !HLBrowserModel methodsFor: 'commands actions'!
  681. commitPackage
  682. self environment commitPackage: self selectedPackage
  683. !
  684. moveMethodToClass: aClassName
  685. self environment
  686. moveMethod: self selectedMethod
  687. toClass: aClassName
  688. !
  689. moveMethodToProtocol: aProtocol
  690. self environment moveMethod: self selectedMethod toProtocol: aProtocol
  691. !
  692. removeMethod
  693. (self manager confirm: 'Do you REALLY want to remove method ', self selectedMethod methodClass name,' >> #', self selectedMethod selector)
  694. ifTrue: [ self environment removeMethod: self selectedMethod ]
  695. ! !
  696. !HLBrowserModel methodsFor: 'compiling'!
  697. compileClassComment: aString
  698. self environment
  699. compileClassComment: aString
  700. for: self selectedClass
  701. !
  702. compileClassDefinition: aString
  703. self environment compileClassDefinition: aString
  704. !
  705. compileMethod: aString
  706. self withCompileErrorHandling: [ self environment
  707. compileMethod: aString
  708. for: self selectedClass
  709. protocol: self compilationProtocol ]
  710. ! !
  711. !HLBrowserModel methodsFor: 'defaults'!
  712. allProtocol
  713. ^ '-- all --'
  714. !
  715. unclassifiedProtocol
  716. ^ 'as yet unclassified'
  717. ! !
  718. !HLBrowserModel methodsFor: 'error handling'!
  719. handleCompileError: anError
  720. self announcer announce: (HLCompileErrorRaised new
  721. error: anError;
  722. yourself)
  723. !
  724. handleParseError: anError
  725. | split line column messageToInsert |
  726. split := anError messageText tokenize: ' : '.
  727. messageToInsert := split second.
  728. "21 = 'Parse error on line ' size + 1"
  729. split := split first copyFrom: 21 to: split first size.
  730. split := split tokenize: ' column '.
  731. line := split first.
  732. column := split second.
  733. self announcer announce: (HLParseErrorRaised new
  734. line: line asNumber;
  735. column: column asNumber;
  736. message: messageToInsert;
  737. error: anError;
  738. yourself)
  739. !
  740. withCompileErrorHandling: aBlock
  741. [
  742. [
  743. aBlock
  744. on: ParseError
  745. do: [:ex | self handleParseError: ex ]
  746. ]
  747. on: UnknownVariableError
  748. do: [ :ex | self handleUnkownVariableError: ex ]
  749. ]
  750. on: CompilerError
  751. do: [ :ex | self handleCompileError: ex ]
  752. ! !
  753. !HLBrowserModel methodsFor: 'private'!
  754. compilationProtocol
  755. | currentProtocol |
  756. currentProtocol := self selectedProtocol.
  757. currentProtocol ifNil: [ currentProtocol := self unclassifiedProtocol ].
  758. self selectedMethod ifNotNil: [ currentProtocol := self selectedMethod protocol ].
  759. ^ currentProtocol = self allProtocol
  760. ifTrue: [ self unclassifiedProtocol ]
  761. ifFalse: [ currentProtocol ]
  762. ! !
  763. !HLBrowserModel methodsFor: 'testing'!
  764. shouldCompileClassDefinition: aString
  765. ^ self selectedClass isNil or: [
  766. aString first asUppercase = aString first ]
  767. ! !
  768. !HLBrowserModel class methodsFor: 'actions'!
  769. on: anEnvironment
  770. ^ self new
  771. environment: anEnvironment;
  772. yourself
  773. ! !
  774. HLWidget subclass: #HLBrowserSourceWidget
  775. instanceVariableNames: 'model methodContents codeWidget'
  776. package: 'Helios-Browser'!
  777. !HLBrowserSourceWidget methodsFor: 'accessing'!
  778. codeWidget
  779. ^ codeWidget ifNil: [ codeWidget := HLSourceCodeWidget on: self model ]
  780. !
  781. contents
  782. ^ self codeWidget contents
  783. !
  784. contents: aString
  785. self methodContents: aString.
  786. self codeWidget contents: aString
  787. !
  788. methodContents
  789. ^ methodContents ifNil: [ methodContents := '' ]
  790. !
  791. methodContents: aString
  792. methodContents := aString
  793. !
  794. model
  795. ^ model
  796. !
  797. model: aBrowserModel
  798. model := aBrowserModel.
  799. self observeModel
  800. ! !
  801. !HLBrowserSourceWidget methodsFor: 'actions'!
  802. focus
  803. self codeWidget focus
  804. !
  805. observeModel
  806. self model announcer
  807. on: HLMethodSelected
  808. do: [ :ann | self onMethodSelected: ann item ];
  809. on: HLClassSelected
  810. do: [ :ann | self onClassSelected: ann item ];
  811. on: HLProtocolSelected
  812. do: [ :ann | self onProtocolSelected: ann item ];
  813. on: HLSourceCodeFocusRequested
  814. do: [ :ann | self onSourceCodeFocusRequested ]
  815. !
  816. observeSystem
  817. SystemAnnouncer current
  818. on: MethodModified
  819. do: [ :ann | self onMethodModified: ann method ]
  820. ! !
  821. !HLBrowserSourceWidget methodsFor: 'initialization'!
  822. initialize
  823. super initialize.
  824. self observeSystem
  825. ! !
  826. !HLBrowserSourceWidget methodsFor: 'reactions'!
  827. onClassSelected: aClass
  828. aClass ifNil: [ ^ self contents: '' ].
  829. self contents: aClass definition
  830. !
  831. onMethodModified: aMethod
  832. self model selectedClass = aMethod methodClass ifFalse: [ ^ self ].
  833. self model selectedMethod ifNil: [ ^ self ].
  834. self model selectedMethod selector = aMethod selector ifFalse: [ ^ self ].
  835. self refresh
  836. !
  837. onMethodSelected: aCompiledMethod
  838. aCompiledMethod ifNil: [ ^ self contents: '' ].
  839. self contents: aCompiledMethod source
  840. !
  841. onProtocolSelected: aString
  842. self model selectedClass ifNil: [ ^ self contents: '' ].
  843. self contents: self model selectedClass definition
  844. !
  845. onSourceCodeFocusRequested
  846. self focus
  847. ! !
  848. !HLBrowserSourceWidget methodsFor: 'rendering'!
  849. renderContentOn: html
  850. self codeWidget renderOn: html
  851. ! !
  852. !HLBrowserSourceWidget methodsFor: 'testing'!
  853. hasFocus
  854. ^ self codeWidget hasFocus
  855. !
  856. hasModification
  857. ^ (self methodContents = self contents) not
  858. ! !
  859. !HLBrowserSourceWidget methodsFor: 'updating'!
  860. refresh
  861. self hasModification ifTrue: [ ^ self ].
  862. self hasFocus ifTrue: [ ^ self ].
  863. self contents: self model selectedMethod source
  864. ! !
  865. !HLBrowserSourceWidget class methodsFor: 'instance creation'!
  866. on: aBrowserModel
  867. ^ self new
  868. model: aBrowserModel;
  869. yourself
  870. ! !
  871. Object subclass: #HLClassCache
  872. instanceVariableNames: 'class selectorsCache overrideCache overriddenCache'
  873. package: 'Helios-Browser'!
  874. !HLClassCache methodsFor: 'accessing'!
  875. overriddenCache
  876. ^ overriddenCache ifNil: [ overriddenCache := HashedCollection new ]
  877. !
  878. overrideCache
  879. ^ overrideCache ifNil: [ overrideCache := HashedCollection new ]
  880. !
  881. selectorsCache
  882. ^ selectorsCache
  883. !
  884. selectorsCache: aCache
  885. selectorsCache := aCache
  886. !
  887. theClass
  888. ^ class
  889. !
  890. theClass: aClass
  891. class := aClass
  892. ! !
  893. !HLClassCache methodsFor: 'actions'!
  894. invalidateChildrenSelector: aSelector
  895. self theClass subclasses do: [ :each |
  896. (self selectorsCache cacheFor: each)
  897. removeSelector: aSelector;
  898. invalidateChildrenSelector: aSelector ]
  899. !
  900. invalidateParentSelector: aSelector
  901. self theClass superclass ifNotNil: [
  902. (self selectorsCache cacheFor: self theClass superclass)
  903. removeSelector: aSelector;
  904. invalidateParentSelector: aSelector ]
  905. !
  906. invalidateSelector: aSelector
  907. self
  908. invalidateParentSelector: aSelector;
  909. invalidateChildrenSelector: aSelector;
  910. removeSelector: aSelector
  911. ! !
  912. !HLClassCache methodsFor: 'private'!
  913. removeSelector: aSelector
  914. self overriddenCache
  915. removeKey: aSelector
  916. ifAbsent: [ ].
  917. self overrideCache
  918. removeKey: aSelector
  919. ifAbsent: [ ]
  920. ! !
  921. !HLClassCache methodsFor: 'testing'!
  922. isOverridden: aMethod
  923. ^ self overriddenCache
  924. at: aMethod selector
  925. ifAbsentPut: [ aMethod isOverridden ]
  926. !
  927. isOverride: aMethod
  928. ^ self overrideCache
  929. at: aMethod selector
  930. ifAbsentPut: [ aMethod isOverride ]
  931. ! !
  932. !HLClassCache class methodsFor: 'instance creation'!
  933. on: aClass selectorsCache: aSelectorsCache
  934. ^ self new
  935. theClass: aClass;
  936. selectorsCache: aSelectorsCache;
  937. yourself
  938. ! !
  939. Object subclass: #HLSelectorsCache
  940. instanceVariableNames: 'classesCache'
  941. package: 'Helios-Browser'!
  942. !HLSelectorsCache methodsFor: 'accessing'!
  943. cacheFor: aClass
  944. aClass ifNil: [ ^ nil ].
  945. ^ self classesCache
  946. at: aClass name
  947. ifAbsentPut: [ self newCacheFor: aClass ]
  948. !
  949. classesCache
  950. ^ classesCache ifNil: [ classesCache := HashedCollection new ]
  951. ! !
  952. !HLSelectorsCache methodsFor: 'actions'!
  953. observeSystem
  954. SystemAnnouncer current
  955. on: MethodAdded
  956. do: [ :ann | self onMethodAdded: ann method ];
  957. on: MethodRemoved
  958. do: [ :ann | self onMethodRemoved: ann method ]
  959. ! !
  960. !HLSelectorsCache methodsFor: 'factory'!
  961. newCacheFor: aClass
  962. ^ HLClassCache
  963. on: aClass
  964. selectorsCache: self
  965. ! !
  966. !HLSelectorsCache methodsFor: 'initialization'!
  967. initialize
  968. super initialize.
  969. self observeSystem
  970. ! !
  971. !HLSelectorsCache methodsFor: 'private'!
  972. invalidateCacheFor: aMethod
  973. (self cacheFor: aMethod methodClass)
  974. invalidateSelector: aMethod selector
  975. ! !
  976. !HLSelectorsCache methodsFor: 'reactions'!
  977. onMethodAdded: aMethod
  978. self invalidateCacheFor: aMethod
  979. !
  980. onMethodRemoved: aMethod
  981. self invalidateCacheFor: aMethod
  982. ! !
  983. !HLSelectorsCache methodsFor: 'testing'!
  984. isOverridden: aMethod
  985. ^ (self cacheFor: aMethod methodClass)
  986. isOverridden: aMethod
  987. !
  988. isOverride: aMethod
  989. ^ (self cacheFor: aMethod methodClass)
  990. isOverride: aMethod
  991. ! !
  992. HLSelectorsCache class instanceVariableNames: 'current'!
  993. !HLSelectorsCache class methodsFor: 'accessing'!
  994. current
  995. ^ current ifNil: [ current := super new ]
  996. !
  997. flush
  998. current := nil
  999. ! !
  1000. !HLSelectorsCache class methodsFor: 'instance creation'!
  1001. new
  1002. self shouldNotImplement
  1003. ! !
  1004. !CompiledMethod methodsFor: '*Helios-Browser'!
  1005. isOverridden
  1006. | selector |
  1007. selector := self selector.
  1008. self methodClass allSubclassesDo: [ :each |
  1009. (each includesSelector: selector)
  1010. ifTrue: [ ^ true ] ].
  1011. ^ false
  1012. !
  1013. isOverride
  1014. | superclass |
  1015. superclass := self methodClass superclass.
  1016. superclass ifNil: [ ^ false ].
  1017. ^ (self methodClass superclass lookupSelector: self selector) notNil
  1018. ! !