IDE.st 44 KB

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