IDE.st 46 KB

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