2
0

IDE.st 47 KB

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