indexing
	cluster: "demangler"
	namespace: "candidate"
	description: "Edits a `SYNC_REPORT' objects."
	original_author: "Justin Finnerty"
	original_date: "July 2005"
	current_date: "$Date: 2005/10/31 07:19:34 $"
	current_author: "$Author: finnerty $"
	revision: "$Revision: 2.5 $"	
	-- $Log: text_report_view.ge,v $
	-- Revision 2.5  2005/10/31 07:19:34  finnerty
	-- Added ability to create symlinks between directories as an alternative to merging. The major changes are in DIRDUP_REPORT with others adding/changing features as required.
	--
	-- Revision 2.4  2005/10/28 04:20:24  finnerty
	-- Removed `do_report' method now implemented in REPORT_VIEW. Added definitions for the deferred features in REPORT_VIEW used by the event loop.
	--
	-- Revision 2.3  2005/09/30 06:49:12  finnerty
	-- Finalised for alpha release with SE and VE compilers
	--
	-- Revision 2.2  2005/09/27 06:14:47  finnerty
	-- Updated to use GOBO and work with SE and VE
	--
	-- Revision 2.1  2005/09/06 22:58:52  finnerty
	-- Renamed *.e to *.ge for gepp
	--
	-- Revision 2.0  2005/08/26 23:31:39  finnerty
	-- == alpha version ==
	--
	-- Revision 1.2  2005/08/24 12:40:42  finnerty
	-- Upgraded text interface to support all required user interactions. Fixed some
	-- logical errors in do_report that occured when a report was skipped but not
	-- reset.
	--
	-- Revision 1.1  2005/08/21 11:56:26  finnerty
	-- Alpha 1 version
	--
	--

			-- Notes: [? ?] <=> [user_wants_action user_is_done]
			-- letters (A), (B) etc indicate choices for user. Choices 
			-- with * indicate "automatic" choices.
class TEXT_REPORT_VIEW
	-- Edits a `SYNC_REPORT' object.
inherit
	REPORT_VIEW
#ifdef SE	
insert
#endif
	TEXT_FORMATTER

creation {ANY}
	-- Construction
	make

feature {ANY}
	-- Action features
feature {ANY}
	report_warning (a_error: STRING) is
			-- Report an error
		require else
			has_report
		do
			put_string ("Error/Warning from report [")
			put_unicode_string (current_report.label)
			put_string ("]:")
			put_new_line
			put_string (a_error)
			put_new_line
		end

feature {REPORT_VIEW}
	-- Implementation features
	report_action is
			-- View actions that have been taken.
		local
			l_result: INTEGER
			l_c, l_p: CHARACTER
			l_title, l_msg, l_list: UC_STRING
		do
			l_c := 'c'
			l_p := 'p'
			display_report ("Completed report", True)
			if current_report.is_repeating_type then
				!!l_title.make_from_string ("** Report actions completed successfully **")
				!!l_msg.make_from_string ("repeat this report's search:continue to next report:undo and continue or restart/repeat")
				!!l_list.make_from_string ("pcu")
			else
				!!l_title.make_from_string ("** Report actions completed successfully **")
				!!l_msg.make_from_string ("continue to next report:undo and continue or restart/repeat")
				!!l_list.make_from_string ("cu")
			end

			l_result := query (l_title, l_msg, l_list)

		   if l_result = l_c.code then
				view_state := Done
			elseif l_result = l_p.code then
				view_state := Generate
			else
				view_state := Undo
			end
		end

	report_edit is
			-- Edit the `current_report's action list.
		local
			l_result: INTEGER
			l_c, l_i: CHARACTER
			l_title, l_msg, l_list: UC_STRING
		do
			l_c := 'c'
			l_i := 'i'
			edit_query
			if not current_report.has_result then
				!!l_title.make_from_string ("** Report now empty **")
				!!l_msg.make_from_string ("restart:ignore and continue to next report")
				!!l_list.make_from_string ("ri")
			else
				!!l_title.make_from_string ("** Report has actions **")
				!!l_msg.make_from_string ("do actions:restart:ignore and continue to next report")
				!!l_list.make_from_string ("cri")
			end

			l_result := query(l_title, l_msg, l_list)
			if l_result = l_c.code then
				view_state := Action
			elseif l_result = l_i.code then
				view_state := Reset
			else
				view_state := Generate
			end
		end

	report_empty is
			-- Show that report has no result.
		local
			l_msg: UC_STRING
		do
			display_report ("Empty report", False)
			put_string ("** Generated report has no actions (no changes necessary). **")
			put_new_line
			!!l_msg.make_from_string ("-- Hit 'Enter' to continue --")
			pause (l_msg)
			view_state := Done
		end

	report_invalid_action is
			-- Display that report can't do action or is now empty
		local
			l_r: CHARACTER
			l_title, l_msg, l_list: UC_STRING
		do
			l_r := 'r'
			put_string ("** ERROR ** Current report could not be done. **")
			put_new_line
			!!l_title.make_from_string ("** Do you want to regenerate report or go to next report? **")
			!!l_msg.make_from_string ("continue:regenerate")
			!!l_list.make_from_string ("cr")
			if query(l_title, l_msg, l_list) = l_r.code then
				view_state := Generate
			else
				view_state := Done
			end
		end

	report_invalid_undo is
			-- Display that undo attempt has failed.
		local
			l_msg: UC_STRING
		do
			put_string ("** ERROR ** Current report could not be undone. **")
			put_new_line
			!!l_msg.make_from_string ("-- Hit 'Enter' to continue --")
			pause (l_msg)
			view_state := Done
		end

	report_show is
			-- Display and possibly remove transforms from a report.
		local
			l_result: INTEGER
			l_c, l_e, l_i: CHARACTER
			l_title, l_msg, l_list: UC_STRING
		do
			l_c := 'c'
			l_e := 'e'
			l_i := 'i'
			display_report ("Generated report", False)
			if current_report.is_repeating_type then
				!!l_title.make_from_string ("** Report has actions **")
				!!l_msg.make_from_string ("do actions:ignore this error and repeat report:ignore report and continue to next report")
				!!l_list.make_from_string ("cri")
			else
				!!l_title.make_from_string ("** Report has actions **")
				!!l_msg.make_from_string ("do actions:edit report (remove some actions):restart:ignore and continue to next report")
				!!l_list.make_from_string ("ceri")
			end

			l_result := query(l_title, l_msg, l_list)
			if l_result = l_e.code then
				view_state := Edit
			elseif l_result = l_c.code then
				view_state := Action
			elseif l_result = l_i.code then
				view_state := Reset
			else
				view_state := Generate
			end
		end

	report_undo is
			-- Have undone a repeating SYNC_REPORT object's actions. 
		local
			l_c: CHARACTER
			l_title, l_msg, l_list: UC_STRING
		do
			l_c := 'c'
			!!l_title.make_from_string ("** Report actions undone successfully **")
			!!l_list.make_from_string ("pc")
			if current_report.is_repeating_type then
				!!l_msg.make_from_string ("find next error:continue to next report")
			else
				!!l_msg.make_from_string ("regenerate report:continue to next report")
			end

			if query (l_title, l_msg, l_list) = l_c.code then
				view_state := Done
			else
				view_state := Generate
			end
		end

feature {NONE}
	-- SYNC_REPORT specific formatted output features
	display_report (a_title: STRING; a_title_only: BOOLEAN) is
			-- Print out the transforms
		local
			l_index: INTEGER
			l_line: STRING
		do
			!!l_line.make_filled('-',width)
			put_string (l_line)
			put_new_line
			put_string (a_title)
			put_string (": " )
			put_unicode_string (current_report.label)
			put_new_line
			put_string (l_line)
			put_new_line
			if not a_title_only then
				put_unicode_string (current_report.help)
				put_new_line
			end
			put_string (l_line)
			put_new_line
			from
				current_report.transforms.start
				l_index := 1
			variant
				current_report.transforms.count - l_index + 1
			until
				current_report.transforms.off
			loop
				put_string ("<")
				put_string (l_index.out)
				put_string ("> [")
				put_unicode_string (current_report.transforms.item_for_iteration.name)
				put_string ("] = ")
				put_unicode_string (current_report.transforms.item_for_iteration.to_text)
				put_new_line
				current_report.transforms.forth
				l_index := l_index + 1
			end
		end

	edit_query is
			-- Ask for transforms to delete
		local
			l_items: DS_HASH_SET[INTEGER]
			l_result: INTEGER
		do
			!!l_items.make_default
			put_string (" Type an index and 'Enter' to delete an action, 'Enter' on a blank line to finish.")
			put_new_line
			from
			until
				input_stream.last_string.is_empty
			loop
				put_string (" Delete entry - ")
				put_new_line
				input_stream.read_line
				if input_stream.last_string.is_integer then
					l_result := input_stream.last_string.to_integer
					if l_result <= current_report.transforms.count and then
						l_result >= 1 then
						l_items.force (l_result)
					end
				end
			end
			from
				l_items.finish
			variant
				-- Indices must be in descending order
				l_items.item_for_iteration
			until
				l_items.off
			loop
				if current_report.transforms.valid_index (l_items.item_for_iteration) then
					current_report.remove_transform (current_report.transforms.item (l_items.item_for_iteration))
				else
#ifdef SE
					put_string (" Incorrect index ["+l_items.item_for_iteration.to_string+"] ignoring")
#else
					put_string (" Incorrect index ["+l_items.item_for_iteration.out+"] ignoring")
#endif
					put_new_line
				end
				l_items.back
			end
#ifdef SE
			put_string (" Number of actions remaining = "+current_report.transforms.count.to_string)
#else
			put_string (" Number of actions remaining = "+current_report.transforms.count.out)
#endif
			put_new_line
		end

feature {NONE}
	-- Construction
	make (a_width: INTEGER; a_out_stream: KI_TEXT_OUTPUT_STREAM; a_in_stream: KI_TEXT_INPUT_STREAM) is
			-- Make formatter for given width
		do
			view_state := Done
			make_text_formatter(a_width, a_out_stream, a_in_stream)
		end
end -- class TEXT_REPORT_VIEW
