Helios-Browser.st 28 KB

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