1
0

Helios-Browser.st 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317
  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. handleUnkownVariableError: anError
  556. self announcer announce: (HLUnknownVariableErrorRaised new
  557. error: anError;
  558. yourself)
  559. !
  560. manager
  561. ^ HLManager current
  562. !
  563. packages
  564. ^ self environment packages
  565. !
  566. selectedClass
  567. ^ selectedClass
  568. !
  569. selectedClass: aClass
  570. selectedClass = aClass ifTrue: [
  571. aClass ifNil: [ ^ self ].
  572. self selectedProtocol: nil ].
  573. aClass
  574. ifNil: [ selectedClass := nil ]
  575. ifNotNil: [
  576. self showInstance
  577. ifTrue: [ selectedClass := aClass theNonMetaClass ]
  578. ifFalse: [ selectedClass := aClass theMetaClass ] ].
  579. self selectedProtocol: nil.
  580. self announcer announce: (HLClassSelected on: self selectedClass)
  581. !
  582. selectedMethod
  583. ^ self selectedClass ifNotNil: [
  584. self selectedClass methodDictionary
  585. at: selectedSelector
  586. ifAbsent: [ nil ] ]
  587. !
  588. selectedMethod: aCompiledMethod
  589. selectedSelector = aCompiledMethod ifTrue: [ ^ self ].
  590. aCompiledMethod
  591. ifNil: [ selectedSelector := nil ]
  592. ifNotNil: [
  593. selectedSelector = aCompiledMethod selector ifTrue: [ ^ self ].
  594. selectedSelector := aCompiledMethod selector ].
  595. self announcer announce: (HLMethodSelected on: aCompiledMethod)
  596. !
  597. selectedPackage
  598. ^ selectedPackage
  599. !
  600. selectedPackage: aPackage
  601. selectedPackage = aPackage ifTrue: [ ^ self ].
  602. selectedPackage := aPackage.
  603. self selectedClass: nil.
  604. self announcer announce: (HLPackageSelected on: aPackage)
  605. !
  606. selectedProtocol
  607. ^ selectedProtocol
  608. !
  609. selectedProtocol: aString
  610. selectedProtocol = aString ifTrue: [ ^ self ].
  611. selectedProtocol := aString.
  612. self selectedMethod: nil.
  613. self announcer announce: (HLProtocolSelected on: aString)
  614. !
  615. showComment
  616. ^ showComment ifNil: [ false ]
  617. !
  618. showComment: aBoolean
  619. showComment := aBoolean.
  620. self announcer announce: HLShowCommentToggled new
  621. !
  622. showInstance
  623. ^ showInstance ifNil: [ true ]
  624. !
  625. showInstance: aBoolean
  626. showInstance := aBoolean.
  627. self selectedClass ifNotNil: [
  628. self selectedClass: (aBoolean
  629. ifTrue: [self selectedClass theNonMetaClass ]
  630. ifFalse: [ self selectedClass theMetaClass ]) ].
  631. self announcer announce: HLShowInstanceToggled new
  632. ! !
  633. !HLBrowserModel methodsFor: 'actions'!
  634. addInstVarNamed: aString
  635. self environment addInstVarNamed: aString to: self selectedClass.
  636. self announcer announce: (HLInstVarAdded new
  637. theClass: self selectedClass;
  638. variableName: aString;
  639. yourself)
  640. !
  641. focusOnClasses
  642. self announcer announce: HLClassesFocusRequested new
  643. !
  644. focusOnMethods
  645. self announcer announce: HLMethodsFocusRequested new
  646. !
  647. focusOnPackages
  648. self announcer announce: HLPackagesFocusRequested new
  649. !
  650. focusOnProtocols
  651. self announcer announce: HLProtocolsFocusRequested new
  652. !
  653. focusOnSourceCode
  654. self announcer announce: HLSourceCodeFocusRequested new
  655. !
  656. save: aString
  657. (self shouldCompileClassDefinition: aString)
  658. ifTrue: [ self compileClassDefinition: aString ]
  659. ifFalse: [ self compileMethod: aString ]
  660. !
  661. saveSourceCode
  662. self announcer announce: HLSaveSourceCode new
  663. ! !
  664. !HLBrowserModel methodsFor: 'commands actions'!
  665. moveMethodToClass: aClassName
  666. self environment
  667. moveMethod: self selectedMethod
  668. toClass: aClassName
  669. !
  670. moveMethodToProtocol: aProtocol
  671. self environment moveMethod: self selectedMethod toProtocol: aProtocol
  672. !
  673. removeMethod
  674. (self manager confirm: 'Do you REALLY want to remove method ', self selectedMethod methodClass name,' >> #', self selectedMethod selector)
  675. ifTrue: [ self environment removeMethod: self selectedMethod ]
  676. ! !
  677. !HLBrowserModel methodsFor: 'compiling'!
  678. compileClassComment: aString
  679. self environment
  680. compileClassComment: aString
  681. for: self selectedClass
  682. !
  683. compileClassDefinition: aString
  684. self environment compileClassDefinition: aString
  685. !
  686. compileMethod: aString
  687. self withCompileErrorHandling: [ self environment
  688. compileMethod: aString
  689. for: self selectedClass
  690. protocol: self compilationProtocol ]
  691. ! !
  692. !HLBrowserModel methodsFor: 'defaults'!
  693. allProtocol
  694. ^ '-- all --'
  695. !
  696. unclassifiedProtocol
  697. ^ 'as yet unclassified'
  698. ! !
  699. !HLBrowserModel methodsFor: 'error handling'!
  700. handleCompileError: anError
  701. self announcer announce: (HLCompileErrorRaised new
  702. error: anError;
  703. yourself)
  704. !
  705. handleParseError: anError
  706. | split line column messageToInsert |
  707. split := anError messageText tokenize: ' : '.
  708. messageToInsert := split second.
  709. "21 = 'Parse error on line ' size + 1"
  710. split := split first copyFrom: 21 to: split first size.
  711. split := split tokenize: ' column '.
  712. line := split first.
  713. column := split second.
  714. self announcer announce: (HLParseErrorRaised new
  715. line: line asNumber;
  716. column: column asNumber;
  717. message: messageToInsert;
  718. error: anError;
  719. yourself)
  720. !
  721. withCompileErrorHandling: aBlock
  722. [
  723. [
  724. aBlock
  725. on: ParseError
  726. do: [:ex | self handleParseError: ex ]
  727. ]
  728. on: UnknownVariableError
  729. do: [ :ex | self handleUnkownVariableError: ex ]
  730. ]
  731. on: CompilerError
  732. do: [ :ex | self handleCompileError: ex ]
  733. ! !
  734. !HLBrowserModel methodsFor: 'private'!
  735. compilationProtocol
  736. | currentProtocol |
  737. currentProtocol := self selectedProtocol.
  738. currentProtocol ifNil: [ currentProtocol := self unclassifiedProtocol ].
  739. self selectedMethod ifNotNil: [ currentProtocol := self selectedMethod protocol ].
  740. ^ currentProtocol = self allProtocol
  741. ifTrue: [ self unclassifiedProtocol ]
  742. ifFalse: [ currentProtocol ]
  743. ! !
  744. !HLBrowserModel methodsFor: 'testing'!
  745. shouldCompileClassDefinition: aString
  746. ^ self selectedClass isNil or: [
  747. aString first asUppercase = aString first ]
  748. ! !
  749. !HLBrowserModel class methodsFor: 'actions'!
  750. on: anEnvironment
  751. ^ self new
  752. environment: anEnvironment;
  753. yourself
  754. ! !
  755. HLWidget subclass: #HLBrowserSourceWidget
  756. instanceVariableNames: 'model methodContents codeWidget'
  757. package: 'Helios-Browser'!
  758. !HLBrowserSourceWidget methodsFor: 'accessing'!
  759. codeWidget
  760. ^ codeWidget ifNil: [ codeWidget := HLSourceCodeWidget on: self model ]
  761. !
  762. contents
  763. ^ self codeWidget contents
  764. !
  765. contents: aString
  766. self methodContents: aString.
  767. self codeWidget contents: aString
  768. !
  769. methodContents
  770. ^ methodContents ifNil: [ methodContents := '' ]
  771. !
  772. methodContents: aString
  773. methodContents := aString
  774. !
  775. model
  776. ^ model
  777. !
  778. model: aBrowserModel
  779. model := aBrowserModel.
  780. self observeModel
  781. ! !
  782. !HLBrowserSourceWidget methodsFor: 'actions'!
  783. focus
  784. self codeWidget focus
  785. !
  786. observeModel
  787. self model announcer
  788. on: HLMethodSelected
  789. do: [ :ann | self onMethodSelected: ann item ];
  790. on: HLClassSelected
  791. do: [ :ann | self onClassSelected: ann item ];
  792. on: HLProtocolSelected
  793. do: [ :ann | self onProtocolSelected: ann item ];
  794. on: HLSourceCodeFocusRequested
  795. do: [ :ann | self onSourceCodeFocusRequested ]
  796. !
  797. observeSystem
  798. SystemAnnouncer current
  799. on: MethodModified
  800. do: [ :ann | self onMethodModified: ann method ]
  801. ! !
  802. !HLBrowserSourceWidget methodsFor: 'initialization'!
  803. initialize
  804. super initialize.
  805. self observeSystem
  806. ! !
  807. !HLBrowserSourceWidget methodsFor: 'reactions'!
  808. onClassSelected: aClass
  809. aClass ifNil: [ ^ self contents: '' ].
  810. self contents: aClass definition
  811. !
  812. onMethodModified: aMethod
  813. self model selectedClass = aMethod methodClass ifFalse: [ ^ self ].
  814. self model selectedMethod ifNil: [ ^ self ].
  815. self model selectedMethod selector = aMethod selector ifFalse: [ ^ self ].
  816. self refresh
  817. !
  818. onMethodSelected: aCompiledMethod
  819. aCompiledMethod ifNil: [ ^ self contents: '' ].
  820. self contents: aCompiledMethod source
  821. !
  822. onProtocolSelected: aString
  823. self model selectedClass ifNil: [ ^ self contents: '' ].
  824. self contents: self model selectedClass definition
  825. !
  826. onSourceCodeFocusRequested
  827. self focus
  828. ! !
  829. !HLBrowserSourceWidget methodsFor: 'rendering'!
  830. renderContentOn: html
  831. self codeWidget renderOn: html
  832. ! !
  833. !HLBrowserSourceWidget methodsFor: 'testing'!
  834. hasFocus
  835. ^ self codeWidget hasFocus
  836. !
  837. hasModification
  838. ^ (self methodContents = self contents) not
  839. ! !
  840. !HLBrowserSourceWidget methodsFor: 'updating'!
  841. refresh
  842. self hasModification ifTrue: [ ^ self ].
  843. self hasFocus ifTrue: [ ^ self ].
  844. self contents: self model selectedMethod source
  845. ! !
  846. !HLBrowserSourceWidget class methodsFor: 'instance creation'!
  847. on: aBrowserModel
  848. ^ self new
  849. model: aBrowserModel;
  850. yourself
  851. ! !
  852. Object subclass: #HLClassCache
  853. instanceVariableNames: 'class selectorsCache overrideCache overriddenCache'
  854. package: 'Helios-Browser'!
  855. !HLClassCache methodsFor: 'accessing'!
  856. overriddenCache
  857. ^ overriddenCache ifNil: [ overriddenCache := HashedCollection new ]
  858. !
  859. overrideCache
  860. ^ overrideCache ifNil: [ overrideCache := HashedCollection new ]
  861. !
  862. selectorsCache
  863. ^ selectorsCache
  864. !
  865. selectorsCache: aCache
  866. selectorsCache := aCache
  867. !
  868. theClass
  869. ^ class
  870. !
  871. theClass: aClass
  872. class := aClass
  873. ! !
  874. !HLClassCache methodsFor: 'actions'!
  875. invalidateChildrenSelector: aSelector
  876. self theClass subclasses do: [ :each |
  877. (self selectorsCache cacheFor: each)
  878. removeSelector: aSelector;
  879. invalidateChildrenSelector: aSelector ]
  880. !
  881. invalidateParentSelector: aSelector
  882. self theClass superclass ifNotNil: [
  883. (self selectorsCache cacheFor: self theClass superclass)
  884. removeSelector: aSelector;
  885. invalidateParentSelector: aSelector ]
  886. !
  887. invalidateSelector: aSelector
  888. self
  889. invalidateParentSelector: aSelector;
  890. invalidateChildrenSelector: aSelector;
  891. removeSelector: aSelector
  892. ! !
  893. !HLClassCache methodsFor: 'private'!
  894. removeSelector: aSelector
  895. self overriddenCache
  896. removeKey: aSelector
  897. ifAbsent: [ ].
  898. self overrideCache
  899. removeKey: aSelector
  900. ifAbsent: [ ]
  901. ! !
  902. !HLClassCache methodsFor: 'testing'!
  903. isOverridden: aMethod
  904. ^ self overriddenCache
  905. at: aMethod selector
  906. ifAbsentPut: [ aMethod isOverridden ]
  907. !
  908. isOverride: aMethod
  909. ^ self overrideCache
  910. at: aMethod selector
  911. ifAbsentPut: [ aMethod isOverride ]
  912. ! !
  913. !HLClassCache class methodsFor: 'instance creation'!
  914. on: aClass selectorsCache: aSelectorsCache
  915. ^ self new
  916. theClass: aClass;
  917. selectorsCache: aSelectorsCache;
  918. yourself
  919. ! !
  920. Object subclass: #HLSelectorsCache
  921. instanceVariableNames: 'classesCache'
  922. package: 'Helios-Browser'!
  923. !HLSelectorsCache methodsFor: 'accessing'!
  924. cacheFor: aClass
  925. aClass ifNil: [ ^ nil ].
  926. ^ self classesCache
  927. at: aClass name
  928. ifAbsentPut: [ self newCacheFor: aClass ]
  929. !
  930. classesCache
  931. ^ classesCache ifNil: [ classesCache := HashedCollection new ]
  932. ! !
  933. !HLSelectorsCache methodsFor: 'actions'!
  934. observeSystem
  935. SystemAnnouncer current
  936. on: MethodAdded
  937. do: [ :ann | self onMethodAdded: ann method ];
  938. on: MethodRemoved
  939. do: [ :ann | self onMethodRemoved: ann method ]
  940. ! !
  941. !HLSelectorsCache methodsFor: 'factory'!
  942. newCacheFor: aClass
  943. ^ HLClassCache
  944. on: aClass
  945. selectorsCache: self
  946. ! !
  947. !HLSelectorsCache methodsFor: 'initialization'!
  948. initialize
  949. super initialize.
  950. self observeSystem
  951. ! !
  952. !HLSelectorsCache methodsFor: 'private'!
  953. invalidateCacheFor: aMethod
  954. (self cacheFor: aMethod methodClass)
  955. invalidateSelector: aMethod selector
  956. ! !
  957. !HLSelectorsCache methodsFor: 'reactions'!
  958. onMethodAdded: aMethod
  959. self invalidateCacheFor: aMethod
  960. !
  961. onMethodRemoved: aMethod
  962. self invalidateCacheFor: aMethod
  963. ! !
  964. !HLSelectorsCache methodsFor: 'testing'!
  965. isOverridden: aMethod
  966. ^ (self cacheFor: aMethod methodClass)
  967. isOverridden: aMethod
  968. !
  969. isOverride: aMethod
  970. ^ (self cacheFor: aMethod methodClass)
  971. isOverride: aMethod
  972. ! !
  973. HLSelectorsCache class instanceVariableNames: 'current'!
  974. !HLSelectorsCache class methodsFor: 'accessing'!
  975. current
  976. ^ current ifNil: [ current := super new ]
  977. !
  978. flush
  979. current := nil
  980. ! !
  981. !HLSelectorsCache class methodsFor: 'instance creation'!
  982. new
  983. self shouldNotImplement
  984. ! !
  985. !CompiledMethod methodsFor: '*Helios-Browser'!
  986. isOverridden
  987. | selector |
  988. selector := self selector.
  989. self methodClass allSubclassesDo: [ :each |
  990. (each includesSelector: selector)
  991. ifTrue: [ ^ true ] ].
  992. ^ false
  993. !
  994. isOverride
  995. | superclass |
  996. superclass := self methodClass superclass.
  997. superclass ifNil: [ ^ false ].
  998. ^ (self methodClass superclass lookupSelector: self selector) notNil
  999. ! !