Helios-Browser.st 28 KB

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