indexing
	cluster: "demangler"
	namespace: "candidate"
	description: "Delete a path in a `SYNCHRONISED_DIRECTORY'."
	original_author: "Justin Finnerty"
	original_date: "July 2005"
	current_date: "$Date: 2005/09/30 06:49:12 $"
	current_author: "$Author: finnerty $"
	revision: "$Revision: 2.2 $"	
	-- $Log: delete_transform.e,v $
	-- Revision 2.2  2005/09/30 06:49:12  finnerty
	-- Finalised for alpha release with SE and VE compilers
	--
	-- Revision 2.1  2005/09/27 06:14:46  finnerty
	-- Updated to use GOBO and work with SE and VE
	--
	-- Revision 2.0  2005/08/26 23:31:39  finnerty
	-- == alpha version ==
	--
	-- Revision 1.3  2005/08/24 12:15:32  finnerty
	-- Changed terminology from "Delete" to "Trash". This better reflects the
	-- actual action.
	--
	-- Revision 1.2  2005/08/21 11:55:21  finnerty
	-- Alpha 1 version
	--
	-- Revision 1.1  2005/08/17 06:41:49  finnerty
	-- Concrete instance of TRANSFORM that removes files
	--

class DELETE_TRANSFORM
	-- Delete a path in a `SYNCHRONISED_DIRECTORY'.
	
inherit
	TRANSFORM

creation {ANY}
	make

feature {ANY}
	-- Queries on object
	name: UC_STRING is
			-- descriptive label for transform type (for REPORT_DISPLAY etc)
		once
			!!Result.make_from_utf8 ("Trash")
		end

	remove is
			-- Perform undo operation on virtual directory.
		do
			m_object.put_parent (m_object_parent)
			if m_rename /= Void then
				m_rename.remove
			end
			-- Indicate we are not doable
			previous_transform := Current
		end
	
	to_text: UC_STRING is
			-- concise description of action to perform (for
			-- REPORT_DISPLAY etc).
		do
			!!Result.make_from_utf8 ("Move to trash [")
			Result.append_string (m_old_path)
			Result.append_string ("].")
		end

feature {ANY}
	-- Perform transformations
	do_action is
			-- Perform a corrective operation on a sync_dir
		do
			-- Do any name change
			if m_rename /= Void then
				m_rename.do_action
			end
			sync_report.sync_dir.move_to (m_old_path, m_object.path)
		end

	do_undo is
			-- Undo a corrective operation on a sync_dir
		do
			sync_report.sync_dir.move_to (m_object.path, m_old_path)
			if m_rename /= Void then
				m_rename.do_undo
			end
		end

feature {NONE}
	-- Perform transformations
	make (an_fso: FILE_SYSTEM_OBJECT; a_report: SYNC_REPORT) is
		local
			l_new_name: STRING
		do
			sync_report := a_report
			m_object := an_fso
			-- Check if name change required
			if sync_report.sync_dir.to_delete_base.has_child_named (m_object.name) then
				l_new_name := an_fso.unique_backup_name (sync_report.sync_dir.to_delete_base)
				!!m_rename.make (an_fso, l_new_name, a_report)
				-- Note: `m_rename' is not added directly to a_report.
			end
			-- Save undo information (after any name change)
			m_object_parent := m_object.parent
			m_old_path := m_object.path
			m_object.put_parent (sync_report.sync_dir.to_delete_base)
		end

	m_rename: RENAME_TRANSFORM
			-- Transform to make a unique name.

	m_old_path: STRING
			-- Old path of object

	m_object: FILE_SYSTEM_OBJECT
			-- Object we act on

	m_object_parent: FILE_SYSTEM_OBJECT
			-- Old parent of `m_object'

end -- class DELETE_TRANSFORM
