IDE.st 48 KB

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