IDE.st 49 KB

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