IDE.st 48 KB

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