IDE.st 47 KB

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