IDE.st 49 KB

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