IDE.st 48 KB

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