module Edit; export Clipboard, Selection, SelectionContext; from StudentVersion import Notepad; from LectureDB import PreviousState, UserWorkSpace, Source; from View import PrivateNotes, Public Layer, Layer; from Tools import PostitLog; from QandA import QuestionLogDB; 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 Eclass operation. Only one level of undo/redo is specified here. Successive invocations of undo toggle between the current and previous states of Eclass. Note that the Eclass editing operations support undo by saving a snapshot of the inputEclass in the previous_state component of the workspace.*); precondition: (* *The previous saved Eclass state is not nil. *) (uws.prev_state != nil); postcondition: (* *The state of the current Eclass is the previous state, and vice versa. *) (uws�.prev_state = uws.lect.items) and (uws.lect.items = uws.prev_state); end EditUndo; operation EditRedo is inputs: uws:UserWorkSpace; outputs: uws�:UserWorkSpace; description: (*Redo the most recent Eclass operation. Only one level of undo/redo is specified here. Successive invocations of redo toggle between the current and previous states of the lecture. Note that the lecture editing operations support redo by saving a snapshot of the inputlecture in the next_state component of the workspace.*); precondition: (* *The next saved Eclass state is not nil. *) (uws.prev_state != nil); postcondition: (* *The state of the current Eclass is the next state, and vice versa. *) (uws�.prev_state = uws.lect.items) and (uws.lect.items = uws.prev_state); end EditRedo; 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; end Edit;