Helios-Browser.st 27 KB

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