using System.Windows.Controls;
using QC.QsprTestObjects.Registry;

namespace QC.QTMApplication;

public class RegistryTreeEditor
{
	protected string oldName = string.Empty;

	public TreeView RegistryTreeView { get; protected set; }

	public event QTMTestContainerEditEventHandler AfterContainerNameEdit;

	public RegistryTreeEditor(TreeView registryTreeView)
	{
		RegistryTreeView = registryTreeView;
	}

	public void BeginContainerNameEdit(QTMTestContainer qtmTestContainer)
	{
		qtmTestContainer.UserInterfaceProperties.IsInEditMode = true;
		qtmTestContainer.UserInterfaceProperties.EditName = qtmTestContainer.Name;
		oldName = qtmTestContainer.Name;
	}

	public void EndContainerNameEdit(QTMTestContainer qtmTestContainer, bool commit)
	{
		if (!commit)
		{
			qtmTestContainer.Name = oldName;
		}
		qtmTestContainer.UserInterfaceProperties.IsInEditMode = false;
		if (this.AfterContainerNameEdit != null && commit)
		{
			this.AfterContainerNameEdit(this, new RegistryContainerNodeNameChangeEventArgs(qtmTestContainer, qtmTestContainer.UserInterfaceProperties.EditName, oldName));
		}
		oldName = string.Empty;
	}
}
