IDE.st 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038
  1. Widget subclass: #TabManager
  2. instanceVariableNames: 'selectedTab tabs opened ul'
  3. category: 'IDE'!
  4. !TabManager methodsFor: 'accessing'!
  5. tabs
  6. ^tabs ifNil: [tabs := Array new]
  7. ! !
  8. !TabManager methodsFor: 'actions'!
  9. updateBodyMargin
  10. self setBodyMargin: '#jtalk' asJQuery height + 27
  11. !
  12. updatePosition
  13. <jQuery('#jtalk').css('top', '').css('bottom', '27px')>
  14. !
  15. removeBodyMargin
  16. self setBodyMargin: 0
  17. !
  18. setBodyMargin: anInteger
  19. '.jtalkBody' asJQuery cssAt: 'margin-bottom' put: anInteger asString, 'px'
  20. !
  21. onResize: aBlock
  22. <jQuery('#jtalk').resizable({
  23. handles: 'n',
  24. resize: aBlock,
  25. minHeight: 230
  26. })>
  27. !
  28. onWindowResize: aBlock
  29. <jQuery(window).resize(aBlock)>
  30. !
  31. open
  32. opened ifFalse: [
  33. 'body' asJQuery addClass: 'jtalkBody'.
  34. '#jtalk' asJQuery show.
  35. ul asJQuery show.
  36. self updateBodyMargin.
  37. selectedTab show.
  38. opened := true]
  39. !
  40. close
  41. opened ifTrue: [
  42. '#jtalk' asJQuery hide.
  43. ul asJQuery hide.
  44. selectedTab hide.
  45. self removeBodyMargin.
  46. 'body' asJQuery removeClass: 'jtalkBody'.
  47. opened := false]
  48. !
  49. newBrowserTab
  50. Browser open
  51. !
  52. selectTab: aWidget
  53. self open.
  54. selectedTab := aWidget.
  55. self tabs do: [:each |
  56. each hide].
  57. aWidget show.
  58. self update
  59. !
  60. closeTab: aWidget
  61. self removeTab: aWidget.
  62. self selectTab: self tabs last.
  63. aWidget remove.
  64. self update
  65. ! !
  66. !TabManager methodsFor: 'adding/Removing'!
  67. addTab: aWidget
  68. self tabs add: aWidget.
  69. '#jtalk' asJQuery append: aWidget.
  70. aWidget hide
  71. !
  72. removeTab: aWidget
  73. self tabs remove: aWidget.
  74. self update
  75. ! !
  76. !TabManager methodsFor: 'initialization'!
  77. initialize
  78. super initialize.
  79. opened := true.
  80. 'body' asJQuery
  81. append: self;
  82. append: [:html | html div id: 'jtalk'];
  83. addClass: 'jtalkBody'.
  84. self
  85. addTab: Transcript current;
  86. addTab: Workspace new;
  87. addTab: TestRunner new.
  88. self selectTab: self tabs last.
  89. self
  90. onResize: [self updateBodyMargin; updatePosition];
  91. onWindowResize: [self updatePosition]
  92. ! !
  93. !TabManager methodsFor: 'rendering'!
  94. renderOn: html
  95. ul := html ul
  96. id: 'jtalkTabs';
  97. yourself.
  98. self renderTabs
  99. !
  100. renderTabFor: aWidget on: html
  101. | li |
  102. li := html li.
  103. selectedTab = aWidget ifTrue: [
  104. li class: 'selected'].
  105. li with: [
  106. aWidget canBeClosed ifTrue: [
  107. html span
  108. class: 'close';
  109. with: 'x';
  110. onClick: [self closeTab: aWidget]].
  111. html span
  112. with: aWidget label;
  113. onClick: [self selectTab: aWidget]]
  114. !
  115. renderTabs
  116. ul contents: [:html |
  117. html li
  118. class: 'closeAll';
  119. with: 'x';
  120. onClick: [self close].
  121. self tabs do: [:each |
  122. self renderTabFor: each on: html].
  123. html li
  124. class: 'newtab';
  125. with: ' + ';
  126. onClick: [self newBrowserTab]]
  127. ! !
  128. !TabManager methodsFor: 'updating'!
  129. update
  130. self renderTabs
  131. ! !
  132. TabManager class instanceVariableNames: 'current'!
  133. !TabManager class methodsFor: 'instance creation'!
  134. current
  135. ^current ifNil: [current := super new]
  136. !
  137. new
  138. self shouldNotImplement
  139. ! !
  140. Widget subclass: #TabWidget
  141. instanceVariableNames: 'div'
  142. category: 'IDE'!
  143. !TabWidget methodsFor: 'accessing'!
  144. label
  145. self subclassResponsibility
  146. ! !
  147. !TabWidget methodsFor: 'actions'!
  148. open
  149. TabManager current addTab: self.
  150. TabManager current selectTab: self
  151. !
  152. show
  153. div asJQuery show
  154. !
  155. hide
  156. div asJQuery hide
  157. !
  158. remove
  159. div asJQuery remove
  160. ! !
  161. !TabWidget methodsFor: 'rendering'!
  162. renderOn: html
  163. div := html div
  164. class: 'jtalkTool';
  165. yourself.
  166. self renderTab
  167. !
  168. renderBoxOn: html
  169. !
  170. renderButtonsOn: html
  171. !
  172. update
  173. self renderTab
  174. !
  175. renderTab
  176. div contents: [:html |
  177. html div
  178. class: 'jt_box';
  179. with: [self renderBoxOn: html].
  180. html div
  181. class: 'jt_buttons';
  182. with: [self renderButtonsOn: html]]
  183. ! !
  184. !TabWidget methodsFor: 'testing'!
  185. canBeClosed
  186. ^false
  187. ! !
  188. !TabWidget class methodsFor: 'instance creation'!
  189. open
  190. ^self new open
  191. ! !
  192. TabWidget subclass: #Workspace
  193. instanceVariableNames: 'sourceArea'
  194. category: 'IDE'!
  195. !Workspace methodsFor: 'accessing'!
  196. label
  197. ^'[Workspace]'
  198. ! !
  199. !Workspace methodsFor: 'actions'!
  200. clearWorkspace
  201. sourceArea clear
  202. !
  203. doIt
  204. sourceArea doIt
  205. !
  206. printIt
  207. sourceArea printIt
  208. !
  209. inspectIt
  210. sourceArea inspectIt
  211. ! !
  212. !Workspace methodsFor: 'rendering'!
  213. renderBoxOn: html
  214. sourceArea := SourceArea new.
  215. sourceArea renderOn: html
  216. !
  217. renderButtonsOn: html
  218. html button
  219. with: 'DoIt';
  220. title: 'ctrl+d';
  221. onClick: [self doIt].
  222. html button
  223. with: 'PrintIt';
  224. title: 'ctrl+p';
  225. onClick: [self printIt].
  226. html button
  227. with: 'InspectIt';
  228. title: 'ctrl+i';
  229. onClick: [self inspectIt].
  230. html button
  231. with: 'Clear workspace';
  232. onClick: [self clearWorkspace]
  233. ! !
  234. TabWidget subclass: #Transcript
  235. instanceVariableNames: 'textarea'
  236. category: 'IDE'!
  237. !Transcript methodsFor: 'accessing'!
  238. label
  239. ^'[Transcript]'
  240. ! !
  241. !Transcript methodsFor: 'actions'!
  242. show: anObject
  243. textarea asJQuery val: textarea asJQuery val, anObject asString.
  244. !
  245. cr
  246. textarea asJQuery val: textarea asJQuery val, String cr.
  247. !
  248. clear
  249. textarea asJQuery val: ''
  250. ! !
  251. !Transcript methodsFor: 'rendering'!
  252. renderBoxOn: html
  253. textarea := html textarea.
  254. textarea asJQuery call: 'tabby'.
  255. textarea
  256. class: 'jt_transcript';
  257. at: 'spellcheck' put: 'false'
  258. !
  259. renderButtonsOn: html
  260. html button
  261. with: 'Clear transcript';
  262. onClick: [self clear]
  263. ! !
  264. Transcript class instanceVariableNames: 'current'!
  265. !Transcript class methodsFor: 'instance creation'!
  266. open
  267. TabManager current
  268. open;
  269. selectTab: self current
  270. !
  271. new
  272. self shouldNotImplement
  273. !
  274. current
  275. ^current ifNil: [current := super new]
  276. ! !
  277. !Transcript class methodsFor: 'printing'!
  278. show: anObject
  279. self current show: anObject
  280. !
  281. cr
  282. self current show: String cr
  283. !
  284. clear
  285. self current clear
  286. ! !
  287. TabWidget subclass: #Browser
  288. instanceVariableNames: 'selectedCategory selectedClass selectedProtocol selectedMethod commitButton categoriesList classesList protocolsList methodsList sourceArea tabsList selectedTab saveButton classButtons methodButtons unsavedChanges input'
  289. category: 'IDE'!
  290. !Browser methodsFor: 'accessing'!
  291. label
  292. ^selectedClass
  293. ifNil: ['Browser (nil)']
  294. ifNotNil: [selectedClass name]
  295. !
  296. categories
  297. | categories |
  298. categories := Array new.
  299. Smalltalk current classes do: [:each |
  300. (categories includes: each category) ifFalse: [
  301. categories add: each category]].
  302. ^categories sort
  303. !
  304. classes
  305. ^(Smalltalk current classes
  306. select: [:each | each category = selectedCategory])
  307. sort: [:a :b | a name < b name]
  308. !
  309. protocols
  310. | klass |
  311. selectedClass ifNotNil: [
  312. selectedTab = #comment ifTrue: [^#()].
  313. klass := selectedTab = #instance
  314. ifTrue: [selectedClass]
  315. ifFalse: [selectedClass class].
  316. klass methodDictionary isEmpty ifTrue: [
  317. ^Array with: 'not yet classified'].
  318. ^klass protocols].
  319. ^Array new
  320. !
  321. methods
  322. | klass |
  323. selectedTab = #comment ifTrue: [^#()].
  324. selectedClass ifNotNil: [
  325. klass := selectedTab = #instance
  326. ifTrue: [selectedClass]
  327. ifFalse: [selectedClass class]].
  328. ^(selectedProtocol
  329. ifNil: [
  330. klass
  331. ifNil: [#()]
  332. ifNotNil: [klass methodDictionary values]]
  333. ifNotNil: [
  334. klass methodDictionary values select: [:each |
  335. each category = selectedProtocol]]) sort: [:a :b | a selector < b selector]
  336. !
  337. source
  338. selectedTab = #comment ifFalse: [
  339. ^(selectedProtocol notNil or: [selectedMethod notNil])
  340. ifFalse: [self declarationSource]
  341. ifTrue: [self methodSource]].
  342. ^selectedClass
  343. ifNil: ['']
  344. ifNotNil: [self classCommentSource]
  345. !
  346. methodSource
  347. ^selectedMethod
  348. ifNil: [self dummyMethodSource]
  349. ifNotNil: [selectedMethod source]
  350. !
  351. dummyMethodSource
  352. ^'messageSelectorAndArgumentNames
  353. "comment stating purpose of message"
  354. | temporary variable names |
  355. statements'
  356. !
  357. declarationSource
  358. ^selectedTab = #instance
  359. ifTrue: [self classDeclarationSource]
  360. ifFalse: [self metaclassDeclarationSource]
  361. !
  362. classDeclarationSource
  363. | stream |
  364. stream := '' writeStream.
  365. selectedClass ifNotNil: [
  366. stream
  367. nextPutAll: selectedClass superclass asString;
  368. nextPutAll: ' subclass: #';
  369. nextPutAll: selectedClass name;
  370. nextPutAll: String lf, String tab;
  371. nextPutAll: 'instanceVariableNames: '''.
  372. selectedClass instanceVariableNames
  373. do: [:each | stream nextPutAll: each]
  374. separatedBy: [stream nextPutAll: ' '].
  375. stream
  376. nextPutAll: '''', String lf, String tab;
  377. nextPutAll: 'category: ''';
  378. nextPutAll: selectedClass category;
  379. nextPutAll: ''''].
  380. ^stream contents
  381. !
  382. metaclassDeclarationSource
  383. | stream |
  384. stream := '' writeStream.
  385. selectedClass ifNotNil: [
  386. stream
  387. nextPutAll: selectedClass asString;
  388. nextPutAll: ' class ';
  389. nextPutAll: 'instanceVariableNames: '''.
  390. selectedClass class instanceVariableNames
  391. do: [:each | stream nextPutAll: each]
  392. separatedBy: [stream nextPutAll: ' '].
  393. stream nextPutAll: ''''].
  394. ^stream contents
  395. !
  396. classCommentSource
  397. ^selectedClass comment
  398. !
  399. selectedClass
  400. ^selectedClass
  401. ! !
  402. !Browser methodsFor: 'actions'!
  403. disableSaveButton
  404. saveButton ifNotNil: [
  405. saveButton at: 'disabled' put: true].
  406. unsavedChanges := false
  407. !
  408. hideClassButtons
  409. classButtons asJQuery hide
  410. !
  411. showClassButtons
  412. classButtons asJQuery show
  413. !
  414. hideMethodButtons
  415. methodButtons asJQuery hide
  416. !
  417. showMethodButtons
  418. methodButtons asJQuery show
  419. !
  420. compile
  421. self disableSaveButton.
  422. selectedTab = #comment
  423. ifTrue: [
  424. selectedClass ifNotNil: [
  425. self compileClassComment] ]
  426. ifFalse: [
  427. (selectedProtocol notNil or: [selectedMethod notNil])
  428. ifFalse: [self compileDefinition]
  429. ifTrue: [self compileMethodDefinition] ]
  430. !
  431. compileClassComment
  432. selectedClass comment: sourceArea val
  433. !
  434. compileMethodDefinition
  435. selectedTab = #instance
  436. ifTrue: [self compileMethodDefinitionFor: selectedClass]
  437. ifFalse: [self compileMethodDefinitionFor: selectedClass class]
  438. !
  439. compileMethodDefinitionFor: aClass
  440. | compiler method source node |
  441. source := sourceArea val.
  442. selectedProtocol ifNil: [selectedProtocol := selectedMethod category].
  443. compiler := Compiler new.
  444. compiler source: source.
  445. node := compiler parse: source.
  446. node isParseFailure ifTrue: [
  447. ^self alert: 'PARSE ERROR: ', node reason, ', position: ', node position asString].
  448. compiler currentClass: aClass.
  449. method := compiler eval: (compiler compileNode: node).
  450. method category: selectedProtocol.
  451. compiler unknownVariables do: [:each |
  452. (self confirm: 'Declare ''', each, ''' as instance variable?') ifTrue: [
  453. self addInstanceVariableNamed: each toClass: aClass.
  454. ^self compileMethodDefinitionFor: aClass]].
  455. aClass addCompiledMethod: method.
  456. compiler setupClass: aClass.
  457. self updateMethodsList.
  458. self selectMethod: method
  459. !
  460. compileDefinition
  461. | newClass |
  462. newClass := Compiler new loadExpression: sourceArea val.
  463. self
  464. resetClassesList;
  465. updateCategoriesList;
  466. updateClassesList
  467. !
  468. commitCategory
  469. selectedCategory ifNotNil: [
  470. (Ajax url: self class commitPathJs, '/', selectedCategory, '.js')
  471. at: 'type' put: 'PUT';
  472. at: 'data' put: (Exporter new exportCategory: selectedCategory);
  473. at: 'error' put: [self alert: 'Commit failed!!'];
  474. send.
  475. (Ajax url: self class commitPathJs, '/', selectedCategory, '.deploy.js')
  476. at: 'type' put: 'PUT';
  477. at: 'data' put: (StrippedExporter new exportCategory: selectedCategory);
  478. at: 'error' put: [self alert: 'Commit failed!!'];
  479. send.
  480. (Ajax url: self class commitPathSt, '/', selectedCategory, '.st')
  481. at: 'type' put: 'PUT';
  482. at: 'data' put: (ChunkExporter new exportCategory: selectedCategory);
  483. at: 'error' put: [self alert: 'Commit failed!!'];
  484. send]
  485. !
  486. cancelChanges
  487. ^unsavedChanges
  488. ifTrue: [self confirm: 'Cancel changes?']
  489. ifFalse: [true]
  490. !
  491. removeClass
  492. (self confirm: 'Do you really want to remove ', selectedClass name, '?')
  493. ifTrue: [
  494. Smalltalk current removeClass: selectedClass.
  495. self resetClassesList.
  496. self selectClass: nil]
  497. !
  498. removeMethod
  499. self cancelChanges ifTrue: [
  500. (self confirm: 'Do you really want to remove #', selectedMethod selector, '?')
  501. ifTrue: [
  502. selectedTab = #instance
  503. ifTrue: [selectedClass removeCompiledMethod: selectedMethod]
  504. ifFalse: [selectedClass class removeCompiledMethod: selectedMethod].
  505. self selectMethod: nil]]
  506. !
  507. setMethodProtocol: aString
  508. self cancelChanges ifTrue: [
  509. (self protocols includes: aString)
  510. ifFalse: [self addNewProtocol]
  511. ifTrue: [
  512. selectedMethod category: aString.
  513. selectedProtocol := aString.
  514. selectedMethod := selectedMethod.
  515. self
  516. updateProtocolsList;
  517. updateMethodsList;
  518. updateSourceAndButtons]]
  519. !
  520. addNewProtocol
  521. | newProtocol |
  522. newProtocol := self prompt: 'New method protocol'.
  523. newProtocol notEmpty ifTrue: [
  524. selectedMethod category: newProtocol.
  525. self setMethodProtocol: newProtocol]
  526. !
  527. selectCategory: aCategory
  528. self cancelChanges ifTrue: [
  529. selectedCategory := aCategory.
  530. selectedClass := selectedProtocol := selectedMethod := nil.
  531. self resetClassesList.
  532. self
  533. updateCategoriesList;
  534. updateClassesList;
  535. updateProtocolsList;
  536. updateMethodsList;
  537. updateSourceAndButtons]
  538. !
  539. selectClass: aClass
  540. self cancelChanges ifTrue: [
  541. selectedClass := aClass.
  542. selectedProtocol := selectedMethod := nil.
  543. self
  544. updateClassesList;
  545. updateProtocolsList;
  546. updateMethodsList;
  547. updateSourceAndButtons]
  548. !
  549. selectProtocol: aString
  550. self cancelChanges ifTrue: [
  551. selectedProtocol := aString.
  552. selectedMethod := nil.
  553. self
  554. updateProtocolsList;
  555. updateMethodsList;
  556. updateSourceAndButtons]
  557. !
  558. selectMethod: aMethod
  559. self cancelChanges ifTrue: [
  560. selectedMethod := aMethod.
  561. self
  562. updateProtocolsList;
  563. updateMethodsList;
  564. updateSourceAndButtons]
  565. !
  566. selectTab: aString
  567. self cancelChanges ifTrue: [
  568. selectedTab := aString.
  569. self selectProtocol: nil.
  570. self updateTabsList]
  571. !
  572. renameClass
  573. | newName |
  574. newName := self prompt: 'Rename class ', selectedClass name.
  575. newName notEmpty ifTrue: [
  576. selectedClass rename: newName.
  577. self
  578. updateClassesList;
  579. updateSourceAndButtons]
  580. !
  581. addInstanceVariableNamed: aString toClass: aClass
  582. ClassBuilder new
  583. addSubclassOf: aClass superclass named: aClass name instanceVariableNames: (aClass instanceVariableNames copy add: aString; yourself)
  584. !
  585. searchReferencesOf: aString
  586. ReferencesBrowser search: aString
  587. !
  588. searchClassReferences
  589. ReferencesBrowser search: selectedClass name
  590. !
  591. search: aString
  592. self cancelChanges ifTrue: [| searchedClass |
  593. searchedClass := Smalltalk current at: aString.
  594. searchedClass isClass
  595. ifTrue: [self class openOn: searchedClass]
  596. ifFalse: [self searchReferencesOf: aString]]
  597. ! !
  598. !Browser methodsFor: 'initialization'!
  599. initialize
  600. super initialize.
  601. selectedTab := #instance.
  602. unsavedChanges := false
  603. ! !
  604. !Browser methodsFor: 'rendering'!
  605. renderBoxOn: html
  606. self
  607. renderTopPanelOn: html;
  608. renderTabsOn: html;
  609. renderBottomPanelOn: html
  610. !
  611. renderTopPanelOn: html
  612. html div
  613. class: 'top';
  614. with: [
  615. self renderInputOn: html.
  616. categoriesList := html ul class: 'jt_column browser categories'.
  617. commitButton := html button
  618. class: 'jt_commit';
  619. title: 'Commit classes in this category to disk';
  620. onClick: [self commitCategory];
  621. with: 'Commit category'.
  622. classesList := ClassesList on: self.
  623. classesList renderOn: html.
  624. protocolsList := html ul class: 'jt_column browser protocols'.
  625. methodsList := html ul class: 'jt_column browser methods'.
  626. self
  627. updateCategoriesList;
  628. updateClassesList;
  629. updateProtocolsList;
  630. updateMethodsList.
  631. html div class: 'jt_clear']
  632. !
  633. renderTabsOn: html
  634. tabsList := html ul class: 'jt_tabs'.
  635. self updateTabsList.
  636. !
  637. renderBottomPanelOn: html
  638. html div
  639. class: 'jt_sourceCode';
  640. with: [
  641. sourceArea := SourceArea new.
  642. sourceArea renderOn: html.
  643. sourceArea
  644. onKeyUp: [self updateStatus]]
  645. !
  646. renderButtonsOn: html
  647. saveButton := html button.
  648. saveButton
  649. with: 'Save';
  650. onClick: [self compile].
  651. methodButtons := html span.
  652. classButtons := html span.
  653. html div
  654. class: 'right';
  655. with: [
  656. html button
  657. with: 'DoIt';
  658. onClick: [sourceArea doIt].
  659. html button
  660. with: 'PrintIt';
  661. onClick: [sourceArea printIt].
  662. html button with: 'InspectIt';
  663. onClick: [sourceArea inspectit]].
  664. self updateSourceAndButtons
  665. !
  666. renderInputOn: html
  667. input := html input
  668. class: 'implementors';
  669. yourself.
  670. input onKeyPress: [:event |
  671. event keyCode = 13 ifTrue: [
  672. self search: input asJQuery val]]
  673. ! !
  674. !Browser methodsFor: 'testing'!
  675. canBeClosed
  676. ^true
  677. ! !
  678. !Browser methodsFor: 'updating'!
  679. updateCategoriesList
  680. categoriesList contents: [:html |
  681. self categories do: [:each || li label |
  682. each isEmpty
  683. ifTrue: [label := 'Unclassified']
  684. ifFalse: [label := each].
  685. li := html li.
  686. selectedCategory = each ifTrue: [
  687. li class: 'selected'].
  688. li
  689. with: label;
  690. onClick: [self selectCategory: each]]]
  691. !
  692. updateClassesList
  693. TabManager current update.
  694. classesList updateNodes.
  695. "classesList contents: [:html |
  696. self classes do: [:each || li |
  697. li := html li.
  698. selectedClass = each ifTrue: [
  699. li class: 'selected'].
  700. li
  701. with: each name;
  702. onClick: [self selectClass: each]]]"
  703. !
  704. updateProtocolsList
  705. protocolsList contents: [:html |
  706. self protocols do: [:each || li |
  707. li := html li.
  708. selectedProtocol = each ifTrue: [
  709. li class: 'selected'].
  710. li
  711. with: each;
  712. onClick: [self selectProtocol: each]]]
  713. !
  714. updateMethodsList
  715. methodsList contents: [:html |
  716. self methods do: [:each || li |
  717. li := html li.
  718. selectedMethod = each ifTrue: [
  719. li class: 'selected'].
  720. li
  721. with: each selector;
  722. onClick: [self selectMethod: each]]]
  723. !
  724. updateTabsList
  725. tabsList contents: [:html || li |
  726. li := html li.
  727. selectedTab = #instance ifTrue: [li class: 'selected'].
  728. li
  729. with: 'Instance';
  730. onClick: [self selectTab: #instance].
  731. li := html li.
  732. selectedTab = #class ifTrue: [li class: 'selected'].
  733. li
  734. with: 'Class';
  735. onClick: [self selectTab: #class].
  736. li := html li.
  737. selectedTab = #comment ifTrue: [li class: 'selected'].
  738. li
  739. with: 'Comment';
  740. onClick: [self selectTab: #comment]]
  741. !
  742. updateSourceAndButtons
  743. self disableSaveButton.
  744. classButtons contents: [:html |
  745. html button
  746. with: 'Rename class';
  747. onClick: [self renameClass].
  748. html button
  749. with: 'Remove class';
  750. onClick: [self removeClass].
  751. html button
  752. with: 'References';
  753. onClick: [self searchClassReferences]].
  754. methodButtons contents: [:html |
  755. html button
  756. with: 'Remove method';
  757. onClick: [self removeMethod].
  758. html select
  759. onChange: [:e :select | self setMethodProtocol: select val];
  760. with: [
  761. html option
  762. with: 'Method protocol';
  763. at: 'disabled' put: 'disabled'.
  764. html option
  765. class: 'important';
  766. with: 'New...'.
  767. self protocols do: [:each |
  768. html option with: each]].
  769. selectedMethod isNil ifFalse: [
  770. html select
  771. onChange: [:e :select | self searchReferencesOf: select val];
  772. with: [
  773. html option
  774. with: 'References';
  775. at: 'disabled' put: 'disabled'.
  776. html option
  777. class: 'important';
  778. with: selectedMethod selector.
  779. selectedMethod messageSends sorted do: [:each |
  780. html option with: each]]]].
  781. selectedMethod isNil
  782. ifTrue: [
  783. self hideMethodButtons.
  784. (selectedClass isNil or: [selectedProtocol notNil])
  785. ifTrue: [self hideClassButtons]
  786. ifFalse: [self showClassButtons]]
  787. ifFalse: [
  788. self hideClassButtons.
  789. self showMethodButtons].
  790. sourceArea val: self source
  791. !
  792. updateStatus
  793. sourceArea val = self source
  794. ifTrue: [
  795. saveButton ifNotNil: [
  796. saveButton at: 'disabled' put: true].
  797. unsavedChanges := false]
  798. ifFalse: [
  799. saveButton ifNotNil: [
  800. saveButton removeAt: 'disabled'].
  801. unsavedChanges := true]
  802. !
  803. resetClassesList
  804. classesList resetNodes
  805. ! !
  806. !Browser class methodsFor: 'accessing'!
  807. commitPathJs
  808. ^'js'
  809. !
  810. commitPathSt
  811. ^'st'
  812. ! !
  813. !Browser class methodsFor: 'convenience'!
  814. openOn: aClass
  815. ^self new
  816. open;
  817. selectCategory: aClass category;
  818. selectClass: aClass
  819. !
  820. open
  821. self new open
  822. ! !
  823. TabWidget subclass: #Inspector
  824. instanceVariableNames: 'label variables object selectedVariable variablesList valueTextarea workspaceTextarea diveButton'
  825. category: 'IDE'!
  826. !Inspector methodsFor: 'accessing'!
  827. label
  828. ^label ifNil: ['Inspector (nil)']
  829. !
  830. variables
  831. ^variables
  832. !
  833. setVariables: aCollection
  834. variables := aCollection
  835. !
  836. setLabel: aString
  837. label := aString
  838. !
  839. selectedVariable
  840. ^selectedVariable
  841. !
  842. selectedVariable: aString
  843. selectedVariable := aString
  844. ! !
  845. !Inspector methodsFor: 'actions'!
  846. inspect: anObject
  847. object := anObject.
  848. variables := #().
  849. object inspectOn: self
  850. !
  851. dive
  852. (self variables at: self selectedVariable) inspect
  853. !
  854. refresh
  855. self
  856. inspect: object;
  857. updateVariablesList;
  858. updateValueTextarea
  859. ! !
  860. !Inspector methodsFor: 'rendering'!
  861. renderBoxOn: html
  862. self
  863. renderTopPanelOn: html;
  864. renderBottomPanelOn: html
  865. !
  866. renderTopPanelOn: html
  867. html div
  868. class: 'top';
  869. with: [
  870. variablesList := html ul class: 'jt_column variables'.
  871. valueTextarea := html textarea class: 'jt_column value'; at: 'readonly' put: 'readonly'.
  872. self
  873. updateVariablesList;
  874. updateValueTextarea.
  875. html div class: 'jt_clear']
  876. !
  877. renderBottomPanelOn: html
  878. html div
  879. class: 'jt_sourceCode';
  880. with: [
  881. workspaceTextarea := html textarea
  882. class: 'source';
  883. at: 'spellcheck' put: 'false'.
  884. workspaceTextarea asJQuery call: 'tabby']
  885. !
  886. renderButtonsOn: html
  887. html button
  888. with: 'Refresh';
  889. onClick: [self refresh].
  890. diveButton := html button
  891. with: 'Dive';
  892. onClick: [self dive].
  893. self updateButtons
  894. ! !
  895. !Inspector methodsFor: 'testing'!
  896. canBeClosed
  897. ^true
  898. ! !
  899. !Inspector methodsFor: 'updating'!
  900. updateVariablesList
  901. variablesList contents: [:html |
  902. self variables keys do: [:each || li |
  903. li := html li.
  904. li
  905. with: each;
  906. onClick: [self selectVariable: each].
  907. self selectedVariable = each ifTrue: [
  908. li class: 'selected']]]
  909. !
  910. selectVariable: aString
  911. self selectedVariable: aString.
  912. self
  913. updateVariablesList;
  914. updateValueTextarea;
  915. updateButtons
  916. !
  917. updateValueTextarea
  918. valueTextarea asJQuery val: (self selectedVariable isNil
  919. ifTrue: ['']
  920. ifFalse: [(self variables at: self selectedVariable) printString])
  921. !
  922. updateButtons
  923. (self selectedVariable notNil and: [(self variables at: self selectedVariable) notNil])
  924. ifFalse: [diveButton at: 'disabled' put: true]
  925. ifTrue: [diveButton removeAt: 'disabled']
  926. ! !
  927. !Inspector class methodsFor: 'instance creation'!
  928. on: anObject
  929. ^self new
  930. inspect: anObject;
  931. yourself
  932. ! !
  933. TabWidget subclass: #ReferencesBrowser
  934. instanceVariableNames: 'implementors senders implementorsList input timer selector sendersList referencedClasses referencedClassesList'
  935. category: 'IDE'!
  936. !ReferencesBrowser methodsFor: 'accessing'!
  937. implementors
  938. ^implementors ifNil: [implementors := Array new]
  939. !
  940. label
  941. ^'[ReferencesBrowser]'
  942. !
  943. selector
  944. ^selector
  945. !
  946. senders
  947. ^senders ifNil: [senders := Array new]
  948. !
  949. classesAndMetaclasses
  950. ^Smalltalk current classes, (Smalltalk current classes collect: [:each | each class])
  951. !
  952. referencedClasses
  953. ^referencedClasses ifNil: [referencedClasses := Array new]
  954. ! !
  955. !ReferencesBrowser methodsFor: 'actions'!
  956. openBrowserOn: aMethod
  957. | browser |
  958. browser := Browser openOn: (aMethod class isMetaclass
  959. ifTrue: [aMethod methodClass instanceClass] ifFalse: [aMethod methodClass]).
  960. aMethod methodClass isMetaclass ifTrue: [browser selectTab: #class].
  961. browser
  962. selectProtocol: aMethod category;
  963. selectMethod: aMethod
  964. !
  965. searchReferencesFor: aString
  966. selector := aString.
  967. implementors := Array new.
  968. senders := Array new.
  969. referencedClasses := Array new.
  970. (selector match: '^[A-Z]')
  971. ifFalse: [self searchSelectorReferencesFor: selector]
  972. ifTrue: [self searchReferencedClassesFor: selector]
  973. !
  974. search: aString
  975. self
  976. searchReferencesFor: aString;
  977. updateImplementorsList;
  978. updateSendersList;
  979. updateReferencedClassesList
  980. !
  981. searchReferencedClassesFor: aString
  982. self classesAndMetaclasses do: [:each |
  983. each methodDictionary values do: [:value |
  984. (((value referencedClasses select: [:each | each notNil])collect: [:each | each name]) includes: selector) ifTrue: [
  985. self referencedClasses add: value]]]
  986. !
  987. searchSelectorReferencesFor: aString
  988. self classesAndMetaclasses do: [:each |
  989. each methodDictionary keysAndValuesDo: [:key :value |
  990. key = selector ifTrue: [self implementors add: value]].
  991. each methodDictionary keysAndValuesDo: [:key :value |
  992. (value messageSends includes: selector) ifTrue: [
  993. self senders add: value]]]
  994. ! !
  995. !ReferencesBrowser methodsFor: 'initialization'!
  996. initialize
  997. super initialize.
  998. selector := ''
  999. ! !
  1000. !ReferencesBrowser methodsFor: 'private'!
  1001. setInputEvents
  1002. input
  1003. onKeyUp: [timer := [self search: input asJQuery val] valueWithTimeout: 100];
  1004. onKeyDown: [timer ifNotNil: [timer clearTimeout]]
  1005. ! !
  1006. !ReferencesBrowser methodsFor: 'rendering'!
  1007. renderBoxOn: html
  1008. self
  1009. renderInputOn: html;
  1010. renderImplementorsOn: html;
  1011. renderSendersOn: html;
  1012. renderReferencedClassesOn: html
  1013. !
  1014. renderInputOn: html
  1015. input := html input
  1016. class: 'implementors';
  1017. yourself.
  1018. input asJQuery val: selector.
  1019. self setInputEvents
  1020. !
  1021. renderImplementorsOn: html
  1022. implementorsList := html ul class: 'jt_column implementors'.
  1023. self updateImplementorsList
  1024. !
  1025. renderSendersOn: html
  1026. sendersList := html ul class: 'jt_column senders'.
  1027. self updateSendersList
  1028. !
  1029. renderReferencedClassesOn: html
  1030. referencedClassesList := html ul class: 'jt_column referenced_classes'.
  1031. self updateReferencedClassesList
  1032. ! !
  1033. !ReferencesBrowser methodsFor: 'testing'!
  1034. canBeClosed
  1035. ^true
  1036. ! !
  1037. !ReferencesBrowser methodsFor: 'updating'!
  1038. updateImplementorsList
  1039. implementorsList contents: [:html |
  1040. html li
  1041. class: 'column_label';
  1042. with: 'Implementors (', self implementors size asString, ')';
  1043. style: 'font-weight: bold'.
  1044. self implementors do: [:each || li |
  1045. li := html li.
  1046. li
  1047. with: (each methodClass asString, ' >> ', self selector);
  1048. onClick: [self openBrowserOn: each]]]
  1049. !
  1050. updateSendersList
  1051. sendersList contents: [:html |
  1052. html li
  1053. class: 'column_label';
  1054. with: 'Senders (', self senders size asString, ')';
  1055. style: 'font-weight: bold'.
  1056. self senders do: [:each |
  1057. html li
  1058. with: (each methodClass asString, ' >> ', each selector);
  1059. onClick: [self openBrowserOn: each]]]
  1060. !
  1061. updateReferencedClassesList
  1062. referencedClassesList contents: [:html |
  1063. html li
  1064. class: 'column_label';
  1065. with: 'Class references (', self referencedClasses size asString, ')';
  1066. style: 'font-weight: bold'.
  1067. self referencedClasses do: [:each |
  1068. html li
  1069. with: (each methodClass asString, ' >> ', each selector);
  1070. onClick: [self openBrowserOn: each]]]
  1071. ! !
  1072. !ReferencesBrowser class methodsFor: 'instance creation'!
  1073. search: aString
  1074. ^self new
  1075. searchReferencesFor: aString;
  1076. open
  1077. ! !
  1078. Widget subclass: #SourceArea
  1079. instanceVariableNames: 'editor div'
  1080. category: 'IDE'!
  1081. !SourceArea methodsFor: 'accessing'!
  1082. val
  1083. ^editor getValue
  1084. !
  1085. val: aString
  1086. editor setValue: aString
  1087. !
  1088. currentLine
  1089. ^editor getLine: (editor getCursor line)
  1090. !
  1091. selection
  1092. ^editor getSelection
  1093. !
  1094. selectionEnd
  1095. ^textarea element selectionEnd
  1096. !
  1097. selectionStart
  1098. ^textarea element selectionStart
  1099. !
  1100. selectionStart: anInteger
  1101. textarea element selectionStart: anInteger
  1102. !
  1103. selectionEnd: anInteger
  1104. textarea element selectionEnd: anInteger
  1105. !
  1106. setEditorOn: aTextarea
  1107. <self['@editor'] = CodeMirror.fromTextArea(aTextarea, {
  1108. theme: 'jtalk',
  1109. lineNumbers: true,
  1110. enterMode: 'classic',
  1111. matchBrackets: true,
  1112. electricChars: false,
  1113. })>
  1114. !
  1115. editor
  1116. ^editor
  1117. ! !
  1118. !SourceArea methodsFor: 'actions'!
  1119. clear
  1120. textarea asJQuery val: ''
  1121. !
  1122. doIt
  1123. | selection |
  1124. editor somethingSelected
  1125. ifFalse: [selection := self currentLine]
  1126. ifTrue: [selection := self selection].
  1127. ^self eval: selection
  1128. !
  1129. eval: aString
  1130. | compiler node |
  1131. compiler := Compiler new.
  1132. node := compiler parseExpression: aString.
  1133. node isParseFailure ifTrue: [
  1134. ^self alert: node reason, ', position: ', node position].
  1135. ^compiler loadExpression: aString
  1136. !
  1137. handleKeyDown: anEvent
  1138. <if(anEvent.ctrlKey) {
  1139. if(anEvent.keyCode === 80) { //ctrl+p
  1140. self._printIt();
  1141. anEvent.preventDefault();
  1142. return false;
  1143. }
  1144. if(anEvent.keyCode === 68) { //ctrl+d
  1145. self._doIt();
  1146. anEvent.preventDefault();
  1147. return false;
  1148. }
  1149. if(anEvent.keyCode === 73) { //ctrl+i
  1150. self._inspectIt();
  1151. anEvent.preventDefault();
  1152. return false;
  1153. }
  1154. }>
  1155. !
  1156. inspectIt
  1157. self doIt inspect
  1158. !
  1159. print: aString
  1160. | start stop |
  1161. start := Dictionary new.
  1162. stop := Dictionary new.
  1163. start at: 'line' put: (editor getCursor: false) line.
  1164. start at: 'ch' put: (editor getCursor: false) ch.
  1165. stop at: 'line' put: (start at: 'line').
  1166. stop at: 'ch' put: ((start at: 'ch') + aString size + 2).
  1167. editor replaceSelection: (editor getSelection, ' ', aString, ' ').
  1168. editor setCursor: (editor getCursor: true).
  1169. editor setSelection: stop end: start
  1170. !
  1171. printIt
  1172. self print: self doIt printString
  1173. ! !
  1174. !SourceArea methodsFor: 'events'!
  1175. onKeyUp: aBlock
  1176. div onKeyUp: aBlock
  1177. !
  1178. onKeyDown: aBlock
  1179. div onKeyDown: aBlock
  1180. ! !
  1181. !SourceArea methodsFor: 'rendering'!
  1182. renderOn: html
  1183. | textarea |
  1184. div := html div class: 'source'.
  1185. div with: [textarea := html textarea].
  1186. self setEditorOn: textarea element.
  1187. div onKeyDown: [:e | self handleKeyDown: e]
  1188. ! !
  1189. Widget subclass: #ClassesList
  1190. instanceVariableNames: 'browser ul nodes'
  1191. category: 'IDE'!
  1192. !ClassesList methodsFor: 'accessing'!
  1193. category
  1194. ^self browser selectedCategory
  1195. !
  1196. nodes
  1197. nodes ifNil: [nodes := self getNodes].
  1198. ^nodes
  1199. !
  1200. browser
  1201. ^browser
  1202. !
  1203. browser: aBrowser
  1204. browser := aBrowser
  1205. !
  1206. getNodes
  1207. | classes children others |
  1208. classes := self browser classes.
  1209. children := #().
  1210. others := #().
  1211. classes do: [:each |
  1212. (classes includes: each superclass)
  1213. ifFalse: [children add: each]
  1214. ifTrue: [others add: each]].
  1215. ^children collect: [:each |
  1216. ClassesListNode on: each browser: self browser classes: others level: 0]
  1217. !
  1218. resetNodes
  1219. nodes := nil
  1220. ! !
  1221. !ClassesList methodsFor: 'rendering'!
  1222. renderOn: html
  1223. ul := html ul
  1224. class: 'jt_column browser classes';
  1225. yourself.
  1226. self updateNodes
  1227. !
  1228. updateNodes
  1229. ul contents: [:html |
  1230. self nodes do: [:each |
  1231. each renderOn: html]]
  1232. ! !
  1233. !ClassesList class methodsFor: 'instance creation'!
  1234. on: aBrowser
  1235. ^self new
  1236. browser: aBrowser;
  1237. yourself
  1238. ! !
  1239. Widget subclass: #ClassesListNode
  1240. instanceVariableNames: 'browser theClass level nodes'
  1241. category: 'IDE'!
  1242. !ClassesListNode methodsFor: ''!
  1243. renderOn: html
  1244. | li |
  1245. li := html li
  1246. onClick: [self browser selectClass: self theClass].
  1247. li asJQuery contents: self label.
  1248. self browser selectedClass = self theClass ifTrue: [
  1249. li class: 'selected'].
  1250. self theClass comment isEmpty ifFalse: [
  1251. li class: 'commented'
  1252. ].
  1253. self nodes do: [:each |
  1254. each renderOn: html]
  1255. ! !
  1256. !ClassesListNode methodsFor: 'accessing'!
  1257. nodes
  1258. ^nodes
  1259. !
  1260. theClass
  1261. ^theClass
  1262. !
  1263. theClass: aClass
  1264. theClass := aClass
  1265. !
  1266. browser
  1267. ^browser
  1268. !
  1269. browser: aBrowser
  1270. browser := aBrowser
  1271. !
  1272. level
  1273. ^level
  1274. !
  1275. level: anInteger
  1276. level := anInteger
  1277. !
  1278. label
  1279. | str |
  1280. str := String new writeStream.
  1281. self level timesRepeat: [
  1282. str nextPutAll: '&nbsp;&nbsp;&nbsp;&nbsp;'].
  1283. str nextPutAll: self theClass name.
  1284. ^str contents
  1285. !
  1286. getNodesFrom: aCollection
  1287. | children others |
  1288. children := #().
  1289. others := #().
  1290. aCollection do: [:each |
  1291. (each superclass = self theClass)
  1292. ifTrue: [children add: each]
  1293. ifFalse: [others add: each]].
  1294. nodes:= children collect: [:each |
  1295. ClassesListNode on: each browser: self browser classes: others level: self level + 1]
  1296. ! !
  1297. !ClassesListNode class methodsFor: 'instance creation'!
  1298. on: aClass browser: aBrowser classes: aCollection level: anInteger
  1299. ^self new
  1300. theClass: aClass;
  1301. browser: aBrowser;
  1302. level: anInteger;
  1303. getNodesFrom: aCollection;
  1304. yourself
  1305. ! !
  1306. TabWidget subclass: #Debugger
  1307. instanceVariableNames: 'error selectedContext sourceArea ul'
  1308. category: 'IDE'!
  1309. !Debugger methodsFor: 'accessing'!
  1310. error
  1311. ^error
  1312. !
  1313. error: anError
  1314. error := anError
  1315. !
  1316. label
  1317. ^'[Debugger]'
  1318. ! !
  1319. !Debugger methodsFor: 'actions'!
  1320. selectContext: aContext
  1321. selectedContext := aContext.
  1322. self updateContextsList.
  1323. self updateSourceArea
  1324. ! !
  1325. !Debugger methodsFor: 'rendering'!
  1326. renderBoxOn: html
  1327. self
  1328. renderTopPanelOn: html;
  1329. renderBottomPanelOn: html
  1330. !
  1331. renderTopPanelOn: html
  1332. selectedContext := self error context.
  1333. html div
  1334. class: 'top';
  1335. with: [
  1336. html div
  1337. class: 'label';
  1338. with: self error messageText.
  1339. ul := html ul
  1340. class: 'jt_column debugger contexts';
  1341. with: [self renderContext: self error context on: html]]
  1342. !
  1343. renderContext: aContext on: html
  1344. | li |
  1345. li := html li.
  1346. selectedContext = aContext ifTrue: [
  1347. li class: 'selected'].
  1348. li
  1349. with: aContext asString;
  1350. onClick: [self selectContext: aContext].
  1351. aContext home ifNotNil: [self renderContext: aContext home on: html]
  1352. !
  1353. renderBottomPanelOn: html
  1354. html div
  1355. class: 'jt_sourceCode';
  1356. with: [
  1357. sourceArea := SourceArea new.
  1358. sourceArea renderOn: html].
  1359. self updateSourceArea
  1360. ! !
  1361. !Debugger methodsFor: 'testing'!
  1362. canBeClosed
  1363. ^true
  1364. ! !
  1365. !Debugger methodsFor: 'updating'!
  1366. updateContextsList
  1367. ul contents: [:html |
  1368. self renderContext: self error context on: html]
  1369. !
  1370. updateSourceArea
  1371. sourceArea val: (selectedContext receiver class methodAt: selectedContext selector) source
  1372. ! !
  1373. ErrorHandler subclass: #DebugErrorHandler
  1374. instanceVariableNames: ''
  1375. category: 'IDE'!
  1376. !DebugErrorHandler methodsFor: 'error handling'!
  1377. handleError: anError
  1378. [Debugger new
  1379. error: anError;
  1380. open] on: Error do: [:error |
  1381. ErrorHandler new handleError: error]
  1382. ! !
  1383. !DebugErrorHandler class methodsFor: 'initialization'!
  1384. initialize
  1385. self register
  1386. ! !
  1387. TabWidget subclass: #ProgressBar
  1388. instanceVariableNames: 'percent progressDiv div'
  1389. category: 'IDE'!
  1390. !ProgressBar methodsFor: 'accessing'!
  1391. percent
  1392. ^percent ifNil: [0]
  1393. !
  1394. percent: aNumber
  1395. percent := aNumber
  1396. ! !
  1397. !ProgressBar methodsFor: 'rendering'!
  1398. renderOn: html
  1399. div := html div
  1400. class: 'progress_bar';
  1401. yourself.
  1402. self renderProgressBar
  1403. !
  1404. renderProgressBar
  1405. div contents: [:html |
  1406. html div
  1407. class: 'progress';
  1408. style: 'width:', self percent asString, '%']
  1409. ! !
  1410. !ProgressBar methodsFor: 'updating'!
  1411. updatePercent: aNumber
  1412. self percent: aNumber.
  1413. self renderProgressBar
  1414. ! !
  1415. TabWidget subclass: #TestRunner
  1416. instanceVariableNames: 'selectedCategories categoriesList selectedClasses classesList selectedMethods progressBar methodsList result statusDiv'
  1417. category: 'IDE'!
  1418. !TestRunner methodsFor: 'accessing'!
  1419. label
  1420. ^'[Test runner]'
  1421. !
  1422. categories
  1423. | categories |
  1424. categories := Array new.
  1425. self allClasses do: [:each |
  1426. (categories includes: each category) ifFalse: [
  1427. categories add: each category]].
  1428. ^categories sort
  1429. !
  1430. classes
  1431. ^(self allClasses
  1432. select: [:each | self selectedCategories includes: each category])
  1433. sort: [:a :b | a name > b name]
  1434. !
  1435. selectedCategories
  1436. ^selectedCategories ifNil: [selectedCategories := Array new]
  1437. !
  1438. allClasses
  1439. ^TestCase allSubclasses
  1440. !
  1441. selectedClasses
  1442. ^selectedClasses ifNil: [selectedClasses := Array new]
  1443. !
  1444. progressBar
  1445. ^progressBar ifNil: [progressBar := ProgressBar new]
  1446. !
  1447. selectedMethods
  1448. ^selectedMethods ifNil: [self selectedClasses collect: [:each |
  1449. each methodDictionary keys select: [:key | key beginsWith: 'test' ]]]
  1450. !
  1451. statusInfo
  1452. ^self printTotal, self printPasses, self printErrors, self printFailures
  1453. !
  1454. result
  1455. ^result
  1456. !
  1457. failedMethods
  1458. self result failures collect: [:each |
  1459. html li
  1460. class: 'failures';
  1461. with: each]
  1462. ! !
  1463. !TestRunner methodsFor: 'actions'!
  1464. selectAllCategories
  1465. self categories do: [:each |
  1466. (selectedCategories includes: each) ifFalse: [
  1467. self selectedCategories add: each]].
  1468. self
  1469. updateCategoriesList;
  1470. updateClassesList
  1471. !
  1472. toggleCategory: aCategory
  1473. (self isSelectedCategory: aCategory)
  1474. ifFalse: [selectedCategories add: aCategory]
  1475. ifTrue: [selectedCategories remove: aCategory].
  1476. self
  1477. updateCategoriesList;
  1478. updateClassesList
  1479. !
  1480. toggleClass: aClass
  1481. (self isSelectedClass: aClass)
  1482. ifFalse: [selectedClasses add: aClass]
  1483. ifTrue: [selectedClasses remove: aClass].
  1484. self
  1485. updateClassesList
  1486. !
  1487. selectAllClasses
  1488. self classes do: [:each |
  1489. (selectedClasses includes: each) ifFalse: [
  1490. self selectedClasses add: each]].
  1491. self
  1492. updateCategoriesList;
  1493. updateClassesList
  1494. !
  1495. run: aCollection
  1496. result := TestResult new.
  1497. self
  1498. updateStatusDiv;
  1499. updateMethodsList.
  1500. self progressBar updatePercent: 0.
  1501. result total: (aCollection inject: 0 into: [:acc :each | acc + each methods size]).
  1502. aCollection do: [:each |
  1503. [each runCaseFor: result.
  1504. self progressBar updatePercent: result runs / result total * 100.
  1505. self updateStatusDiv.
  1506. self updateMethodsList] valueWithTimeout: 100].
  1507. ! !
  1508. !TestRunner methodsFor: 'initialization'!
  1509. initialize
  1510. super initialize.
  1511. result := TestResult new
  1512. ! !
  1513. !TestRunner methodsFor: 'printing'!
  1514. printErrors
  1515. ^self result errors size asString , ' errors, '
  1516. !
  1517. printFailures
  1518. ^self result failures size asString, ' failures'
  1519. !
  1520. printPasses
  1521. ^(((self result total) - (self result errors size + (self result failures size))) asString) , ' passes, '
  1522. !
  1523. printTotal
  1524. ^self result total asString, ' runs, '
  1525. ! !
  1526. !TestRunner methodsFor: 'rendering'!
  1527. renderBoxOn: html
  1528. self
  1529. renderCategoriesOn: html;
  1530. renderClassesOn: html;
  1531. renderResultsOn: html
  1532. !
  1533. renderButtonsOn: html
  1534. html button
  1535. with: 'Run selected';
  1536. onClick: [self run: (self selectedClasses collect: [:each | each new])]
  1537. !
  1538. renderCategoriesOn: html
  1539. categoriesList := html ul class: 'jt_column sunit categories'.
  1540. self updateCategoriesList
  1541. !
  1542. renderClassesOn: html
  1543. classesList := html ul class: 'jt_column sunit classes'.
  1544. self updateClassesList
  1545. !
  1546. renderResultsOn: html
  1547. statusDiv := html div.
  1548. html with: self progressBar.
  1549. methodsList := html ul class: 'jt_column sunit methods'.
  1550. self updateMethodsList.
  1551. self updateStatusDiv
  1552. !
  1553. renderFailuresOn: html
  1554. self result failures do: [:each |
  1555. html li
  1556. class: 'failures';
  1557. with: each]
  1558. !
  1559. renderErrorsOn: html
  1560. self result errors do: [:each |
  1561. html li
  1562. class: 'errors';
  1563. with: each]
  1564. ! !
  1565. !TestRunner methodsFor: 'testing'!
  1566. isSelectedClass: aClass
  1567. ^(self selectedClasses includes: aClass)
  1568. !
  1569. isSelectedCategory: aCategory
  1570. ^(self selectedCategories includes: aCategory)
  1571. ! !
  1572. !TestRunner methodsFor: 'updating'!
  1573. updateCategoriesList
  1574. categoriesList contents: [:html |
  1575. html li
  1576. class: 'all';
  1577. with: 'All';
  1578. onClick: [self selectAllCategories].
  1579. self categories do: [:each || li |
  1580. li := html li.
  1581. (self selectedCategories includes: each) ifTrue: [
  1582. li class: 'selected'].
  1583. li
  1584. with: each;
  1585. onClick: [self toggleCategory: each]]]
  1586. !
  1587. updateClassesList
  1588. classesList contents: [:html |
  1589. (self selectedCategories isEmpty) ifFalse: [
  1590. html li
  1591. class: 'all';
  1592. with: 'All';
  1593. onClick: [self selectAllClasses]].
  1594. self classes do: [:each || li |
  1595. li := html li.
  1596. (self selectedClasses includes: each) ifTrue: [
  1597. li class: 'selected'].
  1598. li
  1599. with: each name;
  1600. onClick: [self toggleClass: each]]]
  1601. !
  1602. updateMethodsList
  1603. methodsList contents: [:html |
  1604. self renderFailuresOn: html.
  1605. self renderErrorsOn: html]
  1606. !
  1607. updateStatusDiv
  1608. statusDiv class: 'sunit status ', result status.
  1609. statusDiv contents: [:html |
  1610. html span with: self statusInfo]
  1611. ! !
  1612. !Object methodsFor: '*IDE'!
  1613. inspect
  1614. Inspector new
  1615. inspect: self;
  1616. open
  1617. !
  1618. inspectOn: anInspector
  1619. | variables |
  1620. variables := Dictionary new.
  1621. variables at: '#self' put: self.
  1622. self class allInstanceVariableNames do: [:each |
  1623. variables at: each put: (self instVarAt: each)].
  1624. anInspector
  1625. setLabel: self printString;
  1626. setVariables: variables
  1627. ! !
  1628. !Date methodsFor: '*IDE'!
  1629. inspectOn: anInspector
  1630. | variables |
  1631. variables := Dictionary new.
  1632. variables at: '#self' put: self.
  1633. variables at: '#year' put: self year.
  1634. variables at: '#month' put: self month.
  1635. variables at: '#day' put: self day.
  1636. variables at: '#hours' put: self hours.
  1637. variables at: '#minutes' put: self minutes.
  1638. variables at: '#seconds' put: self seconds.
  1639. variables at: '#milliseconds' put: self milliseconds.
  1640. anInspector
  1641. setLabel: self printString;
  1642. setVariables: variables
  1643. ! !
  1644. !Collection methodsFor: '*IDE'!
  1645. inspectOn: anInspector
  1646. | variables |
  1647. variables := Dictionary new.
  1648. variables at: '#self' put: self.
  1649. self withIndexDo: [:each :i |
  1650. variables at: i put: each].
  1651. anInspector
  1652. setLabel: self printString;
  1653. setVariables: variables
  1654. ! !
  1655. !String methodsFor: '*IDE'!
  1656. inspectOn: anInspector
  1657. | label |
  1658. super inspectOn: anInspector.
  1659. self printString size > 30
  1660. ifTrue: [label := (self printString copyFrom: 1 to: 30), '...''']
  1661. ifFalse: [label := self printString].
  1662. anInspector setLabel: label
  1663. ! !
  1664. !MethodContext methodsFor: '*IDE'!
  1665. inspectOn: anInspector
  1666. | variables |
  1667. variables := Dictionary new.
  1668. variables at: '#self' put: self.
  1669. variables at: '#home' put: self home.
  1670. variables at: '#receiver' put: self receiver.
  1671. variables at: '#selector' put: self selector.
  1672. variables at: '#temps' put: self temps.
  1673. self class instanceVariableNames do: [:each |
  1674. variables at: each put: (self instVarAt: each)].
  1675. anInspector
  1676. setLabel: self printString;
  1677. setVariables: variables
  1678. ! !
  1679. !Dictionary methodsFor: '*IDE'!
  1680. inspectOn: anInspector
  1681. | variables |
  1682. variables := Dictionary new.
  1683. variables at: '#self' put: self.
  1684. variables at: '#keys' put: self keys.
  1685. self keysAndValuesDo: [:key :value |
  1686. variables at: key put: value].
  1687. anInspector
  1688. setLabel: self printString;
  1689. setVariables: variables
  1690. ! !