<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

using Duality;
using Duality.Cloning;
using Duality.Resources;

using Duality.Editor.Controls;
using Duality.Editor.Properties;

using AdamsLair.WinForms.PropertyEditing;

namespace Duality.Editor.UndoRedoActions
{
	public class EditPropertyAction : UndoRedoAction
	{
		protected	PropertyGrid	parent	= null;
		protected	bool			firstDo			= true;
		protected	PropertyInfo	targetProperty	= null;
		protected	object[]		targetObj		= null;
		protected	object[]		targetValue		= null;
		protected	object[]		backupValue		= null;
		protected	object[]		targetIndices	= null;
		
		public override string Name
		{
			get { return string.Format(GeneralRes.UndoRedo_EditProperty, this.targetProperty.Name); }
		}
		public override bool IsVoid
		{
			get { return this.targetObj == null || this.targetObj.Length == 0; }
		}

		public EditPropertyAction(PropertyGrid parent, PropertyInfo property, IEnumerable<object> target, IEnumerable<object> value, object[] indices = null)
		{
			if (property == null) throw new ArgumentNullException("property");
			if (target == null) throw new ArgumentNullException("target");
			this.targetProperty = property;
			this.targetObj = target.Where(o => o != null).ToArray();
			this.targetValue = value != null ? value.ToArray() : null;
			this.targetIndices = indices;
			this.parent = parent;
		}

		public override bool CanAppend(UndoRedoAction action)
		{
			EditPropertyAction castAction = action as EditPropertyAction;

			if (castAction == null) return false;
			if (castAction.targetProperty != this.targetProperty) return false;
			if (!castAction.targetObj.SequenceEqual(this.targetObj)) return false;

			return true;
		}
		public override void Append(UndoRedoAction action, bool performAction)
		{
			base.Append(action, performAction);
			EditPropertyAction castAction = action as EditPropertyAction;

			if (performAction)
			{
				castAction.backupValue = this.backupValue;
				castAction.Do();
			}
			this.targetValue = castAction.targetValue ?? this.targetValue;
		}
		public override void Do()
		{<commit_msg>UndoRedo List Editing Bugfixes #FIX: Fixed a bug where editing multiple list items in a row could accidentally merge into a single, but incomplete Undo / Redo action that would undo only the latest editing step.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

using Duality;
using Duality.Cloning;
using Duality.Resources;

using Duality.Editor.Controls;
using Duality.Editor.Properties;

using AdamsLair.WinForms.PropertyEditing;

namespace Duality.Editor.UndoRedoActions
{
	public class EditPropertyAction : UndoRedoAction
	{
		protected	PropertyGrid	parent	= null;
		protected	bool			firstDo			= true;
		protected	PropertyInfo	targetProperty	= null;
		protected	object[]		targetObj		= null;
		protected	object[]		targetValue		= null;
		protected	object[]		backupValue		= null;
		protected	object[]		targetIndices	= null;
		
		public override string Name
		{
			get { return string.Format(GeneralRes.UndoRedo_EditProperty, this.targetProperty.Name); }
		}
		public override bool IsVoid
		{
			get { return this.targetObj == null || this.targetObj.Length == 0; }
		}

		public EditPropertyAction(PropertyGrid parent, PropertyInfo property, IEnumerable<object> target, IEnumerable<object> value, object[] indices = null)
		{
			if (property == null) throw new ArgumentNullException("property");
			if (target == null) throw new ArgumentNullException("target");
			this.targetProperty = property;
			this.targetObj = target.Where(o => o != null).ToArray();
			this.targetValue = value != null ? value.ToArray() : null;
			this.targetIndices = indices;
			this.parent = parent;
		}

		public override bool CanAppend(UndoRedoAction action)
		{
			EditPropertyAction castAction = action as EditPropertyAction;

			if (castAction == null) return false;
			if (castAction.targetProperty != this.targetProperty) return false;
			if (!castAction.targetObj.SequenceEqual(this.targetObj)) return false;

			// If we're using an indexer, make sure both actions do and use the same indices
			if (castAction.targetIndices != null || this.targetIndices != null)
			{
				if (castAction.targetIndices == null || this.targetIndices == null) return false;
				if (!castAction.targetIndices.SequenceEqual(this.targetIndices)) return false;
			}

			return true;
		}
		public override void Append(UndoRedoAction action, bool performAction)
		{
			base.Append(action, performAction);
			EditPropertyAction castAction = action as EditPropertyAction;

			if (performAction)
			{
				castAction.backupValue = this.backupValue;
				castAction.Do();
			}
			this.targetValue = castAction.targetValue ?? this.targetValue;
		}
		public override void Do()
		{
{'fraction_non_alphanumeric': 0.0935134029056681, 'fraction_numerical': 0.0004092490280335584, 'mean_word_length': 4.419068736141907, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5707750', 'n_tokens_mistral': 1599, 'n_tokens_neox': 1421, 'n_words': 395}