1
0

IDE.st 48 KB

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