1
0

IDE.st 46 KB

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