TrySmalltalk.st 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972
  1. Smalltalk createPackage: 'TrySmalltalk'!
  2. Object subclass: #AbstractTutorial
  3. instanceVariableNames: ''
  4. package: 'TrySmalltalk'!
  5. !AbstractTutorial commentStamp!
  6. Parent class of all ProfStef tutorials.
  7. To create your own tutorial:
  8. - subclass AbstractTutorial
  9. - implement a few methods which returns a Lesson instance
  10. - implement tutorial which returns a Collection of selectors to the methods you've created.!
  11. !AbstractTutorial methodsFor: 'accessing'!
  12. indexOfLesson: aSelector
  13. ^self tableOfContents indexOf: aSelector.
  14. !
  15. lessonAt: anInteger
  16. | lessonSelector |
  17. lessonSelector := self tableOfContents at: anInteger.
  18. ^ self perform: lessonSelector.
  19. !
  20. size
  21. ^ self tableOfContents size
  22. !
  23. tableOfContents
  24. ^ #(
  25. 'welcome'
  26. 'testLesson'
  27. 'theEnd'
  28. )
  29. ! !
  30. !AbstractTutorial methodsFor: 'pages'!
  31. testLesson
  32. ^ Lesson
  33. title: 'Test Lesson'
  34. contents: '"This lesson is a test"'
  35. !
  36. theEnd
  37. ^ Lesson
  38. title: 'The End'
  39. contents: '"And that''d be pretty much it :)"'
  40. !
  41. welcome
  42. ^ Lesson
  43. title: 'Welcome'
  44. contents: '"Hi, this is a test tutorial."'
  45. ! !
  46. AbstractTutorial subclass: #SmalltalkSyntaxTutorial
  47. instanceVariableNames: ''
  48. package: 'TrySmalltalk'!
  49. !SmalltalkSyntaxTutorial commentStamp!
  50. The default ProfStef tutorial to learn Smalltalk syntax!
  51. !SmalltalkSyntaxTutorial methodsFor: 'contents'!
  52. tableOfContents
  53. ^ #( 'welcome'
  54. 'doingVSPrinting'
  55. 'printing'
  56. 'basicTypesNumbers'
  57. "'basicTypesCharacters'"
  58. 'basicTypesString'
  59. "'basicTypesSymbol'"
  60. 'basicTypesArray'
  61. 'basicTypesDynamicArray'
  62. 'messageSyntaxUnary'
  63. 'messageSyntaxBinary'
  64. 'messageSyntaxKeyword'
  65. 'messageSyntaxExecutionOrder'
  66. 'messageSyntaxExecutionOrderParentheses'
  67. 'mathematicalPrecedence'
  68. 'messageSyntaxCascade'
  69. 'messageSyntaxCascadeShouldNotBeHere'
  70. 'blocks'
  71. 'blocksAssignation'
  72. 'conditionals'
  73. 'loops'
  74. 'iterators'
  75. 'instantiation'
  76. 'reflection'
  77. 'reflectionContinued'
  78. "'pharoEnvironment'"
  79. "'debugger'"
  80. 'theEnd' )
  81. ! !
  82. !SmalltalkSyntaxTutorial methodsFor: 'pages'!
  83. basicTypesArray
  84. ^ Lesson
  85. title: 'Basic types: Array'
  86. contents:
  87. '"Literal arrays are created at parse time:"
  88. #(1 2 3).
  89. #( 1 2 3 #(4 5 6)) size.
  90. #(1 2 4) isEmpty.
  91. #(1 2 3) first.
  92. #(''hello'' ''Javascript'') at: 2 put: ''Smalltalk''; yourself.
  93. ProfStef next.'
  94. !
  95. basicTypesCharacters
  96. ^ Lesson
  97. title: 'Basic types: Characters'
  98. contents:
  99. '"A Character can be instantiated using $ operator:"
  100. $A.
  101. $A class.
  102. $B charCode.
  103. Character cr.
  104. Character space.
  105. "You can print all 256 characters of the ASCII extended set:"
  106. Character allByteCharacters.
  107. ProfStef next.'
  108. !
  109. basicTypesDynamicArray
  110. ^ Lesson
  111. title: 'Basic types: Dynamic Array'
  112. contents:
  113. '"Dynamic Arrays are created at execution time:"
  114. { (2+3) . (6*6) }.
  115. { (2+3) . (6*6) . ''hello'', '' Stef''} size.
  116. { ProfStef } first next.'
  117. !
  118. basicTypesNumbers
  119. ^ Lesson
  120. title: 'Basic types: Numbers'
  121. contents:
  122. '"You now know how to execute Smalltalk code.
  123. Now let''s talk about basic objects.
  124. 1, 2, 100, 2/3 ... are Numbers, and respond to many messages evaluating mathematical expressions.
  125. Evaluate these ones:"
  126. 2.
  127. (1/3).
  128. (1/3) + (4/5).
  129. (18/5) rounded.
  130. 1 class.
  131. 1 negated.
  132. 1 negated negated.
  133. (1 + 3) odd.
  134. ProfStef next.'
  135. !
  136. basicTypesString
  137. ^ Lesson
  138. title: 'Basic types: Strings'
  139. contents:
  140. '"A String is a collection of characters. Use single quotes to create a String object. Print these expressions:"
  141. ''ProfStef''.
  142. ''ProfStef'' size.
  143. ''abc'' asUppercase.
  144. ''Hello World'' reversed.
  145. "You can access each character using at: message"
  146. ''ProfStef'' at: 1.
  147. "String concatenation uses the comma operator:"
  148. ''ProfStef'', '' is cool''.
  149. ProfStef next.'
  150. !
  151. basicTypesSymbol
  152. ^ Lesson
  153. title: 'Basic types: Symbols'
  154. contents:
  155. '"A Symbol is a String which is guaranteed to be globally unique.
  156. There is one and only one Symbol #ProfStef. There may be several ''ProfStef'' String objects.
  157. (Message == returns true if the two objects are the SAME)"
  158. ''ProfStef'' asSymbol.
  159. #ProfStef asString.
  160. (2 asString) == (2 asString).
  161. (2 asString) asSymbol == (2 asString) asSymbol.
  162. (Smalltalk at: #ProfStef) next.'
  163. !
  164. blocks
  165. ^ Lesson
  166. title: 'Blocks'
  167. contents:
  168. '"Cascade is cool !! Let''s talk about blocks.
  169. Blocks are anonymous methods that can be stored into variables and executed on demand.
  170. Blocks are delimited by square brackets: []"
  171. [Transcript open].
  172. "does not open a Transcript because the block is not executed.
  173. Here is a block that adds 2 to its argument (its argument is named x):"
  174. [:x | x+2].
  175. "We can execute a block by sending it value messages."
  176. [:x | x+2] value: 5.
  177. [Transcript open] value.
  178. [:x | x+2] value: 10.
  179. [:x :y| x + y] value:3 value:5.
  180. [ProfStef next] value.'
  181. !
  182. blocksAssignation
  183. ^ Lesson
  184. title: 'Block assignation'
  185. contents:
  186. '"Blocks can be assigned to a variable then executed later.
  187. Note that |b| is the declaration of a variable named ''b'' and that '':='' assigns a value to a variable.
  188. Select the three lines then Print It:"
  189. |b|
  190. b := [:x | x+2].
  191. b value: 12.
  192. ProfStef next.'
  193. !
  194. conditionals
  195. ^ Lesson
  196. title: 'Conditionals'
  197. contents:
  198. '"Conditionals are just messages sent to Boolean objects"
  199. 1 < 2
  200. ifTrue: [100]
  201. ifFalse: [42].
  202. "Here the message is ifTrue:ifFalse
  203. Try this:"
  204. Transcript open.
  205. 3 > 10
  206. ifTrue: [Transcript show: ''maybe there''''s a bug ....'']
  207. ifFalse: [Transcript show: ''No : 3 is less than 10''].
  208. 3 = 3 ifTrue: [ProfStef next].'.
  209. !
  210. debugger
  211. ^ Lesson
  212. title: 'Debugger'
  213. contents: '"The Debugger may be the most famous tool of Smalltalk environments. It will open as soon as an unmanaged Exception occurs.
  214. The following code will open the debugger.
  215. ***This should be rethought completely***"
  216. '
  217. !
  218. doingVSPrinting
  219. ^ Lesson
  220. title: 'Doing VS Printing: Doing'
  221. contents:
  222. '"Cool !! (I like to say Cooool :) ).
  223. You''ve just executed a Smalltalk expression.
  224. More precisely, you sent the message ''next'' to ProfStef class (it''s me !!).
  225. Note you can run this tutorial again by evaluating: ''ProfStef go''.
  226. ''ProfStef previous'' returns to the previous lesson.
  227. You can also Do It using the keyboard shortcut ''CTRL d''
  228. Try to evaluate this expression:"
  229. window alert: ''hello world!!''.
  230. "Then go to the next lesson:"
  231. ProfStef next.'
  232. !
  233. instantiation
  234. ^ Lesson
  235. title: 'Instantiation'
  236. contents:
  237. '"Objects are instances of their class. Usually, we send the message #new to a class for creating an instance of this class.
  238. For example, let''s create an instance of the class Array:"
  239. Array new
  240. add: ''Some text'';
  241. add: 3;
  242. yourself.
  243. "See the array we''ve created? Actually, #(''Some text'' 3) is just a shorthand for instantiating arrays."
  244. "If we use a variable to keep track of this object, we''ll be able to do stuff with it."
  245. "The following code must be ran all at one, as the ''anArray'' variable will cease to exist once the execution finishes:"
  246. |anArray|
  247. anArray := Array new
  248. add: ''Some text'';
  249. add: 3;
  250. yourself.
  251. Transcript show: anArray; cr.
  252. anArray remove: 3.
  253. Transcript show: anArray; cr.
  254. anArray add: ''Some more text!!''.
  255. Transcript show: anArray; cr.
  256. "I''ll put myself in an instance of a class named Dictionary and go to the next lesson:"
  257. ((Dictionary new add: (''move on!!'' -> ProfStef)) at: ''move on!!'') next'
  258. !
  259. iterators
  260. ^ Lesson
  261. title: 'Iterators'
  262. contents:
  263. '"The message do: is sent to a collection of objects (Array, Dictionary, String, etc), evaluating the block for each element.
  264. Here we want to print all the numbers on the Transcript (a console)"
  265. #(11 38 3 -2 10) do: [:each |
  266. Transcript show: each printString; cr].
  267. "Some other really nice iterators"
  268. #(11 38 3 -2 10) collect: [:each | each negated].
  269. #(11 38 3 -2 10) collect: [:each | each odd].
  270. #(11 38 3 -2 10) select: [:each | each odd].
  271. #(11 38 3 -2 10) select: [:each | each > 10].
  272. #(11 38 3 -2 10) reject: [:each | each > 10].
  273. #(11 38 3 -2 10)
  274. do: [:each | Transcript show: each printString]
  275. separatedBy: [Transcript show: ''.''].
  276. (Smalltalk classes select: [:eachClass | eachClass name = ''ProfStef'']) do: [:eachProfstef | eachProfstef next].'
  277. !
  278. loops
  279. ^ Lesson
  280. title: 'Loops'
  281. contents:
  282. '"Loops are high-level collection iterators, implemented as regular methods."
  283. "Basic loops:
  284. to:do:
  285. to:by:do"
  286. 1 to: 100 do:
  287. [:i | Transcript show: i asString; cr ].
  288. 1 to: 100 by: 3 do: [:i | Transcript show: i asString; cr].
  289. 100 to: 0 by: -2 do:
  290. [:i | Transcript show: i asString; cr].
  291. 1 to: 1 do: [:i | ProfStef next].'
  292. !
  293. mathematicalPrecedence
  294. ^ Lesson
  295. title: 'Mathematical precedence'
  296. contents:
  297. '"Traditional precedence rules from mathematics do not follow in Smalltalk."
  298. 2 * 10 + 2.
  299. "Here the message * is sent to 2, which answers 20, then 20 receive the message +
  300. Remember that all messages always follow a simple left-to-right precedence rule, * without exceptions *."
  301. 2 + 2 * 10.
  302. 2 + (2 * 10).
  303. 8 - 5 / 2.
  304. (8 - 5) / 2.
  305. 8 - (5 / 2).
  306. ProfStef next.'
  307. !
  308. messageSyntaxBinary
  309. ^ Lesson
  310. title: 'Message syntax: Binary messages'
  311. contents:
  312. '"Binary messages have the following form:
  313. anObject + anotherObject"
  314. 3 * 2.
  315. Date today year = 2011.
  316. false | false.
  317. true & true.
  318. true & false.
  319. 10 @ 100.
  320. 10 <= 12.
  321. ''ab'', ''cd''.
  322. ProfStef next.'
  323. !
  324. messageSyntaxCascade
  325. ^ Lesson
  326. title: 'Message syntax: Cascade'
  327. contents:
  328. '"; is the cascade operator. It''s useful to send message to the SAME receiver
  329. Open a Transcript (console):"
  330. Transcript open.
  331. "Then:"
  332. Transcript show: ''hello''.
  333. Transcript show: ''Smalltalk''.
  334. Transcript cr.
  335. "is equivalent to:"
  336. Transcript
  337. show: ''hello'';
  338. show: ''Smalltalk'' ;
  339. cr.
  340. "You can close the development tools by clicking on the red circle with a cross at the bottom left of the website.
  341. Try to go to the next lesson with a cascade of two ''next'' messages:"
  342. ProfStef'.
  343. !
  344. messageSyntaxCascadeShouldNotBeHere
  345. ^ Lesson
  346. title: 'Lost ?'
  347. contents:
  348. '"Hey, you should not be here !!!!
  349. Go back and use a cascade !!"
  350. ProfStef previous.'.
  351. !
  352. messageSyntaxExecutionOrder
  353. ^ Lesson
  354. title: 'Message syntax: Execution order'
  355. contents:
  356. '"Unary messages are executed first, then binary messages and finally keyword messages:
  357. Unary > Binary > Keywords"
  358. 2.5 + 3.8 rounded.
  359. 3 max: 2 + 2.
  360. (0@0) class.
  361. 0@0 x: 100.
  362. (0@0 x: 100) class.
  363. "Between messages of similar precedence, expressions are executed from left to right"
  364. -12345 negated asString reversed.
  365. ProfStef next.'
  366. !
  367. messageSyntaxExecutionOrderParentheses
  368. ^ Lesson
  369. title: 'Message syntax: Parentheses'
  370. contents:
  371. '"Use parentheses to change order of evaluation"
  372. (2.5 + 3.8) rounded.
  373. (3 max: 2) + 2.
  374. ProfStef next.'
  375. !
  376. messageSyntaxKeyword
  377. ^ Lesson
  378. title: 'Message syntax: Keyword messages'
  379. contents:
  380. '"Keyword Messages are messages with arguments. They have the following form:
  381. anObject akey: anotherObject akey2: anotherObject2"
  382. ''Web development is a good deal of pain'' copyFrom: 1 to: 30
  383. "The message is copyFrom:to: sent to the String ''Web development is a good deal of pain''"
  384. 1 max: 3.
  385. Array with: ''hello'' with: 2 with: Smalltalk.
  386. "The message is with:with:with: implemented on class Array. Note you can also write"
  387. Array
  388. with: ''Hi there!!''
  389. with: 2
  390. with: Smalltalk.
  391. ProfStef perform: ''next''.'
  392. !
  393. messageSyntaxUnary
  394. ^ Lesson
  395. title: 'Message syntax: Unary messages'
  396. contents:
  397. '"Messages are sent to objects. There are three types of message: Unary, Binary and Keyword.
  398. Unary messages have the following form:
  399. anObject aMessage
  400. You''ve already sent unary messages. For example:"
  401. 1 class.
  402. false not.
  403. Date today.
  404. Number pi.
  405. "And of course: "
  406. ProfStef next.'
  407. !
  408. pharoEnvironment
  409. ^ Lesson
  410. title: 'Pharo environment'
  411. contents:
  412. '"Every Smalltalk system is full of objects.
  413. There are windows, text, numbers, dates, colors, points and much more.
  414. You can interact with objects in a much more direct way than is possible with other programming languages.
  415. Every object understands the message ''explore''. As a result, you get an Explorer window that shows details about the object."
  416. Date today explore.
  417. "This shows that the date object consists of a point in time (start) and a duration (one day long)."
  418. ProfStef explore.
  419. "You see, ProfStef class has a lot of objects. Let''s take a look at my code:"
  420. ProfStef browse.
  421. ProfStef next.'
  422. !
  423. printing
  424. ^ Lesson
  425. title: 'Doing VS Printing: Printing'
  426. contents:
  427. '"Now you''re a Do It master !! Let''s talk about printing.
  428. It''s a Do It which prints the result next to the expression you''ve selected.
  429. For example, select the text below, and click on ''PrintIt'':"
  430. 1 + 2.
  431. "As with ''DoIt'', there is also a shortcut to execute this command.
  432. Try CTRL-p on the following expressions:"
  433. Date today.
  434. "The result is selected, so you can erase it using the backspace key. Try it !!"
  435. Date today asDateString.
  436. Date today asTimeString.
  437. ProfStef next.'
  438. !
  439. reflection
  440. ^ Lesson
  441. title: 'Reflection'
  442. contents:
  443. '"You can inspect and change the system at runtime.
  444. Take a look at the source code of the method #and: of the class Boolean:"
  445. (Boolean methodDictionary at: ''and:'') source.
  446. "Or all the methods it sends:"
  447. (Boolean methodDictionary at: ''and:'') messageSends.
  448. "Here''s all the methods I implement:"
  449. ProfStef methodDictionary.
  450. "Let''s create a new method to go to the next lesson:"
  451. |newMethod|
  452. newMethod := Compiler new
  453. install: ''goToNextLesson ProfStef next.''
  454. forClass: ProfStef
  455. protocol: ''navigation''.
  456. ProfStef class addCompiledMethod: newMethod
  457. "Wow!! I can''t wait to use my new method!!"
  458. ProfStef goToNextLesson.'
  459. !
  460. reflectionContinued
  461. ^ Lesson
  462. title: 'Reflection continued'
  463. contents:
  464. '"So cool, isn''t it ? Before going further, let''s remove this method:"
  465. ProfStef class methodAt: #goToNextLesson.
  466. ProfStef class removeCompiledMethod: (ProfStef class methodAt: #goToNextLesson).
  467. ProfStef class methodAt: #goToNextLesson.
  468. "Then move forward:"
  469. ProfStef perform: #next'
  470. !
  471. theEnd
  472. ^ Lesson
  473. title: 'Tutorial done !!'
  474. contents:
  475. '"This tutorial is done. Enjoy programming Smalltalk with Amber.
  476. You can run this tutorial again by evaluating: ProfStef go.
  477. See you soon !!"
  478. '
  479. !
  480. welcome
  481. ^ Lesson
  482. title: 'Welcome'
  483. contents:
  484. ' "Hello!! I''m Professor Stef.
  485. You must want me to help you learn Smalltalk.
  486. So let''s go to the first lesson. Select the text below and click on the ''DoIt'' button"
  487. ProfStef next.'
  488. ! !
  489. Object subclass: #Lesson
  490. instanceVariableNames: 'title contents'
  491. package: 'TrySmalltalk'!
  492. !Lesson methodsFor: 'accessing'!
  493. contents
  494. ^ contents ifNil: [contents := '']
  495. !
  496. contents: aString
  497. contents := aString
  498. !
  499. title
  500. ^ title ifNil: [title := '']
  501. !
  502. title: aString
  503. title := aString
  504. ! !
  505. !Lesson class methodsFor: 'instance creation'!
  506. title: aTitle contents: someContents
  507. ^ (self new)
  508. title: aTitle;
  509. contents: someContents
  510. ! !
  511. Object subclass: #ProfStef
  512. instanceVariableNames: 'tutorialPlayer widget'
  513. package: 'TrySmalltalk'!
  514. !ProfStef commentStamp!
  515. A ProfStef is the Smalltalk teacher. To start the tutorial, evaluate:
  516. ProfStef go.
  517. To go to the next lesson evaluate:
  518. ProfStef next.
  519. To execute your own tutorial:
  520. ProfStef goOn: MyOwnTutorial
  521. To see a table of contents with all defined tutorials:
  522. ProfStef contents!
  523. !ProfStef methodsFor: 'accessing'!
  524. progress
  525. ^ '(', self tutorialPositionString, '/', self tutorialSizeString, ')'.
  526. !
  527. showCurrentLesson
  528. | lesson |
  529. lesson := self tutorialPlayer currentLesson.
  530. widget contents: lesson contents.
  531. widget setTitle: lesson title , ' ' , self progress.
  532. !
  533. tutorialPlayer
  534. ^ tutorialPlayer ifNil: [tutorialPlayer := TutorialPlayer new]
  535. !
  536. tutorialPositionString
  537. ^ self tutorialPlayer tutorialPosition asString.
  538. !
  539. tutorialSizeString
  540. ^ self tutorialPlayer size asString
  541. !
  542. widget: aWidget
  543. widget := aWidget
  544. ! !
  545. !ProfStef methodsFor: 'navigation'!
  546. first
  547. self tutorialPlayer first.
  548. ^ self showCurrentLesson.
  549. !
  550. next
  551. self tutorialPlayer next.
  552. ^ self showCurrentLesson.
  553. !
  554. previous
  555. self tutorialPlayer previous.
  556. ^ self showCurrentLesson.
  557. ! !
  558. ProfStef class instanceVariableNames: 'instance'!
  559. !ProfStef class methodsFor: 'initialize'!
  560. default
  561. ^ instance ifNil: [instance := self new]
  562. ! !
  563. !ProfStef class methodsFor: 'navigation'!
  564. first
  565. ^ self default first.
  566. !
  567. go
  568. self first.
  569. !
  570. next
  571. ^ self default next.
  572. !
  573. previous
  574. ^ self default previous.
  575. ! !
  576. Widget subclass: #TrySmalltalkWidget
  577. instanceVariableNames: 'workspace contents header'
  578. package: 'TrySmalltalk'!
  579. !TrySmalltalkWidget methodsFor: 'accessing'!
  580. contents
  581. ^self workspace val
  582. !
  583. contents: aString
  584. self workspace val: aString
  585. !
  586. setTitle: aString
  587. header contents: [:html | html with: aString]
  588. !
  589. workspace
  590. ^ workspace ifNil: [
  591. workspace := SourceArea new]
  592. ! !
  593. !TrySmalltalkWidget methodsFor: 'rendering'!
  594. renderButtonsOn: html
  595. html button
  596. with: 'DoIt';
  597. title: 'ctrl+d';
  598. onClick: [self workspace doIt].
  599. html button
  600. with: 'PrintIt';
  601. title: 'ctrl+p';
  602. onClick: [self workspace printIt].
  603. html button
  604. with: 'InspectIt';
  605. title: 'ctrl+i';
  606. onClick: [self workspace inspectIt]
  607. !
  608. renderOn: html
  609. html div
  610. class: 'profStef';
  611. with: [header := html h2];
  612. with: [self workspace renderOn: html];
  613. with: [self renderButtonsOn: html].
  614. ProfStef default
  615. widget: self;
  616. showCurrentLesson
  617. ! !
  618. !TrySmalltalkWidget class methodsFor: 'initialize'!
  619. open
  620. self new appendToJQuery: 'body' asJQuery.
  621. ! !
  622. Object subclass: #TutorialPlayer
  623. instanceVariableNames: 'tutorialPosition tutorial'
  624. package: 'TrySmalltalk'!
  625. !TutorialPlayer commentStamp!
  626. I can navigate through an AbstractTutorial subclass. With #next and #previous you can go forward and backward through the tutorial.!
  627. !TutorialPlayer methodsFor: 'accessing'!
  628. currentLesson
  629. ^ self tutorial lessonAt: self tutorialPosition.
  630. !
  631. size
  632. ^ self tutorial size
  633. !
  634. tutorial
  635. ^ tutorial ifNil: [tutorial := SmalltalkSyntaxTutorial new]
  636. !
  637. tutorial: aTutorial
  638. tutorial := aTutorial
  639. !
  640. tutorialPosition
  641. ^ tutorialPosition ifNil: [
  642. self rewind.
  643. tutorialPosition.
  644. ].
  645. !
  646. tutorialPosition: aTutorialPosition
  647. tutorialPosition := aTutorialPosition
  648. ! !
  649. !TutorialPlayer methodsFor: 'navigation'!
  650. first
  651. self rewind.
  652. ^ self currentLesson
  653. !
  654. last
  655. tutorialPosition := self size.
  656. ^ self currentLesson
  657. !
  658. next
  659. self tutorialPosition < self size
  660. ifTrue: [tutorialPosition := tutorialPosition + 1].
  661. ^ self currentLesson
  662. !
  663. previous
  664. tutorialPosition > 1 ifTrue: [tutorialPosition := tutorialPosition - 1].
  665. ^ self currentLesson
  666. !
  667. rewind
  668. tutorialPosition := 1.
  669. ! !