IDE.st 48 KB

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