IDE.st 45 KB

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