2
0

IDE.st 49 KB

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