IDE.st 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366
  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. 'error' -> [window alert: 'PUT request failed at: ', anURL] }
  913. ! !
  914. !Browser methodsFor: 'rendering'!
  915. renderBoxOn: html
  916. self
  917. renderTopPanelOn: html;
  918. renderTabsOn: html;
  919. renderBottomPanelOn: html
  920. !
  921. renderTopPanelOn: html
  922. html div
  923. class: 'top';
  924. with: [
  925. packagesList := html ul class: 'jt_column browser packages'.
  926. html div class: 'jt_packagesButtons'; with: [
  927. html button
  928. title: 'Commit classes in this package to disk';
  929. onClick: [self commitPackage];
  930. with: 'Commit'.
  931. html button
  932. title: 'Rename package';
  933. onClick: [self renamePackage];
  934. with: 'Rename'.
  935. html button
  936. title: 'Remove this package from the system';
  937. onClick: [self removePackage];
  938. with: 'Remove'].
  939. classesList := ClassesList on: self.
  940. classesList renderOn: html.
  941. protocolsList := html ul class: 'jt_column browser protocols'.
  942. methodsList := html ul class: 'jt_column browser methods'.
  943. self
  944. updateCategoriesList;
  945. updateClassesList;
  946. updateProtocolsList;
  947. updateMethodsList.
  948. html div class: 'jt_clear']
  949. !
  950. renderTabsOn: html
  951. tabsList := html ul class: 'jt_tabs jt_browser'.
  952. self updateTabsList.
  953. !
  954. renderBottomPanelOn: html
  955. html div
  956. class: 'jt_sourceCode';
  957. with: [
  958. sourceArea := SourceArea new.
  959. sourceArea renderOn: html.
  960. sourceArea onKeyDown: [:e |
  961. self handleSourceAreaKeyDown: e].
  962. sourceArea onKeyUp: [self updateStatus]]
  963. !
  964. renderButtonsOn: html
  965. saveButton := html button.
  966. saveButton
  967. with: 'Save';
  968. onClick: [self compile].
  969. methodButtons := html span.
  970. classButtons := html span.
  971. html div
  972. class: 'right';
  973. with: [
  974. html button
  975. with: 'DoIt';
  976. onClick: [sourceArea doIt].
  977. html button
  978. with: 'PrintIt';
  979. onClick: [sourceArea printIt].
  980. html button with: 'InspectIt';
  981. onClick: [sourceArea inspectIt]].
  982. self updateSourceAndButtons
  983. ! !
  984. !Browser methodsFor: 'testing'!
  985. canBeClosed
  986. ^true
  987. ! !
  988. !Browser methodsFor: 'updating'!
  989. updateCategoriesList
  990. packagesList contents: [:html |
  991. self packages do: [:each || li label |
  992. each isEmpty
  993. ifTrue: [label := 'Unclassified']
  994. ifFalse: [label := each].
  995. li := html li.
  996. selectedPackage = each ifTrue: [
  997. li class: 'selected'].
  998. li
  999. with: label;
  1000. onClick: [self selectCategory: each]]]
  1001. !
  1002. updateClassesList
  1003. TabManager current update.
  1004. classesList updateNodes
  1005. !
  1006. updateProtocolsList
  1007. protocolsList contents: [:html |
  1008. self protocols do: [:each || li |
  1009. li := html li.
  1010. selectedProtocol = each ifTrue: [
  1011. li class: 'selected'].
  1012. li
  1013. with: each;
  1014. onClick: [self selectProtocol: each]]]
  1015. !
  1016. updateMethodsList
  1017. methodsList contents: [:html |
  1018. self methods do: [:each || li |
  1019. li := html li.
  1020. selectedMethod = each ifTrue: [
  1021. li class: 'selected'].
  1022. li
  1023. with: each selector;
  1024. onClick: [self selectMethod: each]]]
  1025. !
  1026. updateTabsList
  1027. tabsList contents: [:html || li |
  1028. li := html li.
  1029. selectedTab = #instance ifTrue: [li class: 'selected'].
  1030. li
  1031. with: [
  1032. html span class: 'ltab'.
  1033. html span class: 'mtab'; with: 'Instance'.
  1034. html span class: 'rtab'];
  1035. onClick: [self selectTab: #instance].
  1036. li := html li.
  1037. selectedTab = #class ifTrue: [li class: 'selected'].
  1038. li
  1039. with: [
  1040. html span class: 'ltab'.
  1041. html span class: 'mtab'; with: 'Class'.
  1042. html span class: 'rtab'];
  1043. onClick: [self selectTab: #class].
  1044. li := html li.
  1045. selectedTab = #comment ifTrue: [li class: 'selected'].
  1046. li
  1047. with: [
  1048. html span class: 'ltab'.
  1049. html span class: 'mtab'; with: 'Comment'.
  1050. html span class: 'rtab'];
  1051. onClick: [self selectTab: #comment]]
  1052. !
  1053. updateSourceAndButtons
  1054. self disableSaveButton.
  1055. classButtons contents: [:html |
  1056. html button
  1057. title: 'Create a new class';
  1058. onClick: [self addNewClass];
  1059. with: 'New class'.
  1060. html button
  1061. with: 'Rename class';
  1062. onClick: [self renameClass].
  1063. html button
  1064. with: 'Copy class';
  1065. onClick: [self copyClass].
  1066. html button
  1067. with: 'Remove class';
  1068. onClick: [self removeClass].
  1069. html button
  1070. with: 'References';
  1071. onClick: [self searchClassReferences]].
  1072. methodButtons contents: [:html | | protocolSelect referencesSelect |
  1073. html button
  1074. with: 'Remove method';
  1075. onClick: [self removeMethod].
  1076. protocolSelect := html select.
  1077. protocolSelect
  1078. onChange: [ self setMethodProtocol: protocolSelect asJQuery val];
  1079. with: [
  1080. html option
  1081. with: 'Method protocol';
  1082. at: 'disabled' put: 'disabled'.
  1083. html option
  1084. class: 'important';
  1085. with: 'New...'.
  1086. self protocols do: [:each |
  1087. html option with: each]].
  1088. selectedMethod isNil ifFalse: [
  1089. referencesSelect := html select.
  1090. referencesSelect
  1091. onChange: [self searchReferencesOf: referencesSelect asJQuery val];
  1092. with: [
  1093. html option
  1094. with: 'References';
  1095. at: 'disabled' put: 'disabled'.
  1096. html option
  1097. class: 'important';
  1098. with: selectedMethod selector.
  1099. selectedMethod messageSends sorted do: [:each |
  1100. html option with: each]]]].
  1101. selectedMethod isNil
  1102. ifTrue: [
  1103. self hideMethodButtons.
  1104. (selectedClass isNil or: [selectedProtocol notNil])
  1105. ifTrue: [self hideClassButtons]
  1106. ifFalse: [self showClassButtons]]
  1107. ifFalse: [
  1108. self hideClassButtons.
  1109. self showMethodButtons].
  1110. sourceArea val: self source
  1111. !
  1112. updateStatus
  1113. sourceArea val = self source
  1114. ifTrue: [
  1115. saveButton ifNotNil: [
  1116. saveButton at: 'disabled' put: true].
  1117. unsavedChanges := false]
  1118. ifFalse: [
  1119. saveButton ifNotNil: [
  1120. saveButton removeAt: 'disabled'].
  1121. unsavedChanges := true]
  1122. !
  1123. resetClassesList
  1124. classesList resetNodes
  1125. ! !
  1126. !Browser class methodsFor: 'accessing'!
  1127. commitPathJs
  1128. ^'js'
  1129. !
  1130. commitPathSt
  1131. ^'st'
  1132. ! !
  1133. !Browser class methodsFor: 'convenience'!
  1134. openOn: aClass
  1135. ^self new
  1136. open;
  1137. selectCategory: aClass category;
  1138. selectClass: aClass
  1139. !
  1140. open
  1141. self new open
  1142. ! !
  1143. TabWidget subclass: #Inspector
  1144. instanceVariableNames: 'label variables object selectedVariable variablesList valueTextarea diveButton sourceArea'
  1145. category: 'IDE'!
  1146. !Inspector methodsFor: 'accessing'!
  1147. label
  1148. ^label ifNil: ['Inspector (nil)']
  1149. !
  1150. variables
  1151. ^variables
  1152. !
  1153. setVariables: aCollection
  1154. variables := aCollection
  1155. !
  1156. setLabel: aString
  1157. label := aString
  1158. !
  1159. selectedVariable
  1160. ^selectedVariable
  1161. !
  1162. selectedVariable: aString
  1163. selectedVariable := aString
  1164. !
  1165. sourceArea
  1166. ^sourceArea
  1167. ! !
  1168. !Inspector methodsFor: 'actions'!
  1169. inspect: anObject
  1170. object := anObject.
  1171. variables := #().
  1172. object inspectOn: self
  1173. !
  1174. dive
  1175. (self variables at: self selectedVariable) inspect
  1176. !
  1177. refresh
  1178. self
  1179. inspect: object;
  1180. updateVariablesList;
  1181. updateValueTextarea
  1182. ! !
  1183. !Inspector methodsFor: 'rendering'!
  1184. renderBoxOn: html
  1185. self
  1186. renderTopPanelOn: html;
  1187. renderBottomPanelOn: html
  1188. !
  1189. renderTopPanelOn: html
  1190. html div
  1191. class: 'top';
  1192. with: [
  1193. variablesList := html ul class: 'jt_column variables'.
  1194. valueTextarea := html textarea class: 'jt_column value'; at: 'readonly' put: 'readonly'.
  1195. html div class: 'jt_tabs inspector'; with: [
  1196. html button
  1197. class: 'jt_button inspector refresh';
  1198. with: 'Refresh';
  1199. onClick: [self refresh].
  1200. diveButton := html button
  1201. class: 'jt_button inspector dive';
  1202. with: 'Dive';
  1203. onClick: [self dive]].
  1204. html div class: 'jt_clear'].
  1205. self
  1206. updateVariablesList;
  1207. updateValueTextarea.
  1208. !
  1209. renderBottomPanelOn: html
  1210. html div
  1211. class: 'jt_sourceCode';
  1212. with: [
  1213. sourceArea := SourceArea new
  1214. receiver: object;
  1215. onDoIt: [self refresh];
  1216. yourself.
  1217. sourceArea renderOn: html]
  1218. !
  1219. renderButtonsOn: html
  1220. html button
  1221. with: 'DoIt';
  1222. onClick: [self sourceArea doIt].
  1223. html button
  1224. with: 'PrintIt';
  1225. onClick: [self sourceArea printIt].
  1226. html button
  1227. with: 'InspectIt';
  1228. onClick: [self sourceArea inspectIt].
  1229. self updateButtons
  1230. ! !
  1231. !Inspector methodsFor: 'testing'!
  1232. canBeClosed
  1233. ^true
  1234. ! !
  1235. !Inspector methodsFor: 'updating'!
  1236. updateVariablesList
  1237. variablesList contents: [:html |
  1238. self variables keys do: [:each || li |
  1239. li := html li.
  1240. li
  1241. with: each;
  1242. onClick: [self selectVariable: each].
  1243. self selectedVariable = each ifTrue: [
  1244. li class: 'selected']]]
  1245. !
  1246. selectVariable: aString
  1247. self selectedVariable: aString.
  1248. self
  1249. updateVariablesList;
  1250. updateValueTextarea;
  1251. updateButtons
  1252. !
  1253. updateValueTextarea
  1254. valueTextarea asJQuery val: (self selectedVariable isNil
  1255. ifTrue: ['']
  1256. ifFalse: [(self variables at: self selectedVariable) printString])
  1257. !
  1258. updateButtons
  1259. (self selectedVariable notNil and: [(self variables at: self selectedVariable) notNil])
  1260. ifFalse: [diveButton at: 'disabled' put: true]
  1261. ifTrue: [diveButton removeAt: 'disabled']
  1262. ! !
  1263. !Inspector class methodsFor: 'instance creation'!
  1264. on: anObject
  1265. ^self new
  1266. inspect: anObject;
  1267. yourself
  1268. ! !
  1269. TabWidget subclass: #ReferencesBrowser
  1270. instanceVariableNames: 'implementors senders implementorsList input timer selector sendersList referencedClasses referencedClassesList'
  1271. category: 'IDE'!
  1272. !ReferencesBrowser methodsFor: 'accessing'!
  1273. implementors
  1274. ^implementors ifNil: [implementors := Array new]
  1275. !
  1276. label
  1277. ^'[References]'
  1278. !
  1279. selector
  1280. ^selector
  1281. !
  1282. senders
  1283. ^senders ifNil: [senders := Array new]
  1284. !
  1285. classesAndMetaclasses
  1286. ^Smalltalk current classes, (Smalltalk current classes collect: [:each | each class])
  1287. !
  1288. referencedClasses
  1289. ^referencedClasses ifNil: [referencedClasses := Array new]
  1290. ! !
  1291. !ReferencesBrowser methodsFor: 'actions'!
  1292. openBrowserOn: aMethod
  1293. | browser |
  1294. browser := Browser openOn: (aMethod methodClass isMetaclass
  1295. ifTrue: [aMethod methodClass instanceClass] ifFalse: [aMethod methodClass]).
  1296. aMethod methodClass isMetaclass ifTrue: [browser selectTab: #class].
  1297. browser
  1298. selectProtocol: aMethod category;
  1299. selectMethod: aMethod
  1300. !
  1301. searchReferencesFor: aString
  1302. selector := aString.
  1303. implementors := Array new.
  1304. senders := Array new.
  1305. referencedClasses := Array new.
  1306. (selector match: '^[A-Z]')
  1307. ifFalse: [self searchSelectorReferencesFor: selector]
  1308. ifTrue: [self searchReferencedClassesFor: selector]
  1309. !
  1310. search: aString
  1311. self
  1312. searchReferencesFor: aString;
  1313. updateImplementorsList;
  1314. updateSendersList;
  1315. updateReferencedClassesList
  1316. !
  1317. searchReferencedClassesFor: aString
  1318. self classesAndMetaclasses do: [:each |
  1319. each methodDictionary values do: [:value |
  1320. (value referencedClasses includes: selector) ifTrue: [
  1321. self referencedClasses add: value]]]
  1322. !
  1323. searchSelectorReferencesFor: aString
  1324. self classesAndMetaclasses do: [:each |
  1325. each methodDictionary keysAndValuesDo: [:key :value |
  1326. key = selector ifTrue: [self implementors add: value].
  1327. (value messageSends includes: selector) ifTrue: [
  1328. self senders add: value]]]
  1329. ! !
  1330. !ReferencesBrowser methodsFor: 'initialization'!
  1331. initialize
  1332. super initialize.
  1333. selector := ''
  1334. ! !
  1335. !ReferencesBrowser methodsFor: 'private'!
  1336. setInputEvents
  1337. input
  1338. onKeyUp: [timer := [self search: input asJQuery val] valueWithTimeout: 100];
  1339. onKeyDown: [timer ifNotNil: [timer clearTimeout]]
  1340. ! !
  1341. !ReferencesBrowser methodsFor: 'rendering'!
  1342. renderBoxOn: html
  1343. self
  1344. renderInputOn: html;
  1345. renderImplementorsOn: html;
  1346. renderSendersOn: html;
  1347. renderReferencedClassesOn: html
  1348. !
  1349. renderInputOn: html
  1350. input := html input
  1351. class: 'implementors';
  1352. yourself.
  1353. input asJQuery val: selector.
  1354. self setInputEvents
  1355. !
  1356. renderImplementorsOn: html
  1357. implementorsList := html ul class: 'jt_column implementors'.
  1358. self updateImplementorsList
  1359. !
  1360. renderSendersOn: html
  1361. sendersList := html ul class: 'jt_column senders'.
  1362. self updateSendersList
  1363. !
  1364. renderReferencedClassesOn: html
  1365. referencedClassesList := html ul class: 'jt_column referenced_classes'.
  1366. self updateReferencedClassesList
  1367. ! !
  1368. !ReferencesBrowser methodsFor: 'testing'!
  1369. canBeClosed
  1370. ^true
  1371. ! !
  1372. !ReferencesBrowser methodsFor: 'updating'!
  1373. updateImplementorsList
  1374. implementorsList contents: [:html |
  1375. html li
  1376. class: 'column_label';
  1377. with: 'Implementors (', self implementors size asString, ')';
  1378. style: 'font-weight: bold'.
  1379. self implementors do: [:each || li |
  1380. li := html li.
  1381. li
  1382. with: (each methodClass asString, ' >> ', self selector);
  1383. onClick: [self openBrowserOn: each]]]
  1384. !
  1385. updateSendersList
  1386. sendersList contents: [:html |
  1387. html li
  1388. class: 'column_label';
  1389. with: 'Senders (', self senders size asString, ')';
  1390. style: 'font-weight: bold'.
  1391. self senders do: [:each |
  1392. html li
  1393. with: (each methodClass asString, ' >> ', each selector);
  1394. onClick: [self openBrowserOn: each]]]
  1395. !
  1396. updateReferencedClassesList
  1397. referencedClassesList contents: [:html |
  1398. html li
  1399. class: 'column_label';
  1400. with: 'Class references (', self referencedClasses size asString, ')';
  1401. style: 'font-weight: bold'.
  1402. self referencedClasses do: [:each |
  1403. html li
  1404. with: (each methodClass asString, ' >> ', each selector);
  1405. onClick: [self openBrowserOn: each]]]
  1406. ! !
  1407. !ReferencesBrowser class methodsFor: 'instance creation'!
  1408. search: aString
  1409. ^self new
  1410. searchReferencesFor: aString;
  1411. open
  1412. ! !
  1413. TabWidget subclass: #Debugger
  1414. instanceVariableNames: 'error selectedContext sourceArea ul ul2 inspector saveButton unsavedChanges selectedVariable selectedVariableName inspectButton'
  1415. category: 'IDE'!
  1416. !Debugger methodsFor: 'accessing'!
  1417. error
  1418. ^error
  1419. !
  1420. error: anError
  1421. error := anError
  1422. !
  1423. label
  1424. ^'[Debugger]'
  1425. !
  1426. source
  1427. ^self method
  1428. ifNil: ['Method doesn''t exist!!']
  1429. ifNotNil: [self method source]
  1430. !
  1431. method
  1432. ^selectedContext receiver class methodAt: selectedContext selector
  1433. !
  1434. arguments
  1435. ^self method
  1436. ifNil: [selectedContext temps collect: [:each | nil]]
  1437. ifNotNil: [self method arguments]
  1438. !
  1439. receiver
  1440. ^selectedContext receiver
  1441. ! !
  1442. !Debugger methodsFor: 'actions'!
  1443. selectContext: aContext
  1444. selectedContext := aContext.
  1445. selectedVariable := nil.
  1446. selectedVariableName := nil.
  1447. self
  1448. updateContextsList;
  1449. updateSourceArea;
  1450. updateInspector;
  1451. updateVariablesList;
  1452. updateStatus
  1453. !
  1454. proceed
  1455. self close.
  1456. selectedContext receiver perform: selectedContext selector withArguments: selectedContext temps
  1457. !
  1458. save
  1459. | protocol |
  1460. protocol := (selectedContext receiver class methodDictionary at: selectedContext selector) category.
  1461. selectedContext receiver class compile: sourceArea val category: protocol.
  1462. self updateStatus
  1463. !
  1464. selectVariable: anObject named: aString
  1465. selectedVariable := anObject.
  1466. selectedVariableName := aString.
  1467. inspector contents: [:html | html with: anObject printString].
  1468. self updateVariablesList
  1469. !
  1470. inspectSelectedVariable
  1471. selectedVariable inspect
  1472. ! !
  1473. !Debugger methodsFor: 'initialization'!
  1474. initialize
  1475. super initialize.
  1476. unsavedChanges = false
  1477. ! !
  1478. !Debugger methodsFor: 'rendering'!
  1479. renderTopPanelOn: html
  1480. selectedContext := self error context.
  1481. html div
  1482. class: 'top';
  1483. with: [
  1484. html div
  1485. class: 'label';
  1486. with: self error messageText.
  1487. ul := html ul
  1488. class: 'jt_column debugger contexts';
  1489. with: [self renderContext: self error context on: html]]
  1490. !
  1491. renderContext: aContext on: html
  1492. | li |
  1493. li := html li.
  1494. selectedContext = aContext ifTrue: [
  1495. li class: 'selected'].
  1496. li
  1497. with: aContext asString;
  1498. onClick: [self selectContext: aContext].
  1499. aContext home ifNotNil: [self renderContext: aContext home on: html]
  1500. !
  1501. renderBottomPanelOn: html
  1502. html div
  1503. class: 'jt_sourceCode debugger';
  1504. with: [
  1505. sourceArea := SourceArea new.
  1506. sourceArea renderOn: html].
  1507. ul2 := html ul class: 'jt_column debugger variables'.
  1508. inspector := html div class: 'jt_column debugger inspector'.
  1509. sourceArea
  1510. onKeyUp: [self updateStatus]
  1511. !
  1512. renderButtonsOn: html
  1513. saveButton := html button
  1514. with: 'Save';
  1515. onClick: [self save].
  1516. html button
  1517. with: 'DoIt';
  1518. onClick: [sourceArea doIt].
  1519. html button
  1520. with: 'PrintIt';
  1521. onClick: [sourceArea printIt].
  1522. html button
  1523. with: 'InspectIt';
  1524. onClick: [sourceArea inspectIt].
  1525. html button
  1526. with: 'Proceed';
  1527. onClick: [self proceed].
  1528. html button
  1529. with: 'Abandon';
  1530. onClick: [self close].
  1531. inspectButton := html button
  1532. class: 'jt_button debugger inspect';
  1533. with: 'Inspect';
  1534. onClick: [self inspectSelectedVariable].
  1535. self
  1536. updateSourceArea;
  1537. updateStatus;
  1538. updateVariablesList;
  1539. updateInspector
  1540. !
  1541. renderBoxOn: html
  1542. self
  1543. renderTopPanelOn: html;
  1544. renderBottomPanelOn: html
  1545. ! !
  1546. !Debugger methodsFor: 'testing'!
  1547. canBeClosed
  1548. ^true
  1549. ! !
  1550. !Debugger methodsFor: 'updating'!
  1551. updateContextsList
  1552. ul contents: [:html |
  1553. self renderContext: self error context on: html]
  1554. !
  1555. updateSourceArea
  1556. sourceArea val: self source
  1557. !
  1558. updateStatus
  1559. sourceArea val = self source
  1560. ifTrue: [
  1561. saveButton ifNotNil: [
  1562. saveButton at: 'disabled' put: true].
  1563. unsavedChanges := false]
  1564. ifFalse: [
  1565. saveButton ifNotNil: [
  1566. saveButton removeAt: 'disabled'].
  1567. unsavedChanges := true]
  1568. !
  1569. updateInspector
  1570. inspector contents: [:html |]
  1571. !
  1572. updateVariablesList
  1573. ul2 contents: [:html | | li |
  1574. li := html li
  1575. with: 'self';
  1576. onClick: [self selectVariable: self receiver named: 'self'].
  1577. selectedVariableName = 'self' ifTrue: [
  1578. li class: 'selected'].
  1579. self arguments withIndexDo: [:each :index | | param |
  1580. param := selectedContext temps at: index.
  1581. li := html li
  1582. with: each;
  1583. onClick: [self selectVariable: param named: each].
  1584. selectedVariableName = each ifTrue: [
  1585. li class: 'selected']].
  1586. self receiver class allInstanceVariableNames do: [:each | | ivar |
  1587. ivar := self receiver instVarAt: each.
  1588. li := html li
  1589. with: each;
  1590. onClick: [self selectVariable: ivar named: each].
  1591. selectedVariableName = each ifTrue: [
  1592. li class: 'selected']]].
  1593. selectedVariable ifNil: [inspectButton at: 'disabled' put: true] ifNotNil: [inspectButton removeAt: 'disabled']
  1594. ! !
  1595. TabWidget subclass: #ProgressBar
  1596. instanceVariableNames: 'percent progressDiv div'
  1597. category: 'IDE'!
  1598. !ProgressBar methodsFor: 'accessing'!
  1599. percent
  1600. ^percent ifNil: [0]
  1601. !
  1602. percent: aNumber
  1603. percent := aNumber
  1604. ! !
  1605. !ProgressBar methodsFor: 'rendering'!
  1606. renderOn: html
  1607. div := html div
  1608. class: 'progress_bar';
  1609. yourself.
  1610. self renderProgressBar
  1611. !
  1612. renderProgressBar
  1613. div contents: [:html |
  1614. html div
  1615. class: 'progress';
  1616. style: 'width:', self percent asString, '%']
  1617. ! !
  1618. !ProgressBar methodsFor: 'updating'!
  1619. updatePercent: aNumber
  1620. self percent: aNumber.
  1621. self renderProgressBar
  1622. ! !
  1623. TabWidget subclass: #TestRunner
  1624. instanceVariableNames: 'selectedCategories packagesList selectedClasses classesList selectedMethods progressBar methodsList result statusDiv'
  1625. category: 'IDE'!
  1626. !TestRunner methodsFor: 'accessing'!
  1627. label
  1628. ^'SUnit'
  1629. !
  1630. packages
  1631. | packages |
  1632. packages := Array new.
  1633. self allClasses do: [:each |
  1634. (packages includes: each category) ifFalse: [
  1635. packages add: each category]].
  1636. ^packages sort
  1637. !
  1638. classes
  1639. ^(self allClasses
  1640. select: [:each | self selectedCategories includes: each category])
  1641. sort: [:a :b | a name > b name]
  1642. !
  1643. selectedCategories
  1644. ^selectedCategories ifNil: [selectedCategories := Array new]
  1645. !
  1646. allClasses
  1647. ^TestCase allSubclasses
  1648. !
  1649. selectedClasses
  1650. ^selectedClasses ifNil: [selectedClasses := Array new]
  1651. !
  1652. progressBar
  1653. ^progressBar ifNil: [progressBar := ProgressBar new]
  1654. !
  1655. statusInfo
  1656. ^self printTotal, self printPasses, self printErrors, self printFailures
  1657. !
  1658. result
  1659. ^result
  1660. !
  1661. testCases
  1662. | testCases |
  1663. testCases := #().
  1664. self selectedClasses do: [:each | testCases addAll: each buildSuite].
  1665. ^testCases
  1666. ! !
  1667. !TestRunner methodsFor: 'actions'!
  1668. selectAllCategories
  1669. self packages do: [:each |
  1670. (selectedCategories includes: each) ifFalse: [
  1671. self selectedCategories add: each]].
  1672. self
  1673. updateCategoriesList;
  1674. updateClassesList
  1675. !
  1676. toggleCategory: aCategory
  1677. (self isSelectedCategory: aCategory)
  1678. ifFalse: [selectedCategories add: aCategory]
  1679. ifTrue: [selectedCategories remove: aCategory].
  1680. self
  1681. updateCategoriesList;
  1682. updateClassesList
  1683. !
  1684. toggleClass: aClass
  1685. (self isSelectedClass: aClass)
  1686. ifFalse: [selectedClasses add: aClass]
  1687. ifTrue: [selectedClasses remove: aClass].
  1688. self
  1689. updateClassesList
  1690. !
  1691. selectAllClasses
  1692. self classes do: [:each |
  1693. (selectedClasses includes: each) ifFalse: [
  1694. self selectedClasses add: each]].
  1695. self
  1696. updateCategoriesList;
  1697. updateClassesList
  1698. !
  1699. run: aCollection
  1700. result := TestResult new.
  1701. self
  1702. updateStatusDiv;
  1703. updateMethodsList.
  1704. self progressBar updatePercent: 0.
  1705. result total: aCollection size.
  1706. aCollection do: [:each |
  1707. [each runCaseFor: result.
  1708. self progressBar updatePercent: result runs / result total * 100.
  1709. self updateStatusDiv.
  1710. self updateMethodsList] valueWithTimeout: 100].
  1711. !
  1712. performFailure: aTestCase
  1713. aTestCase perform: aTestCase selector
  1714. ! !
  1715. !TestRunner methodsFor: 'initialization'!
  1716. initialize
  1717. super initialize.
  1718. result := TestResult new
  1719. ! !
  1720. !TestRunner methodsFor: 'printing'!
  1721. printErrors
  1722. ^self result errors size asString , ' errors, '
  1723. !
  1724. printFailures
  1725. ^self result failures size asString, ' failures'
  1726. !
  1727. printPasses
  1728. ^(self result total - self result errors size - self result failures size) asString , ' passes, '
  1729. !
  1730. printTotal
  1731. ^self result total asString, ' runs, '
  1732. ! !
  1733. !TestRunner methodsFor: 'rendering'!
  1734. renderBoxOn: html
  1735. self
  1736. renderCategoriesOn: html;
  1737. renderClassesOn: html;
  1738. renderResultsOn: html
  1739. !
  1740. renderButtonsOn: html
  1741. html button
  1742. with: 'Run selected';
  1743. onClick: [self run: self testCases]
  1744. !
  1745. renderCategoriesOn: html
  1746. packagesList := html ul class: 'jt_column sunit packages'.
  1747. self updateCategoriesList
  1748. !
  1749. renderClassesOn: html
  1750. classesList := html ul class: 'jt_column sunit classes'.
  1751. self updateClassesList
  1752. !
  1753. renderResultsOn: html
  1754. statusDiv := html div.
  1755. html with: self progressBar.
  1756. methodsList := html ul class: 'jt_column sunit results'.
  1757. self updateMethodsList.
  1758. self updateStatusDiv
  1759. !
  1760. renderFailuresOn: html
  1761. self result failures do: [:each |
  1762. html li
  1763. class: 'failures';
  1764. with: each class name, ' >> ', each selector;
  1765. onClick: [self performFailure: each]]
  1766. !
  1767. renderErrorsOn: html
  1768. self result errors do: [:each |
  1769. html li
  1770. class: 'errors';
  1771. with: each class name, ' >> ', each selector;
  1772. onClick: [self performFailure: each]]
  1773. ! !
  1774. !TestRunner methodsFor: 'testing'!
  1775. isSelectedClass: aClass
  1776. ^(self selectedClasses includes: aClass)
  1777. !
  1778. isSelectedCategory: aCategory
  1779. ^(self selectedCategories includes: aCategory)
  1780. ! !
  1781. !TestRunner methodsFor: 'updating'!
  1782. updateCategoriesList
  1783. packagesList contents: [:html |
  1784. html li
  1785. class: 'all';
  1786. with: 'All';
  1787. onClick: [self selectAllCategories].
  1788. self packages do: [:each || li |
  1789. li := html li.
  1790. (self selectedCategories includes: each) ifTrue: [
  1791. li class: 'selected'].
  1792. li
  1793. with: each;
  1794. onClick: [self toggleCategory: each]]]
  1795. !
  1796. updateClassesList
  1797. classesList contents: [:html |
  1798. (self selectedCategories isEmpty) ifFalse: [
  1799. html li
  1800. class: 'all';
  1801. with: 'All';
  1802. onClick: [self selectAllClasses]].
  1803. self classes do: [:each || li |
  1804. li := html li.
  1805. (self selectedClasses includes: each) ifTrue: [
  1806. li class: 'selected'].
  1807. li
  1808. with: each name;
  1809. onClick: [self toggleClass: each]]]
  1810. !
  1811. updateMethodsList
  1812. methodsList contents: [:html |
  1813. self renderErrorsOn: html.
  1814. self renderFailuresOn: html]
  1815. !
  1816. updateStatusDiv
  1817. statusDiv class: 'sunit status ', result status.
  1818. statusDiv contents: [:html |
  1819. html span with: self statusInfo]
  1820. ! !
  1821. TabWidget subclass: #IDETranscript
  1822. instanceVariableNames: 'textarea'
  1823. category: 'IDE'!
  1824. !IDETranscript methodsFor: 'accessing'!
  1825. label
  1826. ^'Transcript'
  1827. ! !
  1828. !IDETranscript methodsFor: 'actions'!
  1829. clear
  1830. textarea asJQuery val: ''
  1831. !
  1832. cr
  1833. textarea asJQuery val: textarea asJQuery val, String cr.
  1834. !
  1835. show: anObject
  1836. textarea asJQuery val: textarea asJQuery val, anObject asString.
  1837. !
  1838. open
  1839. TabManager current
  1840. open;
  1841. selectTab: self
  1842. ! !
  1843. !IDETranscript methodsFor: 'rendering'!
  1844. renderBoxOn: html
  1845. textarea := html textarea.
  1846. textarea
  1847. class: 'jt_transcript';
  1848. at: 'spellcheck' put: 'false'
  1849. !
  1850. renderButtonsOn: html
  1851. html button
  1852. with: 'Clear transcript';
  1853. onClick: [self clear]
  1854. ! !
  1855. IDETranscript class instanceVariableNames: 'current'!
  1856. !IDETranscript class methodsFor: 'initialization'!
  1857. initialize
  1858. Transcript register: self current
  1859. ! !
  1860. !IDETranscript class methodsFor: 'instance creation'!
  1861. new
  1862. self shouldNotImplement
  1863. !
  1864. open
  1865. TabManager current
  1866. open;
  1867. selectTab: self current
  1868. !
  1869. current
  1870. ^current ifNil: [current := super new]
  1871. ! !
  1872. !Object methodsFor: '*IDE'!
  1873. inspect
  1874. Inspector new
  1875. inspect: self;
  1876. open
  1877. !
  1878. inspectOn: anInspector
  1879. | variables |
  1880. variables := Dictionary new.
  1881. variables at: '#self' put: self.
  1882. self class allInstanceVariableNames do: [:each |
  1883. variables at: each put: (self instVarAt: each)].
  1884. anInspector
  1885. setLabel: self printString;
  1886. setVariables: variables
  1887. ! !
  1888. !Date methodsFor: '*IDE'!
  1889. inspectOn: anInspector
  1890. | variables |
  1891. variables := Dictionary new.
  1892. variables at: '#self' put: self.
  1893. variables at: '#year' put: self year.
  1894. variables at: '#month' put: self month.
  1895. variables at: '#day' put: self day.
  1896. variables at: '#hours' put: self hours.
  1897. variables at: '#minutes' put: self minutes.
  1898. variables at: '#seconds' put: self seconds.
  1899. variables at: '#milliseconds' put: self milliseconds.
  1900. anInspector
  1901. setLabel: self printString;
  1902. setVariables: variables
  1903. ! !
  1904. !Collection methodsFor: '*IDE'!
  1905. inspectOn: anInspector
  1906. | variables |
  1907. variables := Dictionary new.
  1908. variables at: '#self' put: self.
  1909. self withIndexDo: [:each :i |
  1910. variables at: i put: each].
  1911. anInspector
  1912. setLabel: self printString;
  1913. setVariables: variables
  1914. ! !
  1915. !String methodsFor: '*IDE'!
  1916. inspectOn: anInspector
  1917. | label |
  1918. super inspectOn: anInspector.
  1919. self printString size > 30
  1920. ifTrue: [label := (self printString copyFrom: 1 to: 30), '...''']
  1921. ifFalse: [label := self printString].
  1922. anInspector setLabel: label
  1923. ! !
  1924. !MethodContext methodsFor: '*IDE'!
  1925. inspectOn: anInspector
  1926. | variables |
  1927. variables := Dictionary new.
  1928. variables at: '#self' put: self.
  1929. variables at: '#home' put: self home.
  1930. variables at: '#receiver' put: self receiver.
  1931. variables at: '#selector' put: self selector.
  1932. variables at: '#temps' put: self temps.
  1933. self class instanceVariableNames do: [:each |
  1934. variables at: each put: (self instVarAt: each)].
  1935. anInspector
  1936. setLabel: self printString;
  1937. setVariables: variables
  1938. ! !
  1939. !Date methodsFor: '*IDE'!
  1940. inspectOn: anInspector
  1941. | variables |
  1942. variables := Dictionary new.
  1943. variables at: '#self' put: self.
  1944. variables at: '#year' put: self year.
  1945. variables at: '#month' put: self month.
  1946. variables at: '#day' put: self day.
  1947. variables at: '#hours' put: self hours.
  1948. variables at: '#minutes' put: self minutes.
  1949. variables at: '#seconds' put: self seconds.
  1950. variables at: '#milliseconds' put: self milliseconds.
  1951. anInspector
  1952. setLabel: self printString;
  1953. setVariables: variables
  1954. ! !
  1955. !Set methodsFor: '*IDE'!
  1956. inspectOn: anInspector
  1957. | variables |
  1958. variables := Dictionary new.
  1959. variables at: '#self' put: self.
  1960. elements withIndexDo: [:each :i |
  1961. variables at: i put: each].
  1962. anInspector
  1963. setLabel: self printString;
  1964. setVariables: variables
  1965. ! !
  1966. !HashedCollection methodsFor: '*IDE'!
  1967. inspectOn: anInspector
  1968. | variables |
  1969. variables := Dictionary new.
  1970. variables at: '#self' put: self.
  1971. variables at: '#keys' put: self keys.
  1972. self keysAndValuesDo: [:key :value |
  1973. variables at: key put: value].
  1974. anInspector
  1975. setLabel: self printString;
  1976. setVariables: variables
  1977. ! !