IDE.st 46 KB

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