IDE.st 44 KB

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