IDE.st 47 KB

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