IDE.st 47 KB

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