1
0

Helios-Browser.st 29 KB

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