2
0

Helios-Browser.st 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  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. aBindingGroup
  21. addGroupKey: 66 labelled: 'Browse';
  22. addGroupKey: 71 labelled: 'Go to';
  23. addGroupKey: 84 labelled: 'Toggle'.
  24. HLBrowserCommand withAllSubclasses do: [ :each |
  25. each key ifNotNil: [
  26. (aBindingGroup at: each bindingGroup)
  27. add: (each on: self model) asBinding ] ]
  28. ! !
  29. !HLBrowser methodsFor: 'rendering'!
  30. renderContentOn: html
  31. html with: (HLContainer with: (HLHorizontalSplitter
  32. with: (HLVerticalSplitter
  33. with: (HLVerticalSplitter
  34. with: self packagesListWidget
  35. with: self classesListWidget)
  36. with: (HLVerticalSplitter
  37. with: self protocolsListWidget
  38. with: self methodsListWidget))
  39. with: self sourceWidget))
  40. ! !
  41. !HLBrowser methodsFor: 'widgets'!
  42. classesListWidget
  43. ^ classesListWidget ifNil: [
  44. classesListWidget := HLClassesListWidget on: self model.
  45. classesListWidget next: self protocolsListWidget ]
  46. !
  47. methodsListWidget
  48. ^ methodsListWidget ifNil: [
  49. methodsListWidget := HLMethodsListWidget on: self model ]
  50. !
  51. packagesListWidget
  52. ^ packagesListWidget ifNil: [
  53. packagesListWidget := HLPackagesListWidget on: self model.
  54. packagesListWidget next: self classesListWidget ]
  55. !
  56. protocolsListWidget
  57. ^ protocolsListWidget ifNil: [
  58. protocolsListWidget := HLProtocolsListWidget on: self model.
  59. protocolsListWidget next: self methodsListWidget ]
  60. !
  61. sourceWidget
  62. ^ sourceWidget ifNil: [
  63. sourceWidget := HLBrowserSourceWidget on: self model ]
  64. ! !
  65. HLBrowser class instanceVariableNames: 'nextId'!
  66. !HLBrowser class methodsFor: 'accessing'!
  67. nextId
  68. nextId ifNil: [ nextId := 0 ].
  69. ^ 'browser_', (nextId + 1) asString
  70. !
  71. tabLabel
  72. ^ 'Browser'
  73. !
  74. tabPriority
  75. ^ 0
  76. ! !
  77. !HLBrowser class methodsFor: 'testing'!
  78. canBeOpenAsTab
  79. ^ true
  80. ! !
  81. HLNavigationListWidget subclass: #HLBrowserListWidget
  82. instanceVariableNames: 'model'
  83. package: 'Helios-Browser'!
  84. !HLBrowserListWidget methodsFor: 'accessing'!
  85. model
  86. ^ model
  87. !
  88. model: aBrowserModel
  89. model := aBrowserModel.
  90. self observeModel
  91. ! !
  92. !HLBrowserListWidget methodsFor: 'actions'!
  93. observeModel
  94. ! !
  95. !HLBrowserListWidget class methodsFor: 'instance creation'!
  96. on: aModel
  97. ^ self new
  98. model: aModel;
  99. yourself
  100. ! !
  101. HLBrowserListWidget subclass: #HLClassesListWidget
  102. instanceVariableNames: ''
  103. package: 'Helios-Browser'!
  104. !HLClassesListWidget methodsFor: 'accessing'!
  105. getChildrenOf: aClass
  106. ^ self items select: [ :each | each superclass = aClass ]
  107. !
  108. getRootClassesOf: aCollection
  109. ^ aCollection select: [ :each |
  110. (aCollection includes: each superclass) not ]
  111. !
  112. iconForItem: aClass
  113. ^ aClass theNonMetaClass comment isEmpty
  114. ifFalse: [ 'icon-none' ]
  115. ifTrue: [ 'icon-question-sign' ]
  116. !
  117. showInstance
  118. ^ self model showInstance
  119. ! !
  120. !HLClassesListWidget methodsFor: 'actions'!
  121. focusMethodsListWidget
  122. self model announcer announce: HLMethodsListFocus new
  123. !
  124. focusProtocolsListWidget
  125. self model announcer announce: HLProtocolsListFocus new
  126. !
  127. observeModel
  128. self model announcer
  129. on: HLPackageSelected do: [ :ann | self onPackageSelected: ann item ];
  130. on: HLShowInstanceToggled do: [ :ann | self onShowInstanceToggled ];
  131. on: HLClassSelected do: [ :ann | self onClassSelected: ann item ]
  132. !
  133. selectItem: aClass
  134. self model selectedClass: aClass
  135. !
  136. showInstance: aBoolean
  137. self model showInstance: aBoolean
  138. ! !
  139. !HLClassesListWidget methodsFor: 'reactions'!
  140. onClassSelected: aClass
  141. self selectedItem: aClass.
  142. aClass ifNil: [ ^ self ].
  143. self focus
  144. !
  145. onPackageSelected: aPackage
  146. self selectedItem: nil.
  147. self items: (aPackage
  148. ifNil: [ #() ]
  149. ifNotNil: [ (aPackage classes
  150. collect: [ :each | each theNonMetaClass ]) asSet asArray ]).
  151. self refresh
  152. !
  153. onShowInstanceToggled
  154. self refresh
  155. ! !
  156. !HLClassesListWidget methodsFor: 'rendering'!
  157. renderButtonsOn: html
  158. html div
  159. class: 'btn-group';
  160. at: 'data-toggle' put: 'buttons-radio';
  161. with: [
  162. html button
  163. class: (String streamContents: [ :str |
  164. str nextPutAll: 'btn'.
  165. self showInstance ifTrue: [
  166. str nextPutAll: ' active'] ]);
  167. with: 'Instance';
  168. onClick: [ self showInstance: true ].
  169. html button
  170. class: (String streamContents: [ :str |
  171. str nextPutAll: 'btn'.
  172. self model showInstance ifFalse: [
  173. str nextPutAll: ' active'] ]);
  174. with: 'Class';
  175. onClick: [ self model showInstance: false ] ].
  176. html button
  177. class: 'btn';
  178. at: 'data-toggle' put: 'button';
  179. with: 'Comment'
  180. !
  181. renderItem: aClass level: anInteger on: html
  182. | li |
  183. li := html li.
  184. li
  185. at: 'list-data' put: (self items indexOf: aClass);
  186. class: (self cssClassForItem: aClass);
  187. with: [
  188. html a
  189. with: [
  190. (html tag: 'i') class: (self iconForItem: aClass).
  191. self renderItemLabel: aClass level: anInteger on: html ];
  192. onClick: [
  193. self activateListItem: li asJQuery ] ].
  194. (self getChildrenOf: aClass) do: [ :each |
  195. self renderItem: each level: anInteger + 1 on: html ]
  196. !
  197. renderItem: aClass on: html
  198. super renderItem: aClass on: html.
  199. (self getChildrenOf: aClass) do: [ :each |
  200. self renderItem: each level: 1 on: html ]
  201. !
  202. renderItemLabel: aClass level: anInteger on: html
  203. html span asJQuery html: (String streamContents: [ :str |
  204. anInteger timesRepeat: [
  205. str nextPutAll: '    '].
  206. str nextPutAll: aClass name ])
  207. !
  208. renderItemLabel: aClass on: html
  209. self renderItemLabel: aClass level: 0 on: html
  210. !
  211. renderListOn: html
  212. (self getRootClassesOf: self items)
  213. do: [ :each | self renderItem: each on: html ]
  214. ! !
  215. HLBrowserListWidget subclass: #HLMethodsListWidget
  216. instanceVariableNames: 'selectorsCache'
  217. package: 'Helios-Browser'!
  218. !HLMethodsListWidget methodsFor: 'accessing'!
  219. allProtocol
  220. ^ self model allProtocol
  221. !
  222. iconForItem: aCompiledMethod
  223. | override overriden |
  224. override := self isOverride: aCompiledMethod.
  225. overriden := self isOverriden: aCompiledMethod.
  226. ^ override
  227. ifTrue: [ overriden
  228. ifTrue: [ 'icon-resize-vertical' ]
  229. ifFalse: [ 'icon-arrow-up' ] ]
  230. ifFalse: [
  231. overriden
  232. ifTrue: [ 'icon-arrow-down' ]
  233. ifFalse: [ 'icon-none' ] ]
  234. !
  235. methodsInProtocol: aString
  236. ^ aString = self allProtocol
  237. ifTrue: [ self model selectedClass methods ]
  238. ifFalse: [ self model selectedClass methodsInProtocol: aString ]
  239. !
  240. overrideSelectors
  241. ^ self selectorsCache
  242. at: 'override'
  243. ifAbsentPut: [
  244. self model selectedClass allSuperclasses
  245. inject: Set new into: [ :acc :each | acc addAll: each selectors; yourself ] ]
  246. !
  247. overridenSelectors
  248. ^ self selectorsCache
  249. at: 'overriden'
  250. ifAbsentPut: [
  251. self model selectedClass allSubclasses
  252. inject: Set new into: [ :acc :each | acc addAll: each selectors; yourself ] ]
  253. !
  254. selectorsCache
  255. ^ selectorsCache
  256. ! !
  257. !HLMethodsListWidget methodsFor: 'actions'!
  258. observeModel
  259. self model announcer on: HLProtocolSelected do: [ :ann |
  260. self onProtocolSelected: ann item ].
  261. self model announcer on: HLShowInstanceToggled do: [ :ann |
  262. self onProtocolSelected: nil ].
  263. self model announcer on: HLMethodSelected do: [ :ann |
  264. self onMethodSelected: ann item ]
  265. !
  266. selectItem: aCompiledMethod
  267. self model selectedMethod: aCompiledMethod
  268. ! !
  269. !HLMethodsListWidget methodsFor: 'cache'!
  270. flushSelectorsCache
  271. selectorsCache := Dictionary new
  272. ! !
  273. !HLMethodsListWidget methodsFor: 'initialization'!
  274. initialize
  275. super initialize.
  276. self flushSelectorsCache
  277. ! !
  278. !HLMethodsListWidget methodsFor: 'reactions'!
  279. onMethodSelected: aMethod
  280. self selectedItem: aMethod.
  281. aMethod ifNil: [ ^ self ].
  282. self focus
  283. !
  284. onProtocolSelected: aString
  285. self selectedItem: nil.
  286. self items: (self model selectedClass
  287. ifNil: [ #() ]
  288. ifNotNil: [ aString
  289. ifNil: [ #() ]
  290. ifNotNil: [ self methodsInProtocol: aString ] ]).
  291. self refresh
  292. ! !
  293. !HLMethodsListWidget methodsFor: 'rendering'!
  294. renderContentOn: html
  295. self model showInstance
  296. ifFalse: [ html div
  297. class: 'class_side';
  298. with: [ super renderContentOn: html ] ]
  299. ifTrue: [ super renderContentOn: html ].
  300. self flushSelectorsCache
  301. !
  302. renderItemLabel: aCompiledMethod on: html
  303. html with: aCompiledMethod selector
  304. ! !
  305. !HLMethodsListWidget methodsFor: 'testing'!
  306. isOverride: aMethod
  307. ^ self overrideSelectors includes: aMethod selector
  308. !
  309. isOverriden: aMethod
  310. ^ self overridenSelectors includes: aMethod selector
  311. ! !
  312. HLBrowserListWidget subclass: #HLPackagesListWidget
  313. instanceVariableNames: ''
  314. package: 'Helios-Browser'!
  315. !HLPackagesListWidget methodsFor: 'accessing'!
  316. initializeItems
  317. ^ items := self model packages sort:[:a :b|
  318. a name < b name]
  319. !
  320. items
  321. ^ items ifNil: [self initializeItems]
  322. ! !
  323. !HLPackagesListWidget methodsFor: 'actions'!
  324. focusClassesListWidget
  325. self model announcer announce: HLClassesListFocus new
  326. !
  327. observeModel
  328. self model announcer on: HLPackageSelected do: [ :ann |
  329. self onPackageSelected: ann item ]
  330. !
  331. selectItem: aPackage
  332. self model selectedPackage: aPackage
  333. ! !
  334. !HLPackagesListWidget methodsFor: 'reactions'!
  335. onPackageSelected: aPackage
  336. self selectedItem: aPackage.
  337. self focus
  338. ! !
  339. !HLPackagesListWidget methodsFor: 'rendering'!
  340. renderButtonsOn: html
  341. html span class: 'info'; with: 'Auto commit'.
  342. html div
  343. class: 'btn-group switch';
  344. at: 'data-toggle' put: 'buttons-radio';
  345. with: [
  346. html button
  347. class: (String streamContents: [ :str |
  348. str nextPutAll: 'btn' ]);
  349. with: 'On'.
  350. html button
  351. class: (String streamContents: [ :str |
  352. str nextPutAll: 'btn active' ]);
  353. with: 'Off' ].
  354. html a
  355. class: 'btn';
  356. with: 'Commit'.
  357. ! !
  358. HLBrowserListWidget subclass: #HLProtocolsListWidget
  359. instanceVariableNames: ''
  360. package: 'Helios-Browser'!
  361. !HLProtocolsListWidget methodsFor: 'accessing'!
  362. allProtocol
  363. ^ self model allProtocol
  364. !
  365. selectedItem
  366. ^ super selectedItem" ifNil: [ self allProtocol ]"
  367. ! !
  368. !HLProtocolsListWidget methodsFor: 'actions'!
  369. observeModel
  370. self model announcer on: HLClassSelected do: [ :ann |
  371. self onClassSelected: ann item ].
  372. self model announcer on: HLShowInstanceToggled do: [ :ann |
  373. self onClassSelected: self model selectedClass ].
  374. self model announcer on: HLProtocolSelected do: [ :ann |
  375. self onProtocolSelected: ann item ]
  376. !
  377. selectItem: aString
  378. self model selectedProtocol: aString
  379. ! !
  380. !HLProtocolsListWidget methodsFor: 'reactions'!
  381. onClassSelected: aClass
  382. self selectedItem: nil.
  383. self items: (aClass
  384. ifNil: [ Array with: self allProtocol ]
  385. ifNotNil: [
  386. (Array with: self allProtocol)
  387. addAll: aClass protocols;
  388. yourself ]).
  389. self refresh
  390. !
  391. onProtocolSelected: aString
  392. self selectedItem: aString.
  393. aString ifNil: [ ^ self ].
  394. self focus
  395. ! !
  396. !HLProtocolsListWidget methodsFor: 'rendering'!
  397. renderContentOn: html
  398. self model showInstance
  399. ifFalse: [ html div
  400. class: 'class_side';
  401. with: [ super renderContentOn: html ] ]
  402. ifTrue: [ super renderContentOn: html ]
  403. ! !
  404. Object subclass: #HLBrowserModel
  405. instanceVariableNames: 'announcer environment selectedPackage selectedClass selectedProtocol selectedMethod showInstance showComment'
  406. package: 'Helios-Browser'!
  407. !HLBrowserModel methodsFor: 'accessing'!
  408. allProtocol
  409. ^ '-- All --'
  410. !
  411. announcer
  412. ^ announcer ifNil: [ announcer := Announcer new ]
  413. !
  414. environment
  415. ^ environment ifNil: [ HLManager current environment ]
  416. !
  417. environment: anEnvironment
  418. environment := anEnvironment
  419. !
  420. packages
  421. ^ self environment packages
  422. !
  423. selectedClass
  424. ^ selectedClass
  425. !
  426. selectedClass: aClass
  427. selectedClass = aClass ifTrue: [ ^ self ].
  428. aClass
  429. ifNil: [ selectedClass := nil ]
  430. ifNotNil: [
  431. self showInstance
  432. ifTrue: [ selectedClass := aClass theNonMetaClass ]
  433. ifFalse: [ selectedClass := aClass theMetaClass ] ].
  434. self selectedProtocol: nil.
  435. self announcer announce: (HLClassSelected on: self selectedClass)
  436. !
  437. selectedMethod
  438. ^ selectedMethod
  439. !
  440. selectedMethod: aCompiledMethod
  441. selectedMethod = aCompiledMethod ifTrue: [ ^ self ].
  442. selectedMethod := aCompiledMethod.
  443. self announcer announce: (HLMethodSelected on: aCompiledMethod)
  444. !
  445. selectedPackage
  446. ^ selectedPackage
  447. !
  448. selectedPackage: aPackage
  449. selectedPackage = aPackage ifTrue: [ ^ self ].
  450. selectedPackage := aPackage.
  451. self selectedClass: nil.
  452. self announcer announce: (HLPackageSelected on: aPackage)
  453. !
  454. selectedProtocol
  455. ^ selectedProtocol
  456. !
  457. selectedProtocol: aString
  458. selectedProtocol = aString ifTrue: [ ^ self ].
  459. selectedProtocol := aString.
  460. self selectedMethod: nil.
  461. self announcer announce: (HLProtocolSelected on: aString)
  462. !
  463. showComment
  464. ^ showComment ifNil: [ false ]
  465. !
  466. showComment: aBoolean
  467. showComment := aBoolean.
  468. self announcer announce: HLShowCommentToggled new
  469. !
  470. showInstance
  471. ^ showInstance ifNil: [ true ]
  472. !
  473. showInstance: aBoolean
  474. showInstance := aBoolean.
  475. self selectedClass ifNotNil: [
  476. self selectedClass: (aBoolean
  477. ifTrue: [self selectedClass theNonMetaClass ]
  478. ifFalse: [ self selectedClass theMetaClass ]) ].
  479. self announcer announce: HLShowInstanceToggled new
  480. ! !
  481. !HLBrowserModel class methodsFor: 'actions'!
  482. on: anEnvironment
  483. ^ self new
  484. environment: anEnvironment;
  485. yourself
  486. ! !
  487. HLWidget subclass: #HLBrowserSourceWidget
  488. instanceVariableNames: 'model codeWidget'
  489. package: 'Helios-Browser'!
  490. !HLBrowserSourceWidget methodsFor: 'accessing'!
  491. codeWidget
  492. ^ codeWidget ifNil: [ codeWidget := HLCodeWidget new ]
  493. !
  494. contents
  495. ^ self sourceArea contents
  496. !
  497. contents: aString
  498. self codeWidget contents: aString
  499. !
  500. model
  501. ^ model
  502. !
  503. model: aBrowserModel
  504. model := aBrowserModel.
  505. self observeModel
  506. ! !
  507. !HLBrowserSourceWidget methodsFor: 'actions'!
  508. observeModel
  509. self model announcer on: HLMethodSelected do: [ :ann |
  510. self onMethodSelected: ann item ].
  511. self model announcer on: HLClassSelected do: [ :ann |
  512. self onClassSelected: ann item ].
  513. self model announcer on: HLProtocolSelected do: [ :ann |
  514. self onProtocolSelected: ann item ]
  515. ! !
  516. !HLBrowserSourceWidget methodsFor: 'reactions'!
  517. onClassSelected: aClass
  518. aClass ifNil: [ ^ self contents: '' ].
  519. self contents: aClass definition
  520. !
  521. onMethodSelected: aCompiledMethod
  522. aCompiledMethod ifNil: [ ^ self contents: '' ].
  523. self contents: aCompiledMethod source
  524. !
  525. onProtocolSelected: aString
  526. self model selectedClass ifNil: [ ^ self contents: '' ].
  527. self contents: self model selectedClass definition
  528. ! !
  529. !HLBrowserSourceWidget methodsFor: 'rendering'!
  530. renderContentOn: html
  531. self codeWidget renderOn: html
  532. ! !
  533. !HLBrowserSourceWidget class methodsFor: 'instance creation'!
  534. on: aBrowserModel
  535. ^ self new
  536. model: aBrowserModel;
  537. yourself
  538. ! !