Helios-Browser.st 30 KB

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