Helios-Browser.st 28 KB

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