Helios-Browser.st 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385
  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 selectedClass = aMethod methodClass ifFalse: [ ^ self ].
  451. self
  452. selectedItem: nil;
  453. selectItem: nil;
  454. setItemsForSelectedProtocol;
  455. refresh
  456. !
  457. onMethodRemoved: aMethod
  458. self items detect: [ :each | each = aMethod selector ] ifNone: [ ^ self ].
  459. self selectedItem ifNotNil: [
  460. (aMethod methodClass = self model selectedClass and: [ aMethod selector = self selectedItem selector ])
  461. ifTrue: [
  462. self selectedItem: nil;
  463. selectItem: nil ] ].
  464. self setItemsForSelectedProtocol.
  465. self refresh
  466. !
  467. onMethodSelected: aMethod
  468. self selectedItem: aMethod.
  469. aMethod ifNil: [ ^ self ].
  470. self hasFocus ifFalse: [
  471. self
  472. activateItem: aMethod;
  473. focus ]
  474. !
  475. onMethodsFocusRequested
  476. self focus
  477. !
  478. onProtocolAdded: aClass
  479. self model selectedClass = aClass ifFalse: [ ^ self ].
  480. self setItemsForSelectedProtocol.
  481. self refresh.
  482. self focus
  483. !
  484. onProtocolRemoved: aClass
  485. self model selectedClass = aClass ifFalse: [ ^ self ].
  486. self setItemsForSelectedProtocol.
  487. self refresh.
  488. self focus
  489. !
  490. onProtocolSelected: aString
  491. self selectedItem: nil.
  492. self setItemsForSelectedProtocol.
  493. self refresh
  494. ! !
  495. !HLMethodsListWidget methodsFor: 'rendering'!
  496. renderContentOn: html
  497. self model showInstance
  498. ifFalse: [ html div
  499. class: 'class_side';
  500. with: [ super renderContentOn: html ] ]
  501. ifTrue: [ super renderContentOn: html ]
  502. !
  503. renderItemLabel: aSelector on: html
  504. html with: aSelector
  505. ! !
  506. !HLMethodsListWidget methodsFor: 'testing'!
  507. isOverridden: aMethod
  508. ^ self selectorsCache isOverridden: aMethod
  509. !
  510. isOverride: aMethod
  511. ^ self selectorsCache isOverride: aMethod
  512. ! !
  513. HLMethodsListWidget class instanceVariableNames: 'selectorsCache'!
  514. !HLMethodsListWidget class methodsFor: 'accessing'!
  515. selectorsCache
  516. ^ HLSelectorsCache current
  517. ! !
  518. HLBrowserListWidget subclass: #HLPackagesListWidget
  519. instanceVariableNames: ''
  520. package: 'Helios-Browser'!
  521. !HLPackagesListWidget methodsFor: 'accessing'!
  522. items
  523. ^ items ifNil: [self initializeItems]
  524. !
  525. label
  526. ^ 'Packages'
  527. ! !
  528. !HLPackagesListWidget methodsFor: 'actions'!
  529. commitPackage
  530. self model commitPackage
  531. !
  532. focusClassesListWidget
  533. self model announcer announce: HLClassesListFocus new
  534. !
  535. observeModel
  536. self model announcer
  537. on: HLPackageSelected
  538. do: [ :ann | self onPackageSelected: ann item ];
  539. on: HLPackagesFocusRequested
  540. do: [ :ann | self onPackagesFocusRequested ]
  541. !
  542. selectItem: aPackage
  543. self model selectedPackage: aPackage
  544. ! !
  545. !HLPackagesListWidget methodsFor: 'initialization'!
  546. initializeItems
  547. ^ items := self model packages
  548. sort: [ :a :b | a name < b name ]
  549. ! !
  550. !HLPackagesListWidget methodsFor: 'reactions'!
  551. onPackageSelected: aPackage
  552. self selectedItem: aPackage.
  553. self hasFocus ifFalse: [
  554. self
  555. activateItem: aPackage;
  556. focus ]
  557. !
  558. onPackagesFocusRequested
  559. self focus
  560. ! !
  561. !HLPackagesListWidget methodsFor: 'rendering'!
  562. renderButtonsOn: html
  563. html div
  564. class: 'buttons';
  565. with: [
  566. html button
  567. class: 'btn';
  568. with: 'Commit';
  569. onClick: [ self commitPackage ] ]
  570. !
  571. renderItemLabel: aPackage on: html
  572. html with: aPackage name
  573. ! !
  574. HLBrowserListWidget subclass: #HLProtocolsListWidget
  575. instanceVariableNames: ''
  576. package: 'Helios-Browser'!
  577. !HLProtocolsListWidget methodsFor: 'accessing'!
  578. allProtocol
  579. ^ self model allProtocol
  580. !
  581. label
  582. ^ 'Protocols'
  583. !
  584. selectedItem
  585. ^ super selectedItem" ifNil: [ self allProtocol ]"
  586. ! !
  587. !HLProtocolsListWidget methodsFor: 'actions'!
  588. observeModel
  589. self model announcer
  590. on: HLClassSelected
  591. do: [ :ann | self onClassSelected: ann item ];
  592. on: HLShowInstanceToggled
  593. do: [ :ann | self onClassSelected: self model selectedClass ];
  594. on: HLProtocolSelected
  595. do: [ :ann | self onProtocolSelected: ann item ];
  596. on: HLProtocolsFocusRequested
  597. do: [ :ann | self onProtocolsFocusRequested ]
  598. !
  599. observeSystem
  600. self model systemAnnouncer
  601. on: ProtocolAdded
  602. do: [ :ann | self onProtocolAdded: ann protocol to: ann theClass ];
  603. on: ProtocolRemoved
  604. do: [ :ann | self onProtocolRemoved: ann protocol from: ann theClass ]
  605. !
  606. selectItem: aString
  607. self model selectedProtocol: aString
  608. ! !
  609. !HLProtocolsListWidget methodsFor: 'private'!
  610. setItemsForClass: aClass
  611. self items: (aClass
  612. ifNil: [ Array with: self allProtocol ]
  613. ifNotNil: [
  614. (Array with: self allProtocol)
  615. addAll: aClass protocols;
  616. yourself ])
  617. !
  618. setItemsForSelectedClass
  619. self setItemsForClass: self model selectedClass
  620. ! !
  621. !HLProtocolsListWidget methodsFor: 'reactions'!
  622. onClassSelected: aClass
  623. self selectedItem: nil.
  624. self setItemsForSelectedClass.
  625. self refresh
  626. !
  627. onProtocolAdded: aString to: aClass
  628. aClass = self model selectedClass ifFalse: [ ^ self ].
  629. self setItemsForSelectedClass.
  630. self refresh
  631. !
  632. onProtocolRemoved: aString from: aClass
  633. aClass = self model selectedClass ifFalse: [ ^ self ].
  634. self model selectedProtocol = aString
  635. ifTrue: [
  636. self
  637. selectedItem: nil;
  638. selectItem: nil ].
  639. self setItemsForSelectedClass.
  640. self refresh
  641. !
  642. onProtocolSelected: aString
  643. self selectedItem: aString.
  644. aString ifNil: [ ^ self ].
  645. self hasFocus ifFalse: [
  646. self
  647. activateItem: aString;
  648. focus ]
  649. !
  650. onProtocolsFocusRequested
  651. self focus
  652. ! !
  653. !HLProtocolsListWidget methodsFor: 'rendering'!
  654. renderContentOn: html
  655. self model showInstance
  656. ifFalse: [ html div
  657. class: 'class_side';
  658. with: [ super renderContentOn: html ] ]
  659. ifTrue: [ super renderContentOn: html ]
  660. ! !
  661. Object subclass: #HLBrowserModel
  662. instanceVariableNames: 'announcer environment selectedPackage selectedClass selectedProtocol selectedSelector showInstance showComment'
  663. package: 'Helios-Browser'!
  664. !HLBrowserModel methodsFor: 'accessing'!
  665. announcer
  666. ^ announcer ifNil: [ announcer := Announcer new ]
  667. !
  668. availableClassNames
  669. ^ self environment availableClassNames
  670. !
  671. availablePackageNames
  672. ^ self environment availablePackageNames
  673. !
  674. availablePackages
  675. ^ self environment availablePackageNames
  676. !
  677. availableProtocols
  678. ^ self environment availableProtocolsFor: self selectedClass
  679. !
  680. environment
  681. ^ environment ifNil: [ HLManager current environment ]
  682. !
  683. environment: anEnvironment
  684. environment := anEnvironment
  685. !
  686. handleUnkownVariableError: anError
  687. self announcer announce: (HLUnknownVariableErrorRaised new
  688. error: anError;
  689. yourself)
  690. !
  691. manager
  692. ^ HLManager current
  693. !
  694. packages
  695. ^ self environment packages
  696. !
  697. selectedClass
  698. ^ selectedClass
  699. !
  700. selectedClass: aClass
  701. selectedClass = aClass ifTrue: [
  702. aClass ifNil: [ ^ self ].
  703. self selectedProtocol: nil ].
  704. aClass
  705. ifNil: [ selectedClass := nil ]
  706. ifNotNil: [
  707. self showInstance
  708. ifTrue: [ selectedClass := aClass theNonMetaClass ]
  709. ifFalse: [ selectedClass := aClass theMetaClass ] ].
  710. self selectedProtocol: nil.
  711. self announcer announce: (HLClassSelected on: self selectedClass)
  712. !
  713. selectedMethod
  714. ^ self selectedClass ifNotNil: [
  715. self selectedClass methodDictionary
  716. at: selectedSelector
  717. ifAbsent: [ nil ] ]
  718. !
  719. selectedMethod: aCompiledMethod
  720. selectedSelector = aCompiledMethod ifTrue: [ ^ self ].
  721. aCompiledMethod
  722. ifNil: [ selectedSelector := nil ]
  723. ifNotNil: [
  724. selectedSelector = aCompiledMethod selector ifTrue: [ ^ self ].
  725. selectedSelector := aCompiledMethod selector ].
  726. self announcer announce: (HLMethodSelected on: aCompiledMethod)
  727. !
  728. selectedPackage
  729. ^ selectedPackage
  730. !
  731. selectedPackage: aPackage
  732. selectedPackage = aPackage ifTrue: [ ^ self ].
  733. selectedPackage := aPackage.
  734. self selectedClass: nil.
  735. self announcer announce: (HLPackageSelected on: aPackage)
  736. !
  737. selectedProtocol
  738. ^ selectedProtocol
  739. !
  740. selectedProtocol: aString
  741. selectedProtocol = aString ifTrue: [ ^ self ].
  742. selectedProtocol := aString.
  743. self selectedMethod: nil.
  744. self announcer announce: (HLProtocolSelected on: aString)
  745. !
  746. showComment
  747. ^ showComment ifNil: [ false ]
  748. !
  749. showComment: aBoolean
  750. showComment := aBoolean.
  751. self announcer announce: HLShowCommentToggled new
  752. !
  753. showInstance
  754. ^ showInstance ifNil: [ true ]
  755. !
  756. showInstance: aBoolean
  757. showInstance := aBoolean.
  758. showComment := false.
  759. self selectedClass ifNotNil: [
  760. self selectedClass: (aBoolean
  761. ifTrue: [self selectedClass theNonMetaClass ]
  762. ifFalse: [ self selectedClass theMetaClass ]) ].
  763. self announcer announce: HLShowInstanceToggled new
  764. !
  765. systemAnnouncer
  766. ^ self environment systemAnnouncer
  767. ! !
  768. !HLBrowserModel methodsFor: 'actions'!
  769. addInstVarNamed: aString
  770. self environment addInstVarNamed: aString to: self selectedClass.
  771. self announcer announce: (HLInstVarAdded new
  772. theClass: self selectedClass;
  773. variableName: aString;
  774. yourself)
  775. !
  776. focusOnClasses
  777. self announcer announce: HLClassesFocusRequested new
  778. !
  779. focusOnMethods
  780. self announcer announce: HLMethodsFocusRequested new
  781. !
  782. focusOnPackages
  783. self announcer announce: HLPackagesFocusRequested new
  784. !
  785. focusOnProtocols
  786. self announcer announce: HLProtocolsFocusRequested new
  787. !
  788. focusOnSourceCode
  789. self announcer announce: HLSourceCodeFocusRequested new
  790. !
  791. save: aString
  792. (self shouldCompileClassDefinition: aString)
  793. ifTrue: [ self compileClassDefinition: aString ]
  794. ifFalse: [ self compileMethod: aString ]
  795. !
  796. saveSourceCode
  797. self announcer announce: HLSaveSourceCode new
  798. ! !
  799. !HLBrowserModel methodsFor: 'commands actions'!
  800. commitPackage
  801. self
  802. withHelperLabelled: 'Committing package ', self selectedPackage name, '...'
  803. do: [ self environment commitPackage: self selectedPackage ]
  804. !
  805. copyClassTo: aClassName
  806. self environment
  807. copyClass: self selectedClass theNonMetaClass
  808. to: aClassName
  809. !
  810. moveClassToPackage: aPackageName
  811. self environment
  812. moveClass: self selectedClass theNonMetaClass
  813. toPackage: aPackageName
  814. !
  815. moveMethodToClass: aClassName
  816. self environment
  817. moveMethod: self selectedMethod
  818. toClass: aClassName
  819. !
  820. moveMethodToProtocol: aProtocol
  821. self environment moveMethod: self selectedMethod toProtocol: aProtocol
  822. !
  823. openClassNamed: aString
  824. | class |
  825. class := self environment classNamed: aString.
  826. self selectedPackage: class package.
  827. self selectedClass: class
  828. !
  829. removeClass
  830. (self manager confirm: 'Do you REALLY want to remove class ', self selectedClass name)
  831. ifTrue: [ self environment removeClass: self selectedClass ]
  832. !
  833. removeMethod
  834. (self manager confirm: 'Do you REALLY want to remove method ', self selectedMethod methodClass name,' >> #', self selectedMethod selector)
  835. ifTrue: [ self environment removeMethod: self selectedMethod ]
  836. !
  837. renameClassTo: aClassName
  838. self environment
  839. renameClass: self selectedClass theNonMetaClass
  840. to: aClassName
  841. ! !
  842. !HLBrowserModel methodsFor: 'compiling'!
  843. compileClassComment: aString
  844. self environment
  845. compileClassComment: aString
  846. for: self selectedClass
  847. !
  848. compileClassDefinition: aString
  849. self environment compileClassDefinition: aString
  850. !
  851. compileMethod: aString
  852. | method |
  853. self withCompileErrorHandling: [
  854. method := self environment
  855. compileMethod: aString
  856. for: self selectedClass
  857. protocol: self compilationProtocol.
  858. self selectedMethod: method ]
  859. ! !
  860. !HLBrowserModel methodsFor: 'defaults'!
  861. allProtocol
  862. ^ '-- all --'
  863. !
  864. unclassifiedProtocol
  865. ^ 'as yet unclassified'
  866. ! !
  867. !HLBrowserModel methodsFor: 'error handling'!
  868. handleCompileError: anError
  869. self announcer announce: (HLCompileErrorRaised new
  870. error: anError;
  871. yourself)
  872. !
  873. handleParseError: anError
  874. | split line column messageToInsert |
  875. split := anError messageText tokenize: ' : '.
  876. messageToInsert := split second.
  877. "21 = 'Parse error on line ' size + 1"
  878. split := split first copyFrom: 21 to: split first size.
  879. split := split tokenize: ' column '.
  880. line := split first.
  881. column := split second.
  882. self announcer announce: (HLParseErrorRaised new
  883. line: line asNumber;
  884. column: column asNumber;
  885. message: messageToInsert;
  886. error: anError;
  887. yourself)
  888. !
  889. withCompileErrorHandling: aBlock
  890. [
  891. [
  892. aBlock
  893. on: ParseError
  894. do: [:ex | self handleParseError: ex ]
  895. ]
  896. on: UnknownVariableError
  897. do: [ :ex | self handleUnkownVariableError: ex ]
  898. ]
  899. on: CompilerError
  900. do: [ :ex | self handleCompileError: ex ]
  901. ! !
  902. !HLBrowserModel methodsFor: 'private'!
  903. compilationProtocol
  904. | currentProtocol |
  905. currentProtocol := self selectedProtocol.
  906. currentProtocol ifNil: [ currentProtocol := self unclassifiedProtocol ].
  907. self selectedMethod ifNotNil: [ currentProtocol := self selectedMethod protocol ].
  908. ^ currentProtocol = self allProtocol
  909. ifTrue: [ self unclassifiedProtocol ]
  910. ifFalse: [ currentProtocol ]
  911. !
  912. withHelperLabelled: aString do: aBlock
  913. "TODO: doesn't belong here"
  914. (window jQuery: '#helper') remove.
  915. [ :html |
  916. html div
  917. id: 'helper';
  918. with: aString ] appendToJQuery: 'body' asJQuery.
  919. [
  920. aBlock value.
  921. (window jQuery: '#helper') remove
  922. ]
  923. valueWithTimeout: 10
  924. ! !
  925. !HLBrowserModel methodsFor: 'testing'!
  926. shouldCompileClassDefinition: aString
  927. ^ self selectedClass isNil or: [
  928. aString first asUppercase = aString first ]
  929. ! !
  930. !HLBrowserModel class methodsFor: 'actions'!
  931. on: anEnvironment
  932. ^ self new
  933. environment: anEnvironment;
  934. yourself
  935. ! !
  936. Object subclass: #HLClassCache
  937. instanceVariableNames: 'class selectorsCache overrideCache overriddenCache'
  938. package: 'Helios-Browser'!
  939. !HLClassCache methodsFor: 'accessing'!
  940. overriddenCache
  941. ^ overriddenCache ifNil: [ overriddenCache := HashedCollection new ]
  942. !
  943. overrideCache
  944. ^ overrideCache ifNil: [ overrideCache := HashedCollection new ]
  945. !
  946. selectorsCache
  947. ^ selectorsCache
  948. !
  949. selectorsCache: aCache
  950. selectorsCache := aCache
  951. !
  952. theClass
  953. ^ class
  954. !
  955. theClass: aClass
  956. class := aClass
  957. ! !
  958. !HLClassCache methodsFor: 'actions'!
  959. invalidateChildrenSelector: aSelector
  960. self theClass subclasses do: [ :each |
  961. (self selectorsCache cacheFor: each)
  962. removeSelector: aSelector;
  963. invalidateChildrenSelector: aSelector ]
  964. !
  965. invalidateParentSelector: aSelector
  966. self theClass superclass ifNotNil: [
  967. (self selectorsCache cacheFor: self theClass superclass)
  968. removeSelector: aSelector;
  969. invalidateParentSelector: aSelector ]
  970. !
  971. invalidateSelector: aSelector
  972. self
  973. invalidateParentSelector: aSelector;
  974. invalidateChildrenSelector: aSelector;
  975. removeSelector: aSelector
  976. ! !
  977. !HLClassCache methodsFor: 'private'!
  978. removeSelector: aSelector
  979. self overriddenCache
  980. removeKey: aSelector
  981. ifAbsent: [ ].
  982. self overrideCache
  983. removeKey: aSelector
  984. ifAbsent: [ ]
  985. ! !
  986. !HLClassCache methodsFor: 'testing'!
  987. isOverridden: aMethod
  988. ^ self overriddenCache
  989. at: aMethod selector
  990. ifAbsentPut: [ aMethod isOverridden ]
  991. !
  992. isOverride: aMethod
  993. ^ self overrideCache
  994. at: aMethod selector
  995. ifAbsentPut: [ aMethod isOverride ]
  996. ! !
  997. !HLClassCache class methodsFor: 'instance creation'!
  998. on: aClass selectorsCache: aSelectorsCache
  999. ^ self new
  1000. theClass: aClass;
  1001. selectorsCache: aSelectorsCache;
  1002. yourself
  1003. ! !
  1004. Object subclass: #HLSelectorsCache
  1005. instanceVariableNames: 'classesCache'
  1006. package: 'Helios-Browser'!
  1007. !HLSelectorsCache methodsFor: 'accessing'!
  1008. cacheFor: aClass
  1009. aClass ifNil: [ ^ nil ].
  1010. ^ self classesCache
  1011. at: aClass name
  1012. ifAbsentPut: [ self newCacheFor: aClass ]
  1013. !
  1014. classesCache
  1015. ^ classesCache ifNil: [ classesCache := HashedCollection new ]
  1016. ! !
  1017. !HLSelectorsCache methodsFor: 'actions'!
  1018. observeSystem
  1019. SystemAnnouncer current
  1020. on: MethodAdded
  1021. do: [ :ann | self onMethodAdded: ann method ];
  1022. on: MethodRemoved
  1023. do: [ :ann | self onMethodRemoved: ann method ]
  1024. ! !
  1025. !HLSelectorsCache methodsFor: 'factory'!
  1026. newCacheFor: aClass
  1027. ^ HLClassCache
  1028. on: aClass
  1029. selectorsCache: self
  1030. ! !
  1031. !HLSelectorsCache methodsFor: 'initialization'!
  1032. initialize
  1033. super initialize.
  1034. self observeSystem
  1035. ! !
  1036. !HLSelectorsCache methodsFor: 'private'!
  1037. invalidateCacheFor: aMethod
  1038. (self cacheFor: aMethod methodClass)
  1039. invalidateSelector: aMethod selector
  1040. ! !
  1041. !HLSelectorsCache methodsFor: 'reactions'!
  1042. onMethodAdded: aMethod
  1043. self invalidateCacheFor: aMethod
  1044. !
  1045. onMethodRemoved: aMethod
  1046. self invalidateCacheFor: aMethod
  1047. ! !
  1048. !HLSelectorsCache methodsFor: 'testing'!
  1049. isOverridden: aMethod
  1050. ^ (self cacheFor: aMethod methodClass)
  1051. isOverridden: aMethod
  1052. !
  1053. isOverride: aMethod
  1054. ^ (self cacheFor: aMethod methodClass)
  1055. isOverride: aMethod
  1056. ! !
  1057. HLSelectorsCache class instanceVariableNames: 'current'!
  1058. !HLSelectorsCache class methodsFor: 'accessing'!
  1059. current
  1060. ^ current ifNil: [ current := super new ]
  1061. !
  1062. flush
  1063. current := nil
  1064. ! !
  1065. !HLSelectorsCache class methodsFor: 'instance creation'!
  1066. new
  1067. self shouldNotImplement
  1068. ! !