1
0

IDE.st 49 KB

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