1
0

Helios-Browser.st 29 KB

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