IDE.st 48 KB

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