IDE.st 47 KB

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