IDE.st 41 KB

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