mirror of
				https://github.com/chibicitiberiu/rainmeter-studio.git
				synced 2024-02-24 04:33:31 +00:00 
			
		
		
		
	Completed rename from RainmeterEditor to RainmeterStudio
This commit is contained in:
		
							
								
								
									
										14
									
								
								RainmeterStudio/Model/DocumentFormat.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								RainmeterStudio/Model/DocumentFormat.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
			
		||||
using System.Windows.Media;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.Model
 | 
			
		||||
{
 | 
			
		||||
    public class DocumentFormat
 | 
			
		||||
    {
 | 
			
		||||
        public string Name { get; set; }
 | 
			
		||||
        public ImageSource Icon { get; set; }
 | 
			
		||||
        public string Description { get; set; }
 | 
			
		||||
        public string DefaultExtension { get; set; }
 | 
			
		||||
        public IDocumentEditorFactory Factory { get; set; }
 | 
			
		||||
        public string Category { get; set; }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										17
									
								
								RainmeterStudio/Model/Events/DocumentOpenedEventArgs.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								RainmeterStudio/Model/Events/DocumentOpenedEventArgs.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.Model.Events
 | 
			
		||||
{
 | 
			
		||||
    public class DocumentOpenedEventArgs : EventArgs
 | 
			
		||||
    {
 | 
			
		||||
        public IDocumentEditor Editor { get; private set; }
 | 
			
		||||
 | 
			
		||||
        public DocumentOpenedEventArgs(IDocumentEditor editor)
 | 
			
		||||
        {
 | 
			
		||||
            Editor = editor;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										13
									
								
								RainmeterStudio/Model/IDocument.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								RainmeterStudio/Model/IDocument.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.Model
 | 
			
		||||
{
 | 
			
		||||
    public interface IDocument
 | 
			
		||||
    {
 | 
			
		||||
        string Name { get; }
 | 
			
		||||
        string FilePath { get; }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										136
									
								
								RainmeterStudio/Model/IDocumentEditor.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										136
									
								
								RainmeterStudio/Model/IDocumentEditor.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,136 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Windows;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.Model
 | 
			
		||||
{
 | 
			
		||||
    public abstract class IDocumentEditor : IDisposable
 | 
			
		||||
    {
 | 
			
		||||
        #region Dirty flag
 | 
			
		||||
 | 
			
		||||
        private bool _dirty = false;
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets a flag indicating if the active document is dirty (modified and not saved)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public virtual bool Dirty
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return _dirty;
 | 
			
		||||
            }
 | 
			
		||||
            protected set
 | 
			
		||||
            {
 | 
			
		||||
                _dirty = value;
 | 
			
		||||
                if (DirtyChanged != null)
 | 
			
		||||
                    DirtyChanged(this, new EventArgs());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Triggered when the dirty flag changes
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public event EventHandler DirtyChanged;
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        #region Document
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the opened document
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public abstract IDocument Document { get; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the title to be displayed in the title bar
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public abstract string Title { get; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Triggered when the title changes
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public event EventHandler TitleChanged;
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        #region EditorUI
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the editor UI
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public abstract UIElement EditorUI { get; }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        #region Selection properties
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets a value indicating if this editor uses the selection properties window
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public virtual bool UsesSelectionProperties
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the name of the selected object
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public virtual string SelectionName
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return String.Empty;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets a list of properties for the currently selected object
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public virtual IEnumerable<string> SelectionProperties
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                yield break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Triggered when the selected object changes (used to update properties)
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public event EventHandler SelectionChanged;
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        #region Toolbox
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets a list of items to populate the toolbox
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public virtual IEnumerable<string> ToolboxItems
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                yield break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public event EventHandler ToolboxChanged;
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        #region Dispose
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Dispose
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public virtual void Dispose()
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										39
									
								
								RainmeterStudio/Model/IDocumentEditorFactory.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								RainmeterStudio/Model/IDocumentEditorFactory.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,39 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using RainmeterStudio.Storage;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.Model
 | 
			
		||||
{
 | 
			
		||||
    public interface IDocumentEditorFactory
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Name of the editor
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        string EditorName { get; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Formats that will be used to populate the 'create document' dialog
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        IEnumerable<DocumentFormat> CreateDocumentFormats { get; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Creates a new editor object
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="document">Document to be edited by the editor</param>
 | 
			
		||||
        /// <returns>A new document editor</returns>
 | 
			
		||||
        IDocumentEditor CreateEditor(IDocument document);
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Creates a new document
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <returns>A new document</returns>
 | 
			
		||||
        IDocument CreateDocument(DocumentFormat format, string path);
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the storage of this factory
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        IDocumentStorage Storage { get; }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										26
									
								
								RainmeterStudio/Model/IDocumentStorage.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								RainmeterStudio/Model/IDocumentStorage.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
			
		||||
namespace RainmeterStudio.Model
 | 
			
		||||
{
 | 
			
		||||
    public interface IDocumentStorage
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Reads a document from file
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="path">Path to file</param>
 | 
			
		||||
        /// <returns>Read document</returns>
 | 
			
		||||
        IDocument Read(string path);
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Writes a document to a file
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="path">Path to file</param>
 | 
			
		||||
        /// <param name="document">Document to write</param>
 | 
			
		||||
        void Write(string path, IDocument document);
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Tests if the file can be read by this storage
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="path">Path to file</param>
 | 
			
		||||
        /// <returns>True if file can be read</returns>
 | 
			
		||||
        bool CanRead(string path);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										114
									
								
								RainmeterStudio/Model/Project.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										114
									
								
								RainmeterStudio/Model/Project.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,114 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Xml.Serialization;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.Model
 | 
			
		||||
{
 | 
			
		||||
    public class Project
 | 
			
		||||
    {
 | 
			
		||||
        [XmlElement("name")]
 | 
			
		||||
        public string Name { get; set; }
 | 
			
		||||
 | 
			
		||||
        [XmlElement("author")]
 | 
			
		||||
        public string Author { get; set; }
 | 
			
		||||
 | 
			
		||||
        [XmlIgnore]
 | 
			
		||||
        public Version Version { get; set; }
 | 
			
		||||
 | 
			
		||||
        [XmlElement("version")]
 | 
			
		||||
        public string VersionString
 | 
			
		||||
        {
 | 
			
		||||
            get 
 | 
			
		||||
            {
 | 
			
		||||
                return Version.ToString();
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                Version = new Version(value);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [XmlElement("autoLoadFile")]
 | 
			
		||||
        public Reference AutoLoadFile { get; set; }
 | 
			
		||||
 | 
			
		||||
        [XmlArray("variableFiles")]
 | 
			
		||||
        public List<Reference> VariableFiles { get; set; }
 | 
			
		||||
 | 
			
		||||
        [XmlIgnore]
 | 
			
		||||
        public Version MinimumRainmeter { get; set; }
 | 
			
		||||
 | 
			
		||||
        [XmlElement("minimumRainmeter")]
 | 
			
		||||
        public string MinimumRainmeterString
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return MinimumRainmeter.ToString();
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                MinimumRainmeter = new Version(value);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [XmlIgnore]
 | 
			
		||||
        public Version MinimumWindows { get; set; }
 | 
			
		||||
 | 
			
		||||
        [XmlElement("minimumWindows")]
 | 
			
		||||
        public string MinimumWindowsString
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return MinimumWindows.ToString();
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                MinimumWindows = new Version(value);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [XmlElement("root")]
 | 
			
		||||
        public Tree<Reference> Root { get; set; }
 | 
			
		||||
 | 
			
		||||
        public Project()
 | 
			
		||||
        {
 | 
			
		||||
            Root = new Tree<Reference>();
 | 
			
		||||
            VariableFiles = new List<Reference>();
 | 
			
		||||
            Version = new Version();
 | 
			
		||||
            MinimumRainmeter = new Version("3.1");
 | 
			
		||||
            MinimumWindows = new Version("5.1");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override bool Equals(object obj)
 | 
			
		||||
        {
 | 
			
		||||
            Project other = obj as Project;
 | 
			
		||||
            
 | 
			
		||||
            if (other == null)
 | 
			
		||||
                return false;
 | 
			
		||||
            
 | 
			
		||||
            bool res = String.Equals(Author, other.Author);
 | 
			
		||||
            res &= Reference.Equals(AutoLoadFile, other.AutoLoadFile);
 | 
			
		||||
            res &= Version.Equals(MinimumRainmeter, other.MinimumRainmeter);
 | 
			
		||||
            res &= Version.Equals(MinimumWindows, other.MinimumWindows);
 | 
			
		||||
            res &= String.Equals(Name, other.Name);
 | 
			
		||||
            res &= Tree<Reference>.Equals(Root, other.Root);
 | 
			
		||||
            res &= Version.Equals(Version, other.Version);
 | 
			
		||||
 | 
			
		||||
            return res;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override int GetHashCode()
 | 
			
		||||
        {
 | 
			
		||||
            int hash = (Author == null) ? 0 : Author.GetHashCode();
 | 
			
		||||
            hash = hash * 7 + ((AutoLoadFile == null) ? 0 : AutoLoadFile.GetHashCode());
 | 
			
		||||
            hash = hash * 7 + ((MinimumRainmeter == null) ? 0 : MinimumRainmeter.GetHashCode());
 | 
			
		||||
            hash = hash * 7 + ((MinimumWindows == null) ? 0 : MinimumWindows.GetHashCode());
 | 
			
		||||
            hash = hash * 7 + ((Name == null) ? 0 : Name.GetHashCode());
 | 
			
		||||
            hash = hash * 7 + ((Root == null) ? 0 : Root.GetHashCode());
 | 
			
		||||
            hash = hash * 7 + ((Version == null) ? 0 : Version.GetHashCode());
 | 
			
		||||
 | 
			
		||||
            return hash;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										30
									
								
								RainmeterStudio/Model/Property.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								RainmeterStudio/Model/Property.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.Model
 | 
			
		||||
{
 | 
			
		||||
    public class Property
 | 
			
		||||
    {
 | 
			
		||||
        public string Name { get; set; }
 | 
			
		||||
 | 
			
		||||
        private object _value;
 | 
			
		||||
        public object Value
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return _value;
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                _value = value;
 | 
			
		||||
 | 
			
		||||
                if (ValueChanged != null)
 | 
			
		||||
                    ValueChanged(this, new EventArgs());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public event EventHandler ValueChanged;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										11
									
								
								RainmeterStudio/Model/RainmeterConfig.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								RainmeterStudio/Model/RainmeterConfig.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.Model
 | 
			
		||||
{
 | 
			
		||||
    public class RainmeterConfig
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										50
									
								
								RainmeterStudio/Model/Reference.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								RainmeterStudio/Model/Reference.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,50 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Xml.Serialization;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.Model
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Reference to a file or folder
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class Reference
 | 
			
		||||
    {
 | 
			
		||||
        [XmlAttribute("name")]
 | 
			
		||||
        public string Name { get; set; }
 | 
			
		||||
 | 
			
		||||
        [XmlAttribute("path")]
 | 
			
		||||
        public string Path { get; set; }
 | 
			
		||||
 | 
			
		||||
        public Reference()
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public Reference(string name, string path = null)
 | 
			
		||||
        {
 | 
			
		||||
            Name = name;
 | 
			
		||||
            Path = path;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override bool Equals(object obj)
 | 
			
		||||
        {
 | 
			
		||||
            var other = obj as Reference;
 | 
			
		||||
            
 | 
			
		||||
            // Types are different, so not equal
 | 
			
		||||
            if (other == null)
 | 
			
		||||
                return false;
 | 
			
		||||
 | 
			
		||||
            // Compare using string equals
 | 
			
		||||
            return String.Equals(Name, other.Name) && String.Equals(Path, other.Path);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override int GetHashCode()
 | 
			
		||||
        {
 | 
			
		||||
            int hash = (Name == null) ? 0 : Name.GetHashCode();
 | 
			
		||||
            hash = hash * 7 + ((Path == null) ? 0 : Path.GetHashCode());
 | 
			
		||||
 | 
			
		||||
            return hash;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										153
									
								
								RainmeterStudio/Model/Tree.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										153
									
								
								RainmeterStudio/Model/Tree.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,153 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Xml.Serialization;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.Model
 | 
			
		||||
{
 | 
			
		||||
    public class Tree<T>
 | 
			
		||||
    {
 | 
			
		||||
        [XmlElement("data")]
 | 
			
		||||
        public T Data { get; set; }
 | 
			
		||||
 | 
			
		||||
        [XmlArray("children"), XmlArrayItem("child")]
 | 
			
		||||
        public List<Tree<T>> Children { get; set; }
 | 
			
		||||
 | 
			
		||||
        public Tree()
 | 
			
		||||
        {
 | 
			
		||||
            Children = new List<Tree<T>>();
 | 
			
		||||
            Data = default(T);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public Tree(T data)
 | 
			
		||||
        {
 | 
			
		||||
            Children = new List<Tree<T>>();
 | 
			
		||||
            Data = data;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public int IndexOf(Tree<T> item)
 | 
			
		||||
        {
 | 
			
		||||
            return Children.IndexOf(item);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void Insert(int index, Tree<T> item)
 | 
			
		||||
        {
 | 
			
		||||
            Children.Insert(index, item);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void RemoveAt(int index)
 | 
			
		||||
        {
 | 
			
		||||
            Children.RemoveAt(index);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public Tree<T> this[int index]
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return Children[index];
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                Children[index] = value;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void Add(Tree<T> item)
 | 
			
		||||
        {
 | 
			
		||||
            Children.Add(item);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void Clear()
 | 
			
		||||
        {
 | 
			
		||||
            Children.Clear();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public bool Contains(Tree<T> item)
 | 
			
		||||
        {
 | 
			
		||||
            return Children.Contains(item);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void CopyTo(Tree<T>[] array, int arrayIndex)
 | 
			
		||||
        {
 | 
			
		||||
            Children.CopyTo(array, arrayIndex);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public int Count
 | 
			
		||||
        {
 | 
			
		||||
            get { return Children.Count; }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public bool IsReadOnly
 | 
			
		||||
        {
 | 
			
		||||
            get { return false; }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public bool Remove(Tree<T> item)
 | 
			
		||||
        {
 | 
			
		||||
            return Children.Remove(item);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public IEnumerator<Tree<T>> GetEnumerator()
 | 
			
		||||
        {
 | 
			
		||||
            return Children.GetEnumerator();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public int IndexOf(T item)
 | 
			
		||||
        {
 | 
			
		||||
            return Children.IndexOf(new Tree<T>(item));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void Insert(int index, T item)
 | 
			
		||||
        {
 | 
			
		||||
            Children.Insert(index, new Tree<T>(item));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void Add(T item)
 | 
			
		||||
        {
 | 
			
		||||
            Children.Add(new Tree<T>(item));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public bool Contains(T item)
 | 
			
		||||
        {
 | 
			
		||||
            return Children.Contains(new Tree<T>(item));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void CopyTo(T[] array, int arrayIndex)
 | 
			
		||||
        {
 | 
			
		||||
            foreach (var node in Children)
 | 
			
		||||
                array[arrayIndex++] = node.Data;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public bool Remove(T item)
 | 
			
		||||
        {
 | 
			
		||||
            return Children.Remove(new Tree<T>(item));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override bool Equals(object obj)
 | 
			
		||||
        {
 | 
			
		||||
            Tree<T> other = obj as Tree<T>;
 | 
			
		||||
            
 | 
			
		||||
            // Types are different, so not equal
 | 
			
		||||
            if (other == null)
 | 
			
		||||
                return false;
 | 
			
		||||
 | 
			
		||||
            // Compare data
 | 
			
		||||
            if (!object.Equals(Data, other.Data))
 | 
			
		||||
                return false;
 | 
			
		||||
 | 
			
		||||
            // Compare children array
 | 
			
		||||
            return Children.SequenceEqual(other.Children);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override int GetHashCode()
 | 
			
		||||
        {
 | 
			
		||||
            int hash = ((Data == null) ? 0 : Data.GetHashCode());
 | 
			
		||||
 | 
			
		||||
            foreach (var c in Children)
 | 
			
		||||
                hash = hash * 7 + c.GetHashCode();
 | 
			
		||||
 | 
			
		||||
            return hash;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user