1
0

IDE.st 49 KB

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