Helios-Browser.st 31 KB

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