Helios-Browser.st 29 KB

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