2
0

IDE.st 48 KB

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