Helios-Browser.st 29 KB

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