IDE.st 49 KB

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