IDE.st 48 KB

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