IDE.st 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302
  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 package |
  655. package := Smalltalk current packageAt: selectedPackage.
  656. newName := self prompt: 'Rename package ', selectedPackage.
  657. newName notEmpty ifTrue: [
  658. Smalltalk current renamePackage: selectedPackage to: newName.
  659. self updateCategoriesList]
  660. !
  661. removePackage
  662. | package |
  663. package := Smalltalk current packageAt: selectedPackage.
  664. (self confirm: 'Do you really want to remove the whole package ', package name, ' with all its classes?')
  665. ifTrue: [
  666. Smalltalk current removePackage: package name.
  667. self updateCategoriesList]
  668. ! !
  669. !Browser methodsFor: 'initialization'!
  670. initialize
  671. super initialize.
  672. selectedTab := #instance.
  673. unsavedChanges := false
  674. ! !
  675. !Browser methodsFor: 'rendering'!
  676. renderBoxOn: html
  677. self
  678. renderTopPanelOn: html;
  679. renderTabsOn: html;
  680. renderBottomPanelOn: html
  681. !
  682. renderTopPanelOn: html
  683. html div
  684. class: 'top';
  685. with: [
  686. packagesList := html ul class: 'jt_column browser packages'.
  687. commitButton := html button
  688. class: 'jt_commit';
  689. title: 'Commit classes in this package to disk';
  690. onClick: [self commitPackage];
  691. with: 'Commit package'.
  692. renameButton := html button
  693. class: 'jt_rename';
  694. title: 'Rename this package';
  695. onClick: [self renamePackage];
  696. with: 'Rename package'.
  697. deleteButton := html button
  698. class: 'jt_delete';
  699. title: 'Remove this package from the system';
  700. onClick: [self removePackage];
  701. with: 'Remove package'.
  702. classesList := ClassesList on: self.
  703. classesList renderOn: html.
  704. protocolsList := html ul class: 'jt_column browser protocols'.
  705. methodsList := html ul class: 'jt_column browser methods'.
  706. self
  707. updateCategoriesList;
  708. updateClassesList;
  709. updateProtocolsList;
  710. updateMethodsList.
  711. html div class: 'jt_clear']
  712. !
  713. renderTabsOn: html
  714. tabsList := html ul class: 'jt_tabs jt_browser'.
  715. self updateTabsList.
  716. !
  717. renderBottomPanelOn: html
  718. html div
  719. class: 'jt_sourceCode';
  720. with: [
  721. sourceArea := SourceArea new.
  722. sourceArea renderOn: html.
  723. sourceArea onKeyDown: [:e |
  724. self handleSourceAreaKeyDown: e].
  725. sourceArea onKeyUp: [self updateStatus]]
  726. !
  727. renderButtonsOn: html
  728. saveButton := html button.
  729. saveButton
  730. with: 'Save';
  731. onClick: [self compile].
  732. methodButtons := html span.
  733. classButtons := html span.
  734. html div
  735. class: 'right';
  736. with: [
  737. html button
  738. with: 'DoIt';
  739. onClick: [sourceArea doIt].
  740. html button
  741. with: 'PrintIt';
  742. onClick: [sourceArea printIt].
  743. html button with: 'InspectIt';
  744. onClick: [sourceArea inspectIt]].
  745. self updateSourceAndButtons
  746. ! !
  747. !Browser methodsFor: 'testing'!
  748. canBeClosed
  749. ^true
  750. ! !
  751. !Browser methodsFor: 'updating'!
  752. updateCategoriesList
  753. packagesList contents: [:html |
  754. self packages do: [:each || li label |
  755. each isEmpty
  756. ifTrue: [label := 'Unclassified']
  757. ifFalse: [label := each].
  758. li := html li.
  759. selectedPackage = each ifTrue: [
  760. li class: 'selected'].
  761. li
  762. with: label;
  763. onClick: [self selectCategory: each]]]
  764. !
  765. updateClassesList
  766. TabManager current update.
  767. classesList updateNodes.
  768. "classesList contents: [:html |
  769. self classes do: [:each || li |
  770. li := html li.
  771. selectedClass = each ifTrue: [
  772. li class: 'selected'].
  773. li
  774. with: each name;
  775. onClick: [self selectClass: each]]]"
  776. !
  777. updateProtocolsList
  778. protocolsList contents: [:html |
  779. self protocols do: [:each || li |
  780. li := html li.
  781. selectedProtocol = each ifTrue: [
  782. li class: 'selected'].
  783. li
  784. with: each;
  785. onClick: [self selectProtocol: each]]]
  786. !
  787. updateMethodsList
  788. methodsList contents: [:html |
  789. self methods do: [:each || li |
  790. li := html li.
  791. selectedMethod = each ifTrue: [
  792. li class: 'selected'].
  793. li
  794. with: each selector;
  795. onClick: [self selectMethod: each]]]
  796. !
  797. updateTabsList
  798. tabsList contents: [:html || li |
  799. li := html li.
  800. selectedTab = #instance ifTrue: [li class: 'selected'].
  801. li
  802. with: [
  803. html span class: 'ltab'.
  804. html span class: 'mtab'; with: 'Instance'.
  805. html span class: 'rtab'];
  806. onClick: [self selectTab: #instance].
  807. li := html li.
  808. selectedTab = #class ifTrue: [li class: 'selected'].
  809. li
  810. with: [
  811. html span class: 'ltab'.
  812. html span class: 'mtab'; with: 'Class'.
  813. html span class: 'rtab'];
  814. onClick: [self selectTab: #class].
  815. li := html li.
  816. selectedTab = #comment ifTrue: [li class: 'selected'].
  817. li
  818. with: [
  819. html span class: 'ltab'.
  820. html span class: 'mtab'; with: 'Comment'.
  821. html span class: 'rtab'];
  822. onClick: [self selectTab: #comment]]
  823. !
  824. updateSourceAndButtons
  825. self disableSaveButton.
  826. classButtons contents: [:html |
  827. html button
  828. with: 'Rename class';
  829. onClick: [self renameClass].
  830. html button
  831. with: 'Remove class';
  832. onClick: [self removeClass].
  833. html button
  834. with: 'References';
  835. onClick: [self searchClassReferences]].
  836. methodButtons contents: [:html |
  837. html button
  838. with: 'Remove method';
  839. onClick: [self removeMethod].
  840. html select
  841. onChange: [:e :select | self setMethodProtocol: select val];
  842. with: [
  843. html option
  844. with: 'Method protocol';
  845. at: 'disabled' put: 'disabled'.
  846. html option
  847. class: 'important';
  848. with: 'New...'.
  849. self protocols do: [:each |
  850. html option with: each]].
  851. selectedMethod isNil ifFalse: [
  852. html select
  853. onChange: [:e :select | self searchReferencesOf: select val];
  854. with: [
  855. html option
  856. with: 'References';
  857. at: 'disabled' put: 'disabled'.
  858. html option
  859. class: 'important';
  860. with: selectedMethod selector.
  861. selectedMethod messageSends sorted do: [:each |
  862. html option with: each]]]].
  863. selectedMethod isNil
  864. ifTrue: [
  865. self hideMethodButtons.
  866. (selectedClass isNil or: [selectedProtocol notNil])
  867. ifTrue: [self hideClassButtons]
  868. ifFalse: [self showClassButtons]]
  869. ifFalse: [
  870. self hideClassButtons.
  871. self showMethodButtons].
  872. sourceArea val: self source
  873. !
  874. updateStatus
  875. sourceArea val = self source
  876. ifTrue: [
  877. saveButton ifNotNil: [
  878. saveButton at: 'disabled' put: true].
  879. unsavedChanges := false]
  880. ifFalse: [
  881. saveButton ifNotNil: [
  882. saveButton removeAt: 'disabled'].
  883. unsavedChanges := true]
  884. !
  885. resetClassesList
  886. classesList resetNodes
  887. ! !
  888. !Browser class methodsFor: 'accessing'!
  889. commitPathJs
  890. ^'js'
  891. !
  892. commitPathSt
  893. ^'st'
  894. ! !
  895. !Browser class methodsFor: 'convenience'!
  896. openOn: aClass
  897. ^self new
  898. open;
  899. selectCategory: aClass category;
  900. selectClass: aClass
  901. !
  902. open
  903. self new open
  904. ! !
  905. TabWidget subclass: #Inspector
  906. instanceVariableNames: 'label variables object selectedVariable variablesList valueTextarea diveButton sourceArea'
  907. category: 'IDE'!
  908. !Inspector methodsFor: 'accessing'!
  909. label
  910. ^label ifNil: ['Inspector (nil)']
  911. !
  912. variables
  913. ^variables
  914. !
  915. setVariables: aCollection
  916. variables := aCollection
  917. !
  918. setLabel: aString
  919. label := aString
  920. !
  921. selectedVariable
  922. ^selectedVariable
  923. !
  924. selectedVariable: aString
  925. selectedVariable := aString
  926. !
  927. sourceArea
  928. ^sourceArea
  929. ! !
  930. !Inspector methodsFor: 'actions'!
  931. inspect: anObject
  932. object := anObject.
  933. variables := #().
  934. object inspectOn: self
  935. !
  936. dive
  937. (self variables at: self selectedVariable) inspect
  938. !
  939. refresh
  940. self
  941. inspect: object;
  942. updateVariablesList;
  943. updateValueTextarea
  944. ! !
  945. !Inspector methodsFor: 'rendering'!
  946. renderBoxOn: html
  947. self
  948. renderTopPanelOn: html;
  949. renderBottomPanelOn: html
  950. !
  951. renderTopPanelOn: html
  952. html div
  953. class: 'top';
  954. with: [
  955. variablesList := html ul class: 'jt_column variables'.
  956. valueTextarea := html textarea class: 'jt_column value'; at: 'readonly' put: 'readonly'.
  957. html div class: 'jt_tabs inspector'; with: [
  958. html button
  959. class: 'jt_button inspector refresh';
  960. with: 'Refresh';
  961. onClick: [self refresh].
  962. diveButton := html button
  963. class: 'jt_button inspector dive';
  964. with: 'Dive';
  965. onClick: [self dive]].
  966. html div class: 'jt_clear'].
  967. self
  968. updateVariablesList;
  969. updateValueTextarea.
  970. !
  971. renderBottomPanelOn: html
  972. html div
  973. class: 'jt_sourceCode';
  974. with: [
  975. sourceArea := SourceArea new
  976. receiver: object;
  977. onDoIt: [self refresh];
  978. yourself.
  979. sourceArea renderOn: html]
  980. !
  981. renderButtonsOn: html
  982. html button
  983. with: 'DoIt';
  984. onClick: [self sourceArea doIt].
  985. html button
  986. with: 'PrintIt';
  987. onClick: [self sourceArea printIt].
  988. html button
  989. with: 'InspectIt';
  990. onClick: [self sourceArea inspectIt].
  991. self updateButtons
  992. ! !
  993. !Inspector methodsFor: 'testing'!
  994. canBeClosed
  995. ^true
  996. ! !
  997. !Inspector methodsFor: 'updating'!
  998. updateVariablesList
  999. variablesList contents: [:html |
  1000. self variables keys do: [:each || li |
  1001. li := html li.
  1002. li
  1003. with: each;
  1004. onClick: [self selectVariable: each].
  1005. self selectedVariable = each ifTrue: [
  1006. li class: 'selected']]]
  1007. !
  1008. selectVariable: aString
  1009. self selectedVariable: aString.
  1010. self
  1011. updateVariablesList;
  1012. updateValueTextarea;
  1013. updateButtons
  1014. !
  1015. updateValueTextarea
  1016. valueTextarea asJQuery val: (self selectedVariable isNil
  1017. ifTrue: ['']
  1018. ifFalse: [(self variables at: self selectedVariable) printString])
  1019. !
  1020. updateButtons
  1021. (self selectedVariable notNil and: [(self variables at: self selectedVariable) notNil])
  1022. ifFalse: [diveButton at: 'disabled' put: true]
  1023. ifTrue: [diveButton removeAt: 'disabled']
  1024. ! !
  1025. !Inspector class methodsFor: 'instance creation'!
  1026. on: anObject
  1027. ^self new
  1028. inspect: anObject;
  1029. yourself
  1030. ! !
  1031. TabWidget subclass: #ReferencesBrowser
  1032. instanceVariableNames: 'implementors senders implementorsList input timer selector sendersList referencedClasses referencedClassesList'
  1033. category: 'IDE'!
  1034. !ReferencesBrowser methodsFor: 'accessing'!
  1035. implementors
  1036. ^implementors ifNil: [implementors := Array new]
  1037. !
  1038. label
  1039. ^'[References]'
  1040. !
  1041. selector
  1042. ^selector
  1043. !
  1044. senders
  1045. ^senders ifNil: [senders := Array new]
  1046. !
  1047. classesAndMetaclasses
  1048. ^Smalltalk current classes, (Smalltalk current classes collect: [:each | each class])
  1049. !
  1050. referencedClasses
  1051. ^referencedClasses ifNil: [referencedClasses := Array new]
  1052. ! !
  1053. !ReferencesBrowser methodsFor: 'actions'!
  1054. openBrowserOn: aMethod
  1055. | browser |
  1056. browser := Browser openOn: (aMethod methodClass isMetaclass
  1057. ifTrue: [aMethod methodClass instanceClass] ifFalse: [aMethod methodClass]).
  1058. aMethod methodClass isMetaclass ifTrue: [browser selectTab: #class].
  1059. browser
  1060. selectProtocol: aMethod category;
  1061. selectMethod: aMethod
  1062. !
  1063. searchReferencesFor: aString
  1064. selector := aString.
  1065. implementors := Array new.
  1066. senders := Array new.
  1067. referencedClasses := Array new.
  1068. (selector match: '^[A-Z]')
  1069. ifFalse: [self searchSelectorReferencesFor: selector]
  1070. ifTrue: [self searchReferencedClassesFor: selector]
  1071. !
  1072. search: aString
  1073. self
  1074. searchReferencesFor: aString;
  1075. updateImplementorsList;
  1076. updateSendersList;
  1077. updateReferencedClassesList
  1078. !
  1079. searchReferencedClassesFor: aString
  1080. self classesAndMetaclasses do: [:each |
  1081. each methodDictionary values do: [:value |
  1082. (((value referencedClasses select: [:each | each notNil])collect: [:each | each name]) includes: selector) ifTrue: [
  1083. self referencedClasses add: value]]]
  1084. !
  1085. searchSelectorReferencesFor: aString
  1086. self classesAndMetaclasses do: [:each |
  1087. each methodDictionary keysAndValuesDo: [:key :value |
  1088. key = selector ifTrue: [self implementors add: value]].
  1089. each methodDictionary keysAndValuesDo: [:key :value |
  1090. (value messageSends includes: selector) ifTrue: [
  1091. self senders add: value]]]
  1092. ! !
  1093. !ReferencesBrowser methodsFor: 'initialization'!
  1094. initialize
  1095. super initialize.
  1096. selector := ''
  1097. ! !
  1098. !ReferencesBrowser methodsFor: 'private'!
  1099. setInputEvents
  1100. input
  1101. onKeyUp: [timer := [self search: input asJQuery val] valueWithTimeout: 100];
  1102. onKeyDown: [timer ifNotNil: [timer clearTimeout]]
  1103. ! !
  1104. !ReferencesBrowser methodsFor: 'rendering'!
  1105. renderBoxOn: html
  1106. self
  1107. renderInputOn: html;
  1108. renderImplementorsOn: html;
  1109. renderSendersOn: html;
  1110. renderReferencedClassesOn: html
  1111. !
  1112. renderInputOn: html
  1113. input := html input
  1114. class: 'implementors';
  1115. yourself.
  1116. input asJQuery val: selector.
  1117. self setInputEvents
  1118. !
  1119. renderImplementorsOn: html
  1120. implementorsList := html ul class: 'jt_column implementors'.
  1121. self updateImplementorsList
  1122. !
  1123. renderSendersOn: html
  1124. sendersList := html ul class: 'jt_column senders'.
  1125. self updateSendersList
  1126. !
  1127. renderReferencedClassesOn: html
  1128. referencedClassesList := html ul class: 'jt_column referenced_classes'.
  1129. self updateReferencedClassesList
  1130. ! !
  1131. !ReferencesBrowser methodsFor: 'testing'!
  1132. canBeClosed
  1133. ^true
  1134. ! !
  1135. !ReferencesBrowser methodsFor: 'updating'!
  1136. updateImplementorsList
  1137. implementorsList contents: [:html |
  1138. html li
  1139. class: 'column_label';
  1140. with: 'Implementors (', self implementors size asString, ')';
  1141. style: 'font-weight: bold'.
  1142. self implementors do: [:each || li |
  1143. li := html li.
  1144. li
  1145. with: (each methodClass asString, ' >> ', self selector);
  1146. onClick: [self openBrowserOn: each]]]
  1147. !
  1148. updateSendersList
  1149. sendersList contents: [:html |
  1150. html li
  1151. class: 'column_label';
  1152. with: 'Senders (', self senders size asString, ')';
  1153. style: 'font-weight: bold'.
  1154. self senders do: [:each |
  1155. html li
  1156. with: (each methodClass asString, ' >> ', each selector);
  1157. onClick: [self openBrowserOn: each]]]
  1158. !
  1159. updateReferencedClassesList
  1160. referencedClassesList contents: [:html |
  1161. html li
  1162. class: 'column_label';
  1163. with: 'Class references (', self referencedClasses size asString, ')';
  1164. style: 'font-weight: bold'.
  1165. self referencedClasses do: [:each |
  1166. html li
  1167. with: (each methodClass asString, ' >> ', each selector);
  1168. onClick: [self openBrowserOn: each]]]
  1169. ! !
  1170. !ReferencesBrowser class methodsFor: 'instance creation'!
  1171. search: aString
  1172. ^self new
  1173. searchReferencesFor: aString;
  1174. open
  1175. ! !
  1176. Widget subclass: #SourceArea
  1177. instanceVariableNames: 'editor div receiver onDoIt'
  1178. category: 'IDE'!
  1179. !SourceArea methodsFor: 'accessing'!
  1180. val
  1181. ^editor getValue
  1182. !
  1183. val: aString
  1184. editor setValue: aString
  1185. !
  1186. currentLine
  1187. ^editor getLine: (editor getCursor line)
  1188. !
  1189. selection
  1190. ^editor getSelection
  1191. !
  1192. selectionEnd
  1193. ^textarea element selectionEnd
  1194. !
  1195. selectionStart
  1196. ^textarea element selectionStart
  1197. !
  1198. selectionStart: anInteger
  1199. textarea element selectionStart: anInteger
  1200. !
  1201. selectionEnd: anInteger
  1202. textarea element selectionEnd: anInteger
  1203. !
  1204. setEditorOn: aTextarea
  1205. <self['@editor'] = CodeMirror.fromTextArea(aTextarea, {
  1206. theme: 'jtalk',
  1207. lineNumbers: true,
  1208. enterMode: 'classic',
  1209. matchBrackets: true,
  1210. electricChars: false,
  1211. })>
  1212. !
  1213. editor
  1214. ^editor
  1215. !
  1216. receiver
  1217. ^receiver ifNil: [DoIt new]
  1218. !
  1219. receiver: anObject
  1220. receiver := anObject
  1221. !
  1222. onDoIt: aBlock
  1223. onDoIt := aBlock
  1224. !
  1225. onDoIt
  1226. ^onDoIt
  1227. !
  1228. currentLineOrSelection
  1229. ^editor somethingSelected
  1230. ifFalse: [self currentLine]
  1231. ifTrue: [self selection]
  1232. ! !
  1233. !SourceArea methodsFor: 'actions'!
  1234. clear
  1235. self val: ''
  1236. !
  1237. doIt
  1238. | result |
  1239. result := self eval: self currentLineOrSelection.
  1240. self onDoIt ifNotNil: [self onDoIt value].
  1241. ^result
  1242. !
  1243. eval: aString
  1244. | compiler |
  1245. compiler := Compiler new.
  1246. [compiler parseExpression: aString] on: Error do: [:ex |
  1247. ^self alert: ex messageText].
  1248. ^(compiler load: 'doIt ^[', aString, '] value' forClass: DoIt) fn applyTo: self receiver arguments: #()
  1249. !
  1250. handleKeyDown: anEvent
  1251. <if(anEvent.ctrlKey) {
  1252. if(anEvent.keyCode === 80) { //ctrl+p
  1253. self._printIt();
  1254. anEvent.preventDefault();
  1255. return false;
  1256. }
  1257. if(anEvent.keyCode === 68) { //ctrl+d
  1258. self._doIt();
  1259. anEvent.preventDefault();
  1260. return false;
  1261. }
  1262. if(anEvent.keyCode === 73) { //ctrl+i
  1263. self._inspectIt();
  1264. anEvent.preventDefault();
  1265. return false;
  1266. }
  1267. }>
  1268. !
  1269. inspectIt
  1270. self doIt inspect
  1271. !
  1272. print: aString
  1273. | start stop |
  1274. start := Dictionary new.
  1275. stop := Dictionary new.
  1276. start at: 'line' put: (editor getCursor: false) line.
  1277. start at: 'ch' put: (editor getCursor: false) ch.
  1278. stop at: 'line' put: (start at: 'line').
  1279. stop at: 'ch' put: ((start at: 'ch') + aString size + 2).
  1280. editor replaceSelection: (editor getSelection, ' ', aString, ' ').
  1281. editor setCursor: (editor getCursor: true).
  1282. editor setSelection: stop end: start
  1283. !
  1284. printIt
  1285. self print: self doIt printString
  1286. !
  1287. fileIn
  1288. Importer new import: self currentLineOrSelection readStream
  1289. ! !
  1290. !SourceArea methodsFor: 'events'!
  1291. onKeyUp: aBlock
  1292. div onKeyUp: aBlock
  1293. !
  1294. onKeyDown: aBlock
  1295. div onKeyDown: aBlock
  1296. ! !
  1297. !SourceArea methodsFor: 'rendering'!
  1298. renderOn: html
  1299. | textarea |
  1300. div := html div class: 'source'.
  1301. div with: [textarea := html textarea].
  1302. self setEditorOn: textarea element.
  1303. div onKeyDown: [:e | self handleKeyDown: e]
  1304. ! !
  1305. Widget subclass: #ClassesList
  1306. instanceVariableNames: 'browser ul nodes'
  1307. category: 'IDE'!
  1308. !ClassesList methodsFor: 'accessing'!
  1309. category
  1310. ^self browser selectedPackage
  1311. !
  1312. nodes
  1313. nodes ifNil: [nodes := self getNodes].
  1314. ^nodes
  1315. !
  1316. browser
  1317. ^browser
  1318. !
  1319. browser: aBrowser
  1320. browser := aBrowser
  1321. !
  1322. getNodes
  1323. | classes children others |
  1324. classes := self browser classes.
  1325. children := #().
  1326. others := #().
  1327. classes do: [:each |
  1328. (classes includes: each superclass)
  1329. ifFalse: [children add: each]
  1330. ifTrue: [others add: each]].
  1331. ^children collect: [:each |
  1332. ClassesListNode on: each browser: self browser classes: others level: 0]
  1333. !
  1334. resetNodes
  1335. nodes := nil
  1336. ! !
  1337. !ClassesList methodsFor: 'rendering'!
  1338. renderOn: html
  1339. ul := html ul
  1340. class: 'jt_column browser classes';
  1341. yourself.
  1342. self updateNodes
  1343. !
  1344. updateNodes
  1345. ul contents: [:html |
  1346. self nodes do: [:each |
  1347. each renderOn: html]]
  1348. ! !
  1349. !ClassesList class methodsFor: 'instance creation'!
  1350. on: aBrowser
  1351. ^self new
  1352. browser: aBrowser;
  1353. yourself
  1354. ! !
  1355. Widget subclass: #ClassesListNode
  1356. instanceVariableNames: 'browser theClass level nodes'
  1357. category: 'IDE'!
  1358. !ClassesListNode methodsFor: ''!
  1359. renderOn: html
  1360. | li cssClass |
  1361. cssClass := ''.
  1362. li := html li
  1363. onClick: [self browser selectClass: self theClass].
  1364. li asJQuery contents: self label.
  1365. self browser selectedClass = self theClass ifTrue: [
  1366. cssClass := cssClass, ' selected'].
  1367. self theClass comment isEmpty ifFalse: [
  1368. cssClass := cssClass, ' commented'].
  1369. li class: cssClass.
  1370. self nodes do: [:each |
  1371. each renderOn: html]
  1372. ! !
  1373. !ClassesListNode methodsFor: 'accessing'!
  1374. nodes
  1375. ^nodes
  1376. !
  1377. theClass
  1378. ^theClass
  1379. !
  1380. theClass: aClass
  1381. theClass := aClass
  1382. !
  1383. browser
  1384. ^browser
  1385. !
  1386. browser: aBrowser
  1387. browser := aBrowser
  1388. !
  1389. level
  1390. ^level
  1391. !
  1392. level: anInteger
  1393. level := anInteger
  1394. !
  1395. label
  1396. | str |
  1397. str := String new writeStream.
  1398. self level timesRepeat: [
  1399. str nextPutAll: '&nbsp;&nbsp;&nbsp;&nbsp;'].
  1400. str nextPutAll: self theClass name.
  1401. ^str contents
  1402. !
  1403. getNodesFrom: aCollection
  1404. | children others |
  1405. children := #().
  1406. others := #().
  1407. aCollection do: [:each |
  1408. (each superclass = self theClass)
  1409. ifTrue: [children add: each]
  1410. ifFalse: [others add: each]].
  1411. nodes:= children collect: [:each |
  1412. ClassesListNode on: each browser: self browser classes: others level: self level + 1]
  1413. ! !
  1414. !ClassesListNode class methodsFor: 'instance creation'!
  1415. on: aClass browser: aBrowser classes: aCollection level: anInteger
  1416. ^self new
  1417. theClass: aClass;
  1418. browser: aBrowser;
  1419. level: anInteger;
  1420. getNodesFrom: aCollection;
  1421. yourself
  1422. ! !
  1423. TabWidget subclass: #Debugger
  1424. instanceVariableNames: 'error selectedContext sourceArea ul ul2 inspector saveButton unsavedChanges selectedVariable selectedVariableName inspectButton'
  1425. category: 'IDE'!
  1426. !Debugger methodsFor: 'accessing'!
  1427. error
  1428. ^error
  1429. !
  1430. error: anError
  1431. error := anError
  1432. !
  1433. label
  1434. ^'[Debugger]'
  1435. !
  1436. source
  1437. ^self method
  1438. ifNil: ['Method doesn''t exist!!']
  1439. ifNotNil: [self method source]
  1440. !
  1441. method
  1442. ^selectedContext receiver class methodAt: selectedContext selector
  1443. !
  1444. arguments
  1445. ^self method
  1446. ifNil: [selectedContext temps collect: [:each | nil]]
  1447. ifNotNil: [self method arguments]
  1448. !
  1449. receiver
  1450. ^selectedContext receiver
  1451. ! !
  1452. !Debugger methodsFor: 'actions'!
  1453. selectContext: aContext
  1454. selectedContext := aContext.
  1455. selectedVariable := nil.
  1456. selectedVariableName := nil.
  1457. self
  1458. updateContextsList;
  1459. updateSourceArea;
  1460. updateInspector;
  1461. updateVariablesList;
  1462. updateStatus
  1463. !
  1464. proceed
  1465. self close.
  1466. selectedContext receiver perform: selectedContext selector withArguments: selectedContext temps
  1467. !
  1468. save
  1469. | protocol |
  1470. protocol := (selectedContext receiver class methodDictionary at: selectedContext selector) category.
  1471. selectedContext receiver class compile: sourceArea val category: protocol.
  1472. self updateStatus
  1473. !
  1474. selectVariable: anObject named: aString
  1475. selectedVariable := anObject.
  1476. selectedVariableName := aString.
  1477. inspector contents: [:html | html with: anObject printString].
  1478. self updateVariablesList
  1479. !
  1480. inspectSelectedVariable
  1481. selectedVariable inspect
  1482. ! !
  1483. !Debugger methodsFor: 'initialization'!
  1484. initialize
  1485. super initialize.
  1486. unsavedChanges = false
  1487. ! !
  1488. !Debugger methodsFor: 'rendering'!
  1489. renderTopPanelOn: html
  1490. selectedContext := self error context.
  1491. html div
  1492. class: 'top';
  1493. with: [
  1494. html div
  1495. class: 'label';
  1496. with: self error messageText.
  1497. ul := html ul
  1498. class: 'jt_column debugger contexts';
  1499. with: [self renderContext: self error context on: html]]
  1500. !
  1501. renderContext: aContext on: html
  1502. | li |
  1503. li := html li.
  1504. selectedContext = aContext ifTrue: [
  1505. li class: 'selected'].
  1506. li
  1507. with: aContext asString;
  1508. onClick: [self selectContext: aContext].
  1509. aContext home ifNotNil: [self renderContext: aContext home on: html]
  1510. !
  1511. renderBottomPanelOn: html
  1512. html div
  1513. class: 'jt_sourceCode debugger';
  1514. with: [
  1515. sourceArea := SourceArea new.
  1516. sourceArea renderOn: html].
  1517. ul2 := html ul class: 'jt_column debugger variables'.
  1518. inspector := html div class: 'jt_column debugger inspector'.
  1519. sourceArea
  1520. onKeyUp: [self updateStatus]
  1521. !
  1522. renderButtonsOn: html
  1523. saveButton := html button
  1524. with: 'Save';
  1525. onClick: [self save].
  1526. html button
  1527. with: 'DoIt';
  1528. onClick: [sourceArea doIt].
  1529. html button
  1530. with: 'PrintIt';
  1531. onClick: [sourceArea printIt].
  1532. html button
  1533. with: 'InspectIt';
  1534. onClick: [sourceArea inspectIt].
  1535. html button
  1536. with: 'Proceed';
  1537. onClick: [self proceed].
  1538. html button
  1539. with: 'Abandon';
  1540. onClick: [self close].
  1541. inspectButton := html button
  1542. class: 'jt_button debugger inspect';
  1543. with: 'Inspect';
  1544. onClick: [self inspectSelectedVariable].
  1545. self
  1546. updateSourceArea;
  1547. updateStatus;
  1548. updateVariablesList;
  1549. updateInspector
  1550. !
  1551. renderBoxOn: html
  1552. self
  1553. renderTopPanelOn: html;
  1554. renderBottomPanelOn: html
  1555. ! !
  1556. !Debugger methodsFor: 'testing'!
  1557. canBeClosed
  1558. ^true
  1559. ! !
  1560. !Debugger methodsFor: 'updating'!
  1561. updateContextsList
  1562. ul contents: [:html |
  1563. self renderContext: self error context on: html]
  1564. !
  1565. updateSourceArea
  1566. sourceArea val: self source
  1567. !
  1568. updateStatus
  1569. sourceArea val = self source
  1570. ifTrue: [
  1571. saveButton ifNotNil: [
  1572. saveButton at: 'disabled' put: true].
  1573. unsavedChanges := false]
  1574. ifFalse: [
  1575. saveButton ifNotNil: [
  1576. saveButton removeAt: 'disabled'].
  1577. unsavedChanges := true]
  1578. !
  1579. updateInspector
  1580. inspector contents: [:html |]
  1581. !
  1582. updateVariablesList
  1583. ul2 contents: [:html | | li |
  1584. li := html li
  1585. with: 'self';
  1586. onClick: [self selectVariable: self receiver named: 'self'].
  1587. selectedVariableName = 'self' ifTrue: [
  1588. li class: 'selected'].
  1589. self arguments withIndexDo: [:each :index | | param |
  1590. param := selectedContext temps at: index.
  1591. li := html li
  1592. with: each;
  1593. onClick: [self selectVariable: param named: each].
  1594. selectedVariableName = each ifTrue: [
  1595. li class: 'selected']].
  1596. self receiver class allInstanceVariableNames do: [:each | | ivar |
  1597. ivar := self receiver instVarAt: each.
  1598. li := html li
  1599. with: each;
  1600. onClick: [self selectVariable: ivar named: each].
  1601. selectedVariableName = each ifTrue: [
  1602. li class: 'selected']]].
  1603. selectedVariable ifNil: [inspectButton at: 'disabled' put: true] ifNotNil: [inspectButton removeAt: 'disabled']
  1604. ! !
  1605. ErrorHandler subclass: #DebugErrorHandler
  1606. instanceVariableNames: ''
  1607. category: 'IDE'!
  1608. !DebugErrorHandler methodsFor: 'error handling'!
  1609. handleError: anError
  1610. [Debugger new
  1611. error: anError;
  1612. open] on: Error do: [:error |
  1613. ErrorHandler new handleError: error]
  1614. ! !
  1615. !DebugErrorHandler class methodsFor: 'initialization'!
  1616. initialize
  1617. self register
  1618. ! !
  1619. TabWidget subclass: #ProgressBar
  1620. instanceVariableNames: 'percent progressDiv div'
  1621. category: 'IDE'!
  1622. !ProgressBar methodsFor: 'accessing'!
  1623. percent
  1624. ^percent ifNil: [0]
  1625. !
  1626. percent: aNumber
  1627. percent := aNumber
  1628. ! !
  1629. !ProgressBar methodsFor: 'rendering'!
  1630. renderOn: html
  1631. div := html div
  1632. class: 'progress_bar';
  1633. yourself.
  1634. self renderProgressBar
  1635. !
  1636. renderProgressBar
  1637. div contents: [:html |
  1638. html div
  1639. class: 'progress';
  1640. style: 'width:', self percent asString, '%']
  1641. ! !
  1642. !ProgressBar methodsFor: 'updating'!
  1643. updatePercent: aNumber
  1644. self percent: aNumber.
  1645. self renderProgressBar
  1646. ! !
  1647. TabWidget subclass: #TestRunner
  1648. instanceVariableNames: 'selectedCategories packagesList selectedClasses classesList selectedMethods progressBar methodsList result statusDiv'
  1649. category: 'IDE'!
  1650. !TestRunner methodsFor: 'accessing'!
  1651. label
  1652. ^'SUnit'
  1653. !
  1654. packages
  1655. | packages |
  1656. packages := Array new.
  1657. self allClasses do: [:each |
  1658. (packages includes: each category) ifFalse: [
  1659. packages add: each category]].
  1660. ^packages sort
  1661. !
  1662. classes
  1663. ^(self allClasses
  1664. select: [:each | self selectedCategories includes: each category])
  1665. sort: [:a :b | a name > b name]
  1666. !
  1667. selectedCategories
  1668. ^selectedCategories ifNil: [selectedCategories := Array new]
  1669. !
  1670. allClasses
  1671. ^TestCase allSubclasses
  1672. !
  1673. selectedClasses
  1674. ^selectedClasses ifNil: [selectedClasses := Array new]
  1675. !
  1676. progressBar
  1677. ^progressBar ifNil: [progressBar := ProgressBar new]
  1678. !
  1679. statusInfo
  1680. ^self printTotal, self printPasses, self printErrors, self printFailures
  1681. !
  1682. result
  1683. ^result
  1684. !
  1685. testCases
  1686. | testCases |
  1687. testCases := #().
  1688. self selectedClasses do: [:each | testCases addAll: each buildSuite].
  1689. ^testCases
  1690. ! !
  1691. !TestRunner methodsFor: 'actions'!
  1692. selectAllCategories
  1693. self packages do: [:each |
  1694. (selectedCategories includes: each) ifFalse: [
  1695. self selectedCategories add: each]].
  1696. self
  1697. updateCategoriesList;
  1698. updateClassesList
  1699. !
  1700. toggleCategory: aCategory
  1701. (self isSelectedCategory: aCategory)
  1702. ifFalse: [selectedCategories add: aCategory]
  1703. ifTrue: [selectedCategories remove: aCategory].
  1704. self
  1705. updateCategoriesList;
  1706. updateClassesList
  1707. !
  1708. toggleClass: aClass
  1709. (self isSelectedClass: aClass)
  1710. ifFalse: [selectedClasses add: aClass]
  1711. ifTrue: [selectedClasses remove: aClass].
  1712. self
  1713. updateClassesList
  1714. !
  1715. selectAllClasses
  1716. self classes do: [:each |
  1717. (selectedClasses includes: each) ifFalse: [
  1718. self selectedClasses add: each]].
  1719. self
  1720. updateCategoriesList;
  1721. updateClassesList
  1722. !
  1723. run: aCollection
  1724. result := TestResult new.
  1725. self
  1726. updateStatusDiv;
  1727. updateMethodsList.
  1728. self progressBar updatePercent: 0.
  1729. result total: aCollection size.
  1730. aCollection do: [:each |
  1731. [each runCaseFor: result.
  1732. self progressBar updatePercent: result runs / result total * 100.
  1733. self updateStatusDiv.
  1734. self updateMethodsList] valueWithTimeout: 100].
  1735. !
  1736. performFailure: aTestCase
  1737. aTestCase perform: aTestCase selector
  1738. ! !
  1739. !TestRunner methodsFor: 'initialization'!
  1740. initialize
  1741. super initialize.
  1742. result := TestResult new
  1743. ! !
  1744. !TestRunner methodsFor: 'printing'!
  1745. printErrors
  1746. ^self result errors size asString , ' errors, '
  1747. !
  1748. printFailures
  1749. ^self result failures size asString, ' failures'
  1750. !
  1751. printPasses
  1752. ^(self result total - self result errors size - self result failures size) asString , ' passes, '
  1753. !
  1754. printTotal
  1755. ^self result total asString, ' runs, '
  1756. ! !
  1757. !TestRunner methodsFor: 'rendering'!
  1758. renderBoxOn: html
  1759. self
  1760. renderCategoriesOn: html;
  1761. renderClassesOn: html;
  1762. renderResultsOn: html
  1763. !
  1764. renderButtonsOn: html
  1765. html button
  1766. with: 'Run selected';
  1767. onClick: [self run: self testCases]
  1768. !
  1769. renderCategoriesOn: html
  1770. packagesList := html ul class: 'jt_column sunit packages'.
  1771. self updateCategoriesList
  1772. !
  1773. renderClassesOn: html
  1774. classesList := html ul class: 'jt_column sunit classes'.
  1775. self updateClassesList
  1776. !
  1777. renderResultsOn: html
  1778. statusDiv := html div.
  1779. html with: self progressBar.
  1780. methodsList := html ul class: 'jt_column sunit results'.
  1781. self updateMethodsList.
  1782. self updateStatusDiv
  1783. !
  1784. renderFailuresOn: html
  1785. self result failures do: [:each |
  1786. html li
  1787. class: 'failures';
  1788. with: each class name, ' >> ', each selector;
  1789. onClick: [self performFailure: each]]
  1790. !
  1791. renderErrorsOn: html
  1792. self result errors do: [:each |
  1793. html li
  1794. class: 'errors';
  1795. with: each class name, ' >> ', each selector;
  1796. onClick: [self performFailure: each]]
  1797. ! !
  1798. !TestRunner methodsFor: 'testing'!
  1799. isSelectedClass: aClass
  1800. ^(self selectedClasses includes: aClass)
  1801. !
  1802. isSelectedCategory: aCategory
  1803. ^(self selectedCategories includes: aCategory)
  1804. ! !
  1805. !TestRunner methodsFor: 'updating'!
  1806. updateCategoriesList
  1807. packagesList contents: [:html |
  1808. html li
  1809. class: 'all';
  1810. with: 'All';
  1811. onClick: [self selectAllCategories].
  1812. self packages do: [:each || li |
  1813. li := html li.
  1814. (self selectedCategories includes: each) ifTrue: [
  1815. li class: 'selected'].
  1816. li
  1817. with: each;
  1818. onClick: [self toggleCategory: each]]]
  1819. !
  1820. updateClassesList
  1821. classesList contents: [:html |
  1822. (self selectedCategories isEmpty) ifFalse: [
  1823. html li
  1824. class: 'all';
  1825. with: 'All';
  1826. onClick: [self selectAllClasses]].
  1827. self classes do: [:each || li |
  1828. li := html li.
  1829. (self selectedClasses includes: each) ifTrue: [
  1830. li class: 'selected'].
  1831. li
  1832. with: each name;
  1833. onClick: [self toggleClass: each]]]
  1834. !
  1835. updateMethodsList
  1836. methodsList contents: [:html |
  1837. self renderErrorsOn: html.
  1838. self renderFailuresOn: html]
  1839. !
  1840. updateStatusDiv
  1841. statusDiv class: 'sunit status ', result status.
  1842. statusDiv contents: [:html |
  1843. html span with: self statusInfo]
  1844. ! !
  1845. !Object methodsFor: '*IDE'!
  1846. inspect
  1847. Inspector new
  1848. inspect: self;
  1849. open
  1850. !
  1851. inspectOn: anInspector
  1852. | variables |
  1853. variables := Dictionary new.
  1854. variables at: '#self' put: self.
  1855. self class allInstanceVariableNames do: [:each |
  1856. variables at: each put: (self instVarAt: each)].
  1857. anInspector
  1858. setLabel: self printString;
  1859. setVariables: variables
  1860. ! !
  1861. !Date methodsFor: '*IDE'!
  1862. inspectOn: anInspector
  1863. | variables |
  1864. variables := Dictionary new.
  1865. variables at: '#self' put: self.
  1866. variables at: '#year' put: self year.
  1867. variables at: '#month' put: self month.
  1868. variables at: '#day' put: self day.
  1869. variables at: '#hours' put: self hours.
  1870. variables at: '#minutes' put: self minutes.
  1871. variables at: '#seconds' put: self seconds.
  1872. variables at: '#milliseconds' put: self milliseconds.
  1873. anInspector
  1874. setLabel: self printString;
  1875. setVariables: variables
  1876. ! !
  1877. !Collection methodsFor: '*IDE'!
  1878. inspectOn: anInspector
  1879. | variables |
  1880. variables := Dictionary new.
  1881. variables at: '#self' put: self.
  1882. self withIndexDo: [:each :i |
  1883. variables at: i put: each].
  1884. anInspector
  1885. setLabel: self printString;
  1886. setVariables: variables
  1887. ! !
  1888. !String methodsFor: '*IDE'!
  1889. inspectOn: anInspector
  1890. | label |
  1891. super inspectOn: anInspector.
  1892. self printString size > 30
  1893. ifTrue: [label := (self printString copyFrom: 1 to: 30), '...''']
  1894. ifFalse: [label := self printString].
  1895. anInspector setLabel: label
  1896. ! !
  1897. !MethodContext methodsFor: '*IDE'!
  1898. inspectOn: anInspector
  1899. | variables |
  1900. variables := Dictionary new.
  1901. variables at: '#self' put: self.
  1902. variables at: '#home' put: self home.
  1903. variables at: '#receiver' put: self receiver.
  1904. variables at: '#selector' put: self selector.
  1905. variables at: '#temps' put: self temps.
  1906. self class instanceVariableNames do: [:each |
  1907. variables at: each put: (self instVarAt: each)].
  1908. anInspector
  1909. setLabel: self printString;
  1910. setVariables: variables
  1911. ! !
  1912. !Dictionary methodsFor: '*IDE'!
  1913. inspectOn: anInspector
  1914. | variables |
  1915. variables := Dictionary new.
  1916. variables at: '#self' put: self.
  1917. variables at: '#keys' put: self keys.
  1918. self keysAndValuesDo: [:key :value |
  1919. variables at: key put: value].
  1920. anInspector
  1921. setLabel: self printString;
  1922. setVariables: variables
  1923. ! !