
Define_model: "MacWrite Example"
Starting_goal is Edit Document.


Task_item: T1 
	Name is First.
	Type is copy.
	Text_size is Word.
	Text_selection is "foobar".
	Text_insertion_point is "*".
	Next is T2.

Task_item: T2
	Name is T2.
	Type is copy.
	Text_size is Arbitrary.
	Text_selection_start is "Now".
	Text_selection_end is "country".
	Next is T3.
	
Task_item: T3
	Name is T3.
	Type is delete.
	Text_size is Word.
	Text_selection is "foobar".
	Text_insertion_point is "*".
	Next is T4.

Task_item: T4
	Name is T4.
	Type is move.
	Text_size is Arbitrary.
	Text_selection_start is "Now".
	Text_selection_end is "country".
	Next is None.

// Dummy visual objects - targets for Look_for and Point_to
Visual_object: Dummy_text_word
	Content is "foobar".

Visual_object: Dummy_text_selection_start
	Content is "Now".

Visual_object: Dummy_text_selection_end
	Content is "country".

Visual_object: Dummy_text_insertion_point
	Content is "*".

// Minimal description of the visual objects in the editor interface
Visual_object: Edit_menu
	Label is Edit.

Visual_object: Cut_menu_item
	Label is Cut.

Visual_object: Copy_menu_item
	Label is Copy.

Visual_object: Paste_menu_item
	Label is Paste.

// Long-Term Memory contents about which items are in which menu
LTM_item: Cut_Command
	Name is Cut.
	Containing_Menu is Edit.
	Menu_Item_Label is Cut.
	Accelerator_Key is COMMAND-X.

LTM_item: Copy_Command
	Name is Copy.
	Containing_Menu is Edit.
	Menu_Item_Label is Copy.
	Accelerator_Key is COMMAND-C.

LTM_item: Paste_Command
	Name is Paste.
	Containing_Menu is Edit.
	Menu_Item_Label is Paste.
	Accelerator_Key is COMMAND-V.
	
	
// Top-Level Unit Task Method

Method_for_goal: Edit Document
	Step.Store First under <current_task_name>.
	Step Check_for_done. 
			Decide: If <current_task_name> is None, Then 
						Delete <current_task>; 
						Delete <current_task_name>;
						Return_with_goal_accomplished.
	Step. Get_task_item_whose Name is <current_task_name> 
			and_store_under <current_task>.
	Step. Accomplish_goal: Perform Unit_task.
	Step. Store Next of <current_task> under <current_task_name>;
			Goto Check_for_done.

Selection_rules_for_goal: Perform Unit_task
	If Type of <current_task> is move, 
				Then Accomplish_goal: Move Text.
	If Type of <current_task> is delete, 
				Then Accomplish_goal: Erase Text.
	If Type of <current_task> is copy, 
				Then Accomplish_goal: Copy Text.
//	... etc. ...
	Return_with_goal_accomplished.


Method_for_goal: Move Text
	Step 1. Accomplish_goal: Cut Selection.
	Step 2. Accomplish_goal: Paste Selection.
	Step 3. Verify "correct text moved".
	Step 4. Return_with_goal_accomplished.

Method_for_goal: Copy Text
	Step 1. Accomplish_goal: Copy Selection.
	Step 2. Accomplish_goal: Paste Selection.
	Step 3. Verify "correct text copied".
	Step 4. Return_with_goal_accomplished.

Method_for_goal: Erase Text
	Step 1. Accomplish_goal: Select Text.
	Step 2. Keystroke DELETE.
	Step 3. Verify "correct text deleted".
	Step 4. Return_with_goal_accomplished.

Method_for_goal: Cut Selection
	Step 1. Accomplish_goal: Select Text.
	Step 2. Accomplish_goal: Issue Command using Cut.
	Step 3. Return_with_goal_accomplished.

Method_for_goal: Copy Selection
	Step 1. Accomplish_goal: Select Text.
	Step 2. Accomplish_goal: Issue Command using Copy.
	Step 3. Return_with_goal_accomplished.

Method_for_goal: Paste Selection
	Step 1. Accomplish_goal: Select Insertion_point.
	Step 2. Accomplish_goal: Issue Command using Paste.
	Step 3. Return_with_goal_accomplished.

Selection_rules_for_goal: Select Text
	If Text_size of <current_task> is Word, Then Accomplish_goal: Select Word.
	If Text_size of <current_task> is Arbitrary, Then Accomplish_goal: Select Arbitrary_text.
	Return_with_goal_accomplished.

Method_for_goal: Select Word
	Step 1. Look_for_object_whose Content is Text_selection of <current_task> and_store_under <target>.
	Step 2. Point_to <target>; Delete <target>.
	Step 3. Double_click mouse_button.
	Step 4. Verify "correct text is selected".
	Step 5. Return_with_goal_accomplished.

Method_for_goal: Select Arbitrary_text
	Step 1. Look_for_object_whose
			Content is Text_selection_start of <current_task>
			and_store_under <target>.
	Step 2. Point_to <target>.
	Step 3. Hold_down mouse_button.
	Step 4. Look_for_object_whose Content is
			Text_selection_end of <current_task>
			and_store_under <target>.
	Step 5. Point_to <target>; Delete <target>.
	Step 6. Release mouse_button.
	Step 7. Verify "correct text is selected".
	Step 8. Return_with_goal_accomplished.

Method_for_goal: Select Insertion_point
	Step 1. Look_for_object_whose
			Content is Text_insertion_point of <current_task>
			and_store_under <target>.
	Step 2. Point_to <target>; Delete <target>.
	Step 3. Click mouse_button.
	Step 4. Verify "insertion cursor is at correct place".
	Step 5. Return_with_goal_accomplished.

Method_for_goal: Issue Command using <command_name>
	// Assumes that user does not use command-key shortcuts
	Step 1. Recall_LTM_item_whose
			Name is <command_name>
			and_store_under <command>.
	Step 2. Look_for_object_whose 
			Label is Containing_Menu  of <command>
			and_store_under <target>.
	Step 3. Point_to <target>.
	Step 4. Hold_down mouse_button.
	Step 5. Verify "correct menu appears".
	Step 6. Look_for_object_whose 
			Label is Menu_Item_Label of <command>
			and_store_under <target>.
	Step 7. Point_to <target>.
	Step 8. Verify "correct menu command is highlighted".
	Step 9. Release mouse_button.
	Step 10.Delete <command>; Delete <target>;
			Return_with_goal_accomplished.
