IDE.st 49 KB

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