1
0

IDE.st 48 KB

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