1
0

Helios-Browser.st 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572
  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. selectedClass: aCompiledMethod methodClass;
  41. selectedProtocol: aCompiledMethod protocol;
  42. selectedMethod: aCompiledMethod;
  43. focusOnSourceCode
  44. !
  45. unregister
  46. super unregister.
  47. {
  48. self packagesListWidget.
  49. self classesListWidget.
  50. self protocolsListWidget.
  51. self methodsListWidget.
  52. self sourceWidget
  53. }
  54. do: [ :each | each unregister ]
  55. ! !
  56. !HLBrowser methodsFor: 'keybindings'!
  57. registerBindingsOn: aBindingGroup
  58. HLToolCommand
  59. registerConcreteClassesOn: aBindingGroup
  60. for: self model
  61. ! !
  62. !HLBrowser methodsFor: 'reactions'!
  63. onClassSelected: anAnnouncement
  64. anAnnouncement item
  65. ifNil: [ self setTabLabel: (self model selectedPackage
  66. ifNil: [ self defaultTabLabel ]
  67. ifNotNil: [ :package | package name ]) ]
  68. ifNotNil: [ :item | self setTabLabel: item name ]
  69. !
  70. onPackageSelected: anAnnouncement
  71. anAnnouncement item ifNotNil: [ :item |
  72. self setTabLabel: item name ]
  73. ! !
  74. !HLBrowser methodsFor: 'rendering'!
  75. renderContentOn: html
  76. html with: (HLContainer with: (HLHorizontalSplitter
  77. with: (HLVerticalSplitter
  78. with: (HLVerticalSplitter
  79. with: self packagesListWidget
  80. with: self classesListWidget)
  81. with: (HLVerticalSplitter
  82. with: self protocolsListWidget
  83. with: self methodsListWidget))
  84. with: self sourceWidget)).
  85. self packagesListWidget focus
  86. ! !
  87. !HLBrowser methodsFor: 'testing'!
  88. canHaveFocus
  89. ^ true
  90. ! !
  91. !HLBrowser methodsFor: 'widgets'!
  92. classesListWidget
  93. ^ classesListWidget ifNil: [
  94. classesListWidget := HLClassesListWidget on: self model.
  95. classesListWidget next: self protocolsListWidget ]
  96. !
  97. methodsListWidget
  98. ^ methodsListWidget ifNil: [
  99. methodsListWidget := HLMethodsListWidget on: self model.
  100. methodsListWidget next: self sourceWidget ]
  101. !
  102. packagesListWidget
  103. ^ packagesListWidget ifNil: [
  104. packagesListWidget := HLPackagesListWidget on: self model.
  105. packagesListWidget next: self classesListWidget ]
  106. !
  107. protocolsListWidget
  108. ^ protocolsListWidget ifNil: [
  109. protocolsListWidget := HLProtocolsListWidget on: self model.
  110. protocolsListWidget next: self methodsListWidget ]
  111. !
  112. sourceWidget
  113. ^ sourceWidget ifNil: [
  114. sourceWidget := HLBrowserBottomWidget new
  115. model: self model;
  116. yourself ]
  117. ! !
  118. HLBrowser class instanceVariableNames: 'nextId'!
  119. !HLBrowser class methodsFor: 'accessing'!
  120. nextId
  121. nextId ifNil: [ nextId := 0 ].
  122. ^ 'browser_', (nextId + 1) asString
  123. !
  124. tabClass
  125. ^ 'browser'
  126. !
  127. tabLabel
  128. ^ 'Browser'
  129. !
  130. tabPriority
  131. ^ 0
  132. ! !
  133. !HLBrowser class methodsFor: 'testing'!
  134. canBeOpenAsTab
  135. ^ true
  136. ! !
  137. HLWidget subclass: #HLBrowserBottomWidget
  138. instanceVariableNames: 'model codeWidget documentationWidget'
  139. package: 'Helios-Browser'!
  140. !HLBrowserBottomWidget commentStamp!
  141. I render the code area of a browser and optionally the documentation for the selected class.!
  142. !HLBrowserBottomWidget methodsFor: 'accessing'!
  143. codeWidget
  144. ^ codeWidget ifNil: [ codeWidget := HLBrowserCodeWidget new
  145. browserModel: self model;
  146. yourself ]
  147. !
  148. documentationWidget
  149. ^ documentationWidget ifNil: [ documentationWidget := HLDocumentationWidget new
  150. model: self model;
  151. yourself ]
  152. !
  153. model
  154. ^ model
  155. !
  156. model: aModel
  157. model := aModel.
  158. self observeModel
  159. !
  160. previous
  161. "For navigation"
  162. !
  163. previous: aWidget
  164. "For navigation"
  165. ! !
  166. !HLBrowserBottomWidget methodsFor: 'actions'!
  167. focus
  168. self codeWidget focus
  169. !
  170. observeModel
  171. self model announcer
  172. on: HLShowInstanceToggled
  173. send: #onShowInstanceToggled
  174. to: self;
  175. on: HLShowCommentToggled
  176. send: #onShowCommentToggled
  177. to: self
  178. ! !
  179. !HLBrowserBottomWidget methodsFor: 'reactions'!
  180. onShowCommentToggled
  181. self refresh
  182. !
  183. onShowInstanceToggled
  184. self refresh
  185. ! !
  186. !HLBrowserBottomWidget methodsFor: 'rendering'!
  187. renderContentOn: html
  188. self model showComment
  189. ifTrue: [ self renderPanesOn: html ]
  190. ifFalse: [ html with: self codeWidget ]
  191. !
  192. renderPanesOn: html
  193. html with: (HLVerticalSplitter
  194. with: self codeWidget
  195. with: self documentationWidget)
  196. ! !
  197. !HLBrowserBottomWidget methodsFor: 'testing'!
  198. canHaveFocus
  199. ^ true
  200. ! !
  201. HLToolModel subclass: #HLBrowserModel
  202. instanceVariableNames: 'showInstance showComment'
  203. package: 'Helios-Browser'!
  204. !HLBrowserModel methodsFor: 'accessing'!
  205. showComment
  206. ^ showComment ifNil: [ true ]
  207. !
  208. showComment: aBoolean
  209. self withChangesDo: [
  210. showComment := aBoolean.
  211. self announcer announce: HLShowCommentToggled new ]
  212. !
  213. showInstance
  214. ^ showInstance ifNil: [ true ]
  215. !
  216. showInstance: aBoolean
  217. self withChangesDo: [
  218. showInstance := aBoolean.
  219. self selectedClass ifNotNil: [
  220. self selectedClass: (aBoolean
  221. ifTrue: [ self selectedClass theNonMetaClass ]
  222. ifFalse: [ self selectedClass theMetaClass ]) ].
  223. self announcer announce: HLShowInstanceToggled new ]
  224. ! !
  225. !HLBrowserModel methodsFor: 'actions'!
  226. focusOnClasses
  227. self announcer announce: HLClassesFocusRequested new
  228. !
  229. focusOnDocumentation
  230. self announcer announce: HLDocumentationFocusRequested new
  231. !
  232. focusOnMethods
  233. self announcer announce: HLMethodsFocusRequested new
  234. !
  235. focusOnPackages
  236. self announcer announce: HLPackagesFocusRequested new
  237. !
  238. focusOnProtocols
  239. self announcer announce: HLProtocolsFocusRequested new
  240. !
  241. focusOnSourceCode
  242. self announcer announce: HLSourceCodeFocusRequested new
  243. !
  244. setClassComment: aString
  245. self environment
  246. setClassCommentOf: self selectedClass theNonMetaClass
  247. to: aString
  248. !
  249. showClassTemplate
  250. self selectedPackage ifNotNil: [ :package |
  251. self announcer announce: (HLShowTemplate new
  252. template: package classTemplate;
  253. yourself) ]
  254. !
  255. showMethodTemplate
  256. self selectedClass ifNotNil: [ :theClass |
  257. self announcer announce: (HLShowTemplate new
  258. template: theClass methodTemplate;
  259. yourself) ]
  260. ! !
  261. !HLBrowserModel methodsFor: 'commands actions'!
  262. editComment
  263. self announcer announce: HLEditComment new
  264. ! !
  265. !HLBrowserModel methodsFor: 'testing'!
  266. isBrowserModel
  267. ^ true
  268. ! !
  269. !HLBrowserModel class methodsFor: 'instance creation'!
  270. on: anEnvironment
  271. ^ self new
  272. environment: anEnvironment;
  273. yourself
  274. ! !
  275. Object subclass: #HLClassCache
  276. instanceVariableNames: 'class selectorsCache overrideCache overriddenCache'
  277. package: 'Helios-Browser'!
  278. !HLClassCache methodsFor: 'accessing'!
  279. overriddenCache
  280. ^ overriddenCache ifNil: [ overriddenCache := HashedCollection new ]
  281. !
  282. overrideCache
  283. ^ overrideCache ifNil: [ overrideCache := HashedCollection new ]
  284. !
  285. selectorsCache
  286. ^ selectorsCache
  287. !
  288. selectorsCache: aCache
  289. selectorsCache := aCache
  290. !
  291. theClass
  292. ^ class
  293. !
  294. theClass: aClass
  295. class := aClass
  296. ! !
  297. !HLClassCache methodsFor: 'actions'!
  298. invalidateChildrenSelector: aSelector
  299. self theClass subclasses do: [ :each |
  300. (self selectorsCache cacheFor: each)
  301. removeSelector: aSelector;
  302. invalidateChildrenSelector: aSelector ]
  303. !
  304. invalidateParentSelector: aSelector
  305. self theClass superclass ifNotNil: [
  306. (self selectorsCache cacheFor: self theClass superclass)
  307. removeSelector: aSelector;
  308. invalidateParentSelector: aSelector ]
  309. !
  310. invalidateSelector: aSelector
  311. self
  312. invalidateParentSelector: aSelector;
  313. invalidateChildrenSelector: aSelector;
  314. removeSelector: aSelector
  315. ! !
  316. !HLClassCache methodsFor: 'private'!
  317. removeSelector: aSelector
  318. self overriddenCache
  319. removeKey: aSelector
  320. ifAbsent: [ ].
  321. self overrideCache
  322. removeKey: aSelector
  323. ifAbsent: [ ]
  324. ! !
  325. !HLClassCache methodsFor: 'testing'!
  326. isOverridden: aMethod
  327. ^ self overriddenCache
  328. at: aMethod selector
  329. ifAbsentPut: [ aMethod isOverridden ]
  330. !
  331. isOverride: aMethod
  332. ^ self overrideCache
  333. at: aMethod selector
  334. ifAbsentPut: [ aMethod isOverride ]
  335. ! !
  336. !HLClassCache class methodsFor: 'instance creation'!
  337. on: aClass selectorsCache: aSelectorsCache
  338. ^ self new
  339. theClass: aClass;
  340. selectorsCache: aSelectorsCache;
  341. yourself
  342. ! !
  343. HLToolListWidget subclass: #HLClassesListWidget
  344. instanceVariableNames: ''
  345. package: 'Helios-Browser'!
  346. !HLClassesListWidget commentStamp!
  347. I render a list of classes in the selected package.!
  348. !HLClassesListWidget methodsFor: 'accessing'!
  349. cssClassForItem: aClass
  350. ^ aClass theNonMetaClass heliosClass
  351. !
  352. getChildrenOf: aClass
  353. ^ self items select: [ :each | each superclass = aClass ]
  354. !
  355. getRootClassesOf: aCollection
  356. ^ aCollection select: [ :each |
  357. (aCollection includes: each superclass) not ]
  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 forceSelectedClass: 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 ])
  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. onDoubleClick: anEvent on: aClass
  519. HLBrowser openAsTab openClassNamed: aClass name
  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: 'classes-list-controls';
  537. with: [
  538. html div
  539. class: 'btn-group';
  540. with: [
  541. html button
  542. class: (String streamContents: [ :str |
  543. str nextPutAll: 'btn'.
  544. self showInstance ifTrue: [
  545. str nextPutAll: ' active' ] ]);
  546. with: 'Instance';
  547. onClick: [ self showInstance: true ].
  548. html button
  549. class: (String streamContents: [ :str |
  550. str nextPutAll: 'btn'.
  551. self showClass ifTrue: [
  552. str nextPutAll: ' active' ] ]);
  553. with: 'Class';
  554. onClick: [ self showInstance: false ]
  555. ].
  556. html label
  557. class: 'checkbox';
  558. with: [
  559. checkbox := html input
  560. type: 'checkbox';
  561. onClick: [ self toggleShowComment ].
  562. html with: 'Doc' ].
  563. ].
  564. self showComment ifTrue: [
  565. checkbox at: 'checked' put: 'checked' ]
  566. !
  567. renderItem: aClass level: anInteger on: html
  568. | li a |
  569. li := html li.
  570. li asJQuery data: 'item' put: aClass.
  571. li
  572. class: (self listCssClassForItem: aClass);
  573. with: [
  574. a := html a
  575. with: [
  576. (html tag: 'i') class: (self cssClassForItem: aClass).
  577. self renderItemLabel: aClass level: anInteger on: html ];
  578. onClick: [
  579. self reactivateListItem: li asJQuery ].
  580. a asJQuery dblclick: [ :ev | self onDoubleClick: ev on: aClass ]
  581. ].
  582. (self getChildrenOf: aClass) do: [ :each |
  583. self renderItem: each level: anInteger + 1 on: html ]
  584. !
  585. renderItem: aClass on: html
  586. super renderItem: aClass on: html.
  587. (self getChildrenOf: aClass) do: [ :each |
  588. self renderItem: each level: 1 on: html ]
  589. !
  590. renderItemLabel: aClass level: anInteger on: html
  591. html span asJQuery html: (String streamContents: [ :str |
  592. anInteger timesRepeat: [
  593. str nextPutAll: '&nbsp;&nbsp;&nbsp;&nbsp;' ].
  594. str nextPutAll: aClass name ])
  595. !
  596. renderItemLabel: aClass on: html
  597. self renderItemLabel: aClass level: 0 on: html
  598. !
  599. renderListOn: html
  600. (self getRootClassesOf: self items)
  601. do: [ :each | self renderItem: each on: html ]
  602. ! !
  603. !HLClassesListWidget methodsFor: 'testing'!
  604. showClass
  605. ^ self model showInstance not
  606. !
  607. showComment
  608. ^ self model showComment
  609. !
  610. showInstance
  611. ^ self model showInstance
  612. ! !
  613. HLFocusableWidget subclass: #HLDocumentationWidget
  614. instanceVariableNames: 'model'
  615. package: 'Helios-Browser'!
  616. !HLDocumentationWidget commentStamp!
  617. I render the documentation for the selected class!
  618. !HLDocumentationWidget methodsFor: 'accessing'!
  619. documentation
  620. ^ self selectedItem
  621. ifNil: [ '' ]
  622. ifNotNil: [ :item | item comment ifEmpty: [ self defaultDocumentation ] ]
  623. !
  624. head
  625. ^ self selectedItem
  626. ifNil: [ self defaultHead ]
  627. ifNotNil: [ :item | item name ]
  628. !
  629. model
  630. ^ model
  631. !
  632. model: aModel
  633. model := aModel.
  634. self
  635. observeSystem;
  636. observeModel
  637. !
  638. selectedItem
  639. ^ self model selectedClass ifNotNil: [ :class | class theNonMetaClass ]
  640. ! !
  641. !HLDocumentationWidget methodsFor: 'actions'!
  642. editDocumentation
  643. self model editComment
  644. !
  645. observeModel
  646. self model announcer
  647. on: HLClassSelected
  648. send: #onClassSelected:
  649. to: self;
  650. on: HLEditComment
  651. send: #onEditDocumentation
  652. to: self;
  653. on: HLDocumentationFocusRequested
  654. send: #onDocumentationFocusRequested
  655. to: self
  656. !
  657. observeSystem
  658. self model systemAnnouncer
  659. on: ClassCommentChanged
  660. send: #onClassCommentChanged:
  661. to: self
  662. !
  663. selectClass: aClass
  664. self model selectedClass: aClass
  665. !
  666. unregister
  667. super unregister.
  668. self model announcer unregister: self
  669. ! !
  670. !HLDocumentationWidget methodsFor: 'defaults'!
  671. defaultDocumentation
  672. ^ 'No documentation is available for this class.'
  673. !
  674. defaultHead
  675. ^ 'No class selected'
  676. ! !
  677. !HLDocumentationWidget methodsFor: 'reactions'!
  678. onClassCommentChanged: anAnnouncement
  679. self model selectedClass ifNil: [ ^ self ].
  680. anAnnouncement theClass = self model selectedClass theNonMetaClass
  681. ifTrue: [ self refresh ]
  682. !
  683. onClassSelected: anAnnouncement
  684. self refresh
  685. !
  686. onDocumentationFocusRequested
  687. self focus
  688. !
  689. onEditDocumentation
  690. self
  691. request: self model selectedClass theNonMetaClass name, ' comment'
  692. value: self model selectedClass theNonMetaClass comment
  693. do: [ :comment | self setClassComment: comment ]
  694. !
  695. setClassComment: aString
  696. self model setClassComment: aString
  697. ! !
  698. !HLDocumentationWidget methodsFor: 'rendering'!
  699. renderContentOn: html
  700. html div
  701. class: 'doc';
  702. with: [
  703. self
  704. renderHeadOn: html;
  705. renderDocOn: html ]
  706. !
  707. renderDocOn: html
  708. self selectedItem ifNotNil: [
  709. self renderInheritanceOn: html.
  710. html h1
  711. with: 'Overview';
  712. with: [
  713. html button
  714. class: 'button default';
  715. with: 'Edit';
  716. onClick: [ self editDocumentation ] ].
  717. (html div
  718. class: 'markdown';
  719. asJQuery) html: ((Showdown at: 'converter') new makeHtml: self documentation) ]
  720. !
  721. renderHeadOn: html
  722. html div
  723. class: 'head';
  724. with: self head
  725. !
  726. renderInheritanceOn: html
  727. html div
  728. class: 'inheritance';
  729. with: [
  730. html with: 'Subclass of '.
  731. self selectedItem superclass
  732. ifNil: [ html em with: 'nil' ]
  733. ifNotNil: [
  734. html a
  735. with: self selectedItem superclass name;
  736. onClick: [ self selectClass: self selectedItem superclass ] ] ]
  737. ! !
  738. HLToolListWidget subclass: #HLMethodsListWidget
  739. instanceVariableNames: 'selectorsCache'
  740. package: 'Helios-Browser'!
  741. !HLMethodsListWidget commentStamp!
  742. I render a list of methods for the selected protocol.!
  743. !HLMethodsListWidget methodsFor: 'accessing'!
  744. allProtocol
  745. ^ self model allProtocol
  746. !
  747. cssClassForItem: aSelector
  748. | override overriden method |
  749. method := self methodForSelector: aSelector.
  750. override := self isOverride: method.
  751. overriden := self isOverridden: method.
  752. ^ override
  753. ifTrue: [ overriden
  754. ifTrue: [ 'override-overridden' ]
  755. ifFalse: [ 'override' ] ]
  756. ifFalse: [
  757. overriden
  758. ifTrue: [ 'overridden' ]
  759. ifFalse: [ '' ] ]
  760. !
  761. label
  762. ^ 'Methods'
  763. !
  764. methodForSelector: aSelector
  765. ^ self model selectedClass
  766. methodDictionary at: aSelector
  767. !
  768. methodsInProtocol: aString
  769. self model selectedClass ifNil: [ ^ #() ].
  770. ^ aString = self allProtocol
  771. ifTrue: [ self model selectedClass methods ]
  772. ifFalse: [ self model selectedClass methodsInProtocol: aString ]
  773. !
  774. overrideSelectors
  775. ^ self selectorsCache
  776. at: 'override'
  777. ifAbsentPut: [
  778. self model selectedClass allSuperclasses
  779. inject: Set new into: [ :acc :each | acc addAll: each selectors; yourself ] ]
  780. !
  781. overridenSelectors
  782. ^ self selectorsCache
  783. at: 'overriden'
  784. ifAbsentPut: [
  785. self model selectedClass allSubclasses
  786. inject: Set new into: [ :acc :each | acc addAll: each selectors; yourself ] ]
  787. !
  788. selectorsCache
  789. ^ self class selectorsCache
  790. !
  791. selectorsInProtocol: aString
  792. ^ ((self methodsInProtocol: aString)
  793. collect: [ :each | each selector ]) sorted
  794. ! !
  795. !HLMethodsListWidget methodsFor: 'actions'!
  796. focus
  797. super focus.
  798. self selectedItem ifNil: [
  799. self model showMethodTemplate ]
  800. !
  801. observeModel
  802. self model announcer
  803. on: HLProtocolSelected
  804. send: #onProtocolSelected:
  805. to: self;
  806. on: HLShowInstanceToggled
  807. send: #onShowInstanceToggled
  808. to: self;
  809. on: HLMethodSelected
  810. send: #onMethodSelected:
  811. to: self;
  812. on: HLMethodsFocusRequested
  813. send: #onMethodsFocusRequested
  814. to: self
  815. !
  816. observeSystem
  817. self model systemAnnouncer
  818. on: ProtocolAdded
  819. send: #onProtocolAdded:
  820. to: self;
  821. on: ProtocolRemoved
  822. send: #onProtocolRemoved:
  823. to: self;
  824. on: MethodAdded
  825. send: #onMethodAdded:
  826. to: self;
  827. on: MethodRemoved
  828. send: #onMethodRemoved:
  829. to: self;
  830. on: MethodMoved
  831. send: #onMethodMoved:
  832. to: self
  833. !
  834. reselectItem: aSelector
  835. self model forceSelectedMethod: (self methodForSelector: aSelector)
  836. !
  837. selectItem: aSelector
  838. aSelector ifNil: [ ^ self model selectedMethod: nil ].
  839. self model selectedMethod: (self methodForSelector: aSelector)
  840. ! !
  841. !HLMethodsListWidget methodsFor: 'private'!
  842. setItemsForProtocol: aString
  843. ^ self items: (aString
  844. ifNil: [ #() ]
  845. ifNotNil: [ self selectorsInProtocol: aString ])
  846. !
  847. setItemsForSelectedProtocol
  848. self setItemsForProtocol: self model selectedProtocol
  849. ! !
  850. !HLMethodsListWidget methodsFor: 'reactions'!
  851. onMethodAdded: anAnnouncement
  852. self model selectedClass = anAnnouncement method methodClass ifFalse: [ ^ self ].
  853. self setItemsForSelectedProtocol.
  854. self refresh
  855. !
  856. onMethodMoved: anAnnouncement
  857. self model selectedMethod = anAnnouncement method ifFalse: [ ^ self ].
  858. self model selectedProtocol = self model allProtocol ifFalse: [
  859. self
  860. selectedItem: nil;
  861. selectItem: nil;
  862. setItemsForSelectedProtocol;
  863. refresh ]
  864. !
  865. onMethodRemoved: anAnnouncement
  866. | method |
  867. method := anAnnouncement method.
  868. self items detect: [ :each | each = method selector ] ifNone: [ ^ self ].
  869. self selectedItem ifNotNil: [
  870. (method methodClass = self model selectedClass and: [ method selector = self selectedItem ])
  871. ifTrue: [
  872. self selectedItem: nil;
  873. selectItem: nil ] ].
  874. self setItemsForSelectedProtocol.
  875. self
  876. refresh;
  877. focus
  878. !
  879. onMethodSelected: anAnnouncement
  880. | selector method |
  881. method := anAnnouncement item.
  882. selector := method isCompiledMethod
  883. ifTrue: [ method selector ]
  884. ifFalse: [ nil ].
  885. self
  886. selectedItem: selector;
  887. activateItem: selector
  888. !
  889. onMethodsFocusRequested
  890. self focus
  891. !
  892. onProtocolAdded: anAnnouncement
  893. self model selectedClass = anAnnouncement theClass ifFalse: [ ^ self ].
  894. self setItemsForSelectedProtocol.
  895. self refresh.
  896. self focus
  897. !
  898. onProtocolRemoved: anAnnouncement
  899. self model selectedClass = anAnnouncement theClass ifFalse: [ ^ self ].
  900. self setItemsForSelectedProtocol.
  901. self refresh.
  902. self focus
  903. !
  904. onProtocolSelected: anAnnouncement
  905. self selectedItem: nil.
  906. self setItemsForSelectedProtocol.
  907. self refresh
  908. !
  909. onShowInstanceToggled
  910. self onProtocolSelected: nil
  911. ! !
  912. !HLMethodsListWidget methodsFor: 'rendering'!
  913. renderContentOn: html
  914. self model showInstance
  915. ifFalse: [ html div
  916. class: 'class_side';
  917. with: [ super renderContentOn: html ] ]
  918. ifTrue: [ super renderContentOn: html ]
  919. !
  920. renderItemLabel: aSelector on: html
  921. html with: aSelector
  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 instanceVariableNames: 'selectorsCache'!
  931. !HLMethodsListWidget class methodsFor: 'accessing'!
  932. selectorsCache
  933. ^ HLSelectorsCache current
  934. ! !
  935. HLToolListWidget subclass: #HLPackagesListWidget
  936. instanceVariableNames: ''
  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: PackageClean
  976. send: #onPackageStateChanged
  977. to: self.
  978. self model systemAnnouncer
  979. on: PackageDirty
  980. send: #onPackageStateChanged
  981. to: self.
  982. !
  983. reselectItem: anItem
  984. self model forceSelectedPackage: anItem
  985. !
  986. selectItem: aPackage
  987. super selectItem: aPackage.
  988. self model selectedPackage: aPackage
  989. ! !
  990. !HLPackagesListWidget methodsFor: 'initialization'!
  991. initializeItems
  992. ^ items := self model packages
  993. sort: [ :a :b | a name < b name ]
  994. ! !
  995. !HLPackagesListWidget methodsFor: 'reactions'!
  996. onClassAdded: anAnnouncement
  997. "Amber doesn't have yet a global organizer for packages"
  998. (self items includes: anAnnouncement theClass package) ifFalse: [
  999. self
  1000. initializeItems;
  1001. refresh ]
  1002. !
  1003. onPackageAdded: anAnnouncement
  1004. self
  1005. initializeItems;
  1006. refresh
  1007. !
  1008. onPackageSelected: anAnnouncement
  1009. | package |
  1010. package := anAnnouncement item.
  1011. self selectedItem: package.
  1012. self hasFocus ifFalse: [
  1013. self
  1014. activateItem: package;
  1015. focus ]
  1016. !
  1017. onPackageStateChanged
  1018. self refresh
  1019. !
  1020. onPackagesFocusRequested
  1021. self focus
  1022. ! !
  1023. !HLPackagesListWidget methodsFor: 'rendering'!
  1024. renderItemLabel: aPackage on: html
  1025. html with: aPackage name
  1026. ! !
  1027. HLToolListWidget subclass: #HLProtocolsListWidget
  1028. instanceVariableNames: ''
  1029. package: 'Helios-Browser'!
  1030. !HLProtocolsListWidget commentStamp!
  1031. I render a list of protocols for the selected class.!
  1032. !HLProtocolsListWidget methodsFor: 'accessing'!
  1033. allProtocol
  1034. ^ self model allProtocol
  1035. !
  1036. cssClassForItem: anItem
  1037. anItem = self allProtocol ifTrue: [ ^ '' ].
  1038. anItem = 'private' ifTrue: [ ^ 'private' ].
  1039. anItem = 'initialization' ifTrue: [ ^ 'initialization' ].
  1040. (anItem match: '^\*') ifTrue: [ ^ 'extension' ].
  1041. ^ ''
  1042. !
  1043. label
  1044. ^ 'Protocols'
  1045. !
  1046. selectedItem
  1047. ^ super selectedItem" ifNil: [ self allProtocol ]"
  1048. ! !
  1049. !HLProtocolsListWidget methodsFor: 'actions'!
  1050. observeModel
  1051. self model announcer
  1052. on: HLClassSelected
  1053. send: #onClassSelected:
  1054. to: self;
  1055. on: HLShowInstanceToggled
  1056. send: #onClassSelected:
  1057. to: self;
  1058. on: HLProtocolSelected
  1059. send: #onProtocolSelected:
  1060. to: self;
  1061. on: HLProtocolsFocusRequested
  1062. send: #onProtocolsFocusRequested
  1063. to: self
  1064. !
  1065. observeSystem
  1066. self model systemAnnouncer
  1067. on: ProtocolAdded
  1068. send: #onProtocolAdded:
  1069. to: self;
  1070. on: ProtocolRemoved
  1071. send: #onProtocolRemoved:
  1072. to: self
  1073. !
  1074. reselectItem: anItem
  1075. self model forceSelectedProtocol: anItem
  1076. !
  1077. selectItem: aString
  1078. self model selectedProtocol: aString
  1079. ! !
  1080. !HLProtocolsListWidget methodsFor: 'private'!
  1081. setItemsForClass: aClass
  1082. self items: (aClass
  1083. ifNil: [ Array with: self allProtocol ]
  1084. ifNotNil: [
  1085. (Array with: self allProtocol)
  1086. addAll: aClass protocols;
  1087. yourself ])
  1088. !
  1089. setItemsForSelectedClass
  1090. self setItemsForClass: self model selectedClass
  1091. ! !
  1092. !HLProtocolsListWidget methodsFor: 'reactions'!
  1093. onClassSelected: anAnnouncement
  1094. self selectedItem: nil.
  1095. self setItemsForSelectedClass.
  1096. self refresh
  1097. !
  1098. onProtocolAdded: anAnnouncement
  1099. | class |
  1100. class := anAnnouncement theClass.
  1101. class = self model selectedClass ifFalse: [ ^ self ].
  1102. self setItemsForSelectedClass.
  1103. self refresh
  1104. !
  1105. onProtocolRemoved: anAnnouncement
  1106. | class protocol |
  1107. class := anAnnouncement theClass.
  1108. protocol := anAnnouncement protocol.
  1109. class = self model selectedClass ifFalse: [ ^ self ].
  1110. self model selectedProtocol = protocol
  1111. ifTrue: [
  1112. self
  1113. selectedItem: nil;
  1114. selectItem: nil ].
  1115. self setItemsForSelectedClass.
  1116. self refresh
  1117. !
  1118. onProtocolSelected: anAnnouncement
  1119. | protocol |
  1120. protocol := anAnnouncement item.
  1121. self selectedItem: protocol.
  1122. protocol ifNil: [ ^ self ].
  1123. self hasFocus ifFalse: [
  1124. self
  1125. activateItem: protocol;
  1126. focus ]
  1127. !
  1128. onProtocolsFocusRequested
  1129. self focus
  1130. ! !
  1131. !HLProtocolsListWidget methodsFor: 'rendering'!
  1132. renderContentOn: html
  1133. self model showInstance
  1134. ifFalse: [ html div
  1135. class: 'class_side';
  1136. with: [ super renderContentOn: html ] ]
  1137. ifTrue: [ super renderContentOn: html ]
  1138. ! !
  1139. Object subclass: #HLSelectorsCache
  1140. instanceVariableNames: 'classesCache'
  1141. package: 'Helios-Browser'!
  1142. !HLSelectorsCache methodsFor: 'accessing'!
  1143. cacheFor: aClass
  1144. aClass ifNil: [ ^ nil ].
  1145. ^ self classesCache
  1146. at: aClass name
  1147. ifAbsentPut: [ self newCacheFor: aClass ]
  1148. !
  1149. classesCache
  1150. ^ classesCache ifNil: [ classesCache := HashedCollection new ]
  1151. ! !
  1152. !HLSelectorsCache methodsFor: 'actions'!
  1153. observeSystem
  1154. SystemAnnouncer current
  1155. on: MethodAdded
  1156. send: #onMethodAdded:
  1157. to: self;
  1158. on: MethodRemoved
  1159. send: #onMethodRemoved:
  1160. to: self
  1161. ! !
  1162. !HLSelectorsCache methodsFor: 'factory'!
  1163. newCacheFor: aClass
  1164. ^ HLClassCache
  1165. on: aClass
  1166. selectorsCache: self
  1167. ! !
  1168. !HLSelectorsCache methodsFor: 'initialization'!
  1169. initialize
  1170. super initialize.
  1171. self observeSystem
  1172. ! !
  1173. !HLSelectorsCache methodsFor: 'private'!
  1174. invalidateCacheFor: aMethod
  1175. (self cacheFor: aMethod methodClass)
  1176. invalidateSelector: aMethod selector
  1177. ! !
  1178. !HLSelectorsCache methodsFor: 'reactions'!
  1179. onMethodAdded: anAnnouncement
  1180. self invalidateCacheFor: anAnnouncement method
  1181. !
  1182. onMethodRemoved: anAnnouncement
  1183. self invalidateCacheFor: anAnnouncement method
  1184. ! !
  1185. !HLSelectorsCache methodsFor: 'testing'!
  1186. isOverridden: aMethod
  1187. ^ (self cacheFor: aMethod methodClass)
  1188. isOverridden: aMethod
  1189. !
  1190. isOverride: aMethod
  1191. ^ (self cacheFor: aMethod methodClass)
  1192. isOverride: aMethod
  1193. ! !
  1194. HLSelectorsCache class instanceVariableNames: 'current'!
  1195. !HLSelectorsCache class methodsFor: 'accessing'!
  1196. current
  1197. ^ current ifNil: [ current := super new ]
  1198. !
  1199. flush
  1200. current := nil
  1201. ! !
  1202. !HLSelectorsCache class methodsFor: 'instance creation'!
  1203. new
  1204. self shouldNotImplement
  1205. ! !