Helios-Browser.st 30 KB

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