Helios-Browser.st 30 KB

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