1
0

Helios-Browser.st 29 KB

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