IDE.st 47 KB

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