1
0

IDE.st 29 KB

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