5.2. Edit Menu (edit.rsl)
(* Chris Noe *)
(* describe the actions and objects of the edit menu of testtool *)
module Edit;
from Test import Test;
export UserWorkSpace, Clipboard, Selection, SelectionContext;
object UserWorkSpace is
components: test:Test and previous_state:PreviousState and
clipboard:Clipboard and selection:Selection and context:SelectionContext;
description: (*
The UserWorkSpace contains the active test upon which the user is
working. The Test component contains the active test. The previous_state
component is used to support one level of command undo.
The Clipboard is used with the Edit cut, copy, and paste operations.
*);
end;
object PreviousState is
components: test:Test;
description: (*
PreviousState is the snapshot of the test before the most
recently performed test operation. Any operations that modify the
test must save the previous state to support Undo.
*);
end PreviousState;
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 test state is not nil. *)
(uws.previous_state.test != nil);
postcondition:
(* * Swap the current and previous states of the test *)
(uws'.previous_state.test = uws.test) and
(uws.test = uws.previous_state.test);
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 EditPaste;
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: view.rsl
| Up: formal specification
| Top: index