Helios-Browser.st 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472
  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. showClassTemplate
  222. self selectedPackage ifNotNil: [ :package |
  223. self announcer announce: (HLShowTemplate new
  224. template: package classTemplate;
  225. yourself) ]
  226. !
  227. showMethodTemplate
  228. self selectedClass ifNotNil: [ :theClass |
  229. self announcer announce: (HLShowTemplate new
  230. template: theClass methodTemplate;
  231. yourself) ]
  232. ! !
  233. !HLBrowserModel methodsFor: 'commands actions'!
  234. editComment
  235. self announcer announce: HLEditComment new
  236. ! !
  237. !HLBrowserModel methodsFor: 'testing'!
  238. isBrowserModel
  239. ^ true
  240. ! !
  241. !HLBrowserModel class methodsFor: 'actions'!
  242. on: anEnvironment
  243. ^ self new
  244. environment: anEnvironment;
  245. yourself
  246. ! !
  247. Object subclass: #HLClassCache
  248. instanceVariableNames: 'class selectorsCache overrideCache overriddenCache'
  249. package: 'Helios-Browser'!
  250. !HLClassCache methodsFor: 'accessing'!
  251. overriddenCache
  252. ^ overriddenCache ifNil: [ overriddenCache := HashedCollection new ]
  253. !
  254. overrideCache
  255. ^ overrideCache ifNil: [ overrideCache := HashedCollection new ]
  256. !
  257. selectorsCache
  258. ^ selectorsCache
  259. !
  260. selectorsCache: aCache
  261. selectorsCache := aCache
  262. !
  263. theClass
  264. ^ class
  265. !
  266. theClass: aClass
  267. class := aClass
  268. ! !
  269. !HLClassCache methodsFor: 'actions'!
  270. invalidateChildrenSelector: aSelector
  271. self theClass subclasses do: [ :each |
  272. (self selectorsCache cacheFor: each)
  273. removeSelector: aSelector;
  274. invalidateChildrenSelector: aSelector ]
  275. !
  276. invalidateParentSelector: aSelector
  277. self theClass superclass ifNotNil: [
  278. (self selectorsCache cacheFor: self theClass superclass)
  279. removeSelector: aSelector;
  280. invalidateParentSelector: aSelector ]
  281. !
  282. invalidateSelector: aSelector
  283. self
  284. invalidateParentSelector: aSelector;
  285. invalidateChildrenSelector: aSelector;
  286. removeSelector: aSelector
  287. ! !
  288. !HLClassCache methodsFor: 'private'!
  289. removeSelector: aSelector
  290. self overriddenCache
  291. removeKey: aSelector
  292. ifAbsent: [ ].
  293. self overrideCache
  294. removeKey: aSelector
  295. ifAbsent: [ ]
  296. ! !
  297. !HLClassCache methodsFor: 'testing'!
  298. isOverridden: aMethod
  299. ^ self overriddenCache
  300. at: aMethod selector
  301. ifAbsentPut: [ aMethod isOverridden ]
  302. !
  303. isOverride: aMethod
  304. ^ self overrideCache
  305. at: aMethod selector
  306. ifAbsentPut: [ aMethod isOverride ]
  307. ! !
  308. !HLClassCache class methodsFor: 'instance creation'!
  309. on: aClass selectorsCache: aSelectorsCache
  310. ^ self new
  311. theClass: aClass;
  312. selectorsCache: aSelectorsCache;
  313. yourself
  314. ! !
  315. HLToolListWidget subclass: #HLClassesListWidget
  316. instanceVariableNames: ''
  317. package: 'Helios-Browser'!
  318. !HLClassesListWidget commentStamp!
  319. I render a list of classes in the selected package.!
  320. !HLClassesListWidget methodsFor: 'accessing'!
  321. cssClassForItem: aClass
  322. aClass theNonMetaClass comment isEmpty
  323. ifTrue: [ ^ 'uncommented' ].
  324. ^ aClass theNonMetaClass heliosClass
  325. !
  326. getChildrenOf: aClass
  327. ^ self items select: [ :each | each superclass = aClass ]
  328. !
  329. getRootClassesOf: aCollection
  330. ^ aCollection select: [ :each |
  331. (aCollection includes: each superclass) not ]
  332. !
  333. label
  334. ^ 'Classes'
  335. ! !
  336. !HLClassesListWidget methodsFor: 'actions'!
  337. focus
  338. super focus.
  339. self selectedItem
  340. ifNil: [ self model showClassTemplate ]
  341. !
  342. focusMethodsListWidget
  343. self model announcer announce: HLMethodsListFocus new
  344. !
  345. focusProtocolsListWidget
  346. self model announcer announce: HLProtocolsListFocus new
  347. !
  348. observeModel
  349. self model announcer
  350. on: HLPackageSelected
  351. send: #onPackageSelected:
  352. to: self;
  353. on: HLShowInstanceToggled
  354. send: #onShowInstanceToggled
  355. to: self;
  356. on: HLShowCommentToggled
  357. send: #onShowCommentToggled
  358. to: self;
  359. on: HLClassSelected
  360. send: #onClassSelected:
  361. to: self;
  362. on: HLClassesFocusRequested
  363. send: #onClassesFocusRequested
  364. to: self
  365. !
  366. observeSystem
  367. self model systemAnnouncer
  368. on: ClassAdded
  369. send: #onClassAdded:
  370. to: self;
  371. on: ClassRemoved
  372. send: #onClassRemoved:
  373. to: self;
  374. on: ClassMoved
  375. send: #onClassMoved:
  376. to: self;
  377. on: ClassRenamed
  378. send: #onClassRenamed:
  379. to: self;
  380. on: ClassMigrated
  381. send: #onClassMigrated:
  382. to: self;
  383. on: ClassCommentChanged
  384. send: #onClassCommentChanged:
  385. to: self
  386. !
  387. selectItem: aClass
  388. self model selectedClass: aClass
  389. !
  390. showComment: aBoolean
  391. self model showComment: aBoolean
  392. !
  393. showInstance: aBoolean
  394. self model showInstance: aBoolean
  395. !
  396. toggleShowComment
  397. self model showComment: self showComment not
  398. ! !
  399. !HLClassesListWidget methodsFor: 'private'!
  400. setItemsForPackage: aPackage
  401. self items: (aPackage
  402. ifNil: [ #() ]
  403. ifNotNil: [ (aPackage classes
  404. collect: [ :each | each theNonMetaClass ])
  405. sort: [ :a :b | a name < b name ] ]).
  406. !
  407. setItemsForSelectedPackage
  408. self setItemsForPackage: self model selectedPackage
  409. ! !
  410. !HLClassesListWidget methodsFor: 'reactions'!
  411. onClassAdded: anAnnouncement
  412. | class |
  413. class := anAnnouncement theClass.
  414. (class package = self model selectedPackage or: [
  415. self items includes: class ]) ifFalse: [ ^ self ].
  416. self setItemsForSelectedPackage.
  417. self refresh
  418. !
  419. onClassCommentChanged: anAnnouncement
  420. | class |
  421. class := anAnnouncement theClass.
  422. class package = self model selectedPackage ifFalse: [ ^ self ].
  423. self refresh
  424. !
  425. onClassMigrated: anAnnouncement
  426. | class oldClass |
  427. class := anAnnouncement theClass.
  428. oldClass := anAnnouncement oldClass.
  429. (self items includes: oldClass) ifFalse: [ ^ self ].
  430. self model selectedClass = oldClass ifTrue: [
  431. self model selectedClass: class ].
  432. self setItemsForSelectedPackage.
  433. self refresh
  434. !
  435. onClassMoved: anAnnouncement
  436. | class oldPackage |
  437. class := anAnnouncement theClass.
  438. oldPackage := anAnnouncement oldPackage.
  439. (oldPackage = self model selectedPackage or: [
  440. class package = self model selectedPackage ])
  441. ifFalse: [ ^ self ].
  442. oldPackage = self model selectedPackage ifTrue: [
  443. self
  444. selectedItem: nil;
  445. selectItem: nil ].
  446. self setItemsForSelectedPackage.
  447. self refresh
  448. !
  449. onClassRemoved: anAnnouncement
  450. | class |
  451. class := anAnnouncement theClass.
  452. class package = self model selectedPackage ifFalse: [ ^ self ].
  453. self selectItem: nil.
  454. self setItemsForSelectedPackage.
  455. self refresh
  456. !
  457. onClassRenamed: anAnnouncement
  458. anAnnouncement theClass package = self model selectedPackage ifFalse: [ ^ self ].
  459. self setItemsForSelectedPackage.
  460. self refresh
  461. !
  462. onClassSelected: anAnnouncement
  463. | selectedClass |
  464. anAnnouncement item ifNil: [ ^ self ].
  465. selectedClass := anAnnouncement item theNonMetaClass.
  466. self selectedItem: selectedClass.
  467. self hasFocus ifFalse: [
  468. self
  469. activateItem: selectedClass;
  470. focus ]
  471. !
  472. onClassesFocusRequested
  473. self focus
  474. !
  475. onPackageSelected: anAnnouncement
  476. self selectedItem: nil.
  477. self setItemsForSelectedPackage.
  478. self refresh
  479. !
  480. onShowCommentToggled
  481. self refresh
  482. !
  483. onShowInstanceToggled
  484. self refresh
  485. ! !
  486. !HLClassesListWidget methodsFor: 'rendering'!
  487. renderButtonsOn: html
  488. | checkbox |
  489. html div
  490. class: 'btn-group';
  491. with: [
  492. html button
  493. class: (String streamContents: [ :str |
  494. str nextPutAll: 'btn'.
  495. self showInstance ifTrue: [
  496. str nextPutAll: ' active' ] ]);
  497. with: 'Instance';
  498. onClick: [ self showInstance: true ].
  499. html button
  500. class: (String streamContents: [ :str |
  501. str nextPutAll: 'btn'.
  502. self showClass ifTrue: [
  503. str nextPutAll: ' active' ] ]);
  504. with: 'Class';
  505. onClick: [ self showInstance: false ] ].
  506. html label
  507. class: 'checkbox';
  508. with: [
  509. checkbox := html input
  510. type: 'checkbox';
  511. onClick: [ self toggleShowComment ].
  512. html with: 'Doc' ].
  513. self showComment ifTrue: [
  514. checkbox at: 'checked' put: 'checked' ]
  515. !
  516. renderItem: aClass level: anInteger on: html
  517. | li |
  518. li := html li.
  519. li asJQuery data: 'item' put: aClass.
  520. li
  521. class: (self listCssClassForItem: aClass);
  522. with: [
  523. html a
  524. with: [
  525. (html tag: 'i') class: (self cssClassForItem: aClass).
  526. self renderItemLabel: aClass level: anInteger on: html ];
  527. onClick: [
  528. self activateListItem: li asJQuery ] ].
  529. (self getChildrenOf: aClass) do: [ :each |
  530. self renderItem: each level: anInteger + 1 on: html ]
  531. !
  532. renderItem: aClass on: html
  533. super renderItem: aClass on: html.
  534. (self getChildrenOf: aClass) do: [ :each |
  535. self renderItem: each level: 1 on: html ]
  536. !
  537. renderItemLabel: aClass level: anInteger on: html
  538. html span asJQuery html: (String streamContents: [ :str |
  539. anInteger timesRepeat: [
  540. str nextPutAll: '&nbsp;&nbsp;&nbsp;&nbsp;' ].
  541. str nextPutAll: aClass name ])
  542. !
  543. renderItemLabel: aClass on: html
  544. self renderItemLabel: aClass level: 0 on: html
  545. !
  546. renderListOn: html
  547. (self getRootClassesOf: self items)
  548. do: [ :each | self renderItem: each on: html ]
  549. ! !
  550. !HLClassesListWidget methodsFor: 'testing'!
  551. showClass
  552. ^ self model showInstance not
  553. !
  554. showComment
  555. ^ self model showComment
  556. !
  557. showInstance
  558. ^ self model showInstance
  559. ! !
  560. HLFocusableWidget subclass: #HLDocumentationWidget
  561. instanceVariableNames: 'model'
  562. package: 'Helios-Browser'!
  563. !HLDocumentationWidget commentStamp!
  564. I render the documentation for the selected class!
  565. !HLDocumentationWidget methodsFor: 'accessing'!
  566. documentation
  567. ^ self selectedItem
  568. ifNil: [ '' ]
  569. ifNotNil: [ :item | item comment ifEmpty: [ self defaultDocumentation ] ]
  570. !
  571. head
  572. ^ self selectedItem
  573. ifNil: [ self defaultHead ]
  574. ifNotNil: [ :item | item name ]
  575. !
  576. model
  577. ^ model
  578. !
  579. model: aModel
  580. model := aModel.
  581. self
  582. observeSystem;
  583. observeModel
  584. !
  585. selectedItem
  586. ^ self model selectedClass ifNotNil: [ :class | class theNonMetaClass ]
  587. ! !
  588. !HLDocumentationWidget methodsFor: 'actions'!
  589. editDocumentation
  590. self model editComment
  591. !
  592. observeModel
  593. self model announcer
  594. on: HLClassSelected
  595. send: #onClassSelected:
  596. to: self;
  597. on: HLEditComment
  598. send: #onEditDocumentation
  599. to: self
  600. !
  601. observeSystem
  602. self model systemAnnouncer
  603. on: ClassCommentChanged
  604. send: #onClassCommentChanged:
  605. to: self
  606. !
  607. selectClass: aClass
  608. self model selectedClass: aClass
  609. !
  610. unregister
  611. super unregister.
  612. self model announcer unregister: self
  613. ! !
  614. !HLDocumentationWidget methodsFor: 'defaults'!
  615. defaultDocumentation
  616. ^ 'No documentation available.
  617. **That''s bad. Seriously.**'
  618. !
  619. defaultHead
  620. ^ 'No class selected'
  621. ! !
  622. !HLDocumentationWidget methodsFor: 'reactions'!
  623. onClassCommentChanged: anAnnouncement
  624. anAnnouncement theClass = self model selectedClass theNonMetaClass
  625. ifTrue: [ self refresh ]
  626. !
  627. onClassSelected: anAnnouncement
  628. self refresh
  629. !
  630. onEditDocumentation
  631. self
  632. request: self model selectedClass theNonMetaClass name, ' comment'
  633. value: self model selectedClass theNonMetaClass comment
  634. do: [ :comment | self setClassComment: comment ]
  635. !
  636. setClassComment: aString
  637. self model setClassComment: aString
  638. ! !
  639. !HLDocumentationWidget methodsFor: 'rendering'!
  640. renderContentOn: html
  641. html div
  642. class: 'doc';
  643. with: [
  644. self
  645. renderHeadOn: html;
  646. renderDocOn: html ]
  647. !
  648. renderDocOn: html
  649. self selectedItem ifNotNil: [
  650. self renderInheritanceOn: html.
  651. html h1
  652. with: 'Overview';
  653. with: [
  654. html button
  655. class: 'button default';
  656. with: 'Edit';
  657. onClick: [ self editDocumentation ] ].
  658. (html div
  659. class: 'markdown';
  660. asJQuery) html: ((Showdown at: 'converter') new makeHtml: self documentation) ]
  661. !
  662. renderHeadOn: html
  663. html div
  664. class: 'head';
  665. with: self head
  666. !
  667. renderInheritanceOn: html
  668. html div
  669. class: 'inheritance';
  670. with: [
  671. html with: 'Subclass of '.
  672. self selectedItem superclass
  673. ifNil: [ html em with: 'nil' ]
  674. ifNotNil: [
  675. html a
  676. with: self selectedItem superclass name;
  677. onClick: [ self selectClass: self selectedItem superclass ] ] ]
  678. ! !
  679. HLToolListWidget subclass: #HLMethodsListWidget
  680. instanceVariableNames: 'selectorsCache'
  681. package: 'Helios-Browser'!
  682. !HLMethodsListWidget commentStamp!
  683. I render a list of methods for the selected protocol.!
  684. !HLMethodsListWidget methodsFor: 'accessing'!
  685. allProtocol
  686. ^ self model allProtocol
  687. !
  688. cssClassForItem: aSelector
  689. | override overriden method |
  690. method := self methodForSelector: aSelector.
  691. override := self isOverride: method.
  692. overriden := self isOverridden: method.
  693. ^ override
  694. ifTrue: [ overriden
  695. ifTrue: [ 'override-overridden' ]
  696. ifFalse: [ 'override' ] ]
  697. ifFalse: [
  698. overriden
  699. ifTrue: [ 'overridden' ]
  700. ifFalse: [ '' ] ]
  701. !
  702. label
  703. ^ 'Methods'
  704. !
  705. methodForSelector: aSelector
  706. ^ self model selectedClass
  707. methodDictionary at: aSelector
  708. !
  709. methodsInProtocol: aString
  710. self model selectedClass ifNil: [ ^ #() ].
  711. ^ aString = self allProtocol
  712. ifTrue: [ self model selectedClass methods ]
  713. ifFalse: [ self model selectedClass methodsInProtocol: aString ]
  714. !
  715. overrideSelectors
  716. ^ self selectorsCache
  717. at: 'override'
  718. ifAbsentPut: [
  719. self model selectedClass allSuperclasses
  720. inject: Set new into: [ :acc :each | acc addAll: each selectors; yourself ] ]
  721. !
  722. overridenSelectors
  723. ^ self selectorsCache
  724. at: 'overriden'
  725. ifAbsentPut: [
  726. self model selectedClass allSubclasses
  727. inject: Set new into: [ :acc :each | acc addAll: each selectors; yourself ] ]
  728. !
  729. selectorsCache
  730. ^ self class selectorsCache
  731. !
  732. selectorsInProtocol: aString
  733. ^ ((self methodsInProtocol: aString)
  734. collect: [ :each | each selector ]) sorted
  735. ! !
  736. !HLMethodsListWidget methodsFor: 'actions'!
  737. focus
  738. super focus.
  739. self selectedItem ifNil: [
  740. self model showMethodTemplate ]
  741. !
  742. observeModel
  743. self model announcer
  744. on: HLProtocolSelected
  745. send: #onProtocolSelected:
  746. to: self;
  747. on: HLShowInstanceToggled
  748. send: #onShowInstanceToggled
  749. to: self;
  750. on: HLMethodSelected
  751. send: #onMethodSelected:
  752. to: self;
  753. on: HLMethodsFocusRequested
  754. send: #onMethodsFocusRequested
  755. to: self
  756. !
  757. observeSystem
  758. self model systemAnnouncer
  759. on: ProtocolAdded
  760. send: #onProtocolAdded:
  761. to: self;
  762. on: ProtocolRemoved
  763. send: #onProtocolRemoved:
  764. to: self;
  765. on: MethodAdded
  766. send: #onMethodAdded:
  767. to: self;
  768. on: MethodRemoved
  769. send: #onMethodRemoved:
  770. to: self;
  771. on: MethodMoved
  772. send: #onMethodMoved:
  773. to: self
  774. !
  775. selectItem: aSelector
  776. aSelector ifNil: [ ^ self model selectedMethod: nil ].
  777. self model selectedMethod: (self methodForSelector: aSelector)
  778. ! !
  779. !HLMethodsListWidget methodsFor: 'private'!
  780. setItemsForProtocol: aString
  781. ^ self items: (aString
  782. ifNil: [ #() ]
  783. ifNotNil: [ self selectorsInProtocol: aString ])
  784. !
  785. setItemsForSelectedProtocol
  786. self setItemsForProtocol: self model selectedProtocol
  787. ! !
  788. !HLMethodsListWidget methodsFor: 'reactions'!
  789. onMethodAdded: anAnnouncement
  790. self model selectedClass = anAnnouncement method methodClass ifFalse: [ ^ self ].
  791. self setItemsForSelectedProtocol.
  792. self refresh
  793. !
  794. onMethodMoved: anAnnouncement
  795. self model selectedMethod = anAnnouncement method ifFalse: [ ^ self ].
  796. self model selectedProtocol = self model allProtocol ifFalse: [
  797. self
  798. selectedItem: nil;
  799. selectItem: nil;
  800. setItemsForSelectedProtocol;
  801. refresh ]
  802. !
  803. onMethodRemoved: anAnnouncement
  804. | method |
  805. method := anAnnouncement method.
  806. self items detect: [ :each | each = method selector ] ifNone: [ ^ self ].
  807. self selectedItem ifNotNil: [
  808. (method methodClass = self model selectedClass and: [ method selector = self selectedItem ])
  809. ifTrue: [
  810. self selectedItem: nil;
  811. selectItem: nil ] ].
  812. self setItemsForSelectedProtocol.
  813. self refresh
  814. !
  815. onMethodSelected: anAnnouncement
  816. | selector method |
  817. method := anAnnouncement item.
  818. selector := method isCompiledMethod
  819. ifTrue: [ method selector ]
  820. ifFalse: [ nil ].
  821. self
  822. selectedItem: selector;
  823. activateItem: selector
  824. !
  825. onMethodsFocusRequested
  826. self focus
  827. !
  828. onProtocolAdded: anAnnouncement
  829. self model selectedClass = anAnnouncement theClass ifFalse: [ ^ self ].
  830. self setItemsForSelectedProtocol.
  831. self refresh.
  832. self focus
  833. !
  834. onProtocolRemoved: anAnnouncement
  835. self model selectedClass = anAnnouncement theClass ifFalse: [ ^ self ].
  836. self setItemsForSelectedProtocol.
  837. self refresh.
  838. self focus
  839. !
  840. onProtocolSelected: anAnnouncement
  841. self selectedItem: nil.
  842. self setItemsForSelectedProtocol.
  843. self refresh
  844. !
  845. onShowInstanceToggled
  846. self onProtocolSelected: nil
  847. ! !
  848. !HLMethodsListWidget methodsFor: 'rendering'!
  849. renderContentOn: html
  850. self model showInstance
  851. ifFalse: [ html div
  852. class: 'class_side';
  853. with: [ super renderContentOn: html ] ]
  854. ifTrue: [ super renderContentOn: html ]
  855. !
  856. renderItemLabel: aSelector on: html
  857. html with: aSelector
  858. ! !
  859. !HLMethodsListWidget methodsFor: 'testing'!
  860. isOverridden: aMethod
  861. ^ self selectorsCache isOverridden: aMethod
  862. !
  863. isOverride: aMethod
  864. ^ self selectorsCache isOverride: aMethod
  865. ! !
  866. HLMethodsListWidget class instanceVariableNames: 'selectorsCache'!
  867. !HLMethodsListWidget class methodsFor: 'accessing'!
  868. selectorsCache
  869. ^ HLSelectorsCache current
  870. ! !
  871. HLToolListWidget subclass: #HLPackagesListWidget
  872. instanceVariableNames: ''
  873. package: 'Helios-Browser'!
  874. !HLPackagesListWidget commentStamp!
  875. I render a list of the system packages.!
  876. !HLPackagesListWidget methodsFor: 'accessing'!
  877. cssClassForItem: anItem
  878. ^ 'package'
  879. !
  880. items
  881. ^ items ifNil: [ self initializeItems ]
  882. !
  883. label
  884. ^ 'Packages'
  885. ! !
  886. !HLPackagesListWidget methodsFor: 'actions'!
  887. commitPackage
  888. self model commitPackage
  889. !
  890. focusClassesListWidget
  891. self model announcer announce: HLClassesListFocus new
  892. !
  893. observeModel
  894. self model announcer
  895. on: HLPackageSelected
  896. send: #onPackageSelected:
  897. to: self;
  898. on: HLPackagesFocusRequested
  899. send: #onPackagesFocusRequested
  900. to: self
  901. !
  902. observeSystem
  903. self model systemAnnouncer
  904. on: ClassAdded
  905. send: #onClassAdded:
  906. to: self.
  907. self model systemAnnouncer
  908. on: PackageAdded
  909. send: #onPackageAdded:
  910. to: self
  911. !
  912. selectItem: aPackage
  913. super selectItem: aPackage.
  914. self model selectedPackage: aPackage
  915. ! !
  916. !HLPackagesListWidget methodsFor: 'initialization'!
  917. initializeItems
  918. ^ items := self model packages
  919. sort: [ :a :b | a name < b name ]
  920. ! !
  921. !HLPackagesListWidget methodsFor: 'reactions'!
  922. onClassAdded: anAnnouncement
  923. "Amber doesn't have yet a global organizer for packages"
  924. (self items includes: anAnnouncement theClass package) ifFalse: [
  925. self
  926. initializeItems;
  927. refresh ]
  928. !
  929. onPackageAdded: anAnnouncement
  930. self
  931. initializeItems;
  932. refresh
  933. !
  934. onPackageSelected: anAnnouncement
  935. | package |
  936. package := anAnnouncement item.
  937. self selectedItem: package.
  938. self hasFocus ifFalse: [
  939. self
  940. activateItem: package;
  941. focus ]
  942. !
  943. onPackagesFocusRequested
  944. self focus
  945. ! !
  946. !HLPackagesListWidget methodsFor: 'rendering'!
  947. renderItemLabel: aPackage on: html
  948. html with: aPackage name
  949. ! !
  950. HLToolListWidget subclass: #HLProtocolsListWidget
  951. instanceVariableNames: ''
  952. package: 'Helios-Browser'!
  953. !HLProtocolsListWidget commentStamp!
  954. I render a list of protocols for the selected class.!
  955. !HLProtocolsListWidget methodsFor: 'accessing'!
  956. allProtocol
  957. ^ self model allProtocol
  958. !
  959. cssClassForItem: anItem
  960. anItem = self allProtocol ifTrue: [ ^ '' ].
  961. anItem = 'private' ifTrue: [ ^ 'private' ].
  962. anItem = 'initialization' ifTrue: [ ^ 'initialization' ].
  963. (anItem match: '^\*') ifTrue: [ ^ 'extension' ].
  964. ^ ''
  965. !
  966. label
  967. ^ 'Protocols'
  968. !
  969. selectedItem
  970. ^ super selectedItem" ifNil: [ self allProtocol ]"
  971. ! !
  972. !HLProtocolsListWidget methodsFor: 'actions'!
  973. observeModel
  974. self model announcer
  975. on: HLClassSelected
  976. send: #onClassSelected:
  977. to: self;
  978. on: HLShowInstanceToggled
  979. send: #onClassSelected:
  980. to: self;
  981. on: HLProtocolSelected
  982. send: #onProtocolSelected:
  983. to: self;
  984. on: HLProtocolsFocusRequested
  985. send: #onProtocolsFocusRequested
  986. to: self
  987. !
  988. observeSystem
  989. self model systemAnnouncer
  990. on: ProtocolAdded
  991. send: #onProtocolAdded:
  992. to: self;
  993. on: ProtocolRemoved
  994. send: #onProtocolRemoved:
  995. to: self
  996. !
  997. selectItem: aString
  998. self model selectedProtocol: aString
  999. ! !
  1000. !HLProtocolsListWidget methodsFor: 'private'!
  1001. setItemsForClass: aClass
  1002. self items: (aClass
  1003. ifNil: [ Array with: self allProtocol ]
  1004. ifNotNil: [
  1005. (Array with: self allProtocol)
  1006. addAll: aClass protocols;
  1007. yourself ])
  1008. !
  1009. setItemsForSelectedClass
  1010. self setItemsForClass: self model selectedClass
  1011. ! !
  1012. !HLProtocolsListWidget methodsFor: 'reactions'!
  1013. onClassSelected: anAnnouncement
  1014. self selectedItem: nil.
  1015. self setItemsForSelectedClass.
  1016. self refresh
  1017. !
  1018. onProtocolAdded: anAnnouncement
  1019. | class |
  1020. class := anAnnouncement theClass.
  1021. class = self model selectedClass ifFalse: [ ^ self ].
  1022. self setItemsForSelectedClass.
  1023. self refresh
  1024. !
  1025. onProtocolRemoved: anAnnouncement
  1026. | class protocol |
  1027. class := anAnnouncement theClass.
  1028. protocol := anAnnouncement protocol.
  1029. class = self model selectedClass ifFalse: [ ^ self ].
  1030. self model selectedProtocol = protocol
  1031. ifTrue: [
  1032. self
  1033. selectedItem: nil;
  1034. selectItem: nil ].
  1035. self setItemsForSelectedClass.
  1036. self refresh
  1037. !
  1038. onProtocolSelected: anAnnouncement
  1039. | protocol |
  1040. protocol := anAnnouncement item.
  1041. self selectedItem: protocol.
  1042. protocol ifNil: [ ^ self ].
  1043. self hasFocus ifFalse: [
  1044. self
  1045. activateItem: protocol;
  1046. focus ]
  1047. !
  1048. onProtocolsFocusRequested
  1049. self focus
  1050. ! !
  1051. !HLProtocolsListWidget methodsFor: 'rendering'!
  1052. renderContentOn: html
  1053. self model showInstance
  1054. ifFalse: [ html div
  1055. class: 'class_side';
  1056. with: [ super renderContentOn: html ] ]
  1057. ifTrue: [ super renderContentOn: html ]
  1058. ! !
  1059. Object subclass: #HLSelectorsCache
  1060. instanceVariableNames: 'classesCache'
  1061. package: 'Helios-Browser'!
  1062. !HLSelectorsCache methodsFor: 'accessing'!
  1063. cacheFor: aClass
  1064. aClass ifNil: [ ^ nil ].
  1065. ^ self classesCache
  1066. at: aClass name
  1067. ifAbsentPut: [ self newCacheFor: aClass ]
  1068. !
  1069. classesCache
  1070. ^ classesCache ifNil: [ classesCache := HashedCollection new ]
  1071. ! !
  1072. !HLSelectorsCache methodsFor: 'actions'!
  1073. observeSystem
  1074. SystemAnnouncer current
  1075. on: MethodAdded
  1076. send: #onMethodAdded:
  1077. to: self;
  1078. on: MethodRemoved
  1079. send: #onMethodRemoved:
  1080. to: self
  1081. ! !
  1082. !HLSelectorsCache methodsFor: 'factory'!
  1083. newCacheFor: aClass
  1084. ^ HLClassCache
  1085. on: aClass
  1086. selectorsCache: self
  1087. ! !
  1088. !HLSelectorsCache methodsFor: 'initialization'!
  1089. initialize
  1090. super initialize.
  1091. self observeSystem
  1092. ! !
  1093. !HLSelectorsCache methodsFor: 'private'!
  1094. invalidateCacheFor: aMethod
  1095. (self cacheFor: aMethod methodClass)
  1096. invalidateSelector: aMethod selector
  1097. ! !
  1098. !HLSelectorsCache methodsFor: 'reactions'!
  1099. onMethodAdded: anAnnouncement
  1100. self invalidateCacheFor: anAnnouncement method
  1101. !
  1102. onMethodRemoved: anAnnouncement
  1103. self invalidateCacheFor: anAnnouncement method
  1104. ! !
  1105. !HLSelectorsCache methodsFor: 'testing'!
  1106. isOverridden: aMethod
  1107. ^ (self cacheFor: aMethod methodClass)
  1108. isOverridden: aMethod
  1109. !
  1110. isOverride: aMethod
  1111. ^ (self cacheFor: aMethod methodClass)
  1112. isOverride: aMethod
  1113. ! !
  1114. HLSelectorsCache class instanceVariableNames: 'current'!
  1115. !HLSelectorsCache class methodsFor: 'accessing'!
  1116. current
  1117. ^ current ifNil: [ current := super new ]
  1118. !
  1119. flush
  1120. current := nil
  1121. ! !
  1122. !HLSelectorsCache class methodsFor: 'instance creation'!
  1123. new
  1124. self shouldNotImplement
  1125. ! !