IDE.st 46 KB

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