1
0

IDE.st 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345
  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: IDETranscript 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: #Browser
  277. instanceVariableNames: 'selectedPackage selectedClass selectedProtocol selectedMethod packagesList classesList protocolsList methodsList sourceArea tabsList selectedTab saveButton classButtons methodButtons unsavedChanges'
  278. category: 'IDE'!
  279. !Browser methodsFor: 'accessing'!
  280. label
  281. ^selectedClass
  282. ifNil: ['Browser (nil)']
  283. ifNotNil: ['Browser: ', selectedClass name]
  284. !
  285. packages
  286. | packages |
  287. packages := Array new.
  288. Smalltalk current classes do: [:each |
  289. (packages includes: each category) ifFalse: [
  290. packages add: each category]].
  291. ^packages sort
  292. !
  293. classes
  294. ^(Smalltalk current classes
  295. select: [:each | each category = selectedPackage])
  296. sort: [:a :b | a name < b name]
  297. !
  298. protocols
  299. | klass |
  300. selectedClass ifNotNil: [
  301. selectedTab = #comment ifTrue: [^#()].
  302. klass := selectedTab = #instance
  303. ifTrue: [selectedClass]
  304. ifFalse: [selectedClass class].
  305. klass methodDictionary isEmpty ifTrue: [
  306. ^Array with: 'not yet classified'].
  307. ^klass protocols].
  308. ^Array new
  309. !
  310. methods
  311. | klass |
  312. selectedTab = #comment ifTrue: [^#()].
  313. selectedClass ifNotNil: [
  314. klass := selectedTab = #instance
  315. ifTrue: [selectedClass]
  316. ifFalse: [selectedClass class]].
  317. ^(selectedProtocol
  318. ifNil: [
  319. klass
  320. ifNil: [#()]
  321. ifNotNil: [klass methodDictionary values]]
  322. ifNotNil: [
  323. klass methodDictionary values select: [:each |
  324. each category = selectedProtocol]]) sort: [:a :b | a selector < b selector]
  325. !
  326. source
  327. selectedTab = #comment ifFalse: [
  328. ^(selectedProtocol notNil or: [selectedMethod notNil])
  329. ifFalse: [self declarationSource]
  330. ifTrue: [self methodSource]].
  331. ^selectedClass
  332. ifNil: ['']
  333. ifNotNil: [self classCommentSource]
  334. !
  335. methodSource
  336. ^selectedMethod
  337. ifNil: [self dummyMethodSource]
  338. ifNotNil: [selectedMethod source]
  339. !
  340. dummyMethodSource
  341. ^'messageSelectorAndArgumentNames
  342. "comment stating purpose of message"
  343. | temporary variable names |
  344. statements'
  345. !
  346. declarationSource
  347. ^selectedTab = #instance
  348. ifTrue: [self classDeclarationSource]
  349. ifFalse: [self metaclassDeclarationSource]
  350. !
  351. classDeclarationSource
  352. | stream |
  353. stream := '' writeStream.
  354. selectedClass ifNil: [^self classDeclarationTemplate].
  355. stream
  356. nextPutAll: selectedClass superclass asString;
  357. nextPutAll: ' subclass: #';
  358. nextPutAll: selectedClass name;
  359. nextPutAll: String lf, String tab;
  360. nextPutAll: 'instanceVariableNames: '''.
  361. selectedClass instanceVariableNames
  362. do: [:each | stream nextPutAll: each]
  363. separatedBy: [stream nextPutAll: ' '].
  364. stream
  365. nextPutAll: '''', String lf, String tab;
  366. nextPutAll: 'package: ''';
  367. nextPutAll: selectedClass category;
  368. nextPutAll: ''''.
  369. ^stream contents
  370. !
  371. metaclassDeclarationSource
  372. | stream |
  373. stream := '' writeStream.
  374. selectedClass ifNotNil: [
  375. stream
  376. nextPutAll: selectedClass asString;
  377. nextPutAll: ' class ';
  378. nextPutAll: 'instanceVariableNames: '''.
  379. selectedClass class instanceVariableNames
  380. do: [:each | stream nextPutAll: each]
  381. separatedBy: [stream nextPutAll: ' '].
  382. stream nextPutAll: ''''].
  383. ^stream contents
  384. !
  385. classCommentSource
  386. ^selectedClass comment
  387. !
  388. selectedClass
  389. ^selectedClass
  390. !
  391. classDeclarationTemplate
  392. ^'Object subclass: #nameOfSubclass
  393. instanceVariableNames: ''''
  394. package: ''', self selectedPackage, ''''
  395. !
  396. selectedPackage
  397. ^selectedPackage
  398. ! !
  399. !Browser methodsFor: 'actions'!
  400. disableSaveButton
  401. saveButton ifNotNil: [
  402. saveButton at: 'disabled' put: true].
  403. unsavedChanges := false
  404. !
  405. hideClassButtons
  406. classButtons asJQuery hide
  407. !
  408. showClassButtons
  409. classButtons asJQuery show
  410. !
  411. hideMethodButtons
  412. methodButtons asJQuery hide
  413. !
  414. showMethodButtons
  415. methodButtons asJQuery show
  416. !
  417. compile
  418. self disableSaveButton.
  419. selectedTab = #comment
  420. ifTrue: [
  421. selectedClass ifNotNil: [
  422. self compileClassComment]]
  423. ifFalse: [
  424. (selectedProtocol notNil or: [selectedMethod notNil])
  425. ifFalse: [self compileDefinition]
  426. ifTrue: [self compileMethodDefinition]]
  427. !
  428. compileClassComment
  429. selectedClass comment: sourceArea val
  430. !
  431. compileMethodDefinition
  432. selectedTab = #instance
  433. ifTrue: [self compileMethodDefinitionFor: selectedClass]
  434. ifFalse: [self compileMethodDefinitionFor: selectedClass class]
  435. !
  436. compileMethodDefinitionFor: aClass
  437. | compiler method source node |
  438. source := sourceArea val.
  439. selectedProtocol ifNil: [selectedProtocol := selectedMethod category].
  440. compiler := Compiler new.
  441. compiler source: source.
  442. node := compiler parse: source.
  443. node isParseFailure ifTrue: [
  444. ^window alert: 'PARSE ERROR: ', node reason, ', position: ', node position asString].
  445. compiler currentClass: aClass.
  446. method := compiler eval: (compiler compileNode: node).
  447. method category: selectedProtocol.
  448. compiler unknownVariables do: [:each |
  449. "Do not try to redeclare javascript's objects"
  450. (window at: each) ifNil: [
  451. (window confirm: 'Declare ''', each, ''' as instance variable?') ifTrue: [
  452. self addInstanceVariableNamed: each toClass: aClass.
  453. ^self compileMethodDefinitionFor: aClass]]].
  454. aClass addCompiledMethod: method.
  455. compiler setupClass: aClass.
  456. self updateMethodsList.
  457. self selectMethod: method
  458. !
  459. compileDefinition
  460. | newClass |
  461. newClass := Compiler new loadExpression: sourceArea val.
  462. self
  463. resetClassesList;
  464. updateCategoriesList;
  465. updateClassesList.
  466. self selectClass: newClass
  467. !
  468. cancelChanges
  469. ^unsavedChanges
  470. ifTrue: [window confirm: 'Cancel changes?']
  471. ifFalse: [true]
  472. !
  473. removeClass
  474. (window confirm: 'Do you really want to remove ', selectedClass name, '?')
  475. ifTrue: [
  476. Smalltalk current removeClass: selectedClass.
  477. self resetClassesList.
  478. self selectClass: nil]
  479. !
  480. removeMethod
  481. self cancelChanges ifTrue: [
  482. (window confirm: 'Do you really want to remove #', selectedMethod selector, '?')
  483. ifTrue: [
  484. selectedTab = #instance
  485. ifTrue: [selectedClass removeCompiledMethod: selectedMethod]
  486. ifFalse: [selectedClass class removeCompiledMethod: selectedMethod].
  487. self selectMethod: nil]]
  488. !
  489. setMethodProtocol: aString
  490. self cancelChanges ifTrue: [
  491. (self protocols includes: aString)
  492. ifFalse: [self addNewProtocol]
  493. ifTrue: [
  494. selectedMethod category: aString.
  495. selectedProtocol := aString.
  496. selectedMethod := selectedMethod.
  497. self
  498. updateProtocolsList;
  499. updateMethodsList;
  500. updateSourceAndButtons]]
  501. !
  502. addNewProtocol
  503. | newProtocol |
  504. newProtocol := window prompt: 'New method protocol'.
  505. (newProtocol notNil and: [newProtocol notEmpty]) ifTrue: [
  506. selectedMethod category: newProtocol.
  507. self setMethodProtocol: newProtocol]
  508. !
  509. selectCategory: aCategory
  510. self cancelChanges ifTrue: [
  511. selectedPackage := aCategory.
  512. selectedClass := selectedProtocol := selectedMethod := nil.
  513. self resetClassesList.
  514. self
  515. updateCategoriesList;
  516. updateClassesList;
  517. updateProtocolsList;
  518. updateMethodsList;
  519. updateSourceAndButtons]
  520. !
  521. selectClass: aClass
  522. self cancelChanges ifTrue: [
  523. selectedClass := aClass.
  524. selectedProtocol := selectedMethod := nil.
  525. self
  526. updateClassesList;
  527. updateProtocolsList;
  528. updateMethodsList;
  529. updateSourceAndButtons]
  530. !
  531. selectProtocol: aString
  532. self cancelChanges ifTrue: [
  533. selectedProtocol := aString.
  534. selectedMethod := nil.
  535. self
  536. updateProtocolsList;
  537. updateMethodsList;
  538. updateSourceAndButtons]
  539. !
  540. selectMethod: aMethod
  541. self cancelChanges ifTrue: [
  542. selectedMethod := aMethod.
  543. self
  544. updateProtocolsList;
  545. updateMethodsList;
  546. updateSourceAndButtons]
  547. !
  548. selectTab: aString
  549. self cancelChanges ifTrue: [
  550. selectedTab := aString.
  551. self selectProtocol: nil.
  552. self updateTabsList]
  553. !
  554. renameClass
  555. | newName |
  556. newName := window prompt: 'Rename class ', selectedClass name.
  557. (newName notNil and: [newName notEmpty]) ifTrue: [
  558. selectedClass rename: newName.
  559. self
  560. updateClassesList;
  561. updateSourceAndButtons]
  562. !
  563. addInstanceVariableNamed: aString toClass: aClass
  564. ClassBuilder new
  565. addSubclassOf: aClass superclass
  566. named: aClass name
  567. instanceVariableNames: (aClass instanceVariableNames copy add: aString; yourself)
  568. package: aClass package name
  569. !
  570. searchReferencesOf: aString
  571. ReferencesBrowser search: aString
  572. !
  573. searchClassReferences
  574. ReferencesBrowser search: selectedClass name
  575. !
  576. search: aString
  577. self cancelChanges ifTrue: [| searchedClass |
  578. searchedClass := Smalltalk current at: aString.
  579. searchedClass isClass
  580. ifTrue: [self class openOn: searchedClass]
  581. ifFalse: [self searchReferencesOf: aString]]
  582. !
  583. handleSourceAreaKeyDown: anEvent
  584. <if(anEvent.ctrlKey) {
  585. if(anEvent.keyCode === 83) { //ctrl+s
  586. self._compile();
  587. anEvent.preventDefault();
  588. return false;
  589. }
  590. }
  591. >
  592. !
  593. commitPackage
  594. selectedPackage ifNotNil: [ |package|
  595. package := Package named: selectedPackage.
  596. jQuery
  597. ajax: package 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: package 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: package 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 select: [:each | each notNil])collect: [:each | each name]) 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. ! !