5.7. Data Editing (edit.rsl)

(****
 *
 * Module Edit defines the objects and operations related to generic editing
 * in the calendar system.
 *
 *)
module Edit;

  from CalendarDB import UserWorkSpace, UserCalendar, PreviousState;
  export Clipboard, Selection, SelectionContext;

  object Clipboard is
    components: string;
    description: (*
        The clipboard holds a selection of cut or copied text.
    *);
  end Clipboard;

  object Selection is
    components: start_position:integer and end_position:integer and
        context:string;
    description: (*
        The workspace text selection is the defined as the starting and ending
        character positions in current workspace text context.
    *);
  end Selection;

  object SelectionContext is
    components: string;
    description: (*
        SelectionContext is the text context in which the user makes a
        selection.
    *);
  end SelectionContext;

  operation EditUndo is
    inputs: uws:UserWorkSpace;
    outputs: uws':UserWorkSpace;

    description: (*
        Undo the most recent scheduling operation.  Only one level of undo/redo
        is specified here.  Successive invocations of undo toggle between the
        current and previous states of the calendar.  Note that the calendar
        editing operations support undo by saving a snapshot of the input
        calendar in the previous_state component of the workspace.
    *);

    precondition:
        (*
         * The previous saved calendar state is not nil.
         *)
        (uws.previous_state != nil);

    postcondition:
        (*
         * The state of the current calendar is the previous state, and vice
         * versa.
         *)
        (uws'.previous_state = uws.calendars[1].items) and
        (uws.calendars[1].items = uws.previous_state);

  end EditUndo;

  operation EditCut is
    inputs: uws:UserWorkSpace;
    outputs: uws':UserWorkSpace;

    description: (*
        The currently selected text segment is copied into the clipboard and
        removed from its context.  The workspace selection in set to empty.
    *);

    precondition:
        (*
         * The selection is not empty.
         *)
        uws.selection != nil;

    postcondition:
        (*
         * The clipboard of the output workspace equals the selection.  The
         * selection context of the output workspace has the selection removed.
         * The selection of the output workspace is nil.
         *)
        (uws'.clipboard = uws.context[
            uws.selection.start_position:uws.selection.end_position])

             and

        (uws'.context = uws.context[1:uws.selection.start_position-1] +
                        uws.context[uws.selection.start_position+1:
                                    #(uws.context)])

             and

        (uws'.selection = nil);

  end EditCut;

  operation EditCopy is
    inputs: uws:UserWorkSpace;
    outputs: uws':UserWorkSpace;

    description: (*
        The currently selected text segment is copied into the clipboard;
    *);

    precondition:
        (*
         * The selection is not empty.
         *)
        uws.selection != nil;

    postcondition:
        (*
         * The clipboard of the output workspace equals the selection.  The
         * context and selection of the output workspace are unchanged.
         *)
        (uws'.clipboard = uws.context[
            uws.selection.start_position:uws.selection.end_position])

             and

        (uws'.context = uws.context)

             and

        (uws'.selection = uws.selection);

  end EditCopy;

  operation EditPaste is
    inputs: uws:UserWorkSpace;
    outputs: uws':UserWorkSpace;

    description: (*
        Paste the contents of the clipboard into the currently selected
        start position, replacing any selected text from start to end position.
    *);

    precondition:
        (*
         * The clipboard is not empty.
         *)
        uws.clipboard != nil;

    postcondition:
        (*
         * The context in the output workspace is the string consiting of
         * everything up to the selection, followed by the clipboard, followed
         * by everything after the selection.  The selection of the output
         * workspace is nil and the clipboard is unchanged.
         *)
        (uws'.context = uws.context[1:uws.selection.start_position-1] +
                        uws.clipboard +
                        uws.context[uws.selection.start_position+1:
                                    #(uws.context)])

             and

        (uws'.selection = nil)

             and

        (uws'.clipboard = uws.clipboard);

  end EditPast;

  operation EditDelete is
    inputs: uws:UserWorkSpace;
    outputs: uws':UserWorkSpace;

    description: (*
        The currently selected text is removed from the context.  The workspace
        selection in set to empty.
    *);

    precondition:
        (*
         * The selection is not empty.
         *)
        uws.selection != nil;

    postcondition:
        (*
         * The selection context of the output workspace has the selection
         * removed.  The selection of the output workspace is nil.
         *)
        (uws'.context = uws.context[1:uws.selection.start_position-1] +
                        uws.context[uws.selection.start_position+1:
                                    #(uws.context)])

             and

        (uws'.selection = nil);

  end EditDelete;

end Edit;





Prev: file.rsl | Next: [none] | Up: spec | Top: index