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