IDE.st 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618
  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: 'sourceArea'
  193. category: 'IDE'!
  194. !Workspace methodsFor: 'accessing'!
  195. label
  196. ^'[Workspace]'
  197. ! !
  198. !Workspace methodsFor: 'actions'!
  199. clearWorkspace
  200. sourceArea clear
  201. !
  202. doIt
  203. sourceArea doIt
  204. !
  205. printIt
  206. sourceArea printIt
  207. !
  208. inspectIt
  209. sourceArea inspectIt
  210. ! !
  211. !Workspace methodsFor: 'rendering'!
  212. renderBoxOn: html
  213. sourceArea := SourceArea new.
  214. sourceArea renderOn: html
  215. !
  216. renderButtonsOn: html
  217. html button
  218. with: 'DoIt';
  219. title: 'ctrl+d';
  220. onClick: [self doIt].
  221. html button
  222. with: 'PrintIt';
  223. title: 'ctrl+p';
  224. onClick: [self printIt].
  225. html button
  226. with: 'InspectIt';
  227. title: 'ctrl+i';
  228. onClick: [self inspectIt].
  229. html button
  230. with: 'Clear workspace';
  231. onClick: [self clearWorkspace]
  232. ! !
  233. TabWidget subclass: #Transcript
  234. instanceVariableNames: 'textarea'
  235. category: 'IDE'!
  236. !Transcript methodsFor: 'accessing'!
  237. label
  238. ^'[Transcript]'
  239. ! !
  240. !Transcript methodsFor: 'actions'!
  241. show: anObject
  242. textarea asJQuery val: textarea asJQuery val, anObject asString.
  243. !
  244. cr
  245. textarea asJQuery val: textarea asJQuery val, String cr.
  246. !
  247. clear
  248. textarea asJQuery val: ''
  249. ! !
  250. !Transcript methodsFor: 'rendering'!
  251. renderBoxOn: html
  252. textarea := html textarea.
  253. textarea asJQuery call: 'tabby'.
  254. textarea
  255. class: 'jt_transcript';
  256. at: 'spellcheck' put: 'false'
  257. !
  258. renderButtonsOn: html
  259. html button
  260. with: 'Clear transcript';
  261. onClick: [self clear]
  262. ! !
  263. Transcript class instanceVariableNames: 'current'!
  264. !Transcript class methodsFor: 'instance creation'!
  265. open
  266. self current open
  267. !
  268. new
  269. self shouldNotImplement
  270. !
  271. current
  272. ^current ifNil: [current := super new]
  273. ! !
  274. !Transcript class methodsFor: 'printing'!
  275. show: anObject
  276. self current show: anObject
  277. !
  278. cr
  279. self current show: String cr
  280. !
  281. clear
  282. self current clear
  283. ! !
  284. TabWidget subclass: #Browser
  285. instanceVariableNames: 'selectedCategory selectedClass selectedProtocol selectedMethod commitButton categoriesList classesList protocolsList methodsList sourceArea tabsList selectedTab saveButton classButtons methodButtons unsavedChanges input'
  286. category: 'IDE'!
  287. !Browser methodsFor: 'accessing'!
  288. label
  289. ^selectedClass
  290. ifNil: ['Browser (nil)']
  291. ifNotNil: [selectedClass name]
  292. !
  293. categories
  294. | categories |
  295. categories := Array new.
  296. Smalltalk current classes do: [:each |
  297. (categories includes: each category) ifFalse: [
  298. categories add: each category]].
  299. ^categories sort
  300. !
  301. classes
  302. ^(Smalltalk current classes
  303. select: [:each | each category = selectedCategory])
  304. sort: [:a :b | a name > b name]
  305. !
  306. protocols
  307. | klass |
  308. selectedClass ifNotNil: [
  309. selectedTab = #comment ifTrue: [^#()].
  310. klass := selectedTab = #instance
  311. ifTrue: [selectedClass]
  312. ifFalse: [selectedClass class].
  313. klass methodDictionary isEmpty ifTrue: [
  314. ^Array with: 'not yet classified'].
  315. ^klass protocols].
  316. ^Array new
  317. !
  318. methods
  319. | klass |
  320. selectedTab = #comment ifTrue: [^#()].
  321. selectedClass ifNotNil: [
  322. klass := selectedTab = #instance
  323. ifTrue: [selectedClass]
  324. ifFalse: [selectedClass class]].
  325. ^(selectedProtocol
  326. ifNil: [
  327. klass
  328. ifNil: [#()]
  329. ifNotNil: [klass methodDictionary values]]
  330. ifNotNil: [
  331. klass methodDictionary values select: [:each |
  332. each category = selectedProtocol]]) sort: [:a :b | a selector > b selector]
  333. !
  334. source
  335. selectedTab = #comment ifFalse: [
  336. ^(selectedProtocol notNil or: [selectedMethod notNil])
  337. ifFalse: [self declarationSource]
  338. ifTrue: [self methodSource]].
  339. ^selectedClass
  340. ifNil: ['']
  341. ifNotNil: [self classCommentSource]
  342. !
  343. methodSource
  344. ^selectedMethod
  345. ifNil: [self dummyMethodSource]
  346. ifNotNil: [selectedMethod source]
  347. !
  348. dummyMethodSource
  349. ^'messageSelectorAndArgumentNames
  350. "comment stating purpose of message"
  351. | temporary variable names |
  352. statements'
  353. !
  354. declarationSource
  355. ^selectedTab = #instance
  356. ifTrue: [self classDeclarationSource]
  357. ifFalse: [self metaclassDeclarationSource]
  358. !
  359. classDeclarationSource
  360. | stream |
  361. stream := '' writeStream.
  362. selectedClass ifNotNil: [
  363. stream
  364. nextPutAll: selectedClass superclass asString;
  365. nextPutAll: ' subclass: #';
  366. nextPutAll: selectedClass name;
  367. nextPutAll: String lf, String tab;
  368. nextPutAll: 'instanceVariableNames: '''.
  369. selectedClass instanceVariableNames
  370. do: [:each | stream nextPutAll: each]
  371. separatedBy: [stream nextPutAll: ' '].
  372. stream
  373. nextPutAll: '''', String lf, String tab;
  374. nextPutAll: 'category: ''';
  375. nextPutAll: selectedClass category;
  376. nextPutAll: ''''].
  377. ^stream contents
  378. !
  379. metaclassDeclarationSource
  380. | stream |
  381. stream := '' writeStream.
  382. selectedClass ifNotNil: [
  383. stream
  384. nextPutAll: selectedClass asString;
  385. nextPutAll: ' class ';
  386. nextPutAll: 'instanceVariableNames: '''.
  387. selectedClass class instanceVariableNames
  388. do: [:each | stream nextPutAll: each]
  389. separatedBy: [stream nextPutAll: ' '].
  390. stream nextPutAll: ''''].
  391. ^stream contents
  392. !
  393. classCommentSource
  394. ^selectedClass comment
  395. !
  396. selectedClass
  397. ^selectedClass
  398. ! !
  399. !Browser methodsFor: 'actions'!
  400. disableSaveButton
  401. saveButton ifNotNil: [
  402. saveButton at: 'disabled' put: true].
  403. unsavedChanges := false
  404. !
  405. hideClassButtons
  406. classButtons asJQuery hide
  407. !
  408. showClassButtons
  409. classButtons asJQuery show
  410. !
  411. hideMethodButtons
  412. methodButtons asJQuery hide
  413. !
  414. showMethodButtons
  415. methodButtons asJQuery show
  416. !
  417. compile
  418. self disableSaveButton.
  419. selectedTab = #comment ifTrue: [
  420. selectedClass ifNotNil: [
  421. self compileClassComment]].
  422. (selectedProtocol notNil or: [selectedMethod notNil])
  423. ifFalse: [self compileDefinition]
  424. ifTrue: [self compileMethodDefinition]
  425. !
  426. compileClassComment
  427. selectedClass comment: sourceArea val
  428. !
  429. compileMethodDefinition
  430. selectedTab = #instance
  431. ifTrue: [self compileMethodDefinitionFor: selectedClass]
  432. ifFalse: [self compileMethodDefinitionFor: selectedClass class]
  433. !
  434. compileMethodDefinitionFor: aClass
  435. | compiler method source node |
  436. source := sourceArea val.
  437. selectedProtocol ifNil: [selectedProtocol := selectedMethod category].
  438. compiler := Compiler new.
  439. node := compiler parse: source.
  440. node isParseFailure ifTrue: [
  441. ^self alert: 'PARSE ERROR: ', node reason, ', position: ', node position asString].
  442. compiler currentClass: aClass.
  443. method := compiler eval: (compiler compileNode: node).
  444. method category: selectedProtocol.
  445. compiler unknownVariables do: [:each |
  446. (self confirm: 'Declare ''', each, ''' as instance variable?') ifTrue: [
  447. self addInstanceVariableNamed: each toClass: aClass.
  448. ^self compileMethodDefinitionFor: aClass]].
  449. aClass addCompiledMethod: method.
  450. compiler setupClass: aClass.
  451. self updateMethodsList.
  452. self selectMethod: method
  453. !
  454. compileDefinition
  455. | newClass |
  456. newClass := Compiler new loadExpression: sourceArea textarea asJQuery val.
  457. self
  458. resetClassesList;
  459. updateCategoriesList;
  460. updateClassesList
  461. !
  462. commitCategory
  463. selectedCategory ifNotNil: [
  464. (Ajax url: self class commitPathJs, '/', selectedCategory, '.js')
  465. at: 'type' put: 'PUT';
  466. at: 'data' put: (Exporter new exportCategory: selectedCategory);
  467. at: 'error' put: [self alert: 'Commit failed!!'];
  468. send.
  469. (Ajax url: self class commitPathSt, '/', selectedCategory, '.st')
  470. at: 'type' put: 'PUT';
  471. at: 'data' put: (ChunkExporter new exportCategory: selectedCategory);
  472. at: 'error' put: [self alert: 'Commit failed!!'];
  473. send]
  474. !
  475. cancelChanges
  476. ^unsavedChanges
  477. ifTrue: [self confirm: 'Cancel changes?']
  478. ifFalse: [true]
  479. !
  480. removeClass
  481. (self confirm: 'Do you really want to remove ', selectedClass name, '?')
  482. ifTrue: [
  483. Smalltalk current basicDelete: selectedClass name.
  484. self resetClassesList.
  485. self selectClass: nil]
  486. !
  487. removeMethod
  488. self cancelChanges ifTrue: [
  489. (self confirm: 'Do you really want to remove #', selectedMethod selector, '?')
  490. ifTrue: [
  491. selectedTab = #instance
  492. ifTrue: [selectedClass removeCompiledMethod: selectedMethod]
  493. ifFalse: [selectedClass class removeCompiledMethod: selectedMethod].
  494. self selectMethod: nil]]
  495. !
  496. setMethodProtocol: aString
  497. self cancelChanges ifTrue: [
  498. (self protocols includes: aString)
  499. ifFalse: [self addNewProtocol]
  500. ifTrue: [
  501. selectedMethod category: aString.
  502. selectedProtocol := aString.
  503. selectedMethod := selectedMethod.
  504. self
  505. updateProtocolsList;
  506. updateMethodsList;
  507. updateSourceAndButtons]]
  508. !
  509. addNewProtocol
  510. | newProtocol |
  511. newProtocol := self prompt: 'New method protocol'.
  512. newProtocol notEmpty ifTrue: [
  513. selectedMethod category: newProtocol.
  514. self setMethodProtocol: newProtocol]
  515. !
  516. selectCategory: aCategory
  517. self cancelChanges ifTrue: [
  518. selectedCategory := aCategory.
  519. selectedClass := selectedProtocol := selectedMethod := nil.
  520. self resetClassesList.
  521. self
  522. updateCategoriesList;
  523. updateClassesList;
  524. updateProtocolsList;
  525. updateMethodsList;
  526. updateSourceAndButtons]
  527. !
  528. selectClass: aClass
  529. self cancelChanges ifTrue: [
  530. selectedClass := aClass.
  531. selectedProtocol := selectedMethod := nil.
  532. self
  533. updateClassesList;
  534. updateProtocolsList;
  535. updateMethodsList;
  536. updateSourceAndButtons]
  537. !
  538. selectProtocol: aString
  539. self cancelChanges ifTrue: [
  540. selectedProtocol := aString.
  541. selectedMethod := nil.
  542. self
  543. updateProtocolsList;
  544. updateMethodsList;
  545. updateSourceAndButtons]
  546. !
  547. selectMethod: aMethod
  548. self cancelChanges ifTrue: [
  549. selectedMethod := aMethod.
  550. self
  551. updateProtocolsList;
  552. updateMethodsList;
  553. updateSourceAndButtons]
  554. !
  555. selectTab: aString
  556. self cancelChanges ifTrue: [
  557. selectedTab := aString.
  558. self selectProtocol: nil.
  559. self updateTabsList]
  560. !
  561. renameClass
  562. | newName |
  563. newName := self prompt: 'Rename class ', selectedClass name.
  564. newName notEmpty ifTrue: [
  565. selectedClass rename: newName.
  566. self
  567. updateClassesList;
  568. updateSourceAndButtons]
  569. !
  570. addInstanceVariableNamed: aString toClass: aClass
  571. ClassBuilder new
  572. addSubclassOf: aClass superclass named: aClass name instanceVariableNames: (aClass instanceVariableNames copy add: aString; yourself)
  573. !
  574. searchReferencesOf: aString
  575. ReferencesBrowser search: aString
  576. !
  577. searchClassReferences
  578. ReferencesBrowser search: selectedClass name
  579. !
  580. search: aString
  581. self cancelChanges ifTrue: [| searchedClass |
  582. searchedClass := Smalltalk current at: aString.
  583. searchedClass isClass
  584. ifTrue: [self class openOn: searchedClass]
  585. ifFalse: [self searchReferencesOf: aString]]
  586. ! !
  587. !Browser methodsFor: 'initialization'!
  588. initialize
  589. super initialize.
  590. selectedTab := #instance.
  591. unsavedChanges := false
  592. ! !
  593. !Browser methodsFor: 'rendering'!
  594. renderBoxOn: html
  595. self
  596. renderTopPanelOn: html;
  597. renderTabsOn: html;
  598. renderBottomPanelOn: html
  599. !
  600. renderTopPanelOn: html
  601. html div
  602. class: 'top';
  603. with: [
  604. self renderInputOn: html.
  605. categoriesList := html ul class: 'jt_column browser categories'.
  606. commitButton := html button
  607. class: 'jt_commit';
  608. title: 'Commit classes in this category to disk';
  609. onClick: [self commitCategory];
  610. with: 'Commit category'.
  611. classesList := ClassesList on: self.
  612. classesList renderOn: html.
  613. protocolsList := html ul class: 'jt_column browser protocols'.
  614. methodsList := html ul class: 'jt_column browser methods'.
  615. self
  616. updateCategoriesList;
  617. updateClassesList;
  618. updateProtocolsList;
  619. updateMethodsList.
  620. html div class: 'jt_clear']
  621. !
  622. renderTabsOn: html
  623. tabsList := html ul class: 'jt_tabs'.
  624. self updateTabsList.
  625. !
  626. renderBottomPanelOn: html
  627. html div
  628. class: 'jt_sourceCode';
  629. with: [
  630. sourceArea := SourceArea new.
  631. sourceArea renderOn: html.
  632. sourceArea textarea
  633. onKeyUp: [self updateStatus]]
  634. !
  635. renderButtonsOn: html
  636. saveButton := html button.
  637. saveButton
  638. with: 'Save';
  639. onClick: [self compile].
  640. methodButtons := html span.
  641. classButtons := html span.
  642. html div
  643. class: 'right';
  644. with: [
  645. html button
  646. with: 'DoIt';
  647. onClick: [sourceArea doIt].
  648. html button
  649. with: 'PrintIt';
  650. onClick: [sourceArea printIt].
  651. html button with: 'InspectIt';
  652. onClick: [sourceArea inspectit]].
  653. self updateSourceAndButtons
  654. !
  655. renderInputOn: html
  656. input := html input
  657. class: 'implementors';
  658. yourself.
  659. input onKeyPress: [:event |
  660. event keyCode = 13 ifTrue: [
  661. self search: input asJQuery val]]
  662. ! !
  663. !Browser methodsFor: 'testing'!
  664. canBeClosed
  665. ^true
  666. ! !
  667. !Browser methodsFor: 'updating'!
  668. updateCategoriesList
  669. categoriesList contents: [:html |
  670. self categories do: [:each || li label |
  671. each isEmpty
  672. ifTrue: [label := 'Unclassified']
  673. ifFalse: [label := each].
  674. li := html li.
  675. selectedCategory = each ifTrue: [
  676. li class: 'selected'].
  677. li
  678. with: label;
  679. onClick: [self selectCategory: each]]]
  680. !
  681. updateClassesList
  682. TabManager current update.
  683. classesList updateNodes.
  684. "classesList contents: [:html |
  685. self classes do: [:each || li |
  686. li := html li.
  687. selectedClass = each ifTrue: [
  688. li class: 'selected'].
  689. li
  690. with: each name;
  691. onClick: [self selectClass: each]]]"
  692. !
  693. updateProtocolsList
  694. protocolsList contents: [:html |
  695. self protocols do: [:each || li |
  696. li := html li.
  697. selectedProtocol = each ifTrue: [
  698. li class: 'selected'].
  699. li
  700. with: each;
  701. onClick: [self selectProtocol: each]]]
  702. !
  703. updateMethodsList
  704. methodsList contents: [:html |
  705. self methods do: [:each || li |
  706. li := html li.
  707. selectedMethod = each ifTrue: [
  708. li class: 'selected'].
  709. li
  710. with: each selector;
  711. onClick: [self selectMethod: each]]]
  712. !
  713. updateTabsList
  714. tabsList contents: [:html || li |
  715. li := html li.
  716. selectedTab = #instance ifTrue: [li class: 'selected'].
  717. li
  718. with: 'Instance';
  719. onClick: [self selectTab: #instance].
  720. li := html li.
  721. selectedTab = #class ifTrue: [li class: 'selected'].
  722. li
  723. with: 'Class';
  724. onClick: [self selectTab: #class].
  725. li := html li.
  726. selectedTab = #comment ifTrue: [li class: 'selected'].
  727. li
  728. with: 'Comment';
  729. onClick: [self selectTab: #comment]]
  730. !
  731. updateSourceAndButtons
  732. self disableSaveButton.
  733. classButtons contents: [:html |
  734. html button
  735. with: 'Rename class';
  736. onClick: [self renameClass].
  737. html button
  738. with: 'Remove class';
  739. onClick: [self removeClass].
  740. html button
  741. with: 'References';
  742. onClick: [self searchClassReferences]].
  743. methodButtons contents: [:html |
  744. html button
  745. with: 'Remove method';
  746. onClick: [self removeMethod].
  747. html select
  748. onChange: [:e :select | self setMethodProtocol: select val];
  749. with: [
  750. html option
  751. with: 'Method protocol';
  752. at: 'disabled' put: 'disabled'.
  753. html option
  754. class: 'important';
  755. with: 'New...'.
  756. self protocols do: [:each |
  757. html option with: each]].
  758. selectedMethod isNil ifFalse: [
  759. html select
  760. onChange: [:e :select | self searchReferencesOf: select val];
  761. with: [
  762. html option
  763. with: 'References';
  764. at: 'disabled' put: 'disabled'.
  765. html option
  766. class: 'important';
  767. with: selectedMethod selector.
  768. selectedMethod messageSends sorted do: [:each |
  769. html option with: each]]]].
  770. selectedMethod isNil
  771. ifTrue: [
  772. self hideMethodButtons.
  773. (selectedClass isNil or: [selectedProtocol notNil])
  774. ifTrue: [self hideClassButtons]
  775. ifFalse: [self showClassButtons]]
  776. ifFalse: [
  777. self hideClassButtons.
  778. self showMethodButtons].
  779. sourceArea val: self source
  780. !
  781. updateStatus
  782. sourceArea textarea asJQuery val = self source
  783. ifTrue: [
  784. saveButton ifNotNil: [
  785. saveButton at: 'disabled' put: true].
  786. unsavedChanges := false]
  787. ifFalse: [
  788. saveButton ifNotNil: [
  789. saveButton removeAt: 'disabled'].
  790. unsavedChanges := true]
  791. !
  792. resetClassesList
  793. classesList resetNodes
  794. ! !
  795. !Browser class methodsFor: 'accessing'!
  796. commitPathJs
  797. ^'js'
  798. !
  799. commitPathSt
  800. ^'st'
  801. ! !
  802. !Browser class methodsFor: 'convenience'!
  803. openOn: aClass
  804. ^self new
  805. open;
  806. selectCategory: aClass category;
  807. selectClass: aClass
  808. !
  809. open
  810. self new open
  811. ! !
  812. TabWidget subclass: #Inspector
  813. instanceVariableNames: 'label variables object selectedVariable variablesList valueTextarea workspaceTextarea diveButton'
  814. category: 'IDE'!
  815. !Inspector methodsFor: 'accessing'!
  816. label
  817. ^label ifNil: ['Inspector (nil)']
  818. !
  819. variables
  820. ^variables
  821. !
  822. setVariables: aCollection
  823. variables := aCollection
  824. !
  825. setLabel: aString
  826. label := aString
  827. !
  828. selectedVariable
  829. ^selectedVariable
  830. !
  831. selectedVariable: aString
  832. selectedVariable := aString
  833. ! !
  834. !Inspector methodsFor: 'actions'!
  835. inspect: anObject
  836. object := anObject.
  837. variables := #().
  838. object inspectOn: self
  839. !
  840. dive
  841. (self variables at: self selectedVariable) inspect
  842. !
  843. refresh
  844. self
  845. inspect: object;
  846. updateVariablesList;
  847. updateValueTextarea
  848. ! !
  849. !Inspector methodsFor: 'rendering'!
  850. renderBoxOn: html
  851. self
  852. renderTopPanelOn: html;
  853. renderBottomPanelOn: html
  854. !
  855. renderTopPanelOn: html
  856. html div
  857. class: 'top';
  858. with: [
  859. variablesList := html ul class: 'jt_column variables'.
  860. valueTextarea := html textarea class: 'jt_column value'; at: 'readonly' put: 'readonly'.
  861. self
  862. updateVariablesList;
  863. updateValueTextarea.
  864. html div class: 'jt_clear']
  865. !
  866. renderBottomPanelOn: html
  867. html div
  868. class: 'jt_sourceCode';
  869. with: [
  870. workspaceTextarea := html textarea
  871. class: 'source';
  872. at: 'spellcheck' put: 'false'.
  873. workspaceTextarea asJQuery call: 'tabby']
  874. !
  875. renderButtonsOn: html
  876. html button
  877. with: 'Refresh';
  878. onClick: [self refresh].
  879. diveButton := html button
  880. with: 'Dive';
  881. onClick: [self dive].
  882. self updateButtons
  883. ! !
  884. !Inspector methodsFor: 'testing'!
  885. canBeClosed
  886. ^true
  887. ! !
  888. !Inspector methodsFor: 'updating'!
  889. updateVariablesList
  890. variablesList contents: [:html |
  891. self variables keys do: [:each || li |
  892. li := html li.
  893. li
  894. with: each;
  895. onClick: [self selectVariable: each].
  896. self selectedVariable = each ifTrue: [
  897. li class: 'selected']]]
  898. !
  899. selectVariable: aString
  900. self selectedVariable: aString.
  901. self
  902. updateVariablesList;
  903. updateValueTextarea;
  904. updateButtons
  905. !
  906. updateValueTextarea
  907. valueTextarea asJQuery val: (self selectedVariable isNil
  908. ifTrue: ['']
  909. ifFalse: [(self variables at: self selectedVariable) printString])
  910. !
  911. updateButtons
  912. (self selectedVariable notNil and: [(self variables at: self selectedVariable) notNil])
  913. ifFalse: [diveButton at: 'disabled' put: true]
  914. ifTrue: [diveButton removeAt: 'disabled']
  915. ! !
  916. !Inspector class methodsFor: 'instance creation'!
  917. on: anObject
  918. ^self new
  919. inspect: anObject;
  920. yourself
  921. ! !
  922. TabWidget subclass: #ReferencesBrowser
  923. instanceVariableNames: 'implementors senders implementorsList input timer selector sendersList referencedClasses referencedClassesList'
  924. category: 'IDE'!
  925. !ReferencesBrowser methodsFor: 'accessing'!
  926. implementors
  927. ^implementors ifNil: [implementors := Array new]
  928. !
  929. label
  930. ^'[ReferencesBrowser]'
  931. !
  932. selector
  933. ^selector
  934. !
  935. senders
  936. ^senders ifNil: [senders := Array new]
  937. !
  938. classesAndMetaclasses
  939. ^Smalltalk current classes, (Smalltalk current classes collect: [:each | each class])
  940. !
  941. referencedClasses
  942. ^referencedClasses ifNil: [referencedClasses := Array new]
  943. ! !
  944. !ReferencesBrowser methodsFor: 'actions'!
  945. openBrowserOn: aMethod
  946. | browser |
  947. browser := Browser openOn: (aMethod class isMetaclass
  948. ifTrue: [aMethod methodClass instanceClass] ifFalse: [aMethod methodClass]).
  949. aMethod methodClass isMetaclass ifTrue: [browser selectTab: #class].
  950. browser
  951. selectProtocol: aMethod category;
  952. selectMethod: aMethod
  953. !
  954. searchReferencesFor: aString
  955. selector := aString.
  956. implementors := Array new.
  957. senders := Array new.
  958. referencedClasses := Array new.
  959. (selector match: '^[A-Z]')
  960. ifFalse: [self searchSelectorReferencesFor: selector]
  961. ifTrue: [self searchReferencedClassesFor: selector]
  962. !
  963. search: aString
  964. self
  965. searchReferencesFor: aString;
  966. updateImplementorsList;
  967. updateSendersList;
  968. updateReferencedClassesList
  969. !
  970. searchReferencedClassesFor: aString
  971. self classesAndMetaclasses do: [:each |
  972. each methodDictionary values do: [:value |
  973. (((value referencedClasses select: [:each | each notNil])collect: [:each | each name]) includes: selector) ifTrue: [
  974. self referencedClasses add: value]]]
  975. !
  976. searchSelectorReferencesFor: aString
  977. self classesAndMetaclasses do: [:each |
  978. each methodDictionary keysAndValuesDo: [:key :value |
  979. key = selector ifTrue: [self implementors add: value]].
  980. each methodDictionary keysAndValuesDo: [:key :value |
  981. (value messageSends includes: selector) ifTrue: [
  982. self senders add: value]]]
  983. ! !
  984. !ReferencesBrowser methodsFor: 'initialization'!
  985. initialize
  986. super initialize.
  987. selector := ''
  988. ! !
  989. !ReferencesBrowser methodsFor: 'private'!
  990. setInputEvents
  991. input
  992. onKeyUp: [timer := [self search: input asJQuery val] valueWithTimeout: 100];
  993. onKeyDown: [timer ifNotNil: [timer clearTimeout]]
  994. ! !
  995. !ReferencesBrowser methodsFor: 'rendering'!
  996. renderBoxOn: html
  997. self
  998. renderInputOn: html;
  999. renderImplementorsOn: html;
  1000. renderSendersOn: html;
  1001. renderReferencedClassesOn: html
  1002. !
  1003. renderInputOn: html
  1004. input := html input
  1005. class: 'implementors';
  1006. yourself.
  1007. input asJQuery val: selector.
  1008. self setInputEvents
  1009. !
  1010. renderImplementorsOn: html
  1011. implementorsList := html ul class: 'jt_column implementors'.
  1012. self updateImplementorsList
  1013. !
  1014. renderSendersOn: html
  1015. sendersList := html ul class: 'jt_column senders'.
  1016. self updateSendersList
  1017. !
  1018. renderReferencedClassesOn: html
  1019. referencedClassesList := html ul class: 'jt_column referenced_classes'.
  1020. self updateReferencedClassesList
  1021. ! !
  1022. !ReferencesBrowser methodsFor: 'testing'!
  1023. canBeClosed
  1024. ^true
  1025. ! !
  1026. !ReferencesBrowser methodsFor: 'updating'!
  1027. updateImplementorsList
  1028. implementorsList contents: [:html |
  1029. html li
  1030. class: 'column_label';
  1031. with: 'Implementors (', self implementors size asString, ')';
  1032. style: 'font-weight: bold'.
  1033. self implementors do: [:each || li |
  1034. li := html li.
  1035. li
  1036. with: (each methodClass asString, ' >> ', self selector);
  1037. onClick: [self openBrowserOn: each]]]
  1038. !
  1039. updateSendersList
  1040. sendersList contents: [:html |
  1041. html li
  1042. class: 'column_label';
  1043. with: 'Senders (', self senders size asString, ')';
  1044. style: 'font-weight: bold'.
  1045. self senders do: [:each |
  1046. html li
  1047. with: (each methodClass asString, ' >> ', each selector);
  1048. onClick: [self openBrowserOn: each]]]
  1049. !
  1050. updateReferencedClassesList
  1051. referencedClassesList contents: [:html |
  1052. html li
  1053. class: 'column_label';
  1054. with: 'Class references (', self referencedClasses size asString, ')';
  1055. style: 'font-weight: bold'.
  1056. self referencedClasses do: [:each |
  1057. html li
  1058. with: (each methodClass asString, ' >> ', each selector);
  1059. onClick: [self openBrowserOn: each]]]
  1060. ! !
  1061. !ReferencesBrowser class methodsFor: 'instance creation'!
  1062. search: aString
  1063. ^self new
  1064. searchReferencesFor: aString;
  1065. open
  1066. ! !
  1067. Widget subclass: #SourceArea
  1068. instanceVariableNames: 'textarea'
  1069. category: 'IDE'!
  1070. !SourceArea methodsFor: 'accessing'!
  1071. val
  1072. ^textarea asJQuery val
  1073. !
  1074. val: aString
  1075. textarea asJQuery val: aString
  1076. !
  1077. currentLine
  1078. | lines startLine endLine|
  1079. lines := textarea asJQuery val tokenize: String lf.
  1080. startLine := endLine := 0.
  1081. lines do: [:each |
  1082. endLine := startLine + each size.
  1083. startLine := endLine + 1.
  1084. endLine >= self selectionStart ifTrue: [
  1085. self selectionEnd: endLine.
  1086. ^each]]
  1087. !
  1088. selection
  1089. <return document.selection>
  1090. !
  1091. selectionEnd
  1092. ^textarea element selectionEnd
  1093. !
  1094. selectionStart
  1095. ^textarea element selectionStart
  1096. !
  1097. selectionStart: anInteger
  1098. textarea element selectionStart: anInteger
  1099. !
  1100. selectionEnd: anInteger
  1101. textarea element selectionEnd: anInteger
  1102. !
  1103. textarea
  1104. ^textarea
  1105. ! !
  1106. !SourceArea methodsFor: 'actions'!
  1107. clear
  1108. textarea asJQuery val: ''
  1109. !
  1110. doIt
  1111. | selection |
  1112. textarea asJQuery focus.
  1113. self selectionStart = self selectionEnd
  1114. ifTrue: [selection := self currentLine]
  1115. ifFalse: [
  1116. selection := textarea asJQuery val copyFrom: self selectionStart + 1 to: self selectionEnd + 1].
  1117. ^self eval: selection
  1118. !
  1119. eval: aString
  1120. | compiler node |
  1121. compiler := Compiler new.
  1122. node := compiler parseExpression: aString.
  1123. node isParseFailure ifTrue: [
  1124. ^self alert: node reason, ', position: ', node position].
  1125. ^compiler loadExpression: aString
  1126. !
  1127. handleKeyDown: anEvent
  1128. <if(anEvent.ctrlKey) {
  1129. if(anEvent.keyCode === 80) { //ctrl+p
  1130. self._printIt();
  1131. anEvent.preventDefault();
  1132. return false;
  1133. }
  1134. if(anEvent.keyCode === 68) { //ctrl+d
  1135. self._doIt();
  1136. anEvent.preventDefault();
  1137. return false;
  1138. }
  1139. if(anEvent.keyCode === 73) { //ctrl+i
  1140. self._inspectIt();
  1141. anEvent.preventDefault();
  1142. return false;
  1143. }
  1144. }>
  1145. !
  1146. inspectIt
  1147. self doIt inspect
  1148. !
  1149. print: aString
  1150. | start |
  1151. start := self selectionEnd.
  1152. textarea asJQuery val: (
  1153. (textarea asJQuery val copyFrom: 1 to: start),
  1154. ' ', aString, ' ',
  1155. (textarea asJQuery val copyFrom: start + 1 to: textarea asJQuery val size)).
  1156. self selectionStart: start.
  1157. self selectionEnd: start + aString size + 2
  1158. !
  1159. printIt
  1160. self print: self doIt printString
  1161. ! !
  1162. !SourceArea methodsFor: 'rendering'!
  1163. renderOn: html
  1164. textarea := html textarea.
  1165. textarea asJQuery call: 'tabby'.
  1166. textarea onKeyDown: [:e | self handleKeyDown: e].
  1167. textarea
  1168. class: 'jt_workspace';
  1169. at: 'spellcheck' put: 'false'
  1170. ! !
  1171. Widget subclass: #ClassesList
  1172. instanceVariableNames: 'browser ul nodes'
  1173. category: 'IDE'!
  1174. !ClassesList methodsFor: 'accessing'!
  1175. category
  1176. ^self browser selectedCategory
  1177. !
  1178. nodes
  1179. nodes ifNil: [nodes := self getNodes].
  1180. ^nodes
  1181. !
  1182. browser
  1183. ^browser
  1184. !
  1185. browser: aBrowser
  1186. browser := aBrowser
  1187. !
  1188. getNodes
  1189. ^(self browser classes select: [:each |
  1190. (self browser classes includes: each superclass) not])
  1191. collect: [:each |
  1192. ClassesListNode on: each browser: self browser level: 0]
  1193. !
  1194. resetNodes
  1195. nodes := nil
  1196. ! !
  1197. !ClassesList methodsFor: 'rendering'!
  1198. renderOn: html
  1199. ul := html ul
  1200. class: 'jt_column browser classes';
  1201. yourself.
  1202. self updateNodes
  1203. !
  1204. updateNodes
  1205. ul contents: [:html |
  1206. self nodes do: [:each |
  1207. each renderOn: html]]
  1208. ! !
  1209. !ClassesList class methodsFor: 'instance creation'!
  1210. on: aBrowser
  1211. ^self new
  1212. browser: aBrowser;
  1213. yourself
  1214. ! !
  1215. Widget subclass: #ClassesListNode
  1216. instanceVariableNames: 'browser theClass level nodes'
  1217. category: 'IDE'!
  1218. !ClassesListNode methodsFor: 'accessing'!
  1219. nodes
  1220. ^nodes ifNil: [nodes := self getNodes]
  1221. !
  1222. theClass
  1223. ^theClass
  1224. !
  1225. theClass: aClass
  1226. theClass := aClass
  1227. !
  1228. browser
  1229. ^browser
  1230. !
  1231. browser: aBrowser
  1232. browser := aBrowser
  1233. !
  1234. level
  1235. ^level
  1236. !
  1237. level: anInteger
  1238. level := anInteger
  1239. !
  1240. label
  1241. | str |
  1242. str := String new writeStream.
  1243. self level timesRepeat: [
  1244. str nextPutAll: '&nbsp;&nbsp;&nbsp;&nbsp;'].
  1245. str nextPutAll: self theClass name.
  1246. ^str contents
  1247. !
  1248. getNodes
  1249. ^(self browser classes select: [:each |
  1250. each superclass = self theClass])
  1251. collect: [:each |
  1252. ClassesListNode on: each browser: self browser level: self level + 1]
  1253. ! !
  1254. !ClassesListNode methodsFor: 'rendering'!
  1255. renderOn: html
  1256. | li |
  1257. li := html li
  1258. onClick: [self browser selectClass: self theClass].
  1259. li asJQuery contents: self label.
  1260. self browser selectedClass = self theClass ifTrue: [
  1261. li class: 'selected'].
  1262. self nodes do: [:each |
  1263. each renderOn: html]
  1264. ! !
  1265. !ClassesListNode class methodsFor: 'instance creation'!
  1266. on: aClass browser: aBrowser level: anInteger
  1267. ^self new
  1268. theClass: aClass;
  1269. browser: aBrowser;
  1270. level: anInteger;
  1271. yourself
  1272. ! !
  1273. !Object methodsFor: '*IDE'!
  1274. inspect
  1275. Inspector new
  1276. inspect: self;
  1277. open
  1278. !
  1279. inspectOn: anInspector
  1280. | variables |
  1281. variables := Dictionary new.
  1282. variables at: '#self' put: self.
  1283. self class allInstanceVariableNames do: [:each |
  1284. variables at: each put: (self instVarAt: each)].
  1285. anInspector
  1286. setLabel: self printString;
  1287. setVariables: variables
  1288. ! !
  1289. !Date methodsFor: '*IDE'!
  1290. inspectOn: anInspector
  1291. | variables |
  1292. variables := Dictionary new.
  1293. variables at: '#self' put: self.
  1294. variables at: '#year' put: self year.
  1295. variables at: '#month' put: self month.
  1296. variables at: '#day' put: self day.
  1297. variables at: '#hours' put: self hours.
  1298. variables at: '#minutes' put: self minutes.
  1299. variables at: '#seconds' put: self seconds.
  1300. variables at: '#milliseconds' put: self milliseconds.
  1301. anInspector
  1302. setLabel: self printString;
  1303. setVariables: variables
  1304. ! !
  1305. !Collection methodsFor: '*IDE'!
  1306. inspectOn: anInspector
  1307. | variables |
  1308. variables := Dictionary new.
  1309. variables at: '#self' put: self.
  1310. self withIndexDo: [:each :i |
  1311. variables at: i put: each].
  1312. anInspector
  1313. setLabel: self printString;
  1314. setVariables: variables
  1315. ! !
  1316. !String methodsFor: '*IDE'!
  1317. inspectOn: anInspector
  1318. | label |
  1319. super inspectOn: anInspector.
  1320. self printString size > 30
  1321. ifTrue: [label := (self printString copyFrom: 1 to: 30), '...''']
  1322. ifFalse: [label := self printString].
  1323. anInspector setLabel: label
  1324. ! !
  1325. !MethodContext methodsFor: '*IDE'!
  1326. inspectOn: anInspector
  1327. | variables |
  1328. variables := Dictionary new.
  1329. variables at: '#self' put: self.
  1330. variables at: '#home' put: self home.
  1331. variables at: '#receiver' put: self receiver.
  1332. variables at: '#selector' put: self selector.
  1333. self class instanceVariableNames do: [:each |
  1334. variables at: each put: (self instVarAt: each)].
  1335. anInspector
  1336. setLabel: self printString;
  1337. setVariables: variables
  1338. ! !
  1339. !Dictionary methodsFor: '*IDE'!
  1340. inspectOn: anInspector
  1341. | variables |
  1342. variables := Dictionary new.
  1343. variables at: '#self' put: self.
  1344. variables at: '#keys' put: self keys.
  1345. self keysAndValuesDo: [:key :value |
  1346. variables at: key put: value].
  1347. anInspector
  1348. setLabel: self printString;
  1349. setVariables: variables
  1350. ! !