Helios-Browser.st 30 KB

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