Helios-Browser.st 30 KB

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