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: #ProgressBar
  82. slots: {#percent. #progressDiv. #div}
  83. package: 'IDE'!
  84. !ProgressBar methodsFor: 'accessing'!
  85. percent
  86. ^ percent ifNil: [ 0 ]
  87. !
  88. percent: aNumber
  89. percent := aNumber
  90. ! !
  91. !ProgressBar methodsFor: 'rendering'!
  92. renderOn: html
  93. div := html div
  94. class: 'progress_bar';
  95. yourself.
  96. self renderProgressBar
  97. !
  98. renderProgressBar
  99. div contents: [ :html |
  100. html div
  101. class: 'progress';
  102. style: 'width:', self percent asString, '%' ]
  103. ! !
  104. !ProgressBar methodsFor: 'updating'!
  105. updatePercent: aNumber
  106. self percent: aNumber.
  107. self renderProgressBar
  108. ! !
  109. Widget subclass: #SourceArea
  110. slots: {#editor. #div. #receiver. #onDoIt}
  111. package: 'IDE'!
  112. !SourceArea methodsFor: 'accessing'!
  113. currentLine
  114. ^ editor getLine: (editor getCursor line)
  115. !
  116. currentLineOrSelection
  117. ^ editor somethingSelected
  118. ifFalse: [ self currentLine ]
  119. ifTrue: [ self selection ]
  120. !
  121. editor
  122. ^ editor
  123. !
  124. onDoIt
  125. ^ onDoIt
  126. !
  127. onDoIt: aBlock
  128. onDoIt := aBlock
  129. !
  130. receiver
  131. ^ receiver ifNil: [ DoIt new ]
  132. !
  133. receiver: anObject
  134. receiver := anObject
  135. !
  136. selection
  137. ^ editor getSelection
  138. !
  139. setEditorOn: aTextarea
  140. editor := codeMirrorLib provided fromTextArea: aTextarea options: #{
  141. #theme -> ('ide.codeMirrorTheme' settingValueIfAbsent: 'default').
  142. #mode -> 'text/x-stsrc'.
  143. #lineNumbers -> true.
  144. #enterMode -> 'flat'.
  145. #indentWithTabs -> true.
  146. #indentUnit -> 4.
  147. #matchBrackets -> true.
  148. #electricChars -> false
  149. }
  150. !
  151. val
  152. ^ editor getValue
  153. !
  154. val: aString
  155. editor setValue: aString
  156. ! !
  157. !SourceArea methodsFor: 'actions'!
  158. clear
  159. self val: ''
  160. !
  161. doIt
  162. | result |
  163. result := self eval: self currentLineOrSelection.
  164. self onDoIt ifNotNil: [ self onDoIt value ].
  165. ^ result
  166. !
  167. eval: aString
  168. | compiler |
  169. compiler := Compiler new.
  170. [ compiler parseExpression: aString ] on: Error do: [ :ex |
  171. ^ Terminal alert: ex messageText ].
  172. ^ compiler evaluateExpression: aString on: self receiver
  173. !
  174. fileIn
  175. Importer new import: self currentLineOrSelection readStream
  176. !
  177. focus
  178. self editor focus.
  179. !
  180. handleKeyDown: anEvent
  181. <inlineJS: 'if(anEvent.ctrlKey) {
  182. if(anEvent.keyCode === 80) { //ctrl+p
  183. anEvent.preventDefault();
  184. $self._printIt();
  185. return false;
  186. }
  187. if(anEvent.keyCode === 68) { //ctrl+d
  188. anEvent.preventDefault();
  189. $self._doIt();
  190. return false;
  191. }
  192. if(anEvent.keyCode === 73) { //ctrl+i
  193. anEvent.preventDefault();
  194. $self._inspectIt();
  195. return false;
  196. }
  197. }'>
  198. !
  199. inspectIt
  200. self doIt inspect
  201. !
  202. print: aString
  203. | start stop currentLine |
  204. currentLine := (editor getCursor: false) line.
  205. start := HashedCollection new.
  206. start at: 'line' put: currentLine.
  207. start at: 'ch' put: (editor getCursor: false) ch.
  208. (editor getSelection) ifEmpty: [
  209. "select current line if selection is empty"
  210. start at: 'ch' put: (editor getLine: currentLine) size.
  211. editor setSelection: #{'line' -> currentLine. 'ch' -> 0} end: start.
  212. ].
  213. stop := HashedCollection new.
  214. stop at: 'line' put: currentLine.
  215. stop at: 'ch' put: ((start at: 'ch') + aString size + 2).
  216. editor replaceSelection: (editor getSelection, ' ', aString, ' ').
  217. editor setCursor: (editor getCursor: true).
  218. editor setSelection: stop end: start
  219. !
  220. printIt
  221. self print: self doIt printString.
  222. self focus.
  223. ! !
  224. !SourceArea methodsFor: 'events'!
  225. onKeyDown: aBlock
  226. div onKeyDown: aBlock
  227. !
  228. onKeyUp: aBlock
  229. div onKeyUp: aBlock
  230. ! !
  231. !SourceArea methodsFor: 'rendering'!
  232. renderOn: html
  233. | textarea |
  234. div := html div class: 'source'.
  235. div with: [ textarea := html textarea ].
  236. self setEditorOn: textarea asDomNode.
  237. div onKeyDown: [ :e | self handleKeyDown: e ]
  238. ! !
  239. !SourceArea class methodsFor: 'initialization'!
  240. initialize
  241. super initialize.
  242. self setupCodeMirror
  243. !
  244. setupCodeMirror
  245. <inlineJS: 'codeMirrorLib.keyMap["default"].fallthrough = ["basic"]'>
  246. ! !
  247. Widget subclass: #TabManager
  248. slots: {#selectedTab. #tabs. #opened. #ul. #input}
  249. package: 'IDE'!
  250. !TabManager methodsFor: 'accessing'!
  251. labelFor: aWidget
  252. | label maxSize |
  253. maxSize := 15.
  254. label := aWidget label copyFrom: 0 to: (aWidget label size min: maxSize).
  255. aWidget label size > maxSize ifTrue: [
  256. label := label, '...' ].
  257. ^ label
  258. !
  259. tabs
  260. ^ tabs ifNil: [ tabs := Array new ]
  261. ! !
  262. !TabManager methodsFor: 'actions'!
  263. close
  264. opened ifTrue: [
  265. '#amber' asJQuery hide.
  266. ul asJQuery hide.
  267. selectedTab hide.
  268. self removeBodyMargin.
  269. 'body' asJQuery removeClass: 'amberBody'.
  270. opened := false ]
  271. !
  272. closeTab: aWidget
  273. self removeTab: aWidget.
  274. self selectTab: self tabs last.
  275. aWidget remove.
  276. self update
  277. !
  278. newBrowserTab
  279. Browser open
  280. !
  281. onResize: aBlock
  282. '#amber' asJQuery resizable: #{
  283. 'handles' -> 'n'.
  284. 'resize' -> aBlock.
  285. 'minHeight' -> 230
  286. }
  287. !
  288. onWindowResize: aBlock
  289. window asJQuery resize: aBlock
  290. !
  291. open
  292. opened ifFalse: [
  293. 'body' asJQuery addClass: 'amberBody'.
  294. '#amber' asJQuery show.
  295. ul asJQuery show.
  296. self updateBodyMargin.
  297. selectedTab show.
  298. opened := true ]
  299. !
  300. removeBodyMargin
  301. self setBodyMargin: 0
  302. !
  303. search: aString
  304. | searchedClass |
  305. searchedClass := Smalltalk globals at: aString.
  306. searchedClass isClass
  307. ifTrue: [ Browser openOn: searchedClass ]
  308. ifFalse: [ ReferencesBrowser search: aString ]
  309. !
  310. selectTab: aWidget
  311. (self tabs includes: aWidget) ifFalse: [ ^ self ].
  312. self open.
  313. selectedTab := aWidget.
  314. self tabs do: [ :each |
  315. each hide ].
  316. aWidget show.
  317. self update
  318. !
  319. setBodyMargin: anInteger
  320. '.amberBody' asJQuery css: 'margin-bottom' put: anInteger asString, 'px'
  321. !
  322. updateBodyMargin
  323. self setBodyMargin: '#amber' asJQuery height
  324. !
  325. updatePosition
  326. '#amber' asJQuery
  327. css: 'top' put: '';
  328. css: 'bottom' put: '0px'
  329. ! !
  330. !TabManager methodsFor: 'adding/Removing'!
  331. addTab: aWidget
  332. self tabs add: aWidget.
  333. aWidget appendToJQuery: '#amber' asJQuery.
  334. aWidget hide
  335. !
  336. removeTab: aWidget
  337. self tabs remove: aWidget.
  338. self update
  339. ! !
  340. !TabManager methodsFor: 'initialization'!
  341. initialize
  342. super initialize.
  343. Inspector register: IDEInspector.
  344. opened := true.
  345. [ :html | html div id: 'amber' ] appendToJQuery: 'body' asJQuery.
  346. 'body' asJQuery
  347. addClass: 'amberBody'.
  348. self appendToJQuery: '#amber' asJQuery.
  349. self
  350. addTab: IDETranscript current;
  351. addTab: Workspace new;
  352. addTab: TestRunner new.
  353. self selectTab: self tabs last.
  354. self
  355. onResize: [ self updateBodyMargin; updatePosition ];
  356. onWindowResize: [ self updatePosition ]
  357. ! !
  358. !TabManager methodsFor: 'rendering'!
  359. renderOn: html
  360. html div id: 'logo'.
  361. self renderToolbarOn: html.
  362. ul := html ul
  363. id: 'amberTabs';
  364. yourself.
  365. self renderTabs
  366. !
  367. renderTabFor: aWidget on: html
  368. | li |
  369. li := html li.
  370. selectedTab = aWidget ifTrue: [
  371. li class: 'selected' ].
  372. li with: [
  373. html span class: 'ltab'.
  374. html span
  375. class: 'mtab';
  376. with: [
  377. aWidget canBeClosed ifTrue: [
  378. html span
  379. class: 'close';
  380. with: 'x';
  381. onClick: [ self closeTab: aWidget ]].
  382. html span with: (self labelFor: aWidget) ].
  383. html span class: 'rtab' ];
  384. onClick: [ self selectTab: aWidget ]
  385. !
  386. renderTabs
  387. ul contents: [ :html |
  388. self tabs do: [ :each |
  389. self renderTabFor: each on: html ].
  390. html li
  391. class: 'newtab';
  392. with: [
  393. html span class: 'ltab'.
  394. html span class: 'mtab'; with: ' + '.
  395. html span class: 'rtab' ];
  396. onClick: [ self newBrowserTab ]]
  397. !
  398. renderToolbarOn: html
  399. html div
  400. id: 'amber_toolbar';
  401. with: [
  402. input := html input
  403. class: 'implementors';
  404. yourself.
  405. input onKeyPress: [ :event |
  406. event keyCode = 13 ifTrue: [
  407. self search: input asJQuery val ]].
  408. html div id: 'amber_close'; onClick: [ self close ]]
  409. ! !
  410. !TabManager methodsFor: 'updating'!
  411. update
  412. self renderTabs
  413. ! !
  414. TabManager class slots: {#current}!
  415. !TabManager class methodsFor: 'actions'!
  416. toggleAmberIDE
  417. '#amber' asJQuery length = 0
  418. ifTrue: [ Browser open ]
  419. ifFalse: [
  420. ('#amber' asJQuery is: ':visible')
  421. ifTrue: [ TabManager current close ]
  422. ifFalse: [ TabManager current open ] ]
  423. ! !
  424. !TabManager class methodsFor: 'instance creation'!
  425. current
  426. ^ current ifNil: [ current := super new ]
  427. !
  428. new
  429. self shouldNotImplement
  430. ! !
  431. Widget subclass: #TabWidget
  432. slots: {#div}
  433. package: 'IDE'!
  434. !TabWidget methodsFor: 'accessing'!
  435. label
  436. self subclassResponsibility
  437. ! !
  438. !TabWidget methodsFor: 'actions'!
  439. close
  440. TabManager current closeTab: self
  441. !
  442. hide
  443. div asJQuery hide
  444. !
  445. open
  446. TabManager current addTab: self.
  447. TabManager current selectTab: self
  448. !
  449. remove
  450. div asJQuery remove
  451. !
  452. show
  453. div asJQuery show
  454. ! !
  455. !TabWidget methodsFor: 'rendering'!
  456. renderBoxOn: html
  457. !
  458. renderButtonsOn: html
  459. !
  460. renderOn: html
  461. div := html div
  462. class: 'amberTool';
  463. yourself.
  464. self renderTab
  465. !
  466. renderTab
  467. div contents: [ :html |
  468. html div
  469. class: 'amber_box';
  470. with: [ self renderBoxOn: html ].
  471. html div
  472. class: 'amber_buttons';
  473. with: [ self renderButtonsOn: html ]]
  474. !
  475. update
  476. self renderTab
  477. ! !
  478. !TabWidget methodsFor: 'testing'!
  479. canBeClosed
  480. ^ false
  481. ! !
  482. !TabWidget class methodsFor: 'instance creation'!
  483. open
  484. ^ self new open
  485. ! !
  486. TabWidget subclass: #Browser
  487. slots: {#selectedPackage. #selectedClass. #selectedProtocol. #selectedMethod. #packagesList. #classesList. #protocolsList. #methodsList. #sourceArea. #tabsList. #selectedTab. #saveButton. #classButtons. #methodButtons. #unsavedChanges}
  488. package: 'IDE'!
  489. !Browser methodsFor: 'accessing'!
  490. classCommentSource
  491. ^ selectedClass comment
  492. !
  493. classDeclarationTemplate
  494. ^ 'Object subclass: #NameOfSubclass
  495. instanceVariableNames: ''''
  496. package: ''', self selectedPackage, ''''
  497. !
  498. classes
  499. ^ ((Smalltalk classes
  500. select: [ :each | each category = selectedPackage ])
  501. sort: [ :a :b | a name < b name ]) asSet
  502. !
  503. declarationSource
  504. | klass |
  505. klass := self selectedClassOrMetaClass.
  506. ^ klass ifNotNil: [ klass definition ] ifNil: [
  507. selectedTab = #instance ifTrue: [ self classDeclarationTemplate ] ifFalse: [ '' ]
  508. ]
  509. !
  510. dummyMethodSource
  511. ^ 'messageSelectorAndArgumentNames
  512. "comment stating purpose of message"
  513. | temporary variable names |
  514. statements'
  515. !
  516. label
  517. ^ selectedClass
  518. ifNil: [ 'Browser (nil)' ]
  519. ifNotNil: [ 'Browser: ', selectedClass name ]
  520. !
  521. methodSource
  522. ^ selectedMethod
  523. ifNil: [ self dummyMethodSource ]
  524. ifNotNil: [ selectedMethod source ]
  525. !
  526. methods
  527. | klass |
  528. selectedTab = #comment ifTrue: [ ^ #() ].
  529. klass := self selectedClassOrMetaClass.
  530. ^ (selectedProtocol
  531. ifNil: [
  532. klass
  533. ifNil: [ #() ]
  534. ifNotNil: [ klass methodDictionary values ]]
  535. ifNotNil: [
  536. klass methodsInProtocol: selectedProtocol ])
  537. sort: [ :a :b | a selector < b selector ]
  538. !
  539. packages
  540. | packages |
  541. packages := Array new.
  542. Smalltalk classes do: [ :each |
  543. (packages includes: each category) ifFalse: [
  544. packages add: each category ]].
  545. ^ packages sort
  546. !
  547. protocols
  548. | klass |
  549. selectedClass ifNil: [ ^ #() ].
  550. selectedTab = #comment ifTrue: [ ^ #() ].
  551. klass := self selectedClassOrMetaClass.
  552. klass ifNil: [ ^ #() ].
  553. klass methodDictionary ifEmpty: [ ^ {'not yet classified'} ].
  554. ^ klass protocols
  555. !
  556. selectedClass
  557. ^ selectedClass
  558. !
  559. selectedClassOrMetaClass
  560. ^ selectedClass ifNotNil: [
  561. selectedTab = #instance
  562. ifTrue: [ selectedClass ]
  563. ifFalse: [ selectedClass theMetaClass ] ]
  564. !
  565. selectedPackage
  566. ^ selectedPackage
  567. !
  568. source
  569. selectedTab = #comment ifFalse: [
  570. ^ (selectedProtocol notNil or: [ selectedMethod notNil ])
  571. ifFalse: [ self declarationSource ]
  572. ifTrue: [ self methodSource ]].
  573. ^ selectedClass
  574. ifNil: [ '' ]
  575. ifNotNil: [ self classCommentSource ]
  576. ! !
  577. !Browser methodsFor: 'actions'!
  578. addNewClass
  579. | className |
  580. className := Terminal prompt: 'New class'.
  581. (className notNil and: [ className notEmpty ]) ifTrue: [
  582. Object subclass: className instanceVariableNames: '' package: self selectedPackage.
  583. self
  584. resetClassesList;
  585. updateClassesList.
  586. self selectClass: (Smalltalk globals at: className) ]
  587. !
  588. addNewProtocol
  589. | newProtocol |
  590. newProtocol := Terminal prompt: 'New method protocol'.
  591. (newProtocol notNil and: [ newProtocol notEmpty ]) ifTrue: [
  592. selectedMethod protocol: newProtocol.
  593. self setMethodProtocol: newProtocol ]
  594. !
  595. cancelChanges
  596. ^ unsavedChanges
  597. ifTrue: [ Terminal confirm: 'Cancel changes?' ]
  598. ifFalse: [ true ]
  599. !
  600. commitPackage
  601. selectedPackage ifNotNil: [
  602. (Package named: selectedPackage) commit ]
  603. !
  604. compile
  605. | currentEditLine |
  606. self disableSaveButton.
  607. currentEditLine := sourceArea editor getCursor.
  608. selectedTab = #comment
  609. ifTrue: [
  610. selectedClass ifNotNil: [
  611. self compileClassComment ]]
  612. ifFalse: [
  613. (selectedProtocol notNil or: [ selectedMethod notNil ])
  614. ifFalse: [ self compileDefinition ]
  615. ifTrue: [ self compileMethodDefinition ]].
  616. sourceArea editor setCursor: currentEditLine.
  617. !
  618. compileClassComment
  619. selectedClass comment: sourceArea val
  620. !
  621. compileDefinition
  622. | newClass |
  623. newClass := Compiler new evaluateExpression: sourceArea val.
  624. self
  625. resetClassesList;
  626. updateCategoriesList;
  627. updateClassesList.
  628. self selectClass: newClass
  629. !
  630. compileMethodDefinition
  631. self compileMethodDefinitionFor: self selectedClassOrMetaClass
  632. !
  633. compileMethodDefinitionFor: aClass
  634. | compiler package method compiledSource source node |
  635. source := sourceArea val.
  636. selectedProtocol ifNil: [ selectedProtocol := selectedMethod protocol ].
  637. [[ method := Compiler new
  638. install: source forClass: aClass protocol: selectedProtocol ]
  639. on: ParseError do: [ :e |
  640. ^ Terminal alert: 'PARSE ERROR: ', e messageText ]]
  641. on: UnknownVariableError do: [ :e |
  642. "Do not try to redeclare javascript's objects"
  643. (Platform includesGlobal: e variableName) ifFalse: [
  644. (Terminal confirm: 'Declare ''', e variableName, ''' as instance variable?') ifFalse: [ ^ nil ] ifTrue: [
  645. Environment new addInstVarNamed: e variableName to: aClass.
  646. ^ self compileMethodDefinitionFor: aClass ] ] ].
  647. self updateMethodsList.
  648. self selectMethod: method
  649. !
  650. copyClass
  651. | className |
  652. className := Terminal prompt: 'Copy class'.
  653. (className notNil and: [ className notEmpty ]) ifTrue: [
  654. ClassBuilder new copyClass: self selectedClass named: className.
  655. self
  656. resetClassesList;
  657. updateClassesList.
  658. self selectClass: (Smalltalk globals at: className) ]
  659. !
  660. disableSaveButton
  661. saveButton ifNotNil: [
  662. saveButton at: 'disabled' put: true ].
  663. unsavedChanges := false
  664. !
  665. handleSourceAreaKeyDown: anEvent
  666. <inlineJS: 'if(anEvent.ctrlKey) {
  667. if(anEvent.keyCode === 83) { //ctrl+s
  668. $self._compile();
  669. anEvent.preventDefault();
  670. return false;
  671. }
  672. }
  673. '>
  674. !
  675. hideClassButtons
  676. classButtons asJQuery hide
  677. !
  678. hideMethodButtons
  679. methodButtons asJQuery hide
  680. !
  681. removeClass
  682. (Terminal confirm: 'Do you really want to remove ', selectedClass name, '?')
  683. ifTrue: [
  684. Smalltalk removeClass: selectedClass.
  685. self resetClassesList.
  686. self selectClass: nil ]
  687. !
  688. removeMethod
  689. self cancelChanges ifTrue: [
  690. (Terminal confirm: 'Do you really want to remove #', selectedMethod selector, '?')
  691. ifTrue: [
  692. self selectedClassOrMetaClass removeCompiledMethod: selectedMethod.
  693. self selectMethod: nil ]]
  694. !
  695. removePackage
  696. (Terminal confirm: 'Do you really want to remove the whole package ', selectedPackage, ' with all its classes?')
  697. ifTrue: [
  698. Smalltalk removePackage: selectedPackage.
  699. self updateCategoriesList ]
  700. !
  701. renameClass
  702. | newName |
  703. newName := Terminal prompt: 'Rename class ', selectedClass name.
  704. (newName notNil and: [ newName notEmpty ]) ifTrue: [
  705. selectedClass rename: newName.
  706. self
  707. updateClassesList;
  708. updateSourceAndButtons ]
  709. !
  710. renamePackage
  711. | newName |
  712. newName := Terminal prompt: 'Rename package ', selectedPackage.
  713. newName ifNotNil: [ newName ifNotEmpty: [
  714. Smalltalk renamePackage: selectedPackage to: newName.
  715. self updateCategoriesList ]]
  716. !
  717. search: aString
  718. self cancelChanges ifTrue: [ | searchedClass |
  719. searchedClass := Smalltalk globals at: aString.
  720. searchedClass isClass
  721. ifTrue: [ self class openOn: searchedClass ]
  722. ifFalse: [ self searchReferencesOf: aString ]]
  723. !
  724. searchClassReferences
  725. ReferencesBrowser search: selectedClass name
  726. !
  727. searchReferencesOf: aString
  728. ReferencesBrowser search: aString
  729. !
  730. selectCategory: aCategory
  731. self cancelChanges ifTrue: [
  732. selectedPackage := aCategory.
  733. selectedClass := selectedProtocol := selectedMethod := nil.
  734. self resetClassesList.
  735. self
  736. updateCategoriesList;
  737. updateClassesList;
  738. updateProtocolsList;
  739. updateMethodsList;
  740. updateSourceAndButtons ]
  741. !
  742. selectClass: aClass
  743. self cancelChanges ifTrue: [
  744. selectedClass := aClass.
  745. selectedProtocol := selectedMethod := nil.
  746. self
  747. updateClassesList;
  748. updateProtocolsList;
  749. updateMethodsList;
  750. updateSourceAndButtons ]
  751. !
  752. selectMethod: aMethod
  753. self cancelChanges ifTrue: [
  754. selectedMethod := aMethod.
  755. self
  756. updateProtocolsList;
  757. updateMethodsList;
  758. updateSourceAndButtons ]
  759. !
  760. selectProtocol: aString
  761. self cancelChanges ifTrue: [
  762. selectedProtocol := aString.
  763. selectedMethod := nil.
  764. self
  765. updateProtocolsList;
  766. updateMethodsList;
  767. updateSourceAndButtons ]
  768. !
  769. selectTab: aString
  770. self cancelChanges ifTrue: [
  771. selectedTab := aString.
  772. self selectProtocol: nil.
  773. self updateTabsList ]
  774. !
  775. setMethodProtocol: aString
  776. | klass |
  777. klass := self selectedClassOrMetaClass.
  778. self cancelChanges ifTrue: [ selectedMethod origin = klass
  779. ifFalse: [ Terminal alert: 'Method is from trait composition.' ]
  780. ifTrue: [ (self protocols includes: aString)
  781. ifFalse: [ self addNewProtocol ]
  782. ifTrue: [
  783. selectedMethod protocol: aString.
  784. klass compile: selectedMethod source protocol: aString.
  785. selectedProtocol := aString.
  786. self
  787. updateProtocolsList;
  788. updateMethodsList;
  789. updateSourceAndButtons ]]]
  790. !
  791. showClassButtons
  792. classButtons asJQuery show
  793. !
  794. showMethodButtons
  795. methodButtons asJQuery show
  796. ! !
  797. !Browser methodsFor: 'initialization'!
  798. initialize
  799. super initialize.
  800. selectedTab := #instance.
  801. selectedPackage := self packages first.
  802. unsavedChanges := false
  803. ! !
  804. !Browser methodsFor: 'rendering'!
  805. renderBottomPanelOn: html
  806. html div
  807. class: 'amber_sourceCode';
  808. with: [
  809. sourceArea := SourceArea new.
  810. sourceArea renderOn: html.
  811. sourceArea onKeyDown: [ :e |
  812. self handleSourceAreaKeyDown: e ].
  813. sourceArea onKeyUp: [ self updateStatus ]]
  814. !
  815. renderBoxOn: html
  816. self
  817. renderTopPanelOn: html;
  818. renderTabsOn: html;
  819. renderBottomPanelOn: html
  820. !
  821. renderButtonsOn: html
  822. saveButton := html button.
  823. saveButton
  824. with: 'Save';
  825. onClick: [ self compile ].
  826. methodButtons := html span.
  827. classButtons := html span.
  828. html div
  829. class: 'right';
  830. with: [
  831. html button
  832. with: 'DoIt';
  833. onClick: [ sourceArea doIt ].
  834. html button
  835. with: 'PrintIt';
  836. onClick: [ sourceArea printIt ].
  837. html button with: 'InspectIt';
  838. onClick: [ sourceArea inspectIt ]].
  839. self updateSourceAndButtons
  840. !
  841. renderTabsOn: html
  842. tabsList := html ul class: 'amber_tabs amber_browser'.
  843. self updateTabsList.
  844. !
  845. renderTopPanelOn: html
  846. html div
  847. class: 'top';
  848. with: [
  849. packagesList := html ul class: 'amber_column browser packages'.
  850. html div class: 'amber_packagesButtons'; with: [
  851. html button
  852. title: 'Commit classes in this package to disk';
  853. onClick: [ self commitPackage ];
  854. with: 'Commit'.
  855. html button
  856. title: 'Rename package';
  857. onClick: [ self renamePackage ];
  858. with: 'Rename'.
  859. html button
  860. title: 'Remove this package from the system';
  861. onClick: [ self removePackage ];
  862. with: 'Remove' ].
  863. classesList := ClassesList on: self.
  864. classesList renderOn: html.
  865. protocolsList := html ul class: 'amber_column browser protocols'.
  866. methodsList := html ul class: 'amber_column browser methods'.
  867. self
  868. updateCategoriesList;
  869. updateClassesList;
  870. updateProtocolsList;
  871. updateMethodsList.
  872. html div class: 'amber_clear' ]
  873. ! !
  874. !Browser methodsFor: 'testing'!
  875. canBeClosed
  876. ^ true
  877. ! !
  878. !Browser methodsFor: 'updating'!
  879. resetClassesList
  880. classesList resetNodes
  881. !
  882. updateCategoriesList
  883. packagesList contents: [ :html |
  884. self packages do: [ :each || li label |
  885. label := each ifEmpty: [ 'Unclassified' ].
  886. li := html li.
  887. selectedPackage = each ifTrue: [
  888. li class: 'selected' ].
  889. li
  890. with: label;
  891. onClick: [ self selectCategory: each ]] ]
  892. !
  893. updateClassesList
  894. TabManager current update.
  895. classesList updateNodes
  896. !
  897. updateMethodsList
  898. methodsList contents: [ :html |
  899. self methods do: [ :each || li |
  900. li := html li.
  901. selectedMethod = each ifTrue: [
  902. li class: 'selected' ].
  903. li
  904. with: each selector;
  905. with: (each origin = self selectedClassOrMetaClass ifTrue: [''] ifFalse: [ ' (', each origin name, ')' ]);
  906. onClick: [ self selectMethod: each ]] ]
  907. !
  908. updateProtocolsList
  909. protocolsList contents: [ :html |
  910. self protocols do: [ :each || li |
  911. li := html li.
  912. selectedProtocol = each ifTrue: [
  913. li class: 'selected' ].
  914. li
  915. with: each;
  916. onClick: [ self selectProtocol: each ]] ]
  917. !
  918. updateSourceAndButtons
  919. | currentProtocol |
  920. self disableSaveButton.
  921. classButtons contents: [ :html |
  922. html button
  923. title: 'Create a new class';
  924. onClick: [ self addNewClass ];
  925. with: 'New class'.
  926. html button
  927. with: 'Rename class';
  928. onClick: [ self renameClass ].
  929. html button
  930. with: 'Copy class';
  931. onClick: [ self copyClass ].
  932. html button
  933. with: 'Remove class';
  934. onClick: [ self removeClass ].
  935. html button
  936. with: 'References';
  937. onClick: [ self searchClassReferences ]].
  938. methodButtons contents: [ :html | | protocolSelect referencesSelect |
  939. html button
  940. with: 'Remove method';
  941. onClick: [ self removeMethod ].
  942. protocolSelect := html select.
  943. protocolSelect
  944. onChange: [ self setMethodProtocol: protocolSelect asJQuery val ];
  945. with: [
  946. html option
  947. with: 'Method protocol';
  948. at: 'disabled' put: 'disabled'.
  949. html option
  950. class: 'important';
  951. with: 'New...'.
  952. currentProtocol := selectedProtocol.
  953. (currentProtocol isNil and: [ selectedMethod notNil ])
  954. ifTrue: [ currentProtocol := selectedMethod category ].
  955. self protocols do: [ :each | | option |
  956. option := html option with: each.
  957. currentProtocol = each ifTrue: [ option at: 'selected' put: 'selected' ] ] ].
  958. selectedMethod isNil ifFalse: [
  959. referencesSelect := html select.
  960. referencesSelect
  961. onChange: [ self searchReferencesOf: referencesSelect asJQuery val ];
  962. with: [ |option|
  963. html option
  964. with: 'References';
  965. at: 'disabled' put: 'disabled';
  966. at: 'selected' put: 'selected'.
  967. html option
  968. class: 'important';
  969. with: selectedMethod selector.
  970. selectedMethod messageSends sorted do: [ :each |
  971. html option with: each ]] ]].
  972. selectedMethod isNil
  973. ifTrue: [
  974. self hideMethodButtons.
  975. (selectedClass isNil or: [ selectedProtocol notNil ])
  976. ifTrue: [ self hideClassButtons ]
  977. ifFalse: [ self showClassButtons ]]
  978. ifFalse: [
  979. self hideClassButtons.
  980. self showMethodButtons ].
  981. sourceArea val: self source
  982. !
  983. updateStatus
  984. sourceArea val = self source
  985. ifTrue: [
  986. saveButton ifNotNil: [
  987. saveButton at: 'disabled' put: true ].
  988. unsavedChanges := false ]
  989. ifFalse: [
  990. saveButton ifNotNil: [
  991. saveButton removeAt: 'disabled' ].
  992. unsavedChanges := true ]
  993. !
  994. updateTabsList
  995. tabsList contents: [ :html || li |
  996. li := html li.
  997. selectedTab = #instance ifTrue: [ li class: 'selected' ].
  998. li
  999. with: [
  1000. html span class: 'ltab'.
  1001. html span class: 'mtab'; with: 'Instance'.
  1002. html span class: 'rtab' ];
  1003. onClick: [ self selectTab: #instance ].
  1004. li := html li.
  1005. selectedTab = #class ifTrue: [ li class: 'selected' ].
  1006. li
  1007. with: [
  1008. html span class: 'ltab'.
  1009. html span class: 'mtab'; with: 'Class'.
  1010. html span class: 'rtab' ];
  1011. onClick: [ self selectTab: #class ].
  1012. li := html li.
  1013. selectedTab = #comment ifTrue: [ li class: 'selected' ].
  1014. li
  1015. with: [
  1016. html span class: 'ltab'.
  1017. html span class: 'mtab'; with: 'Comment'.
  1018. html span class: 'rtab' ];
  1019. onClick: [ self selectTab: #comment ]]
  1020. ! !
  1021. !Browser class methodsFor: 'convenience'!
  1022. open
  1023. self new open
  1024. !
  1025. openOn: aClass
  1026. ^ self new
  1027. open;
  1028. selectCategory: aClass category;
  1029. selectClass: aClass
  1030. ! !
  1031. TabWidget subclass: #Debugger
  1032. slots: {#error. #selectedContext. #sourceArea. #ul. #ul2. #inspector. #saveButton. #unsavedChanges. #selectedVariable. #selectedVariableName. #inspectButton}
  1033. package: 'IDE'!
  1034. !Debugger methodsFor: 'accessing'!
  1035. allVariables
  1036. | all |
  1037. all := Dictionary new.
  1038. self receiver class allInstanceVariableNames do: [ :each |
  1039. all at: each put: (self receiver instVarAt: each) ].
  1040. selectedContext locals keysAndValuesDo: [ :key :value |
  1041. all at: key put: value ].
  1042. ^ all
  1043. !
  1044. error
  1045. ^ error
  1046. !
  1047. error: anError
  1048. error := anError
  1049. !
  1050. label
  1051. ^ '[ Debugger ]'
  1052. !
  1053. method
  1054. ^ selectedContext method
  1055. !
  1056. receiver
  1057. ^ selectedContext receiver
  1058. !
  1059. source
  1060. ^ self method
  1061. ifNil: [ 'Method doesn''t exist!!' ]
  1062. ifNotNil: [ self method source ]
  1063. ! !
  1064. !Debugger methodsFor: 'actions'!
  1065. inspectSelectedVariable
  1066. selectedVariable inspect
  1067. !
  1068. proceed
  1069. self close.
  1070. selectedContext receiver perform: selectedContext selector withArguments: selectedContext locals
  1071. !
  1072. save
  1073. | protocol |
  1074. protocol := (selectedContext receiver class methodDictionary at: selectedContext selector) category.
  1075. selectedContext receiver class compile: sourceArea val protocol: protocol.
  1076. self updateStatus
  1077. !
  1078. selectContext: aContext
  1079. selectedContext := aContext.
  1080. selectedVariable := nil.
  1081. selectedVariableName := nil.
  1082. self
  1083. updateContextsList;
  1084. updateSourceArea;
  1085. updateInspector;
  1086. updateVariablesList;
  1087. updateStatus
  1088. !
  1089. selectVariable: anObject named: aString
  1090. selectedVariable := anObject.
  1091. selectedVariableName := aString.
  1092. inspector contents: [ :html | html with: anObject printString ].
  1093. self updateVariablesList
  1094. ! !
  1095. !Debugger methodsFor: 'initialization'!
  1096. initialize
  1097. super initialize.
  1098. unsavedChanges = false
  1099. ! !
  1100. !Debugger methodsFor: 'rendering'!
  1101. renderBottomPanelOn: html
  1102. html div
  1103. class: 'amber_sourceCode debugger';
  1104. with: [
  1105. sourceArea := SourceArea new.
  1106. sourceArea renderOn: html ].
  1107. ul2 := html ul class: 'amber_column debugger variables'.
  1108. inspector := html div class: 'amber_column debugger inspector'.
  1109. sourceArea
  1110. onKeyUp: [ self updateStatus ]
  1111. !
  1112. renderBoxOn: html
  1113. self
  1114. renderTopPanelOn: html;
  1115. renderBottomPanelOn: html
  1116. !
  1117. renderButtonsOn: html
  1118. saveButton := html button
  1119. with: 'Save';
  1120. onClick: [ self save ].
  1121. html button
  1122. with: 'DoIt';
  1123. onClick: [ sourceArea doIt ].
  1124. html button
  1125. with: 'PrintIt';
  1126. onClick: [ sourceArea printIt ].
  1127. html button
  1128. with: 'InspectIt';
  1129. onClick: [ sourceArea inspectIt ].
  1130. html button
  1131. with: 'Proceed';
  1132. onClick: [ self proceed ].
  1133. html button
  1134. with: 'Abandon';
  1135. onClick: [ self close ].
  1136. inspectButton := html button
  1137. class: 'amber_button debugger inspect';
  1138. with: 'Inspect';
  1139. onClick: [ self inspectSelectedVariable ].
  1140. self
  1141. updateSourceArea;
  1142. updateStatus;
  1143. updateVariablesList;
  1144. updateInspector
  1145. !
  1146. renderContext: aContext on: html
  1147. | li context |
  1148. context := aContext.
  1149. [ context notNil ] whileTrue: [
  1150. li := html li.
  1151. selectedContext = context ifTrue: [ li class: 'selected' ].
  1152. li
  1153. with: context asString;
  1154. onClick: (context in: [:ctx | [ self selectContext: ctx ]]).
  1155. context := context outerContext ]
  1156. !
  1157. renderTopPanelOn: html
  1158. selectedContext := self error context.
  1159. html div
  1160. class: 'top';
  1161. with: [
  1162. html div
  1163. class: 'label';
  1164. with: self error messageText.
  1165. ul := html ul
  1166. class: 'amber_column debugger contexts';
  1167. with: [ self renderContext: self error context on: html ]]
  1168. ! !
  1169. !Debugger methodsFor: 'testing'!
  1170. canBeClosed
  1171. ^ true
  1172. ! !
  1173. !Debugger methodsFor: 'updating'!
  1174. updateContextsList
  1175. ul contents: [ :html |
  1176. self renderContext: self error context on: html ]
  1177. !
  1178. updateInspector
  1179. inspector contents: [ :html | ]
  1180. !
  1181. updateSourceArea
  1182. sourceArea val: self source
  1183. !
  1184. updateStatus
  1185. sourceArea val = self source
  1186. ifTrue: [
  1187. saveButton ifNotNil: [
  1188. saveButton at: 'disabled' put: true ].
  1189. unsavedChanges := false ]
  1190. ifFalse: [
  1191. saveButton ifNotNil: [
  1192. saveButton removeAt: 'disabled' ].
  1193. unsavedChanges := true ]
  1194. !
  1195. updateVariablesList
  1196. ul2 contents: [ :html | | li |
  1197. li := html li
  1198. with: 'self';
  1199. onClick: [ self selectVariable: self receiver named: 'self' ].
  1200. selectedVariableName = 'self' ifTrue: [ li class: 'selected' ].
  1201. self allVariables keysAndValuesDo: [ :key :value |
  1202. li := html li
  1203. with: key;
  1204. onClick: [ self selectVariable: value named: key ].
  1205. selectedVariableName = key ifTrue: [
  1206. li class: 'selected' ] ] ].
  1207. selectedVariable
  1208. ifNil: [ inspectButton at: 'disabled' put: true ]
  1209. ifNotNil: [ inspectButton removeAt: 'disabled' ]
  1210. ! !
  1211. TabWidget subclass: #IDEInspector
  1212. slots: {#label. #variables. #object. #selectedVariable. #variablesList. #valueTextarea. #diveButton. #sourceArea}
  1213. package: 'IDE'!
  1214. !IDEInspector methodsFor: 'accessing'!
  1215. label
  1216. ^ label ifNil: [ 'Inspector (nil)' ]
  1217. !
  1218. selectedVariable
  1219. ^ selectedVariable
  1220. !
  1221. selectedVariable: aString
  1222. selectedVariable := aString
  1223. !
  1224. setLabel: aString
  1225. label := aString
  1226. !
  1227. setVariables: aCollection
  1228. variables := aCollection
  1229. !
  1230. sourceArea
  1231. ^ sourceArea
  1232. !
  1233. variables
  1234. ^ variables
  1235. ! !
  1236. !IDEInspector methodsFor: 'actions'!
  1237. dive
  1238. (self variables at: self selectedVariable) inspect
  1239. !
  1240. inspect: anObject
  1241. object := anObject.
  1242. variables := #().
  1243. object inspectOn: self
  1244. !
  1245. refresh
  1246. self
  1247. inspect: object;
  1248. updateVariablesList;
  1249. updateValueTextarea
  1250. ! !
  1251. !IDEInspector methodsFor: 'rendering'!
  1252. renderBottomPanelOn: html
  1253. html div
  1254. class: 'amber_sourceCode';
  1255. with: [
  1256. sourceArea := SourceArea new
  1257. receiver: object;
  1258. onDoIt: [ self refresh ];
  1259. yourself.
  1260. sourceArea renderOn: html ]
  1261. !
  1262. renderBoxOn: html
  1263. self
  1264. renderTopPanelOn: html;
  1265. renderBottomPanelOn: html
  1266. !
  1267. renderButtonsOn: html
  1268. html button
  1269. with: 'DoIt';
  1270. onClick: [ self sourceArea doIt ].
  1271. html button
  1272. with: 'PrintIt';
  1273. onClick: [ self sourceArea printIt ].
  1274. html button
  1275. with: 'InspectIt';
  1276. onClick: [ self sourceArea inspectIt ].
  1277. self updateButtons
  1278. !
  1279. renderTopPanelOn: html
  1280. html div
  1281. class: 'top';
  1282. with: [
  1283. variablesList := html ul class: 'amber_column variables'.
  1284. valueTextarea := html textarea class: 'amber_column value'; at: 'readonly' put: 'readonly'; yourself.
  1285. html div class: 'amber_tabs inspector'; with: [
  1286. html button
  1287. class: 'amber_button inspector refresh';
  1288. with: 'Refresh';
  1289. onClick: [ self refresh ].
  1290. diveButton := html button
  1291. class: 'amber_button inspector dive';
  1292. with: 'Dive';
  1293. onClick: [ self dive ]].
  1294. html div class: 'amber_clear' ].
  1295. self
  1296. updateVariablesList;
  1297. updateValueTextarea.
  1298. ! !
  1299. !IDEInspector methodsFor: 'testing'!
  1300. canBeClosed
  1301. ^ true
  1302. ! !
  1303. !IDEInspector methodsFor: 'updating'!
  1304. selectVariable: aString
  1305. self selectedVariable: aString.
  1306. self
  1307. updateVariablesList;
  1308. updateValueTextarea;
  1309. updateButtons
  1310. !
  1311. updateButtons
  1312. (self selectedVariable notNil and: [ (self variables at: self selectedVariable) notNil ])
  1313. ifFalse: [ diveButton at: 'disabled' put: true ]
  1314. ifTrue: [ diveButton removeAt: 'disabled' ]
  1315. !
  1316. updateValueTextarea
  1317. valueTextarea asJQuery val: (self selectedVariable isNil
  1318. ifTrue: [ '' ]
  1319. ifFalse: [ (self variables at: self selectedVariable) printString ])
  1320. !
  1321. updateVariablesList
  1322. variablesList contents: [ :html |
  1323. self variables keysDo: [ :each || li |
  1324. li := html li.
  1325. li
  1326. with: each;
  1327. onClick: [ self selectVariable: each ].
  1328. self selectedVariable = each ifTrue: [
  1329. li class: 'selected' ]] ]
  1330. ! !
  1331. !IDEInspector class methodsFor: 'instance creation'!
  1332. inspect: anObject
  1333. ^ self new
  1334. inspect: anObject;
  1335. open;
  1336. yourself
  1337. !
  1338. on: anObject
  1339. ^ self new
  1340. inspect: anObject;
  1341. yourself
  1342. ! !
  1343. TabWidget subclass: #IDETranscript
  1344. slots: {#textarea}
  1345. package: 'IDE'!
  1346. !IDETranscript methodsFor: 'accessing'!
  1347. label
  1348. ^ 'Transcript'
  1349. ! !
  1350. !IDETranscript methodsFor: 'actions'!
  1351. clear
  1352. textarea asJQuery val: ''
  1353. !
  1354. cr
  1355. textarea asJQuery val: textarea asJQuery val, String cr.
  1356. !
  1357. open
  1358. TabManager current
  1359. open;
  1360. selectTab: self
  1361. !
  1362. show: anObject
  1363. textarea ifNil: [ self open ].
  1364. textarea asJQuery val: textarea asJQuery val, anObject asString.
  1365. ! !
  1366. !IDETranscript methodsFor: 'rendering'!
  1367. renderBoxOn: html
  1368. textarea := html textarea.
  1369. textarea
  1370. class: 'amber_transcript';
  1371. at: 'spellcheck' put: 'false'
  1372. !
  1373. renderButtonsOn: html
  1374. html button
  1375. with: 'Clear transcript';
  1376. onClick: [ self clear ]
  1377. ! !
  1378. IDETranscript class slots: {#current}!
  1379. !IDETranscript class methodsFor: 'initialization'!
  1380. initialize
  1381. Transcript register: self current
  1382. ! !
  1383. !IDETranscript class methodsFor: 'instance creation'!
  1384. current
  1385. ^ current ifNil: [ current := super new ]
  1386. !
  1387. new
  1388. self shouldNotImplement
  1389. !
  1390. open
  1391. TabManager current
  1392. open;
  1393. selectTab: self current
  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. ! !