IDE.st 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201
  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. [
  73. anError context ifNil: [ anError context: thisContext ].
  74. Debugger new error: anError; open ]
  75. on: Error do: [ :error | 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 instVarNamed: 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. selectedVariableValue
  1225. ^ (self variables detect: [ :each | each key = self selectedVariable ]) value
  1226. !
  1227. setLabel: aString
  1228. label := aString
  1229. !
  1230. setVariables: aCollection
  1231. variables :=
  1232. (aCollection respondsTo: #associations)
  1233. ifTrue: [ aCollection associations ]
  1234. ifFalse: [ aCollection ]
  1235. !
  1236. sourceArea
  1237. ^ sourceArea
  1238. !
  1239. variables
  1240. ^ variables
  1241. ! !
  1242. !IDEInspector methodsFor: 'actions'!
  1243. dive
  1244. self selectedVariableValue inspect
  1245. !
  1246. inspect: anObject
  1247. object := anObject.
  1248. variables := #().
  1249. object inspectOn: self
  1250. !
  1251. refresh
  1252. self
  1253. inspect: object;
  1254. updateVariablesList;
  1255. updateValueTextarea
  1256. ! !
  1257. !IDEInspector methodsFor: 'rendering'!
  1258. renderBottomPanelOn: html
  1259. html div
  1260. class: 'amber_sourceCode';
  1261. with: [
  1262. sourceArea := SourceArea new
  1263. receiver: object;
  1264. onDoIt: [ self refresh ];
  1265. yourself.
  1266. sourceArea renderOn: html ]
  1267. !
  1268. renderBoxOn: html
  1269. self
  1270. renderTopPanelOn: html;
  1271. renderBottomPanelOn: html
  1272. !
  1273. renderButtonsOn: html
  1274. html button
  1275. with: 'DoIt';
  1276. onClick: [ self sourceArea doIt ].
  1277. html button
  1278. with: 'PrintIt';
  1279. onClick: [ self sourceArea printIt ].
  1280. html button
  1281. with: 'InspectIt';
  1282. onClick: [ self sourceArea inspectIt ].
  1283. self updateButtons
  1284. !
  1285. renderTopPanelOn: html
  1286. html div
  1287. class: 'top';
  1288. with: [
  1289. variablesList := html ul class: 'amber_column variables'.
  1290. valueTextarea := html textarea class: 'amber_column value'; at: 'readonly' put: 'readonly'; yourself.
  1291. html div class: 'amber_tabs inspector'; with: [
  1292. html button
  1293. class: 'amber_button inspector refresh';
  1294. with: 'Refresh';
  1295. onClick: [ self refresh ].
  1296. diveButton := html button
  1297. class: 'amber_button inspector dive';
  1298. with: 'Dive';
  1299. onClick: [ self dive ]].
  1300. html div class: 'amber_clear' ].
  1301. self
  1302. updateVariablesList;
  1303. updateValueTextarea.
  1304. ! !
  1305. !IDEInspector methodsFor: 'testing'!
  1306. canBeClosed
  1307. ^ true
  1308. ! !
  1309. !IDEInspector methodsFor: 'updating'!
  1310. selectVariable: aString
  1311. self selectedVariable: aString.
  1312. self
  1313. updateVariablesList;
  1314. updateValueTextarea;
  1315. updateButtons
  1316. !
  1317. updateButtons
  1318. (self selectedVariable notNil and: [ self selectedVariableValue notNil ])
  1319. ifFalse: [ diveButton at: 'disabled' put: true ]
  1320. ifTrue: [ diveButton removeAt: 'disabled' ]
  1321. !
  1322. updateValueTextarea
  1323. valueTextarea asJQuery val: (self selectedVariable isNil
  1324. ifTrue: [ '' ]
  1325. ifFalse: [ self selectedVariableValue printString ])
  1326. !
  1327. updateVariablesList
  1328. variablesList contents: [ :html |
  1329. self variables do: [ :each || li |
  1330. li := html li.
  1331. li
  1332. with: each key;
  1333. onClick: [ self selectVariable: each key ].
  1334. self selectedVariable = each key ifTrue: [
  1335. li class: 'selected' ]] ]
  1336. ! !
  1337. !IDEInspector class methodsFor: 'instance creation'!
  1338. inspect: anObject
  1339. ^ self new
  1340. inspect: anObject;
  1341. open;
  1342. yourself
  1343. !
  1344. on: anObject
  1345. ^ self new
  1346. inspect: anObject;
  1347. yourself
  1348. ! !
  1349. TabWidget subclass: #IDETranscript
  1350. slots: {#textarea}
  1351. package: 'IDE'!
  1352. !IDETranscript methodsFor: 'accessing'!
  1353. label
  1354. ^ 'Transcript'
  1355. ! !
  1356. !IDETranscript methodsFor: 'actions'!
  1357. clear
  1358. textarea asJQuery val: ''
  1359. !
  1360. cr
  1361. textarea asJQuery val: textarea asJQuery val, String cr.
  1362. !
  1363. open
  1364. TabManager current
  1365. open;
  1366. selectTab: self
  1367. !
  1368. show: anObject
  1369. textarea ifNil: [ self open ].
  1370. textarea asJQuery val: textarea asJQuery val, anObject asString.
  1371. ! !
  1372. !IDETranscript methodsFor: 'rendering'!
  1373. renderBoxOn: html
  1374. textarea := html textarea.
  1375. textarea
  1376. class: 'amber_transcript';
  1377. at: 'spellcheck' put: 'false'
  1378. !
  1379. renderButtonsOn: html
  1380. html button
  1381. with: 'Clear transcript';
  1382. onClick: [ self clear ]
  1383. ! !
  1384. IDETranscript class slots: {#current}!
  1385. !IDETranscript class methodsFor: 'initialization'!
  1386. initialize
  1387. Transcript register: self current
  1388. ! !
  1389. !IDETranscript class methodsFor: 'instance creation'!
  1390. current
  1391. ^ current ifNil: [ current := super new ]
  1392. !
  1393. new
  1394. self shouldNotImplement
  1395. !
  1396. open
  1397. TabManager current
  1398. open;
  1399. selectTab: self current
  1400. ! !
  1401. TabWidget subclass: #ReferencesBrowser
  1402. slots: {#implementors. #senders. #implementorsList. #input. #timer. #selector. #sendersList. #referencedClasses. #referencedClassesList. #matches. #matchesList}
  1403. package: 'IDE'!
  1404. !ReferencesBrowser methodsFor: 'accessing'!
  1405. classesAndMetaclasses
  1406. ^ Smalltalk classes, (Smalltalk classes collect: [ :each | each theMetaClass ]) copyWithout: nil
  1407. !
  1408. implementors
  1409. ^ implementors ifNil: [ implementors := Array new ]
  1410. !
  1411. label
  1412. ^ '[ References ]'
  1413. !
  1414. matches
  1415. ^ matches ifNil: [ matches := Array new ]
  1416. !
  1417. referencedClasses
  1418. ^ referencedClasses ifNil: [ referencedClasses := Array new ]
  1419. !
  1420. selector
  1421. ^ selector
  1422. !
  1423. senders
  1424. ^ senders ifNil: [ senders := Array new ]
  1425. ! !
  1426. !ReferencesBrowser methodsFor: 'actions'!
  1427. openBrowserOn: aMethod
  1428. | browser |
  1429. browser := Browser openOn: (aMethod methodClass isMetaclass
  1430. ifTrue: [ aMethod methodClass instanceClass ] ifFalse: [ aMethod methodClass ]).
  1431. aMethod methodClass isMetaclass ifTrue: [ browser selectTab: #class ].
  1432. browser
  1433. selectProtocol: aMethod category;
  1434. selectMethod: aMethod
  1435. !
  1436. search: aString
  1437. self
  1438. searchReferencesFor: aString;
  1439. updateImplementorsList;
  1440. updateSendersList;
  1441. updateReferencedClassesList;
  1442. updateMatchesList
  1443. !
  1444. searchMethodSource
  1445. | regex |
  1446. regex := selector allButFirst.
  1447. self classesAndMetaclasses do: [ :each |
  1448. each methodDictionary valuesDo: [ :value |
  1449. (value source match: regex) ifTrue: [
  1450. self matches add: value ]] ]
  1451. !
  1452. searchReferencedClasses
  1453. self classesAndMetaclasses do: [ :each |
  1454. each methodDictionary valuesDo: [ :value |
  1455. (value referencedClasses includes: selector) ifTrue: [
  1456. self referencedClasses add: value ]] ]
  1457. !
  1458. searchReferencesFor: aString
  1459. selector := aString.
  1460. implementors := Array new.
  1461. senders := Array new.
  1462. referencedClasses := Array new.
  1463. matches := Array new.
  1464. self searchMethodSource.
  1465. (selector match: '^[A-Z]')
  1466. ifFalse: [ self searchSelectorReferences ]
  1467. ifTrue: [ self searchReferencedClasses ]
  1468. !
  1469. searchSelectorReferences
  1470. self classesAndMetaclasses do: [ :each |
  1471. each methodDictionary keysAndValuesDo: [ :key :value |
  1472. key = selector ifTrue: [ self implementors add: value ].
  1473. (value messageSends includes: selector) ifTrue: [
  1474. self senders add: value ]] ]
  1475. ! !
  1476. !ReferencesBrowser methodsFor: 'initialization'!
  1477. initialize
  1478. super initialize.
  1479. selector := ''
  1480. ! !
  1481. !ReferencesBrowser methodsFor: 'private'!
  1482. setInputEvents
  1483. input
  1484. onKeyUp: [ timer := [ self search: input asJQuery val ] valueWithTimeout: 100 ];
  1485. onKeyDown: [ timer ifNotNil: [ timer clearTimeout ]]
  1486. ! !
  1487. !ReferencesBrowser methodsFor: 'rendering'!
  1488. renderBoxOn: html
  1489. self
  1490. renderInputOn: html;
  1491. renderImplementorsOn: html;
  1492. renderSendersOn: html;
  1493. renderReferencedClassesOn: html;
  1494. renderMatchesOn: html
  1495. !
  1496. renderImplementorsOn: html
  1497. implementorsList := html ul class: 'amber_column implementors'.
  1498. self updateImplementorsList
  1499. !
  1500. renderInputOn: html
  1501. input := html input
  1502. class: 'implementors';
  1503. yourself.
  1504. input asJQuery val: selector.
  1505. self setInputEvents
  1506. !
  1507. renderMatchesOn: html
  1508. matchesList := html ul class: 'amber_column matches'.
  1509. self updateMatchesList
  1510. !
  1511. renderReferencedClassesOn: html
  1512. referencedClassesList := html ul class: 'amber_column referenced_classes'.
  1513. self updateReferencedClassesList
  1514. !
  1515. renderSendersOn: html
  1516. sendersList := html ul class: 'amber_column senders'.
  1517. self updateSendersList
  1518. ! !
  1519. !ReferencesBrowser methodsFor: 'testing'!
  1520. canBeClosed
  1521. ^ true
  1522. ! !
  1523. !ReferencesBrowser methodsFor: 'updating'!
  1524. updateImplementorsList
  1525. implementorsList contents: [ :html |
  1526. html li
  1527. class: 'column_label';
  1528. with: 'Implementors (', self implementors size asString, ')';
  1529. style: 'font-weight: bold'.
  1530. self implementors do: [ :each || li |
  1531. li := html li.
  1532. li
  1533. with: each asString;
  1534. onClick: [ self openBrowserOn: each ]] ]
  1535. !
  1536. updateMatchesList
  1537. matchesList contents: [ :html |
  1538. html li
  1539. class: 'column_label';
  1540. with: 'Regex matches (', self matches size asString, ')';
  1541. style: 'font-weight: bold'.
  1542. self matches do: [ :each || li |
  1543. li := html li.
  1544. li
  1545. with: each asString;
  1546. onClick: [ self openBrowserOn: each ]] ]
  1547. !
  1548. updateReferencedClassesList
  1549. referencedClassesList contents: [ :html |
  1550. html li
  1551. class: 'column_label';
  1552. with: 'Class references (', self referencedClasses size asString, ')';
  1553. style: 'font-weight: bold'.
  1554. self referencedClasses do: [ :each |
  1555. html li
  1556. with: each asString;
  1557. onClick: [ self openBrowserOn: each ]] ]
  1558. !
  1559. updateSendersList
  1560. sendersList contents: [ :html |
  1561. html li
  1562. class: 'column_label';
  1563. with: 'Senders (', self senders size asString, ')';
  1564. style: 'font-weight: bold'.
  1565. self senders do: [ :each |
  1566. html li
  1567. with: each asString;
  1568. onClick: [ self openBrowserOn: each ]] ]
  1569. ! !
  1570. !ReferencesBrowser class methodsFor: 'instance creation'!
  1571. search: aString
  1572. ^ self new
  1573. searchReferencesFor: aString;
  1574. open
  1575. ! !
  1576. TabWidget subclass: #TestRunner
  1577. slots: {#selectedCategories. #packagesList. #selectedClasses. #classesList. #selectedMethods. #progressBar. #methodsList. #result. #statusDiv}
  1578. package: 'IDE'!
  1579. !TestRunner methodsFor: 'accessing'!
  1580. allClasses
  1581. ^ TestCase allSubclasses select: [ :each | each isAbstract not ]
  1582. !
  1583. classes
  1584. ^ (self allClasses
  1585. select: [ :each | self selectedCategories includes: each category ])
  1586. sort: [ :a :b | a name > b name ]
  1587. !
  1588. label
  1589. ^ 'SUnit'
  1590. !
  1591. packages
  1592. | packages |
  1593. packages := Array new.
  1594. self allClasses do: [ :each |
  1595. (packages includes: each category) ifFalse: [
  1596. packages add: each category ]].
  1597. ^ packages sort
  1598. !
  1599. progressBar
  1600. ^ progressBar ifNil: [ progressBar := ProgressBar new ]
  1601. !
  1602. result
  1603. ^ result
  1604. !
  1605. selectedCategories
  1606. ^ selectedCategories ifNil: [ selectedCategories := Array new ]
  1607. !
  1608. selectedClasses
  1609. ^ selectedClasses ifNil: [ selectedClasses := Array new ]
  1610. !
  1611. statusInfo
  1612. ^ self printTotal, self printPasses, self printErrors, self printFailures
  1613. !
  1614. testCases
  1615. | testCases |
  1616. testCases := #().
  1617. (self selectedClasses
  1618. select: [ :each | self selectedCategories includes: each category ])
  1619. do: [ :each | testCases addAll: each buildSuite ].
  1620. ^ testCases
  1621. ! !
  1622. !TestRunner methodsFor: 'actions'!
  1623. performFailure: aTestCase
  1624. aTestCase runCase
  1625. !
  1626. run: aCollection
  1627. | worker |
  1628. worker := TestSuiteRunner on: aCollection.
  1629. result := worker result.
  1630. worker announcer on: ResultAnnouncement do: [ :ann |
  1631. ann result == result ifTrue: [
  1632. self progressBar updatePercent: result runs / result total * 100.
  1633. self updateStatusDiv.
  1634. self updateMethodsList
  1635. ]
  1636. ].
  1637. worker run
  1638. !
  1639. selectAllCategories
  1640. self packages do: [ :each |
  1641. (selectedCategories includes: each) ifFalse: [
  1642. self selectedCategories add: each ]].
  1643. self
  1644. updateCategoriesList;
  1645. updateClassesList
  1646. !
  1647. selectAllClasses
  1648. self classes do: [ :each |
  1649. (selectedClasses includes: each) ifFalse: [
  1650. self selectedClasses add: each ]].
  1651. self
  1652. updateCategoriesList;
  1653. updateClassesList
  1654. !
  1655. toggleCategory: aCategory
  1656. (self isSelectedCategory: aCategory)
  1657. ifFalse: [ selectedCategories add: aCategory ]
  1658. ifTrue: [ selectedCategories remove: aCategory ].
  1659. self
  1660. updateCategoriesList;
  1661. updateClassesList
  1662. !
  1663. toggleClass: aClass
  1664. (self isSelectedClass: aClass)
  1665. ifFalse: [ selectedClasses add: aClass ]
  1666. ifTrue: [ selectedClasses remove: aClass ].
  1667. self
  1668. updateClassesList
  1669. ! !
  1670. !TestRunner methodsFor: 'initialization'!
  1671. initialize
  1672. super initialize.
  1673. result := TestResult new
  1674. ! !
  1675. !TestRunner methodsFor: 'printing'!
  1676. printErrors
  1677. ^ self result errors size asString , ' errors, '
  1678. !
  1679. printFailures
  1680. ^ self result failures size asString, ' failures'
  1681. !
  1682. printPasses
  1683. ^ (self result runs - self result errors size - self result failures size) asString , ' passes, '
  1684. !
  1685. printTotal
  1686. ^ self result total asString, ' runs, '
  1687. ! !
  1688. !TestRunner methodsFor: 'rendering'!
  1689. renderBoxOn: html
  1690. self
  1691. renderCategoriesOn: html;
  1692. renderClassesOn: html;
  1693. renderResultsOn: html
  1694. !
  1695. renderButtonsOn: html
  1696. html button
  1697. with: 'Run selected';
  1698. onClick: [ self run: self testCases ]
  1699. !
  1700. renderCategoriesOn: html
  1701. packagesList := html ul class: 'amber_column sunit packages'.
  1702. self updateCategoriesList
  1703. !
  1704. renderClassesOn: html
  1705. classesList := html ul class: 'amber_column sunit classes'.
  1706. self updateClassesList
  1707. !
  1708. renderErrorsOn: html
  1709. self result errors do: [ :each |
  1710. html li
  1711. class: 'errors';
  1712. with: each class name, ' >> ', each selector;
  1713. onClick: [ self performFailure: each ]]
  1714. !
  1715. renderFailuresOn: html
  1716. self result failures do: [ :each |
  1717. html li
  1718. class: 'failures';
  1719. with: each class name, ' >> ', each selector;
  1720. onClick: [ self performFailure: each ]]
  1721. !
  1722. renderResultsOn: html
  1723. statusDiv := html div.
  1724. html with: self progressBar.
  1725. methodsList := html ul class: 'amber_column sunit results'.
  1726. self updateMethodsList.
  1727. self updateStatusDiv
  1728. ! !
  1729. !TestRunner methodsFor: 'testing'!
  1730. isSelectedCategory: aCategory
  1731. ^ (self selectedCategories includes: aCategory)
  1732. !
  1733. isSelectedClass: aClass
  1734. ^ (self selectedClasses includes: aClass)
  1735. ! !
  1736. !TestRunner methodsFor: 'updating'!
  1737. updateCategoriesList
  1738. packagesList contents: [ :html |
  1739. html li
  1740. class: 'all';
  1741. with: 'All';
  1742. onClick: [ self selectAllCategories ].
  1743. self packages do: [ :each || li |
  1744. li := html li.
  1745. (self selectedCategories includes: each) ifTrue: [
  1746. li class: 'selected' ].
  1747. li
  1748. with: each;
  1749. onClick: [ self toggleCategory: each ]] ]
  1750. !
  1751. updateClassesList
  1752. classesList contents: [ :html |
  1753. self selectedCategories ifNotEmpty: [
  1754. html li
  1755. class: 'all';
  1756. with: 'All';
  1757. onClick: [ self selectAllClasses ]].
  1758. self classes do: [ :each || li |
  1759. li := html li.
  1760. (self selectedClasses includes: each) ifTrue: [
  1761. li class: 'selected' ].
  1762. li
  1763. with: each name;
  1764. onClick: [ self toggleClass: each ]] ]
  1765. !
  1766. updateMethodsList
  1767. methodsList contents: [ :html |
  1768. self renderErrorsOn: html.
  1769. self renderFailuresOn: html ]
  1770. !
  1771. updateStatusDiv
  1772. statusDiv class: 'sunit status ', result status.
  1773. statusDiv contents: [ :html |
  1774. html span with: self statusInfo ]
  1775. ! !
  1776. TabWidget subclass: #Workspace
  1777. slots: {#sourceArea}
  1778. package: 'IDE'!
  1779. !Workspace methodsFor: 'accessing'!
  1780. label
  1781. ^ 'Workspace'
  1782. ! !
  1783. !Workspace methodsFor: 'actions'!
  1784. clearWorkspace
  1785. sourceArea clear
  1786. !
  1787. doIt
  1788. sourceArea doIt
  1789. !
  1790. fileIn
  1791. sourceArea fileIn
  1792. !
  1793. inspectIt
  1794. sourceArea inspectIt
  1795. !
  1796. printIt
  1797. sourceArea printIt
  1798. !
  1799. show
  1800. super show.
  1801. sourceArea focus.
  1802. ! !
  1803. !Workspace methodsFor: 'rendering'!
  1804. renderBoxOn: html
  1805. sourceArea := SourceArea new.
  1806. sourceArea renderOn: html
  1807. !
  1808. renderButtonsOn: html
  1809. html button
  1810. with: 'DoIt';
  1811. title: 'ctrl+d';
  1812. onClick: [ self doIt ].
  1813. html button
  1814. with: 'PrintIt';
  1815. title: 'ctrl+p';
  1816. onClick: [ self printIt ].
  1817. html button
  1818. with: 'InspectIt';
  1819. title: 'ctrl+i';
  1820. onClick: [ self inspectIt ].
  1821. html button
  1822. with: 'FileIn';
  1823. title: 'ctrl+f';
  1824. onClick: [ self fileIn ].
  1825. html button
  1826. with: 'Clear workspace';
  1827. onClick: [ self clearWorkspace ]
  1828. ! !