IDE.st 47 KB

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