2
0

IDE.st 47 KB

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