Helios-Browser.st 15 KB

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