home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 August / macformat-027.iso / mac / Shareware City / Developers / Oberon⁄F / Samples / Mod / Ex7 (.txt) < prev    next >
Encoding:
Oberon Document  |  1994-06-07  |  4.3 KB  |  73 lines  |  [oODC/obnF]

  1. Documents.StdDocumentDesc
  2. Documents.DocumentDesc
  3. Containers.ViewDesc
  4. Views.ViewDesc
  5. Stores.StoreDesc
  6. Documents.ModelDesc
  7. Containers.ModelDesc
  8. Models.ModelDesc
  9. Stores.ElemDesc
  10. TextViews.StdViewDesc
  11. TextViews.ViewDesc
  12. TextModels.StdModelDesc
  13. TextModels.ModelDesc
  14. TextModels.AttributesDesc
  15. Geneva
  16. Geneva
  17. Helvetica
  18. Geneva
  19. Geneva
  20. Geneva
  21. MODULE SamplesEx7;
  22.     IMPORT Domains, Models, TextModels, TextControllers;
  23.     PROCEDURE Do*;
  24.         VAR c: TextControllers.Controller; beg, end: LONGINT;
  25.             r: TextModels.Reader; ch: CHAR;
  26.             buf: TextModels.Model; w: TextModels.Writer; script: Domains.Operation;
  27.     BEGIN
  28.         c := TextControllers.Focus();
  29.         IF (c # NIL) & c.HasSelection() THEN
  30.             c.GetSelection(beg, end);
  31.             (* upper case text will be copied into this buffer *)
  32.             buf := TextModels.dir.New(); w := buf.NewWriter(NIL);
  33.             r := c.text.NewReader(NIL); r.SetPos(beg);
  34.             r.ReadChar(ch);
  35.             WHILE (r.Pos() <= end) & ~r.eot DO
  36.                 IF (ch >= "a") & (ch <= "z") THEN ch := CAP(ch) END;
  37.                 w.WriteChar(ch);
  38.                 r.ReadChar(ch)
  39.             END;
  40.             Models.BeginScript(c.text, "Uppercase", script);
  41.             c.text.Delete(beg, end); c.text.CopyFrom(beg, buf, 0, end - beg);
  42.             Models.EndScript(c.text, script)
  43.         END
  44.     END Do;
  45. END SamplesEx7.
  46. TextControllers.StdCtrlDesc
  47. TextControllers.ControllerDesc
  48. Containers.ControllerDesc
  49. Controllers.ControllerDesc
  50. TextRulers.StdRulerDesc
  51. TextRulers.RulerDesc
  52. TextRulers.StdStyleDesc
  53. TextRulers.StyleDesc
  54. TextRulers.AttributesDesc
  55. Geneva
  56. DevCommanders.StdViewDesc
  57. DevCommanders.ViewDesc
  58. Geneva
  59. Geneva
  60. Example 7
  61. This example shows how the built-in text subsystem of Oberon/F can be extended by new commands. To demonstrate this possibility, a command is shown which fetches the selection in the focus view (assuming the focus view is a text view), creates a new empty text, copies the selection into this new text (but with all small letters turned into capital letters), and then replaces the selection by the newly created text. In short, this command turns the selected text stretch into all capital letters.
  62. As an example, select the test string several lines below, and then click on the following commander:
  63.  SamplesEx7.Do
  64. teSTstring834 .-st
  65. You'll note that the selection has turned into all caps.
  66. But now comes the surprise: execute Undo
  67. Uppercase in the Edit menu. As a result, the effect of the uppercase operation is undone! In Oberon/F, most operations are undoable; this also holds for the Delete and CopyFrom procedures in the above example. Thus, you need to do nothing special in order to render such a command undoable!
  68. However, you may have noticed that there is something special in the sample program: there is a BeginScript / EndScript pair of procedure calls before resp. after the calls to Delete / CopyFrom. They bundle the sequence of a Delete followed by a CopyFrom into one single compound
  69. command, meaning that the user need not undo both of these operations individually, but rather in one single step.
  70. In this example we have seen how an existing displayed text and its selection are accessed, how a buffer text is created, and how the selected text stretch is replaced by the buffer's contents.
  71. Geneva
  72. Documents.ControllerDesc
  73.