1
0

IDE.st 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030
  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 ifTrue: [
  423. selectedClass ifNotNil: [
  424. self compileClassComment]].
  425. (selectedProtocol notNil or: [selectedMethod notNil])
  426. ifFalse: [self compileDefinition]
  427. ifTrue: [self compileMethodDefinition]
  428. !
  429. compileClassComment
  430. selectedClass comment: sourceArea val
  431. !
  432. compileMethodDefinition
  433. selectedTab = #instance
  434. ifTrue: [self compileMethodDefinitionFor: selectedClass]
  435. ifFalse: [self compileMethodDefinitionFor: selectedClass class]
  436. !
  437. compileMethodDefinitionFor: aClass
  438. | compiler method source node |
  439. source := sourceArea val.
  440. selectedProtocol ifNil: [selectedProtocol := selectedMethod category].
  441. compiler := Compiler new.
  442. compiler source: source.
  443. node := compiler parse: source.
  444. node isParseFailure ifTrue: [
  445. ^self alert: 'PARSE ERROR: ', node reason, ', position: ', node position asString].
  446. compiler currentClass: aClass.
  447. method := compiler eval: (compiler compileNode: node).
  448. method category: selectedProtocol.
  449. compiler unknownVariables do: [:each |
  450. (self confirm: 'Declare ''', each, ''' as instance variable?') ifTrue: [
  451. self addInstanceVariableNamed: each toClass: aClass.
  452. ^self compileMethodDefinitionFor: aClass]].
  453. aClass addCompiledMethod: method.
  454. compiler setupClass: aClass.
  455. self updateMethodsList.
  456. self selectMethod: method
  457. !
  458. compileDefinition
  459. | newClass |
  460. newClass := Compiler new loadExpression: sourceArea val.
  461. self
  462. resetClassesList;
  463. updateCategoriesList;
  464. updateClassesList
  465. !
  466. commitCategory
  467. selectedCategory ifNotNil: [
  468. (Ajax url: self class commitPathJs, '/', selectedCategory, '.js')
  469. at: 'type' put: 'PUT';
  470. at: 'data' put: (Exporter new exportCategory: selectedCategory);
  471. at: 'error' put: [self alert: 'Commit failed!!'];
  472. send.
  473. (Ajax url: self class commitPathJs, '/', selectedCategory, '.deploy.js')
  474. at: 'type' put: 'PUT';
  475. at: 'data' put: (StrippedExporter new exportCategory: selectedCategory);
  476. at: 'error' put: [self alert: 'Commit failed!!'];
  477. send.
  478. (Ajax url: self class commitPathSt, '/', selectedCategory, '.st')
  479. at: 'type' put: 'PUT';
  480. at: 'data' put: (ChunkExporter new exportCategory: selectedCategory);
  481. at: 'error' put: [self alert: 'Commit failed!!'];
  482. send]
  483. !
  484. cancelChanges
  485. ^unsavedChanges
  486. ifTrue: [self confirm: 'Cancel changes?']
  487. ifFalse: [true]
  488. !
  489. removeClass
  490. (self confirm: 'Do you really want to remove ', selectedClass name, '?')
  491. ifTrue: [
  492. Smalltalk current removeClass: selectedClass.
  493. self resetClassesList.
  494. self selectClass: nil]
  495. !
  496. removeMethod
  497. self cancelChanges ifTrue: [
  498. (self confirm: 'Do you really want to remove #', selectedMethod selector, '?')
  499. ifTrue: [
  500. selectedTab = #instance
  501. ifTrue: [selectedClass removeCompiledMethod: selectedMethod]
  502. ifFalse: [selectedClass class removeCompiledMethod: selectedMethod].
  503. self selectMethod: nil]]
  504. !
  505. setMethodProtocol: aString
  506. self cancelChanges ifTrue: [
  507. (self protocols includes: aString)
  508. ifFalse: [self addNewProtocol]
  509. ifTrue: [
  510. selectedMethod category: aString.
  511. selectedProtocol := aString.
  512. selectedMethod := selectedMethod.
  513. self
  514. updateProtocolsList;
  515. updateMethodsList;
  516. updateSourceAndButtons]]
  517. !
  518. addNewProtocol
  519. | newProtocol |
  520. newProtocol := self prompt: 'New method protocol'.
  521. newProtocol notEmpty ifTrue: [
  522. selectedMethod category: newProtocol.
  523. self setMethodProtocol: newProtocol]
  524. !
  525. selectCategory: aCategory
  526. self cancelChanges ifTrue: [
  527. selectedCategory := aCategory.
  528. selectedClass := selectedProtocol := selectedMethod := nil.
  529. self resetClassesList.
  530. self
  531. updateCategoriesList;
  532. updateClassesList;
  533. updateProtocolsList;
  534. updateMethodsList;
  535. updateSourceAndButtons]
  536. !
  537. selectClass: aClass
  538. self cancelChanges ifTrue: [
  539. selectedClass := aClass.
  540. selectedProtocol := selectedMethod := nil.
  541. self
  542. updateClassesList;
  543. updateProtocolsList;
  544. updateMethodsList;
  545. updateSourceAndButtons]
  546. !
  547. selectProtocol: aString
  548. self cancelChanges ifTrue: [
  549. selectedProtocol := aString.
  550. selectedMethod := nil.
  551. self
  552. updateProtocolsList;
  553. updateMethodsList;
  554. updateSourceAndButtons]
  555. !
  556. selectMethod: aMethod
  557. self cancelChanges ifTrue: [
  558. selectedMethod := aMethod.
  559. self
  560. updateProtocolsList;
  561. updateMethodsList;
  562. updateSourceAndButtons]
  563. !
  564. selectTab: aString
  565. self cancelChanges ifTrue: [
  566. selectedTab := aString.
  567. self selectProtocol: nil.
  568. self updateTabsList]
  569. !
  570. renameClass
  571. | newName |
  572. newName := self prompt: 'Rename class ', selectedClass name.
  573. newName notEmpty ifTrue: [
  574. selectedClass rename: newName.
  575. self
  576. updateClassesList;
  577. updateSourceAndButtons]
  578. !
  579. addInstanceVariableNamed: aString toClass: aClass
  580. ClassBuilder new
  581. addSubclassOf: aClass superclass named: aClass name instanceVariableNames: (aClass instanceVariableNames copy add: aString; yourself)
  582. !
  583. searchReferencesOf: aString
  584. ReferencesBrowser search: aString
  585. !
  586. searchClassReferences
  587. ReferencesBrowser search: selectedClass name
  588. !
  589. search: aString
  590. self cancelChanges ifTrue: [| searchedClass |
  591. searchedClass := Smalltalk current at: aString.
  592. searchedClass isClass
  593. ifTrue: [self class openOn: searchedClass]
  594. ifFalse: [self searchReferencesOf: aString]]
  595. ! !
  596. !Browser methodsFor: 'initialization'!
  597. initialize
  598. super initialize.
  599. selectedTab := #instance.
  600. unsavedChanges := false
  601. ! !
  602. !Browser methodsFor: 'rendering'!
  603. renderBoxOn: html
  604. self
  605. renderTopPanelOn: html;
  606. renderTabsOn: html;
  607. renderBottomPanelOn: html
  608. !
  609. renderTopPanelOn: html
  610. html div
  611. class: 'top';
  612. with: [
  613. self renderInputOn: html.
  614. categoriesList := html ul class: 'jt_column browser categories'.
  615. commitButton := html button
  616. class: 'jt_commit';
  617. title: 'Commit classes in this category to disk';
  618. onClick: [self commitCategory];
  619. with: 'Commit category'.
  620. classesList := ClassesList on: self.
  621. classesList renderOn: html.
  622. protocolsList := html ul class: 'jt_column browser protocols'.
  623. methodsList := html ul class: 'jt_column browser methods'.
  624. self
  625. updateCategoriesList;
  626. updateClassesList;
  627. updateProtocolsList;
  628. updateMethodsList.
  629. html div class: 'jt_clear']
  630. !
  631. renderTabsOn: html
  632. tabsList := html ul class: 'jt_tabs'.
  633. self updateTabsList.
  634. !
  635. renderBottomPanelOn: html
  636. html div
  637. class: 'jt_sourceCode';
  638. with: [
  639. sourceArea := SourceArea new.
  640. sourceArea renderOn: html.
  641. sourceArea
  642. onKeyUp: [self updateStatus]]
  643. !
  644. renderButtonsOn: html
  645. saveButton := html button.
  646. saveButton
  647. with: 'Save';
  648. onClick: [self compile].
  649. methodButtons := html span.
  650. classButtons := html span.
  651. html div
  652. class: 'right';
  653. with: [
  654. html button
  655. with: 'DoIt';
  656. onClick: [sourceArea doIt].
  657. html button
  658. with: 'PrintIt';
  659. onClick: [sourceArea printIt].
  660. html button with: 'InspectIt';
  661. onClick: [sourceArea inspectit]].
  662. self updateSourceAndButtons
  663. !
  664. renderInputOn: html
  665. input := html input
  666. class: 'implementors';
  667. yourself.
  668. input onKeyPress: [:event |
  669. event keyCode = 13 ifTrue: [
  670. self search: input asJQuery val]]
  671. ! !
  672. !Browser methodsFor: 'testing'!
  673. canBeClosed
  674. ^true
  675. ! !
  676. !Browser methodsFor: 'updating'!
  677. updateCategoriesList
  678. categoriesList contents: [:html |
  679. self categories do: [:each || li label |
  680. each isEmpty
  681. ifTrue: [label := 'Unclassified']
  682. ifFalse: [label := each].
  683. li := html li.
  684. selectedCategory = each ifTrue: [
  685. li class: 'selected'].
  686. li
  687. with: label;
  688. onClick: [self selectCategory: each]]]
  689. !
  690. updateClassesList
  691. TabManager current update.
  692. classesList updateNodes.
  693. "classesList contents: [:html |
  694. self classes do: [:each || li |
  695. li := html li.
  696. selectedClass = each ifTrue: [
  697. li class: 'selected'].
  698. li
  699. with: each name;
  700. onClick: [self selectClass: each]]]"
  701. !
  702. updateProtocolsList
  703. protocolsList contents: [:html |
  704. self protocols do: [:each || li |
  705. li := html li.
  706. selectedProtocol = each ifTrue: [
  707. li class: 'selected'].
  708. li
  709. with: each;
  710. onClick: [self selectProtocol: each]]]
  711. !
  712. updateMethodsList
  713. methodsList contents: [:html |
  714. self methods do: [:each || li |
  715. li := html li.
  716. selectedMethod = each ifTrue: [
  717. li class: 'selected'].
  718. li
  719. with: each selector;
  720. onClick: [self selectMethod: each]]]
  721. !
  722. updateTabsList
  723. tabsList contents: [:html || li |
  724. li := html li.
  725. selectedTab = #instance ifTrue: [li class: 'selected'].
  726. li
  727. with: 'Instance';
  728. onClick: [self selectTab: #instance].
  729. li := html li.
  730. selectedTab = #class ifTrue: [li class: 'selected'].
  731. li
  732. with: 'Class';
  733. onClick: [self selectTab: #class].
  734. li := html li.
  735. selectedTab = #comment ifTrue: [li class: 'selected'].
  736. li
  737. with: 'Comment';
  738. onClick: [self selectTab: #comment]]
  739. !
  740. updateSourceAndButtons
  741. self disableSaveButton.
  742. classButtons contents: [:html |
  743. html button
  744. with: 'Rename class';
  745. onClick: [self renameClass].
  746. html button
  747. with: 'Remove class';
  748. onClick: [self removeClass].
  749. html button
  750. with: 'References';
  751. onClick: [self searchClassReferences]].
  752. methodButtons contents: [:html |
  753. html button
  754. with: 'Remove method';
  755. onClick: [self removeMethod].
  756. html select
  757. onChange: [:e :select | self setMethodProtocol: select val];
  758. with: [
  759. html option
  760. with: 'Method protocol';
  761. at: 'disabled' put: 'disabled'.
  762. html option
  763. class: 'important';
  764. with: 'New...'.
  765. self protocols do: [:each |
  766. html option with: each]].
  767. selectedMethod isNil ifFalse: [
  768. html select
  769. onChange: [:e :select | self searchReferencesOf: select val];
  770. with: [
  771. html option
  772. with: 'References';
  773. at: 'disabled' put: 'disabled'.
  774. html option
  775. class: 'important';
  776. with: selectedMethod selector.
  777. selectedMethod messageSends sorted do: [:each |
  778. html option with: each]]]].
  779. selectedMethod isNil
  780. ifTrue: [
  781. self hideMethodButtons.
  782. (selectedClass isNil or: [selectedProtocol notNil])
  783. ifTrue: [self hideClassButtons]
  784. ifFalse: [self showClassButtons]]
  785. ifFalse: [
  786. self hideClassButtons.
  787. self showMethodButtons].
  788. sourceArea val: self source
  789. !
  790. updateStatus
  791. sourceArea val = self source
  792. ifTrue: [
  793. saveButton ifNotNil: [
  794. saveButton at: 'disabled' put: true].
  795. unsavedChanges := false]
  796. ifFalse: [
  797. saveButton ifNotNil: [
  798. saveButton removeAt: 'disabled'].
  799. unsavedChanges := true]
  800. !
  801. resetClassesList
  802. classesList resetNodes
  803. ! !
  804. !Browser class methodsFor: 'accessing'!
  805. commitPathJs
  806. ^'js'
  807. !
  808. commitPathSt
  809. ^'st'
  810. ! !
  811. !Browser class methodsFor: 'convenience'!
  812. openOn: aClass
  813. ^self new
  814. open;
  815. selectCategory: aClass category;
  816. selectClass: aClass
  817. !
  818. open
  819. self new open
  820. ! !
  821. TabWidget subclass: #Inspector
  822. instanceVariableNames: 'label variables object selectedVariable variablesList valueTextarea workspaceTextarea diveButton'
  823. category: 'IDE'!
  824. !Inspector methodsFor: 'accessing'!
  825. label
  826. ^label ifNil: ['Inspector (nil)']
  827. !
  828. variables
  829. ^variables
  830. !
  831. setVariables: aCollection
  832. variables := aCollection
  833. !
  834. setLabel: aString
  835. label := aString
  836. !
  837. selectedVariable
  838. ^selectedVariable
  839. !
  840. selectedVariable: aString
  841. selectedVariable := aString
  842. ! !
  843. !Inspector methodsFor: 'actions'!
  844. inspect: anObject
  845. object := anObject.
  846. variables := #().
  847. object inspectOn: self
  848. !
  849. dive
  850. (self variables at: self selectedVariable) inspect
  851. !
  852. refresh
  853. self
  854. inspect: object;
  855. updateVariablesList;
  856. updateValueTextarea
  857. ! !
  858. !Inspector methodsFor: 'rendering'!
  859. renderBoxOn: html
  860. self
  861. renderTopPanelOn: html;
  862. renderBottomPanelOn: html
  863. !
  864. renderTopPanelOn: html
  865. html div
  866. class: 'top';
  867. with: [
  868. variablesList := html ul class: 'jt_column variables'.
  869. valueTextarea := html textarea class: 'jt_column value'; at: 'readonly' put: 'readonly'.
  870. self
  871. updateVariablesList;
  872. updateValueTextarea.
  873. html div class: 'jt_clear']
  874. !
  875. renderBottomPanelOn: html
  876. html div
  877. class: 'jt_sourceCode';
  878. with: [
  879. workspaceTextarea := html textarea
  880. class: 'source';
  881. at: 'spellcheck' put: 'false'.
  882. workspaceTextarea asJQuery call: 'tabby']
  883. !
  884. renderButtonsOn: html
  885. html button
  886. with: 'Refresh';
  887. onClick: [self refresh].
  888. diveButton := html button
  889. with: 'Dive';
  890. onClick: [self dive].
  891. self updateButtons
  892. ! !
  893. !Inspector methodsFor: 'testing'!
  894. canBeClosed
  895. ^true
  896. ! !
  897. !Inspector methodsFor: 'updating'!
  898. updateVariablesList
  899. variablesList contents: [:html |
  900. self variables keys do: [:each || li |
  901. li := html li.
  902. li
  903. with: each;
  904. onClick: [self selectVariable: each].
  905. self selectedVariable = each ifTrue: [
  906. li class: 'selected']]]
  907. !
  908. selectVariable: aString
  909. self selectedVariable: aString.
  910. self
  911. updateVariablesList;
  912. updateValueTextarea;
  913. updateButtons
  914. !
  915. updateValueTextarea
  916. valueTextarea asJQuery val: (self selectedVariable isNil
  917. ifTrue: ['']
  918. ifFalse: [(self variables at: self selectedVariable) printString])
  919. !
  920. updateButtons
  921. (self selectedVariable notNil and: [(self variables at: self selectedVariable) notNil])
  922. ifFalse: [diveButton at: 'disabled' put: true]
  923. ifTrue: [diveButton removeAt: 'disabled']
  924. ! !
  925. !Inspector class methodsFor: 'instance creation'!
  926. on: anObject
  927. ^self new
  928. inspect: anObject;
  929. yourself
  930. ! !
  931. TabWidget subclass: #ReferencesBrowser
  932. instanceVariableNames: 'implementors senders implementorsList input timer selector sendersList referencedClasses referencedClassesList'
  933. category: 'IDE'!
  934. !ReferencesBrowser methodsFor: 'accessing'!
  935. implementors
  936. ^implementors ifNil: [implementors := Array new]
  937. !
  938. label
  939. ^'[ReferencesBrowser]'
  940. !
  941. selector
  942. ^selector
  943. !
  944. senders
  945. ^senders ifNil: [senders := Array new]
  946. !
  947. classesAndMetaclasses
  948. ^Smalltalk current classes, (Smalltalk current classes collect: [:each | each class])
  949. !
  950. referencedClasses
  951. ^referencedClasses ifNil: [referencedClasses := Array new]
  952. ! !
  953. !ReferencesBrowser methodsFor: 'actions'!
  954. openBrowserOn: aMethod
  955. | browser |
  956. browser := Browser openOn: (aMethod class isMetaclass
  957. ifTrue: [aMethod methodClass instanceClass] ifFalse: [aMethod methodClass]).
  958. aMethod methodClass isMetaclass ifTrue: [browser selectTab: #class].
  959. browser
  960. selectProtocol: aMethod category;
  961. selectMethod: aMethod
  962. !
  963. searchReferencesFor: aString
  964. selector := aString.
  965. implementors := Array new.
  966. senders := Array new.
  967. referencedClasses := Array new.
  968. (selector match: '^[A-Z]')
  969. ifFalse: [self searchSelectorReferencesFor: selector]
  970. ifTrue: [self searchReferencedClassesFor: selector]
  971. !
  972. search: aString
  973. self
  974. searchReferencesFor: aString;
  975. updateImplementorsList;
  976. updateSendersList;
  977. updateReferencedClassesList
  978. !
  979. searchReferencedClassesFor: aString
  980. self classesAndMetaclasses do: [:each |
  981. each methodDictionary values do: [:value |
  982. (((value referencedClasses select: [:each | each notNil])collect: [:each | each name]) includes: selector) ifTrue: [
  983. self referencedClasses add: value]]]
  984. !
  985. searchSelectorReferencesFor: aString
  986. self classesAndMetaclasses do: [:each |
  987. each methodDictionary keysAndValuesDo: [:key :value |
  988. key = selector ifTrue: [self implementors add: value]].
  989. each methodDictionary keysAndValuesDo: [:key :value |
  990. (value messageSends includes: selector) ifTrue: [
  991. self senders add: value]]]
  992. ! !
  993. !ReferencesBrowser methodsFor: 'initialization'!
  994. initialize
  995. super initialize.
  996. selector := ''
  997. ! !
  998. !ReferencesBrowser methodsFor: 'private'!
  999. setInputEvents
  1000. input
  1001. onKeyUp: [timer := [self search: input asJQuery val] valueWithTimeout: 100];
  1002. onKeyDown: [timer ifNotNil: [timer clearTimeout]]
  1003. ! !
  1004. !ReferencesBrowser methodsFor: 'rendering'!
  1005. renderBoxOn: html
  1006. self
  1007. renderInputOn: html;
  1008. renderImplementorsOn: html;
  1009. renderSendersOn: html;
  1010. renderReferencedClassesOn: html
  1011. !
  1012. renderInputOn: html
  1013. input := html input
  1014. class: 'implementors';
  1015. yourself.
  1016. input asJQuery val: selector.
  1017. self setInputEvents
  1018. !
  1019. renderImplementorsOn: html
  1020. implementorsList := html ul class: 'jt_column implementors'.
  1021. self updateImplementorsList
  1022. !
  1023. renderSendersOn: html
  1024. sendersList := html ul class: 'jt_column senders'.
  1025. self updateSendersList
  1026. !
  1027. renderReferencedClassesOn: html
  1028. referencedClassesList := html ul class: 'jt_column referenced_classes'.
  1029. self updateReferencedClassesList
  1030. ! !
  1031. !ReferencesBrowser methodsFor: 'testing'!
  1032. canBeClosed
  1033. ^true
  1034. ! !
  1035. !ReferencesBrowser methodsFor: 'updating'!
  1036. updateImplementorsList
  1037. implementorsList contents: [:html |
  1038. html li
  1039. class: 'column_label';
  1040. with: 'Implementors (', self implementors size asString, ')';
  1041. style: 'font-weight: bold'.
  1042. self implementors do: [:each || li |
  1043. li := html li.
  1044. li
  1045. with: (each methodClass asString, ' >> ', self selector);
  1046. onClick: [self openBrowserOn: each]]]
  1047. !
  1048. updateSendersList
  1049. sendersList contents: [:html |
  1050. html li
  1051. class: 'column_label';
  1052. with: 'Senders (', self senders size asString, ')';
  1053. style: 'font-weight: bold'.
  1054. self senders do: [:each |
  1055. html li
  1056. with: (each methodClass asString, ' >> ', each selector);
  1057. onClick: [self openBrowserOn: each]]]
  1058. !
  1059. updateReferencedClassesList
  1060. referencedClassesList contents: [:html |
  1061. html li
  1062. class: 'column_label';
  1063. with: 'Class references (', self referencedClasses size asString, ')';
  1064. style: 'font-weight: bold'.
  1065. self referencedClasses do: [:each |
  1066. html li
  1067. with: (each methodClass asString, ' >> ', each selector);
  1068. onClick: [self openBrowserOn: each]]]
  1069. ! !
  1070. !ReferencesBrowser class methodsFor: 'instance creation'!
  1071. search: aString
  1072. ^self new
  1073. searchReferencesFor: aString;
  1074. open
  1075. ! !
  1076. Widget subclass: #SourceArea
  1077. instanceVariableNames: 'editor div'
  1078. category: 'IDE'!
  1079. !SourceArea methodsFor: 'accessing'!
  1080. val
  1081. ^editor getValue
  1082. !
  1083. val: aString
  1084. editor setValue: aString
  1085. !
  1086. currentLine
  1087. ^editor getLine: (editor getCursor line)
  1088. !
  1089. selection
  1090. ^editor getSelection
  1091. !
  1092. selectionEnd
  1093. ^textarea element selectionEnd
  1094. !
  1095. selectionStart
  1096. ^textarea element selectionStart
  1097. !
  1098. selectionStart: anInteger
  1099. textarea element selectionStart: anInteger
  1100. !
  1101. selectionEnd: anInteger
  1102. textarea element selectionEnd: anInteger
  1103. !
  1104. setEditorOn: aTextarea
  1105. <self['@editor'] = CodeMirror.fromTextArea(aTextarea, {
  1106. theme: 'jtalk',
  1107. lineNumbers: true,
  1108. enterMode: 'classic',
  1109. matchBrackets: true,
  1110. electricChars: false,
  1111. })>
  1112. !
  1113. editor
  1114. ^editor
  1115. ! !
  1116. !SourceArea methodsFor: 'actions'!
  1117. clear
  1118. textarea asJQuery val: ''
  1119. !
  1120. doIt
  1121. | selection |
  1122. editor somethingSelected
  1123. ifFalse: [selection := self currentLine]
  1124. ifTrue: [selection := self selection].
  1125. ^self eval: selection
  1126. !
  1127. eval: aString
  1128. | compiler node |
  1129. compiler := Compiler new.
  1130. node := compiler parseExpression: aString.
  1131. node isParseFailure ifTrue: [
  1132. ^self alert: node reason, ', position: ', node position].
  1133. ^compiler loadExpression: aString
  1134. !
  1135. handleKeyDown: anEvent
  1136. <if(anEvent.ctrlKey) {
  1137. if(anEvent.keyCode === 80) { //ctrl+p
  1138. self._printIt();
  1139. anEvent.preventDefault();
  1140. return false;
  1141. }
  1142. if(anEvent.keyCode === 68) { //ctrl+d
  1143. self._doIt();
  1144. anEvent.preventDefault();
  1145. return false;
  1146. }
  1147. if(anEvent.keyCode === 73) { //ctrl+i
  1148. self._inspectIt();
  1149. anEvent.preventDefault();
  1150. return false;
  1151. }
  1152. }>
  1153. !
  1154. inspectIt
  1155. self doIt inspect
  1156. !
  1157. print: aString
  1158. | start stop |
  1159. start := Dictionary new.
  1160. stop := Dictionary new.
  1161. start at: 'line' put: (editor getCursor: false) line.
  1162. start at: 'ch' put: (editor getCursor: false) ch.
  1163. stop at: 'line' put: (start at: 'line').
  1164. stop at: 'ch' put: ((start at: 'ch') + aString size + 2).
  1165. editor replaceSelection: (editor getSelection, ' ', aString, ' ').
  1166. editor setCursor: (editor getCursor: true).
  1167. editor setSelection: stop end: start
  1168. !
  1169. printIt
  1170. self print: self doIt printString
  1171. ! !
  1172. !SourceArea methodsFor: 'events'!
  1173. onKeyUp: aBlock
  1174. div onKeyUp: aBlock
  1175. !
  1176. onKeyDown: aBlock
  1177. div onKeyDown: aBlock
  1178. ! !
  1179. !SourceArea methodsFor: 'rendering'!
  1180. renderOn: html
  1181. | textarea |
  1182. div := html div class: 'source'.
  1183. div with: [textarea := html textarea].
  1184. self setEditorOn: textarea element.
  1185. div onKeyDown: [:e | self handleKeyDown: e]
  1186. ! !
  1187. Widget subclass: #ClassesList
  1188. instanceVariableNames: 'browser ul nodes'
  1189. category: 'IDE'!
  1190. !ClassesList methodsFor: 'accessing'!
  1191. category
  1192. ^self browser selectedCategory
  1193. !
  1194. nodes
  1195. nodes ifNil: [nodes := self getNodes].
  1196. ^nodes
  1197. !
  1198. browser
  1199. ^browser
  1200. !
  1201. browser: aBrowser
  1202. browser := aBrowser
  1203. !
  1204. getNodes
  1205. | classes children others |
  1206. classes := self browser classes.
  1207. children := #().
  1208. others := #().
  1209. classes do: [:each |
  1210. (classes includes: each superclass)
  1211. ifFalse: [children add: each]
  1212. ifTrue: [others add: each]].
  1213. ^children collect: [:each |
  1214. ClassesListNode on: each browser: self browser classes: others level: 0]
  1215. !
  1216. resetNodes
  1217. nodes := nil
  1218. ! !
  1219. !ClassesList methodsFor: 'rendering'!
  1220. renderOn: html
  1221. ul := html ul
  1222. class: 'jt_column browser classes';
  1223. yourself.
  1224. self updateNodes
  1225. !
  1226. updateNodes
  1227. ul contents: [:html |
  1228. self nodes do: [:each |
  1229. each renderOn: html]]
  1230. ! !
  1231. !ClassesList class methodsFor: 'instance creation'!
  1232. on: aBrowser
  1233. ^self new
  1234. browser: aBrowser;
  1235. yourself
  1236. ! !
  1237. Widget subclass: #ClassesListNode
  1238. instanceVariableNames: 'browser theClass level nodes'
  1239. category: 'IDE'!
  1240. !ClassesListNode methodsFor: 'accessing'!
  1241. nodes
  1242. ^nodes
  1243. !
  1244. theClass
  1245. ^theClass
  1246. !
  1247. theClass: aClass
  1248. theClass := aClass
  1249. !
  1250. browser
  1251. ^browser
  1252. !
  1253. browser: aBrowser
  1254. browser := aBrowser
  1255. !
  1256. level
  1257. ^level
  1258. !
  1259. level: anInteger
  1260. level := anInteger
  1261. !
  1262. label
  1263. | str |
  1264. str := String new writeStream.
  1265. self level timesRepeat: [
  1266. str nextPutAll: '&nbsp;&nbsp;&nbsp;&nbsp;'].
  1267. str nextPutAll: self theClass name.
  1268. ^str contents
  1269. !
  1270. getNodesFrom: aCollection
  1271. | children others |
  1272. children := #().
  1273. others := #().
  1274. aCollection do: [:each |
  1275. (each superclass = self theClass)
  1276. ifTrue: [children add: each]
  1277. ifFalse: [others add: each]].
  1278. nodes:= children collect: [:each |
  1279. ClassesListNode on: each browser: self browser classes: others level: self level + 1]
  1280. ! !
  1281. !ClassesListNode methodsFor: 'rendering'!
  1282. renderOn: html
  1283. | li |
  1284. li := html li
  1285. onClick: [self browser selectClass: self theClass].
  1286. li asJQuery contents: self label.
  1287. self browser selectedClass = self theClass ifTrue: [
  1288. li class: 'selected'].
  1289. self nodes do: [:each |
  1290. each renderOn: html]
  1291. ! !
  1292. !ClassesListNode class methodsFor: 'instance creation'!
  1293. on: aClass browser: aBrowser classes: aCollection level: anInteger
  1294. ^self new
  1295. theClass: aClass;
  1296. browser: aBrowser;
  1297. level: anInteger;
  1298. getNodesFrom: aCollection;
  1299. yourself
  1300. ! !
  1301. TabWidget subclass: #Debugger
  1302. instanceVariableNames: 'error selectedContext sourceArea ul'
  1303. category: 'IDE'!
  1304. !Debugger methodsFor: 'accessing'!
  1305. error
  1306. ^error
  1307. !
  1308. error: anError
  1309. error := anError
  1310. !
  1311. label
  1312. ^'[Debugger]'
  1313. ! !
  1314. !Debugger methodsFor: 'actions'!
  1315. selectContext: aContext
  1316. selectedContext := aContext.
  1317. self updateContextsList.
  1318. self updateSourceArea
  1319. ! !
  1320. !Debugger methodsFor: 'rendering'!
  1321. renderBoxOn: html
  1322. self
  1323. renderTopPanelOn: html;
  1324. renderBottomPanelOn: html
  1325. !
  1326. renderTopPanelOn: html
  1327. selectedContext := self error context.
  1328. html div
  1329. class: 'top';
  1330. with: [
  1331. html div
  1332. class: 'label';
  1333. with: self error messageText.
  1334. ul := html ul
  1335. class: 'jt_column debugger contexts';
  1336. with: [self renderContext: self error context on: html]]
  1337. !
  1338. renderContext: aContext on: html
  1339. | li |
  1340. li := html li.
  1341. selectedContext = aContext ifTrue: [
  1342. li class: 'selected'].
  1343. li
  1344. with: aContext asString;
  1345. onClick: [self selectContext: aContext].
  1346. aContext home ifNotNil: [self renderContext: aContext home on: html]
  1347. !
  1348. renderBottomPanelOn: html
  1349. html div
  1350. class: 'jt_sourceCode';
  1351. with: [
  1352. sourceArea := SourceArea new.
  1353. sourceArea renderOn: html].
  1354. self updateSourceArea
  1355. ! !
  1356. !Debugger methodsFor: 'testing'!
  1357. canBeClosed
  1358. ^true
  1359. ! !
  1360. !Debugger methodsFor: 'updating'!
  1361. updateContextsList
  1362. ul contents: [:html |
  1363. self renderContext: self error context on: html]
  1364. !
  1365. updateSourceArea
  1366. sourceArea val: (selectedContext receiver class methodAt: selectedContext selector) source
  1367. ! !
  1368. ErrorHandler subclass: #DebugErrorHandler
  1369. instanceVariableNames: ''
  1370. category: 'IDE'!
  1371. !DebugErrorHandler methodsFor: 'error handling'!
  1372. handleError: anError
  1373. [Debugger new
  1374. error: anError;
  1375. open] on: Error do: [:error |
  1376. ErrorHandler new handleError: error]
  1377. ! !
  1378. !DebugErrorHandler class methodsFor: 'initialization'!
  1379. initialize
  1380. self register
  1381. ! !
  1382. TabWidget subclass: #ProgressBar
  1383. instanceVariableNames: 'percent progressDiv div'
  1384. category: 'IDE'!
  1385. !ProgressBar methodsFor: 'accessing'!
  1386. percent
  1387. ^percent ifNil: [0]
  1388. !
  1389. percent: aNumber
  1390. percent := aNumber
  1391. ! !
  1392. !ProgressBar methodsFor: 'rendering'!
  1393. renderOn: html
  1394. div := html div
  1395. class: 'progress_bar';
  1396. yourself.
  1397. self renderProgressBar
  1398. !
  1399. renderProgressBar
  1400. div contents: [:html |
  1401. html div
  1402. class: 'progress';
  1403. style: 'width:', self percent asString, '%']
  1404. ! !
  1405. !ProgressBar methodsFor: 'updating'!
  1406. updatePercent: aNumber
  1407. self percent: aNumber.
  1408. self renderProgressBar
  1409. ! !
  1410. TabWidget subclass: #TestRunner
  1411. instanceVariableNames: 'selectedCategories categoriesList selectedClasses classesList selectedMethods progressBar methodsList result statusDiv'
  1412. category: 'IDE'!
  1413. !TestRunner methodsFor: 'accessing'!
  1414. label
  1415. ^'[Test runner]'
  1416. !
  1417. categories
  1418. | categories |
  1419. categories := Array new.
  1420. self allClasses do: [:each |
  1421. (categories includes: each category) ifFalse: [
  1422. categories add: each category]].
  1423. ^categories sort
  1424. !
  1425. classes
  1426. ^(self allClasses
  1427. select: [:each | self selectedCategories includes: each category])
  1428. sort: [:a :b | a name > b name]
  1429. !
  1430. selectedCategories
  1431. ^selectedCategories ifNil: [selectedCategories := Array new]
  1432. !
  1433. allClasses
  1434. ^TestCase allSubclasses
  1435. !
  1436. selectedClasses
  1437. ^selectedClasses ifNil: [selectedClasses := Array new]
  1438. !
  1439. progressBar
  1440. ^progressBar ifNil: [progressBar := ProgressBar new]
  1441. !
  1442. selectedMethods
  1443. ^selectedMethods ifNil: [self selectedClasses collect: [:each |
  1444. each methodDictionary keys select: [:key | key beginsWith: 'test' ]]]
  1445. !
  1446. statusInfo
  1447. ^self printTotal, self printPasses, self printErrors, self printFailures
  1448. !
  1449. result
  1450. ^result
  1451. !
  1452. failedMethods
  1453. self result failures collect: [:each |
  1454. html li
  1455. class: 'failures';
  1456. with: each]
  1457. ! !
  1458. !TestRunner methodsFor: 'actions'!
  1459. selectAllCategories
  1460. self categories do: [:each |
  1461. (selectedCategories includes: each) ifFalse: [
  1462. self selectedCategories add: each]].
  1463. self
  1464. updateCategoriesList;
  1465. updateClassesList
  1466. !
  1467. toggleCategory: aCategory
  1468. (self isSelectedCategory: aCategory)
  1469. ifFalse: [selectedCategories add: aCategory]
  1470. ifTrue: [selectedCategories remove: aCategory].
  1471. self
  1472. updateCategoriesList;
  1473. updateClassesList
  1474. !
  1475. toggleClass: aClass
  1476. (self isSelectedClass: aClass)
  1477. ifFalse: [selectedClasses add: aClass]
  1478. ifTrue: [selectedClasses remove: aClass].
  1479. self
  1480. updateClassesList
  1481. !
  1482. selectAllClasses
  1483. self classes do: [:each |
  1484. (selectedClasses includes: each) ifFalse: [
  1485. self selectedClasses add: each]].
  1486. self
  1487. updateCategoriesList;
  1488. updateClassesList
  1489. !
  1490. run: aCollection
  1491. result := TestResult new.
  1492. self
  1493. updateStatusDiv;
  1494. updateMethodsList.
  1495. self progressBar updatePercent: 0.
  1496. result total: (aCollection inject: 0 into: [:acc :each | acc + each methods size]).
  1497. aCollection do: [:each |
  1498. [each runCaseFor: result.
  1499. self progressBar updatePercent: result runs / result total * 100.
  1500. self updateStatusDiv.
  1501. self updateMethodsList] valueWithTimeout: 100].
  1502. ! !
  1503. !TestRunner methodsFor: 'initialization'!
  1504. initialize
  1505. super initialize.
  1506. result := TestResult new
  1507. ! !
  1508. !TestRunner methodsFor: 'printing'!
  1509. printErrors
  1510. ^self result errors size asString , ' errors, '
  1511. !
  1512. printFailures
  1513. ^self result failures size asString, ' failures'
  1514. !
  1515. printPasses
  1516. ^(((self result total) - (self result errors size + (self result failures size))) asString) , ' passes, '
  1517. !
  1518. printTotal
  1519. ^self result total asString, ' runs, '
  1520. ! !
  1521. !TestRunner methodsFor: 'rendering'!
  1522. renderBoxOn: html
  1523. self
  1524. renderCategoriesOn: html;
  1525. renderClassesOn: html;
  1526. renderResultsOn: html
  1527. !
  1528. renderButtonsOn: html
  1529. html button
  1530. with: 'Run selected';
  1531. onClick: [self run: (self selectedClasses collect: [:each | each new])]
  1532. !
  1533. renderCategoriesOn: html
  1534. categoriesList := html ul class: 'jt_column sunit categories'.
  1535. self updateCategoriesList
  1536. !
  1537. renderClassesOn: html
  1538. classesList := html ul class: 'jt_column sunit classes'.
  1539. self updateClassesList
  1540. !
  1541. renderResultsOn: html
  1542. statusDiv := html div.
  1543. html with: self progressBar.
  1544. methodsList := html ul class: 'jt_column sunit methods'.
  1545. self updateMethodsList.
  1546. self updateStatusDiv
  1547. !
  1548. renderFailuresOn: html
  1549. self result failures do: [:each |
  1550. html li
  1551. class: 'failures';
  1552. with: each]
  1553. !
  1554. renderErrorsOn: html
  1555. self result errors do: [:each |
  1556. html li
  1557. class: 'errors';
  1558. with: each]
  1559. ! !
  1560. !TestRunner methodsFor: 'testing'!
  1561. isSelectedClass: aClass
  1562. ^(self selectedClasses includes: aClass)
  1563. !
  1564. isSelectedCategory: aCategory
  1565. ^(self selectedCategories includes: aCategory)
  1566. ! !
  1567. !TestRunner methodsFor: 'updating'!
  1568. updateCategoriesList
  1569. categoriesList contents: [:html |
  1570. html li
  1571. class: 'all';
  1572. with: 'All';
  1573. onClick: [self selectAllCategories].
  1574. self categories do: [:each || li |
  1575. li := html li.
  1576. (self selectedCategories includes: each) ifTrue: [
  1577. li class: 'selected'].
  1578. li
  1579. with: each;
  1580. onClick: [self toggleCategory: each]]]
  1581. !
  1582. updateClassesList
  1583. classesList contents: [:html |
  1584. (self selectedCategories isEmpty) ifFalse: [
  1585. html li
  1586. class: 'all';
  1587. with: 'All';
  1588. onClick: [self selectAllClasses]].
  1589. self classes do: [:each || li |
  1590. li := html li.
  1591. (self selectedClasses includes: each) ifTrue: [
  1592. li class: 'selected'].
  1593. li
  1594. with: each name;
  1595. onClick: [self toggleClass: each]]]
  1596. !
  1597. updateMethodsList
  1598. methodsList contents: [:html |
  1599. self renderFailuresOn: html.
  1600. self renderErrorsOn: html]
  1601. !
  1602. updateStatusDiv
  1603. statusDiv class: 'sunit status ', result status.
  1604. statusDiv contents: [:html |
  1605. html span with: self statusInfo]
  1606. ! !
  1607. !Object methodsFor: '*IDE'!
  1608. inspect
  1609. Inspector new
  1610. inspect: self;
  1611. open
  1612. !
  1613. inspectOn: anInspector
  1614. | variables |
  1615. variables := Dictionary new.
  1616. variables at: '#self' put: self.
  1617. self class allInstanceVariableNames do: [:each |
  1618. variables at: each put: (self instVarAt: each)].
  1619. anInspector
  1620. setLabel: self printString;
  1621. setVariables: variables
  1622. ! !
  1623. !Date methodsFor: '*IDE'!
  1624. inspectOn: anInspector
  1625. | variables |
  1626. variables := Dictionary new.
  1627. variables at: '#self' put: self.
  1628. variables at: '#year' put: self year.
  1629. variables at: '#month' put: self month.
  1630. variables at: '#day' put: self day.
  1631. variables at: '#hours' put: self hours.
  1632. variables at: '#minutes' put: self minutes.
  1633. variables at: '#seconds' put: self seconds.
  1634. variables at: '#milliseconds' put: self milliseconds.
  1635. anInspector
  1636. setLabel: self printString;
  1637. setVariables: variables
  1638. ! !
  1639. !Collection methodsFor: '*IDE'!
  1640. inspectOn: anInspector
  1641. | variables |
  1642. variables := Dictionary new.
  1643. variables at: '#self' put: self.
  1644. self withIndexDo: [:each :i |
  1645. variables at: i put: each].
  1646. anInspector
  1647. setLabel: self printString;
  1648. setVariables: variables
  1649. ! !
  1650. !String methodsFor: '*IDE'!
  1651. inspectOn: anInspector
  1652. | label |
  1653. super inspectOn: anInspector.
  1654. self printString size > 30
  1655. ifTrue: [label := (self printString copyFrom: 1 to: 30), '...''']
  1656. ifFalse: [label := self printString].
  1657. anInspector setLabel: label
  1658. ! !
  1659. !MethodContext methodsFor: '*IDE'!
  1660. inspectOn: anInspector
  1661. | variables |
  1662. variables := Dictionary new.
  1663. variables at: '#self' put: self.
  1664. variables at: '#home' put: self home.
  1665. variables at: '#receiver' put: self receiver.
  1666. variables at: '#selector' put: self selector.
  1667. variables at: '#temps' put: self temps.
  1668. self class instanceVariableNames do: [:each |
  1669. variables at: each put: (self instVarAt: each)].
  1670. anInspector
  1671. setLabel: self printString;
  1672. setVariables: variables
  1673. ! !
  1674. !Dictionary methodsFor: '*IDE'!
  1675. inspectOn: anInspector
  1676. | variables |
  1677. variables := Dictionary new.
  1678. variables at: '#self' put: self.
  1679. variables at: '#keys' put: self keys.
  1680. self keysAndValuesDo: [:key :value |
  1681. variables at: key put: value].
  1682. anInspector
  1683. setLabel: self printString;
  1684. setVariables: variables
  1685. ! !