TrySmalltalk.st 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965
  1. Smalltalk current createPackage: 'TrySmalltalk' properties: #{}!
  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. 'instanciation'
  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 :) ). You''ve just executed a Smalltalk expression. More precisely, you sent the message ''next'' to
  223. ProfStef class (it''s me !!).
  224. Note you can run this tutorial again by evaluating: ''ProfStef go''.
  225. ''ProfStef previous'' returns to the previous lesson.
  226. You can also Do It using the keyboard shortcut ''CTRL d''
  227. Try to evaluate this expression:"
  228. window alert: ''hello world!!''.
  229. "Then go to the next lesson:"
  230. ProfStef next.'
  231. !
  232. instanciation
  233. ^ Lesson
  234. title: 'Instanciation'
  235. contents:
  236. '"Objects are instances of their class. Usually, we send the message #new to a class for creating an instance of this class.
  237. For example, let''s create an instance of the class Array:"
  238. Array new
  239. add: ''Some text'';
  240. add: 3.;
  241. yourself.
  242. "See the array we''ve created? Actually, #(''Some text'' 3) is just a shorthand for instantiating arrays."
  243. "If we use a variable to keep track of this object, we''ll be able to do stuff with it."
  244. "The following code must be ran all at one, as the ''anArray'' variable will cease to exist once the execution finishes:"
  245. |anArray|
  246. anArray := Array new
  247. add: ''Some text'';
  248. add: 3;
  249. yourself.
  250. Transcript show: anArray; cr.
  251. anArray remove: 3.
  252. Transcript show: anArray; cr.
  253. anArray add: ''Some more text!!''.
  254. Transcript show: anArray; cr.
  255. "I''ll put myself in an instance of a class named Dictionary and go to the next lesson:"
  256. ((Dictionary new add: (''move on!!'' -> ProfStef)) at: ''move on!!'') next'
  257. !
  258. iterators
  259. ^ Lesson
  260. title: 'Iterators'
  261. contents:
  262. '"The message do: is sent to a collection of objects (Array, Dictionary, String, etc), evaluating the block for each element.
  263. Here we want to print all the numbers on the Transcript (a console)"
  264. #(11 38 3 -2 10) do: [:each |
  265. Transcript show: each printString; cr].
  266. "Some other really nice iterators"
  267. #(11 38 3 -2 10) collect: [:each | each negated].
  268. #(11 38 3 -2 10) collect: [:each | each odd].
  269. #(11 38 3 -2 10) select: [:each | each odd].
  270. #(11 38 3 -2 10) select: [:each | each > 10].
  271. #(11 38 3 -2 10) reject: [:each | each > 10].
  272. #(11 38 3 -2 10)
  273. do: [:each | Transcript show: each printString]
  274. separatedBy: [Transcript show: ''.''].
  275. (Smalltalk current classes select: [:eachClass | eachClass name = ''ProfStef'']) do: [:eachProfstef | eachProfstef next].'
  276. !
  277. loops
  278. ^ Lesson
  279. title: 'Loops'
  280. contents:
  281. '"Loops are high-level collection iterators, implemented as regular methods."
  282. "Basic loops:
  283. to:do:
  284. to:by:do"
  285. 1 to: 100 do:
  286. [:i | Transcript show: i asString; cr ].
  287. 1 to: 100 by: 3 do: [:i | Transcript show: i asString; cr].
  288. 100 to: 0 by: -2 do:
  289. [:i | Transcript show: i asString; cr].
  290. 1 to: 1 do: [:i | ProfStef next].'
  291. !
  292. mathematicalPrecedence
  293. ^ Lesson
  294. title: 'Mathematical precedence'
  295. contents:
  296. '"Traditional precedence rules from mathematics do not follow in Smalltalk."
  297. 2 * 10 + 2.
  298. "Here the message * is sent to 2, which answers 20, then 20 receive the message +
  299. Remember that all messages always follow a simple left-to-right precedence rule, * without exceptions *."
  300. 2 + 2 * 10.
  301. 2 + (2 * 10).
  302. 8 - 5 / 2.
  303. (8 - 5) / 2.
  304. 8 - (5 / 2).
  305. ProfStef next.'
  306. !
  307. messageSyntaxBinary
  308. ^ Lesson
  309. title: 'Message syntax: Binary messages'
  310. contents:
  311. '"Binary messages have the following form:
  312. anObject + anotherObject"
  313. 3 * 2.
  314. Date today year = 2011.
  315. false | false.
  316. true & true.
  317. true & false.
  318. 10 @ 100.
  319. 10 <= 12.
  320. ''ab'', ''cd''.
  321. ProfStef next.'
  322. !
  323. messageSyntaxCascade
  324. ^ Lesson
  325. title: 'Message syntax: Cascade'
  326. contents:
  327. '"; is the cascade operator. It''s useful to send message to the SAME receiver
  328. Open a Transcript (console):"
  329. Transcript open.
  330. "Then:"
  331. Transcript show: ''hello''.
  332. Transcript show: ''Smalltalk''.
  333. Transcript cr.
  334. "is equivalent to:"
  335. Transcript
  336. show: ''hello'';
  337. show: ''Smalltalk'' ;
  338. cr.
  339. "You can close the development tools by clicking on the red circle with a cross at the bottom left of the website.
  340. Try to go to the next lesson with a cascade of two ''next'' messages:"
  341. ProfStef'.
  342. !
  343. messageSyntaxCascadeShouldNotBeHere
  344. ^ Lesson
  345. title: 'Lost ?'
  346. contents:
  347. '"Hey, you should not be here !!!!
  348. Go back and use a cascade !!"
  349. ProfStef previous.'.
  350. !
  351. messageSyntaxExecutionOrder
  352. ^ Lesson
  353. title: 'Message syntax: Execution order'
  354. contents:
  355. '"Unary messages are executed first, then binary messages and finally keyword messages:
  356. Unary > Binary > Keywords"
  357. 2.5 + 3.8 rounded.
  358. 3 max: 2 + 2.
  359. (0@0) class.
  360. 0@0 x: 100.
  361. (0@0 x: 100) class.
  362. "Between messages of similar precedence, expressions are executed from left to right"
  363. -12345 negated asString reversed.
  364. ProfStef next.'
  365. !
  366. messageSyntaxExecutionOrderParentheses
  367. ^ Lesson
  368. title: 'Message syntax: Parentheses'
  369. contents:
  370. '"Use parentheses to change order of evaluation"
  371. (2.5 + 3.8) rounded.
  372. (3 max: 2) + 2.
  373. ProfStef next.'
  374. !
  375. messageSyntaxKeyword
  376. ^ Lesson
  377. title: 'Message syntax: Keyword messages'
  378. contents:
  379. '"Keyword Messages are messages with arguments. They have the following form:
  380. anObject akey: anotherObject akey2: anotherObject2"
  381. ''Web development is a good deal of pain'' copyFrom: 1 to: 30
  382. "The message is copyFrom:to: sent to the String ''Web development is a good deal of pain''"
  383. 1 max: 3.
  384. Array with: ''hello'' with: 2 with: Smalltalk.
  385. "The message is with:with:with: implemented on class Array. Note you can also write"
  386. Array
  387. with: ''Hi there!!''
  388. with: 2
  389. with: Smalltalk.
  390. ProfStef perform: ''next''.'
  391. !
  392. messageSyntaxUnary
  393. ^ Lesson
  394. title: 'Message syntax: Unary messages'
  395. contents:
  396. '"Messages are sent to objects. There are three types of message: Unary, Binary and Keyword.
  397. Unary messages have the following form:
  398. anObject aMessage
  399. You''ve already sent unary messages. For example:"
  400. 1 class.
  401. false not.
  402. Date today.
  403. Number pi.
  404. "And of course: "
  405. ProfStef next.'
  406. !
  407. pharoEnvironment
  408. ^ Lesson
  409. title: 'Pharo environment'
  410. contents:
  411. '"Every Smalltalk system is full of objects. There are windows, text, numbers, dates, colors, points and much more. You can interact with objects in a much more direct way than is possible with other programming languages.
  412. Every object understands the message ''explore''. As a result, you get an Explorer window that shows details about the object."
  413. Date today explore.
  414. "This shows that the date object consists of a point in time (start) and a duration (one day long)."
  415. ProfStef explore.
  416. "You see, ProfStef class has a lot of objects. Let''s take a look at my code:"
  417. ProfStef browse.
  418. ProfStef next.'
  419. !
  420. printing
  421. ^ Lesson
  422. title: 'Doing VS Printing: Printing'
  423. contents:
  424. '"Now you''re a Do It master !! Let''s talk about printing. It''s a Do It which prints the result next to the expression you''ve selected.
  425. For example, select the text below, and click on ''PrintIt'':"
  426. 1 + 2.
  427. "As with ''DoIt'', there is also a shortcut to execute this command.
  428. Try CTRL-p on the following expressions:"
  429. Date today.
  430. "The result is selected, so you can erase it using the backspace key. Try it !!"
  431. Date today asDateString.
  432. Date today asTimeString.
  433. ProfStef next.'
  434. !
  435. reflection
  436. ^ Lesson
  437. title: 'Reflection'
  438. contents:
  439. '"You can inspect and change the system at runtime.
  440. Take a look at the source code of the method #and: of the class Boolean:"
  441. (Boolean methodDictionary at: ''and:'') source.
  442. "Or all the methods it sends:"
  443. (Boolean methodDictionary at: ''and:'') messageSends.
  444. "Here''s all the methods I implement:"
  445. ProfStef methodDictionary.
  446. "Let''s create a new method to go to the next lesson:"
  447. |newMethod|
  448. newMethod := Compiler new load: ''goToNextLesson ProfStef next.'' forClass: ProfStef.
  449. ProfStef class addCompiledMethod: newMethod
  450. "Wow!! I can''t wait to use my new method!!"
  451. ProfStef goToNextLesson.'
  452. !
  453. reflectionContinued
  454. ^ Lesson
  455. title: 'Reflection continued'
  456. contents:
  457. '"So cool, isn''t it ? Before going further, let''s remove this method:"
  458. ProfStef class methodAt: #goToNextLesson.
  459. ProfStef class removeCompiledMethod: (ProfStef class methodAt: #goToNextLesson).
  460. ProfStef class methodAt: #goToNextLesson.
  461. "Then move forward:"
  462. ProfStef perform:#next'
  463. !
  464. theEnd
  465. ^ Lesson
  466. title: 'Tutorial done !!'
  467. contents:
  468. '"This tutorial is done. Enjoy programming Smalltalk with JTalk.
  469. You can run this tutorial again by evaluating: ProfStef go.
  470. See you soon !!"
  471. '
  472. !
  473. welcome
  474. ^ Lesson
  475. title: 'Welcome'
  476. contents:
  477. ' "Hello!! I''m Professor Stef.
  478. You must want me to help you learn Smalltalk.
  479. So let''s go to the first lesson. Select the text below and click on the ''DoIt'' button"
  480. ProfStef next.'
  481. ! !
  482. Object subclass: #Lesson
  483. instanceVariableNames: 'title contents'
  484. package: 'TrySmalltalk'!
  485. !Lesson methodsFor: 'accessing'!
  486. contents
  487. ^ contents ifNil: [contents := '']
  488. !
  489. contents: aString
  490. contents := aString
  491. !
  492. title
  493. ^ title ifNil: [title := '']
  494. !
  495. title: aString
  496. title := aString
  497. ! !
  498. !Lesson class methodsFor: 'instance creation'!
  499. title: aTitle contents: someContents
  500. ^ (self new)
  501. title: aTitle;
  502. contents: someContents
  503. ! !
  504. Object subclass: #ProfStef
  505. instanceVariableNames: 'tutorialPlayer widget'
  506. package: 'TrySmalltalk'!
  507. !ProfStef commentStamp!
  508. A ProfStef is the Smalltalk teacher. To start the tutorial, evaluate:
  509. ProfStef go.
  510. To go to the next lesson evaluate:
  511. ProfStef next.
  512. To execute your own tutorial:
  513. ProfStef goOn: MyOwnTutorial
  514. To see a table of contents with all defined tutorials:
  515. ProfStef contents!
  516. !ProfStef methodsFor: 'accessing'!
  517. progress
  518. ^ '(', self tutorialPositionString, '/', self tutorialSizeString, ')'.
  519. !
  520. showCurrentLesson
  521. | lesson |
  522. lesson := self tutorialPlayer currentLesson.
  523. widget contents: lesson contents.
  524. widget setTitle: lesson title , ' ' , self progress.
  525. !
  526. tutorialPlayer
  527. ^ tutorialPlayer ifNil: [tutorialPlayer := TutorialPlayer new]
  528. !
  529. tutorialPositionString
  530. ^ self tutorialPlayer tutorialPosition asString.
  531. !
  532. tutorialSizeString
  533. ^ self tutorialPlayer size asString
  534. !
  535. widget: aWidget
  536. widget := aWidget
  537. ! !
  538. !ProfStef methodsFor: 'navigation'!
  539. first
  540. self tutorialPlayer first.
  541. ^ self showCurrentLesson.
  542. !
  543. next
  544. self tutorialPlayer next.
  545. ^ self showCurrentLesson.
  546. !
  547. previous
  548. self tutorialPlayer previous.
  549. ^ self showCurrentLesson.
  550. ! !
  551. ProfStef class instanceVariableNames: 'instance'!
  552. !ProfStef class methodsFor: 'initialize'!
  553. default
  554. ^ instance ifNil: [instance := self new]
  555. ! !
  556. !ProfStef class methodsFor: 'navigation'!
  557. first
  558. ^ self default first.
  559. !
  560. go
  561. self first.
  562. !
  563. next
  564. ^ self default next.
  565. !
  566. previous
  567. ^ self default previous.
  568. ! !
  569. Widget subclass: #TrySmalltalkWidget
  570. instanceVariableNames: 'workspace contents header'
  571. package: 'TrySmalltalk'!
  572. !TrySmalltalkWidget methodsFor: 'accessing'!
  573. contents
  574. ^self workspace val
  575. !
  576. contents: aString
  577. self workspace val: aString
  578. !
  579. setTitle: aString
  580. header contents: [:html | html with: aString]
  581. !
  582. workspace
  583. ^ workspace ifNil: [
  584. workspace := SourceArea new]
  585. ! !
  586. !TrySmalltalkWidget methodsFor: 'rendering'!
  587. renderButtonsOn: html
  588. html button
  589. with: 'DoIt';
  590. title: 'ctrl+d';
  591. onClick: [self workspace doIt].
  592. html button
  593. with: 'PrintIt';
  594. title: 'ctrl+p';
  595. onClick: [self workspace printIt].
  596. html button
  597. with: 'InspectIt';
  598. title: 'ctrl+i';
  599. onClick: [self workspace inspectIt]
  600. !
  601. renderOn: html
  602. html div
  603. class: 'profStef';
  604. with: [header := html h2];
  605. with: [self workspace renderOn: html];
  606. with: [self renderButtonsOn: html].
  607. ProfStef default
  608. widget: self;
  609. showCurrentLesson
  610. ! !
  611. !TrySmalltalkWidget class methodsFor: 'initialize'!
  612. open
  613. self new appendToJQuery: 'body' asJQuery.
  614. ! !
  615. Object subclass: #TutorialPlayer
  616. instanceVariableNames: 'tutorialPosition tutorial'
  617. package: 'TrySmalltalk'!
  618. !TutorialPlayer commentStamp!
  619. I can navigate through an AbstractTutorial subclass. With #next and #previous you can go forward and backward through the tutorial.!
  620. !TutorialPlayer methodsFor: 'accessing'!
  621. currentLesson
  622. ^ self tutorial lessonAt: self tutorialPosition.
  623. !
  624. size
  625. ^ self tutorial size
  626. !
  627. tutorial
  628. ^ tutorial ifNil: [tutorial := SmalltalkSyntaxTutorial new]
  629. !
  630. tutorial: aTutorial
  631. tutorial := aTutorial
  632. !
  633. tutorialPosition
  634. ^ tutorialPosition ifNil: [
  635. self rewind.
  636. tutorialPosition.
  637. ].
  638. !
  639. tutorialPosition: aTutorialPosition
  640. tutorialPosition := aTutorialPosition
  641. ! !
  642. !TutorialPlayer methodsFor: 'navigation'!
  643. first
  644. self rewind.
  645. ^ self currentLesson
  646. !
  647. last
  648. tutorialPosition := self size.
  649. ^ self currentLesson
  650. !
  651. next
  652. self tutorialPosition < self size
  653. ifTrue: [tutorialPosition := tutorialPosition + 1].
  654. ^ self currentLesson
  655. !
  656. previous
  657. tutorialPosition > 1 ifTrue: [tutorialPosition := tutorialPosition - 1].
  658. ^ self currentLesson
  659. !
  660. rewind
  661. tutorialPosition := 1.
  662. ! !