1
0

IDE.st 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415
  1. Widget subclass: #TabManager
  2. instanceVariableNames: 'selectedTab tabs opened ul'
  3. category: 'IDE'!
  4. !TabManager methodsFor: 'accessing'!
  5. tabs
  6. ^tabs ifNil: [tabs := Array new]
  7. ! !
  8. !TabManager methodsFor: 'actions'!
  9. updateBodyMargin
  10. self setBodyMargin: '#jtalk' asJQuery height + 27
  11. !
  12. updatePosition
  13. <jQuery('#jtalk').css('top', '').css('bottom', '27px')>
  14. !
  15. removeBodyMargin
  16. self setBodyMargin: 0
  17. !
  18. setBodyMargin: anInteger
  19. '.jtalkBody' asJQuery cssAt: 'margin-bottom' put: anInteger asString, 'px'
  20. !
  21. onResize: aBlock
  22. <jQuery('#jtalk').resizable({
  23. handles: 'n',
  24. resize: aBlock,
  25. minHeight: 230
  26. })>
  27. !
  28. onWindowResize: aBlock
  29. <jQuery(window).resize(aBlock)>
  30. !
  31. open
  32. opened ifFalse: [
  33. 'body' asJQuery addClass: 'jtalkBody'.
  34. '#jtalk' asJQuery show.
  35. ul asJQuery show.
  36. self updateBodyMargin.
  37. selectedTab show.
  38. opened := true]
  39. !
  40. close
  41. opened ifTrue: [
  42. '#jtalk' asJQuery hide.
  43. ul asJQuery hide.
  44. selectedTab hide.
  45. self removeBodyMargin.
  46. 'body' asJQuery removeClass: 'jtalkBody'.
  47. opened := false]
  48. !
  49. newBrowserTab
  50. Browser open
  51. !
  52. selectTab: aWidget
  53. self open.
  54. selectedTab := aWidget.
  55. self tabs do: [:each |
  56. each hide].
  57. aWidget show.
  58. self update
  59. !
  60. closeTab: aWidget
  61. self removeTab: aWidget.
  62. self selectTab: self tabs last.
  63. aWidget remove.
  64. self update
  65. ! !
  66. !TabManager methodsFor: 'adding/Removing'!
  67. addTab: aWidget
  68. self tabs add: aWidget.
  69. '#jtalk' asJQuery append: aWidget.
  70. aWidget hide
  71. !
  72. removeTab: aWidget
  73. self tabs remove: aWidget.
  74. self update
  75. ! !
  76. !TabManager methodsFor: 'initialization'!
  77. initialize
  78. super initialize.
  79. opened := true.
  80. 'body' asJQuery
  81. append: self;
  82. append: [:html | html div id: 'jtalk'];
  83. addClass: 'jtalkBody'.
  84. self
  85. addTab: Transcript current;
  86. addTab: Workspace new.
  87. self selectTab: self tabs last.
  88. self
  89. onResize: [self updateBodyMargin; updatePosition];
  90. onWindowResize: [self updatePosition]
  91. ! !
  92. !TabManager methodsFor: 'rendering'!
  93. renderOn: html
  94. ul := html ul
  95. id: 'jtalkTabs';
  96. yourself.
  97. self renderTabs
  98. !
  99. renderTabFor: aWidget on: html
  100. | li |
  101. li := html li.
  102. selectedTab = aWidget ifTrue: [
  103. li class: 'selected'].
  104. li with: [
  105. html span
  106. with: aWidget label;
  107. onClick: [self selectTab: aWidget].
  108. aWidget canBeClosed ifTrue: [
  109. html span
  110. class: 'close';
  111. with: 'x';
  112. onClick: [self closeTab: aWidget]]]
  113. !
  114. renderTabs
  115. ul contents: [:html |
  116. html li
  117. class: 'closeAll';
  118. with: 'x';
  119. onClick: [self close].
  120. self tabs do: [:each |
  121. self renderTabFor: each on: html].
  122. html li
  123. class: 'newtab';
  124. with: ' + ';
  125. onClick: [self newBrowserTab]]
  126. ! !
  127. !TabManager methodsFor: 'updating'!
  128. update
  129. self renderTabs
  130. ! !
  131. TabManager class instanceVariableNames: 'current'!
  132. !TabManager class methodsFor: 'instance creation'!
  133. current
  134. ^current ifNil: [current := super new]
  135. !
  136. new
  137. self shouldNotImplement
  138. ! !
  139. Widget subclass: #TabWidget
  140. instanceVariableNames: 'div'
  141. category: 'IDE'!
  142. !TabWidget methodsFor: 'accessing'!
  143. label
  144. self subclassResponsibility
  145. ! !
  146. !TabWidget methodsFor: 'actions'!
  147. open
  148. TabManager current addTab: self.
  149. TabManager current selectTab: self
  150. !
  151. show
  152. div asJQuery show
  153. !
  154. hide
  155. div asJQuery hide
  156. !
  157. remove
  158. div asJQuery remove
  159. ! !
  160. !TabWidget methodsFor: 'rendering'!
  161. renderOn: html
  162. div := html div
  163. class: 'jtalkTool';
  164. yourself.
  165. self renderTab
  166. !
  167. renderBoxOn: html
  168. !
  169. renderButtonsOn: html
  170. !
  171. update
  172. self renderTab
  173. !
  174. renderTab
  175. div contents: [:html |
  176. html div
  177. class: 'jt_box';
  178. with: [self renderBoxOn: html].
  179. html div
  180. class: 'jt_buttons';
  181. with: [self renderButtonsOn: html]]
  182. ! !
  183. !TabWidget methodsFor: 'testing'!
  184. canBeClosed
  185. ^false
  186. ! !
  187. !TabWidget class methodsFor: 'instance creation'!
  188. open
  189. ^self new open
  190. ! !
  191. TabWidget subclass: #Workspace
  192. instanceVariableNames: 'textarea'
  193. category: 'IDE'!
  194. !Workspace methodsFor: 'accessing'!
  195. label
  196. ^'[Workspace]'
  197. !
  198. selection
  199. <return document.selection>
  200. !
  201. selectionStart
  202. <return jQuery('.jt_workspace')[0].selectionStart>
  203. !
  204. selectionEnd
  205. <return jQuery('.jt_workspace')[0].selectionEnd>
  206. !
  207. selectionStart: anInteger
  208. <jQuery('.jt_workspace')[0].selectionStart = anInteger>
  209. !
  210. selectionEnd: anInteger
  211. <jQuery('.jt_workspace')[0].selectionEnd = anInteger>
  212. !
  213. currentLine
  214. | lines startLine endLine|
  215. lines := textarea asJQuery val tokenize: String lf.
  216. startLine := endLine := 0.
  217. lines do: [:each |
  218. endLine := startLine + each size.
  219. startLine := endLine + 1.
  220. endLine >= self selectionStart ifTrue: [
  221. self selectionEnd: endLine.
  222. ^each]]
  223. ! !
  224. !Workspace methodsFor: 'actions'!
  225. handleKeyDown: anEvent
  226. <if(anEvent.ctrlKey) {
  227. if(anEvent.keyCode === 80) { //ctrl+p
  228. self._printIt();
  229. anEvent.preventDefault();
  230. return false;
  231. }
  232. if(anEvent.keyCode === 68) { //ctrl+d
  233. self._doIt();
  234. anEvent.preventDefault();
  235. return false;
  236. }
  237. if(anEvent.keyCode === 73) { //ctrl+i
  238. self._inspectIt();
  239. anEvent.preventDefault();
  240. return false;
  241. }
  242. }>
  243. !
  244. clearWorkspace
  245. textarea asJQuery val: ''
  246. !
  247. doIt
  248. | selection |
  249. textarea asJQuery focus.
  250. self selectionStart = self selectionEnd
  251. ifTrue: [selection := self currentLine]
  252. ifFalse: [
  253. selection := textarea asJQuery val copyFrom: self selectionStart + 1 to: self selectionEnd + 1].
  254. ^self eval: selection
  255. !
  256. printIt
  257. self print: self doIt printString
  258. !
  259. print: aString
  260. | start |
  261. start := self selectionEnd.
  262. textarea asJQuery val: (
  263. (textarea asJQuery val copyFrom: 1 to: start),
  264. ' ', aString, ' ',
  265. (textarea asJQuery val copyFrom: start + 1 to: textarea asJQuery val size)).
  266. self selectionStart: start.
  267. self selectionEnd: start + aString size + 2
  268. !
  269. eval: aString
  270. | compiler node |
  271. compiler := Compiler new.
  272. node := compiler parseExpression: aString.
  273. node isParseFailure ifTrue: [
  274. ^self alert: node reason, ', position: ', node position].
  275. ^compiler loadExpression: aString
  276. !
  277. inspectIt
  278. self doIt inspect
  279. ! !
  280. !Workspace methodsFor: 'rendering'!
  281. renderBoxOn: html
  282. textarea := html textarea.
  283. textarea asJQuery call: 'tabby'.
  284. textarea onKeyDown: [:e | self handleKeyDown: e].
  285. textarea
  286. class: 'jt_workspace';
  287. at: 'spellcheck' put: 'false'
  288. !
  289. renderButtonsOn: html
  290. html button
  291. with: 'DoIt';
  292. title: 'ctrl+d';
  293. onClick: [self doIt].
  294. html button
  295. with: 'PrintIt';
  296. title: 'ctrl+p';
  297. onClick: [self printIt].
  298. html button
  299. with: 'InspectIt';
  300. title: 'ctrl+i';
  301. onClick: [self inspectIt].
  302. html button
  303. with: 'Clear workspace';
  304. onClick: [self clearWorkspace]
  305. ! !
  306. TabWidget subclass: #Transcript
  307. instanceVariableNames: 'textarea'
  308. category: 'IDE'!
  309. !Transcript methodsFor: 'accessing'!
  310. label
  311. ^'[Transcript]'
  312. ! !
  313. !Transcript methodsFor: 'actions'!
  314. show: anObject
  315. textarea asJQuery val: textarea asJQuery val, anObject asString.
  316. !
  317. cr
  318. textarea asJQuery val: textarea asJQuery val, String cr.
  319. !
  320. clear
  321. textarea asJQuery val: ''
  322. ! !
  323. !Transcript methodsFor: 'rendering'!
  324. renderBoxOn: html
  325. textarea := html textarea.
  326. textarea asJQuery call: 'tabby'.
  327. textarea
  328. class: 'jt_transcript';
  329. at: 'spellcheck' put: 'false'
  330. !
  331. renderButtonsOn: html
  332. html button
  333. with: 'Clear transcript';
  334. onClick: [self clear]
  335. ! !
  336. Transcript class instanceVariableNames: 'current'!
  337. !Transcript class methodsFor: 'instance creation'!
  338. open
  339. self current open
  340. !
  341. new
  342. self shouldNotImplement
  343. !
  344. current
  345. ^current ifNil: [current := super new]
  346. ! !
  347. !Transcript class methodsFor: 'printing'!
  348. show: anObject
  349. self current show: anObject
  350. !
  351. cr
  352. self current show: String cr
  353. !
  354. clear
  355. self current clear
  356. ! !
  357. TabWidget subclass: #Browser
  358. instanceVariableNames: 'selectedCategory selectedClass selectedProtocol selectedMethod commitButton categoriesList classesList protocolsList methodsList sourceTextarea tabsList selectedTab saveButton classButtons methodButtons unsavedChanges input'
  359. category: 'IDE'!
  360. !Browser methodsFor: 'accessing'!
  361. label
  362. ^selectedClass
  363. ifNil: ['Browser (nil)']
  364. ifNotNil: [selectedClass name]
  365. !
  366. categories
  367. | categories |
  368. categories := Array new.
  369. Smalltalk current classes do: [:each |
  370. (categories includes: each category) ifFalse: [
  371. categories add: each category]].
  372. ^categories sort
  373. !
  374. classes
  375. ^(Smalltalk current classes
  376. select: [:each | each category = selectedCategory])
  377. sort: [:a :b | a name > b name]
  378. !
  379. protocols
  380. | klass |
  381. selectedClass ifNotNil: [
  382. selectedTab = #comment ifTrue: [^#()].
  383. klass := selectedTab = #instance
  384. ifTrue: [selectedClass]
  385. ifFalse: [selectedClass class].
  386. klass methodDictionary isEmpty ifTrue: [
  387. ^Array with: 'not yet classified'].
  388. ^klass protocols].
  389. ^Array new
  390. !
  391. methods
  392. | klass |
  393. selectedTab = #comment ifTrue: [^#()].
  394. selectedClass ifNotNil: [
  395. klass := selectedTab = #instance
  396. ifTrue: [selectedClass]
  397. ifFalse: [selectedClass class]].
  398. ^(selectedProtocol
  399. ifNil: [
  400. klass
  401. ifNil: [#()]
  402. ifNotNil: [klass methodDictionary values]]
  403. ifNotNil: [
  404. klass methodDictionary values select: [:each |
  405. each category = selectedProtocol]]) sort: [:a :b | a selector > b selector]
  406. !
  407. source
  408. selectedTab = #comment ifFalse: [
  409. ^(selectedProtocol notNil or: [selectedMethod notNil])
  410. ifFalse: [self declarationSource]
  411. ifTrue: [self methodSource]].
  412. ^selectedClass
  413. ifNil: ['']
  414. ifNotNil: [self classCommentSource]
  415. !
  416. methodSource
  417. ^selectedMethod
  418. ifNil: [self dummyMethodSource]
  419. ifNotNil: [selectedMethod source]
  420. !
  421. dummyMethodSource
  422. ^'messageSelectorAndArgumentNames
  423. "comment stating purpose of message"
  424. | temporary variable names |
  425. statements'
  426. !
  427. declarationSource
  428. ^selectedTab = #instance
  429. ifTrue: [self classDeclarationSource]
  430. ifFalse: [self metaclassDeclarationSource]
  431. !
  432. classDeclarationSource
  433. | stream |
  434. stream := '' writeStream.
  435. selectedClass ifNotNil: [
  436. stream
  437. nextPutAll: selectedClass superclass asString;
  438. nextPutAll: ' subclass: #';
  439. nextPutAll: selectedClass name;
  440. nextPutAll: String lf, String tab;
  441. nextPutAll: 'instanceVariableNames: '''.
  442. selectedClass instanceVariableNames
  443. do: [:each | stream nextPutAll: each]
  444. separatedBy: [stream nextPutAll: ' '].
  445. stream
  446. nextPutAll: '''', String lf, String tab;
  447. nextPutAll: 'category: ''';
  448. nextPutAll: selectedClass category;
  449. nextPutAll: ''''].
  450. ^stream contents
  451. !
  452. metaclassDeclarationSource
  453. | stream |
  454. stream := '' writeStream.
  455. selectedClass ifNotNil: [
  456. stream
  457. nextPutAll: selectedClass asString;
  458. nextPutAll: ' class ';
  459. nextPutAll: 'instanceVariableNames: '''.
  460. selectedClass class instanceVariableNames
  461. do: [:each | stream nextPutAll: each]
  462. separatedBy: [stream nextPutAll: ' '].
  463. stream nextPutAll: ''''].
  464. ^stream contents
  465. !
  466. classCommentSource
  467. ^selectedClass comment
  468. ! !
  469. !Browser methodsFor: 'actions'!
  470. enableSaveButton
  471. saveButton removeAt: 'disabled'.
  472. unsavedChanges := true
  473. !
  474. disableSaveButton
  475. saveButton ifNotNil: [
  476. saveButton at: 'disabled' put: true].
  477. unsavedChanges := false
  478. !
  479. hideClassButtons
  480. classButtons asJQuery hide
  481. !
  482. showClassButtons
  483. classButtons asJQuery show
  484. !
  485. hideMethodButtons
  486. methodButtons asJQuery hide
  487. !
  488. showMethodButtons
  489. methodButtons asJQuery show
  490. !
  491. compile
  492. self disableSaveButton.
  493. selectedTab = #comment ifTrue: [
  494. selectedClass ifNotNil: [
  495. self compileClassComment]].
  496. (selectedProtocol notNil or: [selectedMethod notNil])
  497. ifFalse: [self compileDefinition]
  498. ifTrue: [self compileMethodDefinition]
  499. !
  500. compileClassComment
  501. selectedClass comment: sourceTextarea asJQuery val
  502. !
  503. compileMethodDefinition
  504. selectedTab = #instance
  505. ifTrue: [self compileMethodDefinitionFor: selectedClass]
  506. ifFalse: [self compileMethodDefinitionFor: selectedClass class]
  507. !
  508. compileMethodDefinitionFor: aClass
  509. | compiler method source node |
  510. source := sourceTextarea asJQuery val.
  511. selectedProtocol ifNil: [selectedProtocol := selectedMethod category].
  512. compiler := Compiler new.
  513. node := compiler parse: source.
  514. node isParseFailure ifTrue: [
  515. ^self alert: 'PARSE ERROR: ', node reason, ', position: ', node position asString].
  516. compiler currentClass: aClass.
  517. method := compiler eval: (compiler compileNode: node).
  518. method category: selectedProtocol.
  519. compiler unknownVariables do: [:each |
  520. (self confirm: 'Declare ''', each, ''' as instance variable?') ifTrue: [
  521. self addInstanceVariableNamed: each toClass: aClass.
  522. ^self compileMethodDefinitionFor: aClass]].
  523. aClass addCompiledMethod: method.
  524. compiler setupClass: aClass.
  525. self updateMethodsList.
  526. self selectMethod: method
  527. !
  528. compileDefinition
  529. | newClass |
  530. newClass := Compiler new loadExpression: sourceTextarea asJQuery val.
  531. self
  532. updateCategoriesList;
  533. updateClassesList
  534. !
  535. commitCategory
  536. selectedCategory ifNotNil: [
  537. (Ajax url: self class commitPathJs, '/', selectedCategory, '.js')
  538. at: 'type' put: 'PUT';
  539. at: 'data' put: (Exporter new exportCategory: selectedCategory);
  540. at: 'error' put: [self alert: 'Commit failed!!'];
  541. send.
  542. (Ajax url: self class commitPathSt, '/', selectedCategory, '.st')
  543. at: 'type' put: 'PUT';
  544. at: 'data' put: (ChunkExporter new exportCategory: selectedCategory);
  545. at: 'error' put: [self alert: 'Commit failed!!'];
  546. send]
  547. !
  548. cancelChanges
  549. ^unsavedChanges
  550. ifTrue: [self confirm: 'Cancel changes?']
  551. ifFalse: [true]
  552. !
  553. removeClass
  554. (self confirm: 'Do you really want to remove ', selectedClass name, '?')
  555. ifTrue: [
  556. Smalltalk current basicDelete: selectedClass name.
  557. self selectClass: nil]
  558. !
  559. removeMethod
  560. self cancelChanges ifTrue: [
  561. (self confirm: 'Do you really want to remove #', selectedMethod selector, '?')
  562. ifTrue: [
  563. selectedTab = #instance
  564. ifTrue: [selectedClass removeCompiledMethod: selectedMethod]
  565. ifFalse: [selectedClass class removeCompiledMethod: selectedMethod].
  566. self selectMethod: nil]]
  567. !
  568. setMethodProtocol: aString
  569. self cancelChanges ifTrue: [
  570. (self protocols includes: aString)
  571. ifFalse: [self addNewProtocol]
  572. ifTrue: [
  573. selectedMethod category: aString.
  574. selectedProtocol := aString.
  575. selectedMethod := selectedMethod.
  576. self
  577. updateProtocolsList;
  578. updateMethodsList;
  579. updateSourceAndButtons]]
  580. !
  581. addNewProtocol
  582. | newProtocol |
  583. newProtocol := self prompt: 'New method protocol'.
  584. newProtocol notEmpty ifTrue: [
  585. selectedMethod category: newProtocol.
  586. self setMethodProtocol: newProtocol]
  587. !
  588. selectCategory: aCategory
  589. self cancelChanges ifTrue: [
  590. selectedCategory := aCategory.
  591. selectedClass := selectedProtocol := selectedMethod := nil.
  592. self
  593. updateCategoriesList;
  594. updateClassesList;
  595. updateProtocolsList;
  596. updateMethodsList;
  597. updateSourceAndButtons]
  598. !
  599. selectClass: aClass
  600. self cancelChanges ifTrue: [
  601. selectedClass := aClass.
  602. selectedProtocol := selectedMethod := nil.
  603. self
  604. updateClassesList;
  605. updateProtocolsList;
  606. updateMethodsList;
  607. updateSourceAndButtons]
  608. !
  609. selectProtocol: aString
  610. self cancelChanges ifTrue: [
  611. selectedProtocol := aString.
  612. selectedMethod := nil.
  613. self
  614. updateProtocolsList;
  615. updateMethodsList;
  616. updateSourceAndButtons]
  617. !
  618. selectMethod: aMethod
  619. self cancelChanges ifTrue: [
  620. selectedMethod := aMethod.
  621. self
  622. updateProtocolsList;
  623. updateMethodsList;
  624. updateSourceAndButtons]
  625. !
  626. selectTab: aString
  627. self cancelChanges ifTrue: [
  628. selectedTab := aString.
  629. self selectProtocol: nil.
  630. self updateTabsList]
  631. !
  632. renameClass
  633. | newName |
  634. newName := self prompt: 'Rename class ', selectedClass name.
  635. newName notEmpty ifTrue: [
  636. selectedClass rename: newName.
  637. self
  638. updateClassesList;
  639. updateSourceAndButtons]
  640. !
  641. addInstanceVariableNamed: aString toClass: aClass
  642. ClassBuilder new
  643. addSubclassOf: aClass superclass named: aClass name instanceVariableNames: (aClass instanceVariableNames copy add: aString; yourself)
  644. !
  645. searchReferencesOf: aString
  646. ReferencesBrowser search: aString
  647. !
  648. searchClassReferences
  649. ReferencesBrowser search: selectedClass name
  650. !
  651. search: aString
  652. self cancelChanges ifTrue: [| searchedClass |
  653. searchedClass := Smalltalk current at: aString.
  654. searchedClass isClass
  655. ifTrue: [self class openOn: searchedClass]
  656. ifFalse: [self searchReferencesOf: aString]]
  657. ! !
  658. !Browser methodsFor: 'initialization'!
  659. initialize
  660. super initialize.
  661. selectedTab := #instance.
  662. unsavedChanges := false
  663. ! !
  664. !Browser methodsFor: 'rendering'!
  665. renderBoxOn: html
  666. self
  667. renderTopPanelOn: html;
  668. renderTabsOn: html;
  669. renderBottomPanelOn: html
  670. !
  671. renderTopPanelOn: html
  672. html div
  673. class: 'top';
  674. with: [
  675. self renderInputOn: html.
  676. categoriesList := html ul class: 'jt_column browser categories'.
  677. commitButton := html button
  678. class: 'jt_commit';
  679. title: 'Commit classes in this category to disk';
  680. onClick: [self commitCategory];
  681. with: 'Commit category'.
  682. classesList := html ul class: 'jt_column browser classes'.
  683. protocolsList := html ul class: 'jt_column browser protocols'.
  684. methodsList := html ul class: 'jt_column browser methods'.
  685. self
  686. updateCategoriesList;
  687. updateClassesList;
  688. updateProtocolsList;
  689. updateMethodsList.
  690. html div class: 'jt_clear']
  691. !
  692. renderTabsOn: html
  693. tabsList := html ul class: 'jt_tabs'.
  694. self updateTabsList.
  695. !
  696. renderBottomPanelOn: html
  697. html div
  698. class: 'jt_sourceCode';
  699. with: [
  700. sourceTextarea := html textarea
  701. onKeyPress: [self enableSaveButton];
  702. class: 'source';
  703. at: 'spellcheck' put: 'false'.
  704. sourceTextarea asJQuery call: 'tabby']
  705. !
  706. renderButtonsOn: html
  707. saveButton := html button.
  708. saveButton
  709. with: 'Save';
  710. onClick: [self compile].
  711. methodButtons := html span.
  712. classButtons := html span.
  713. self updateSourceAndButtons
  714. !
  715. renderInputOn: html
  716. input := html input
  717. class: 'implementors';
  718. yourself.
  719. input onKeyPress: [:event |
  720. event keyCode = 13 ifTrue: [
  721. self search: input asJQuery val]]
  722. ! !
  723. !Browser methodsFor: 'testing'!
  724. canBeClosed
  725. ^true
  726. ! !
  727. !Browser methodsFor: 'updating'!
  728. updateCategoriesList
  729. categoriesList contents: [:html |
  730. self categories do: [:each || li label |
  731. each isEmpty
  732. ifTrue: [label := 'Unclassified']
  733. ifFalse: [label := each].
  734. li := html li.
  735. selectedCategory = each ifTrue: [
  736. li class: 'selected'].
  737. li
  738. with: label;
  739. onClick: [self selectCategory: each]]]
  740. !
  741. updateClassesList
  742. TabManager current update.
  743. classesList contents: [:html |
  744. self classes do: [:each || li |
  745. li := html li.
  746. selectedClass = each ifTrue: [
  747. li class: 'selected'].
  748. li
  749. with: each name;
  750. onClick: [self selectClass: each]]]
  751. !
  752. updateProtocolsList
  753. protocolsList contents: [:html |
  754. self protocols do: [:each || li |
  755. li := html li.
  756. selectedProtocol = each ifTrue: [
  757. li class: 'selected'].
  758. li
  759. with: each;
  760. onClick: [self selectProtocol: each]]]
  761. !
  762. updateMethodsList
  763. methodsList contents: [:html |
  764. self methods do: [:each || li |
  765. li := html li.
  766. selectedMethod = each ifTrue: [
  767. li class: 'selected'].
  768. li
  769. with: each selector;
  770. onClick: [self selectMethod: each]]]
  771. !
  772. updateTabsList
  773. tabsList contents: [:html || li |
  774. li := html li.
  775. selectedTab = #instance ifTrue: [li class: 'selected'].
  776. li
  777. with: 'Instance';
  778. onClick: [self selectTab: #instance].
  779. li := html li.
  780. selectedTab = #class ifTrue: [li class: 'selected'].
  781. li
  782. with: 'Class';
  783. onClick: [self selectTab: #class].
  784. li := html li.
  785. selectedTab = #comment ifTrue: [li class: 'selected'].
  786. li
  787. with: 'Comment';
  788. onClick: [self selectTab: #comment]]
  789. !
  790. updateSourceAndButtons
  791. self disableSaveButton.
  792. classButtons contents: [:html |
  793. html button
  794. with: 'Rename class';
  795. onClick: [self renameClass].
  796. html button
  797. with: 'Remove class';
  798. onClick: [self removeClass].
  799. html button
  800. with: 'References';
  801. onClick: [self searchClassReferences]].
  802. methodButtons contents: [:html |
  803. html button
  804. with: 'Remove method';
  805. onClick: [self removeMethod].
  806. html select
  807. onChange: [:e :select | self setMethodProtocol: select val];
  808. with: [
  809. html option
  810. with: 'Method protocol';
  811. at: 'disabled' put: 'disabled'.
  812. html option
  813. class: 'important';
  814. with: 'New...'.
  815. self protocols do: [:each |
  816. html option with: each]].
  817. selectedMethod isNil ifFalse: [
  818. html select
  819. onChange: [:e :select | self searchReferencesOf: select val];
  820. with: [
  821. html option
  822. with: 'References';
  823. at: 'disabled' put: 'disabled'.
  824. html option
  825. class: 'important';
  826. with: selectedMethod selector.
  827. selectedMethod messageSends sorted do: [:each |
  828. html option with: each]]]].
  829. selectedMethod isNil
  830. ifTrue: [
  831. self hideMethodButtons.
  832. (selectedClass isNil or: [selectedProtocol notNil])
  833. ifTrue: [self hideClassButtons]
  834. ifFalse: [self showClassButtons]]
  835. ifFalse: [
  836. self hideClassButtons.
  837. self showMethodButtons].
  838. sourceTextarea asJQuery val: self source
  839. ! !
  840. !Browser class methodsFor: 'accessing'!
  841. commitPathJs
  842. ^'js'
  843. !
  844. commitPathSt
  845. ^'st'
  846. ! !
  847. !Browser class methodsFor: 'convenience'!
  848. openOn: aClass
  849. ^self new
  850. open;
  851. selectCategory: aClass category;
  852. selectClass: aClass
  853. !
  854. open
  855. self new open
  856. ! !
  857. TabWidget subclass: #Inspector
  858. instanceVariableNames: 'label variables object selectedVariable variablesList valueTextarea workspaceTextarea diveButton'
  859. category: 'IDE'!
  860. !Inspector methodsFor: 'accessing'!
  861. label
  862. ^label ifNil: ['Inspector (nil)']
  863. !
  864. variables
  865. ^variables
  866. !
  867. setVariables: aCollection
  868. variables := aCollection
  869. !
  870. setLabel: aString
  871. label := aString
  872. !
  873. selectedVariable
  874. ^selectedVariable
  875. !
  876. selectedVariable: aString
  877. selectedVariable := aString
  878. ! !
  879. !Inspector methodsFor: 'actions'!
  880. inspect: anObject
  881. object := anObject.
  882. variables := #().
  883. object inspectOn: self
  884. !
  885. dive
  886. (self variables at: self selectedVariable) inspect
  887. !
  888. refresh
  889. self
  890. inspect: object;
  891. updateVariablesList;
  892. updateValueTextarea
  893. ! !
  894. !Inspector methodsFor: 'rendering'!
  895. renderBoxOn: html
  896. self
  897. renderTopPanelOn: html;
  898. renderBottomPanelOn: html
  899. !
  900. renderTopPanelOn: html
  901. html div
  902. class: 'top';
  903. with: [
  904. variablesList := html ul class: 'jt_column variables'.
  905. valueTextarea := html textarea class: 'jt_column value'; at: 'readonly' put: 'readonly'.
  906. self
  907. updateVariablesList;
  908. updateValueTextarea.
  909. html div class: 'jt_clear']
  910. !
  911. renderBottomPanelOn: html
  912. html div
  913. class: 'jt_sourceCode';
  914. with: [
  915. workspaceTextarea := html textarea
  916. class: 'source';
  917. at: 'spellcheck' put: 'false'.
  918. workspaceTextarea asJQuery call: 'tabby']
  919. !
  920. renderButtonsOn: html
  921. html button
  922. with: 'Refresh';
  923. onClick: [self refresh].
  924. diveButton := html button
  925. with: 'Dive';
  926. onClick: [self dive].
  927. self updateButtons
  928. ! !
  929. !Inspector methodsFor: 'testing'!
  930. canBeClosed
  931. ^true
  932. ! !
  933. !Inspector methodsFor: 'updating'!
  934. updateVariablesList
  935. variablesList contents: [:html |
  936. self variables keys do: [:each || li |
  937. li := html li.
  938. li
  939. with: each;
  940. onClick: [self selectVariable: each].
  941. self selectedVariable = each ifTrue: [
  942. li class: 'selected']]]
  943. !
  944. selectVariable: aString
  945. self selectedVariable: aString.
  946. self
  947. updateVariablesList;
  948. updateValueTextarea;
  949. updateButtons
  950. !
  951. updateValueTextarea
  952. valueTextarea asJQuery val: (self selectedVariable isNil
  953. ifTrue: ['']
  954. ifFalse: [(self variables at: self selectedVariable) printString])
  955. !
  956. updateButtons
  957. (self selectedVariable notNil and: [(self variables at: self selectedVariable) notNil])
  958. ifFalse: [diveButton at: 'disabled' put: true]
  959. ifTrue: [diveButton removeAt: 'disabled']
  960. ! !
  961. !Inspector class methodsFor: 'instance creation'!
  962. on: anObject
  963. ^self new
  964. inspect: anObject;
  965. yourself
  966. ! !
  967. TabWidget subclass: #ReferencesBrowser
  968. instanceVariableNames: 'implementors senders implementorsList input timer selector sendersList referencedClasses referencedClassesList'
  969. category: 'IDE'!
  970. !ReferencesBrowser methodsFor: 'accessing'!
  971. implementors
  972. ^implementors ifNil: [implementors := Array new]
  973. !
  974. label
  975. ^'[ReferencesBrowser]'
  976. !
  977. selector
  978. ^selector
  979. !
  980. senders
  981. ^senders ifNil: [senders := Array new]
  982. !
  983. classesAndMetaclasses
  984. ^Smalltalk current classes, (Smalltalk current classes collect: [:each | each class])
  985. !
  986. referencedClasses
  987. ^referencedClasses ifNil: [referencedClasses := Array new]
  988. ! !
  989. !ReferencesBrowser methodsFor: 'actions'!
  990. openBrowserOn: aMethod
  991. | browser |
  992. browser := Browser openOn: (aMethod class isMetaclass
  993. ifTrue: [aMethod methodClass instanceClass] ifFalse: [aMethod methodClass]).
  994. aMethod methodClass isMetaclass ifTrue: [browser selectTab: #class].
  995. browser
  996. selectProtocol: aMethod category;
  997. selectMethod: aMethod
  998. !
  999. searchReferencesFor: aString
  1000. selector := aString.
  1001. implementors := Array new.
  1002. senders := Array new.
  1003. referencedClasses := Array new.
  1004. (selector match: '^[A-Z]')
  1005. ifFalse: [self searchSelectorReferencesFor: selector]
  1006. ifTrue: [self searchReferencedClassesFor: selector]
  1007. !
  1008. search: aString
  1009. self
  1010. searchReferencesFor: aString;
  1011. updateImplementorsList;
  1012. updateSendersList;
  1013. updateReferencedClassesList
  1014. !
  1015. searchReferencedClassesFor: aString
  1016. self classesAndMetaclasses do: [:each |
  1017. each methodDictionary values do: [:value |
  1018. (((value referencedClasses select: [:each | each notNil])collect: [:each | each name]) includes: selector) ifTrue: [
  1019. self referencedClasses add: value]]]
  1020. !
  1021. searchSelectorReferencesFor: aString
  1022. self classesAndMetaclasses do: [:each |
  1023. each methodDictionary keysAndValuesDo: [:key :value |
  1024. key = selector ifTrue: [self implementors add: value]].
  1025. each methodDictionary keysAndValuesDo: [:key :value |
  1026. (value messageSends includes: selector) ifTrue: [
  1027. self senders add: value]]]
  1028. ! !
  1029. !ReferencesBrowser methodsFor: 'initialization'!
  1030. initialize
  1031. super initialize.
  1032. selector := ''
  1033. ! !
  1034. !ReferencesBrowser methodsFor: 'private'!
  1035. setInputEvents
  1036. input
  1037. onKeyUp: [timer := [self search: input asJQuery val] valueWithTimeout: 100];
  1038. onKeyDown: [timer ifNotNil: [timer clearTimeout]]
  1039. ! !
  1040. !ReferencesBrowser methodsFor: 'rendering'!
  1041. renderBoxOn: html
  1042. self
  1043. renderInputOn: html;
  1044. renderImplementorsOn: html;
  1045. renderSendersOn: html;
  1046. renderReferencedClassesOn: html
  1047. !
  1048. renderInputOn: html
  1049. input := html input
  1050. class: 'implementors';
  1051. yourself.
  1052. input asJQuery val: selector.
  1053. self setInputEvents
  1054. !
  1055. renderImplementorsOn: html
  1056. implementorsList := html ul class: 'jt_column implementors'.
  1057. self updateImplementorsList
  1058. !
  1059. renderSendersOn: html
  1060. sendersList := html ul class: 'jt_column senders'.
  1061. self updateSendersList
  1062. !
  1063. renderReferencedClassesOn: html
  1064. referencedClassesList := html ul class: 'jt_column referenced_classes'.
  1065. self updateReferencedClassesList
  1066. ! !
  1067. !ReferencesBrowser methodsFor: 'testing'!
  1068. canBeClosed
  1069. ^true
  1070. ! !
  1071. !ReferencesBrowser methodsFor: 'updating'!
  1072. updateImplementorsList
  1073. implementorsList contents: [:html |
  1074. html li
  1075. class: 'column_label';
  1076. with: 'Implementors (', self implementors size asString, ')';
  1077. style: 'font-weight: bold'.
  1078. self implementors do: [:each || li |
  1079. li := html li.
  1080. li
  1081. with: (each methodClass asString, ' >> ', self selector);
  1082. onClick: [self openBrowserOn: each]]]
  1083. !
  1084. updateSendersList
  1085. sendersList contents: [:html |
  1086. html li
  1087. class: 'column_label';
  1088. with: 'Senders (', self senders size asString, ')';
  1089. style: 'font-weight: bold'.
  1090. self senders do: [:each |
  1091. html li
  1092. with: (each methodClass asString, ' >> ', each selector);
  1093. onClick: [self openBrowserOn: each]]]
  1094. !
  1095. updateReferencedClassesList
  1096. referencedClassesList contents: [:html |
  1097. html li
  1098. class: 'column_label';
  1099. with: 'Class references (', self referencedClasses size asString, ')';
  1100. style: 'font-weight: bold'.
  1101. self referencedClasses do: [:each |
  1102. html li
  1103. with: (each methodClass asString, ' >> ', each selector);
  1104. onClick: [self openBrowserOn: each]]]
  1105. ! !
  1106. !ReferencesBrowser class methodsFor: 'instance creation'!
  1107. search: aString
  1108. ^self new
  1109. searchReferencesFor: aString;
  1110. open
  1111. ! !
  1112. !Object methodsFor: '*IDE'!
  1113. inspect
  1114. Inspector new
  1115. inspect: self;
  1116. open
  1117. !
  1118. inspectOn: anInspector
  1119. | variables |
  1120. variables := Dictionary new.
  1121. variables at: '#self' put: self.
  1122. self class allInstanceVariableNames do: [:each |
  1123. variables at: each put: (self instVarAt: each)].
  1124. anInspector
  1125. setLabel: self printString;
  1126. setVariables: variables
  1127. ! !
  1128. !Date methodsFor: '*IDE'!
  1129. inspectOn: anInspector
  1130. | variables |
  1131. variables := Dictionary new.
  1132. variables at: '#self' put: self.
  1133. variables at: '#year' put: self year.
  1134. variables at: '#month' put: self month.
  1135. variables at: '#day' put: self day.
  1136. variables at: '#hours' put: self hours.
  1137. variables at: '#minutes' put: self minutes.
  1138. variables at: '#seconds' put: self seconds.
  1139. variables at: '#milliseconds' put: self milliseconds.
  1140. anInspector
  1141. setLabel: self printString;
  1142. setVariables: variables
  1143. ! !
  1144. !Collection methodsFor: '*IDE'!
  1145. inspectOn: anInspector
  1146. | variables |
  1147. variables := Dictionary new.
  1148. variables at: '#self' put: self.
  1149. self withIndexDo: [:each :i |
  1150. variables at: i put: each].
  1151. anInspector
  1152. setLabel: self printString;
  1153. setVariables: variables
  1154. ! !
  1155. !String methodsFor: '*IDE'!
  1156. inspectOn: anInspector
  1157. | label |
  1158. super inspectOn: anInspector.
  1159. self printString size > 30
  1160. ifTrue: [label := (self printString copyFrom: 1 to: 30), '...''']
  1161. ifFalse: [label := self printString].
  1162. anInspector setLabel: label
  1163. ! !
  1164. !MethodContext methodsFor: '*IDE'!
  1165. inspectOn: anInspector
  1166. | variables |
  1167. variables := Dictionary new.
  1168. variables at: '#self' put: self.
  1169. variables at: '#home' put: self home.
  1170. variables at: '#receiver' put: self receiver.
  1171. variables at: '#selector' put: self selector.
  1172. self class instanceVariableNames do: [:each |
  1173. variables at: each put: (self instVarAt: each)].
  1174. anInspector
  1175. setLabel: self printString;
  1176. setVariables: variables
  1177. ! !
  1178. !Dictionary methodsFor: '*IDE'!
  1179. inspectOn: anInspector
  1180. | variables |
  1181. variables := Dictionary new.
  1182. variables at: '#self' put: self.
  1183. variables at: '#keys' put: self keys.
  1184. self keysAndValuesDo: [:key :value |
  1185. variables at: key put: value].
  1186. anInspector
  1187. setLabel: self printString;
  1188. setVariables: variables
  1189. ! !