IDE.st 47 KB

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