(****
 *
 * Module Edit defines the operations related to undoing and redoing changes made to a test along
 * with cutting, copying, and pasting text to the test displayed in the StudentInterface.
 *
 *)

module Edit;

 operation UndoChange is
	inputs: txt':Text;
	outputs: txt:Text;
	description: (*
		UndoChange reverts the most recent change made to the currently displayed Test
		in the StudentInterface. The UndoChange operation can only undo changes made to
		the text answer of a question made by a student. The UndoChage operation can be
		used consecutively up to thirty times.
	*);
	
 precondition:
	(*
	 * Some text must exist in the test and the text must have been changed at least once
	 * before the UndoChange operation can be used.
	 *)
	(exists (txt' in Test) (txt = txt'));

 postcondition:
	(*
	 * The most recent change to the text on the test is reverted back to its original
	 * form before the most recent change was made.
	 *)
	(txt' = txt);
 end UndoChange;

 operation RedoChange is
	inputs: txt: Text;
	outputs: txt':Text;
	description: (*
		Redochange restores the most recent change made to the currently displayed Test
		in the StudentInterface. The RedoChange operation can only redo changes made to 
		the text answer of a question made by a student. The RedoChange operation can be
		used consecutively up to thirty times.
	*);

 precondition:
	(*
	 * Some text must exist in the test and the text must have been changed at least once
	 * before the RedoChange operation can be used.
	 *)
	(exists (txt' in Test) (txt' = txt));

 postcondition: 
	(*
	 * The most recent change to the text on the test is restored to what is was changed to
	 * before it was changed back to its original form.
	 *)
	(txt = txt');
 end RedoChange;

 operation CutText is
	inputs: htxt:HighlightedText;
	outputs: ctxt:Text;
	description: (*
		CutText will remove a piece of highlighted text from the test currently displayed
		in StudentInterface. The text will not be deleted, but will be temporarily saved
		on the computer being used by the student until he decides to put it back onto
		the test. 
	*);
 precondition:
	(*
	 * Some text must exist in the test and the student must manually highlight the text to
	 * be cut from the test.
	 *)
	(exists (Text in Test) (htxt));
 
 postcondition:
	(*
	 * The highighted text is cut out from the test and saved as a temporary file on the 
	 * computer being used by the student.
	 *)
	(ctxt = htxt);
 end CutText;

 operation CopyText is
	inputs: htxt:HighlightedText;
	outputs: cptxt:Text;
	description: (*
		CopyText will copy a piece of highlighted text from the test currently displayed
		in the StudentInterface. The copied text is saved as a temporary file on the
		computer being used by the student until the student decides to put the copied
		text back onto the test.
	*);
 
 precondition:
	(*
	 * Some text must exist in the test and the student must manually highlight the text to
	 * be copied from the test.
	 *)
	(exists (Text in Test) (htxt));

 postcondition:
	(*
	 * The highlighted text is copied from the test and saved as a temporary file on the
	 * computer being used by the student.
	 *)
	(cptxt = htxt);

 end CopyText;

 operation PasteText is
	inputs: ctxt:Text, cptxt:Text;
	outputs: Text;
	description: (*
		PasteText will put a piece of text that was cut out or copied from the test back
		onto the currently displayed test. The PasteText operation will look for any 
		temporarily saved files of text made from cutting or copyig text from the test file
		and put the text saved to the temporary file back onto the test where the cursor is
		currently positioned.
	*);
	
 precondition:
	(*
	 * Some temporaray file made from cutting or copying paste must exist.
	 *)
	(exists (t in Test) (ctxt = t or cptxt = t));

 postcondition:
	(*
	 * The text retrieved from the temporary file made by cutting or copying text from the test
	 * is put back on the test in the location where the cursor is currently positioned.
	 *)
	((ctxt in Test)

		or

	(cptxt in Test));
 end PasteText;

end Edit;