IDE.st 47 KB

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