IDE.st 49 KB

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