Split into smaller projects, now uses plugins.

This commit is contained in:
2014-08-12 16:33:13 +03:00
parent 69913fa251
commit b8c8f2a1b0
80 changed files with 1520 additions and 494 deletions

View File

@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RainmeterStudio.Core.Documents;
namespace RainmeterStudio.Core.Model.Events
{
public abstract class DocumentEventArgsBase : EventArgs
{
/// <summary>
/// Gets the newly created document editor
/// </summary>
public IDocumentEditor Editor { get; private set; }
/// <summary>
/// Gets the opened document
/// </summary>
public IDocument Document { get { return Editor.AttachedDocument; } }
/// <summary>
/// Initializes the DocumentOpenedEventArgs
/// </summary>
/// <param name="editor">The document editor</param>
public DocumentEventArgsBase(IDocumentEditor editor)
{
Editor = editor;
}
}
/// <summary>
/// Event arguments for the document opened event
/// </summary>
public class DocumentOpenedEventArgs : DocumentEventArgsBase
{
/// <summary>
/// Initializes the DocumentOpenedEventArgs
/// </summary>
/// <param name="editor">The document editor</param>
public DocumentOpenedEventArgs(IDocumentEditor editor)
: base(editor)
{
}
}
/// <summary>
/// Event arguments for the document closed event
/// </summary>
public class DocumentClosedEventArgs : DocumentEventArgsBase
{
/// <summary>
/// Initializes the DocumentClosedEventArgs
/// </summary>
/// <param name="editor">The document editor</param>
public DocumentClosedEventArgs(IDocumentEditor editor)
: base(editor)
{
}
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
namespace RainmeterStudio.Core.Model
{
public interface IDocument : INotifyPropertyChanged
{
Reference Reference { get; }
bool IsDirty { get; set; }
}
}

View File

@ -0,0 +1,247 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using RainmeterStudio.Core.Storage;
namespace RainmeterStudio.Core.Model
{
/// <summary>
/// Defines a Rainmeter Studio project
/// </summary>
public class Project
{
#region Name property
private string _name;
/// <summary>
/// Gets or sets the name of the project
/// </summary>
[XmlElement("name")]
public string Name
{
get
{
return _name;
}
set
{
_name = value;
if (Root != null)
Root.Data = new Reference(Name, Path);
}
}
private string _path;
#endregion
#region Path property
/// <summary>
/// Gets or sets the file path of this project
/// </summary>
[XmlIgnore]
public string Path
{
get
{
return _path;
}
set
{
_path = value;
if (Root != null)
Root.Data = new Reference(Name, Path);
}
}
#endregion
#region Author property
/// <summary>
/// Gets or sets the author of the project
/// </summary>
[XmlElement("author")]
public string Author { get; set; }
#endregion
#region Version property
/// <summary>
/// Gets or sets the version of the project
/// </summary>
[XmlIgnore]
public Version Version { get; set; }
/// <summary>
/// Gets or sets the string representation of the project version
/// </summary>
[XmlElement("version")]
public string VersionString
{
get
{
return Version.ToString();
}
set
{
Version = new Version(value);
}
}
#endregion
#region Auto-load file property
/// <summary>
/// Gets or sets the reference to the file to automatically load at package installation
/// </summary>
[XmlElement("autoLoadFile")]
public Reference AutoLoadFile { get; set; }
#endregion
#region Variable files property
/// <summary>
/// Gets or sets the list of variable files
/// </summary>
[XmlArray("variableFiles")]
public List<Reference> VariableFiles { get; set; }
#endregion
#region Minimum rainmeter & windows properties
/// <summary>
/// Gets or sets the minimum rainmeter version
/// </summary>
[XmlIgnore]
public Version MinimumRainmeter { get; set; }
/// <summary>
/// Gets or sets the string representation of the minimum rainmeter version
/// </summary>
[XmlElement("minimumRainmeter")]
public string MinimumRainmeterString
{
get
{
return MinimumRainmeter.ToString();
}
set
{
MinimumRainmeter = new Version(value);
}
}
/// <summary>
/// Gets or sets the minimum Windows version
/// </summary>
[XmlIgnore]
public Version MinimumWindows { get; set; }
/// <summary>
/// Gets or sets the string representation of the minimum Windows version
/// </summary>
[XmlElement("minimumWindows")]
public string MinimumWindowsString
{
get
{
return MinimumWindows.ToString();
}
set
{
MinimumWindows = new Version(value);
}
}
#endregion
#region Root property
/// <summary>
/// Gets or sets the root node
/// </summary>
[XmlIgnore]
public Tree<Reference> Root { get; set; }
/// <summary>
/// Gets or sets the serializable root node
/// </summary>
/// <remarks>Warning: not efficient</remarks>
[XmlElement("root")]
public SerializableTree<Reference> SerializableRoot
{
get
{
return Root.AsSerializableTree();
}
set
{
Root = value.AsTree();
}
}
#endregion
#region Constructor
/// <summary>
/// Initializes a project
/// </summary>
public Project()
{
Root = new Tree<Reference>();
VariableFiles = new List<Reference>();
Version = new Version();
MinimumRainmeter = new Version("3.1");
MinimumWindows = new Version("5.1");
}
#endregion
#region Equals
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;
}
#endregion
}
}

View File

@ -0,0 +1,254 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
namespace RainmeterStudio.Core.Model
{
public interface IProperty : INotifyPropertyChanged
{
/// <summary>
/// Gets the name of the property
/// </summary>
string Name { get; }
/// <summary>
/// Gets or sets the value of the property
/// </summary>
object Value { get; set; }
/// <summary>
/// Gets the data type of the property
/// </summary>
Type Type { get; }
/// <summary>
/// Gets the children of this property
/// </summary>
ObservableCollection<IProperty> Children { get; }
}
/// <summary>
/// Represents a property
/// </summary>
public class Property : IProperty
{
#region Name property
/// <summary>
/// Gets the name of the property
/// </summary>
public virtual string Name { get; private set; }
#endregion
#region Value property
private object _value;
/// <summary>
/// Gets or sets the value of the property
/// </summary>
public virtual object Value
{
get
{
return _value;
}
set
{
// Test if type changed
bool typeChanged = (_value.GetType() != value.GetType());
// Set value
_value = value;
// Trigger event
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("Value"));
if (typeChanged)
PropertyChanged(this, new PropertyChangedEventArgs("Type"));
}
}
}
#endregion
#region Type property
/// <summary>
/// Gets the type of the property
/// </summary>
public virtual Type Type
{
get
{
return Value.GetType();
}
}
#endregion
#region Children property
/// <summary>
/// Gets the children of this property
/// </summary>
public ObservableCollection<IProperty> Children { get; private set; }
#endregion
#region Property changed event
/// <summary>
/// Triggered when a property changes
/// </summary>
public virtual event PropertyChangedEventHandler PropertyChanged;
#endregion
#region Constructors
/// <summary>
/// Initializes this property
/// </summary>
/// <param name="name">Name of the property</param>
public Property(string name)
{
Name = name;
Value = null;
Children = new ObservableCollection<IProperty>();
}
/// <summary>
/// Initializes this property
/// </summary>
/// <param name="name">Name of the property</param>
/// <param name="value">Value of the property</param>
public Property(string name, object value)
{
Name = name;
Value = value;
Children = new ObservableCollection<IProperty>();
}
#endregion
}
namespace Generic
{
/// <summary>
/// Generic property
/// </summary>
/// <typeparam name="T">Type of property</typeparam>
public class Property<T> : IProperty
{
#region Value property
private T _value;
/// <summary>
/// Gets or sets the value of this property
/// </summary>
public T Value
{
get
{
return _value;
}
set
{
// Set value
_value = value;
// Trigger event
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("Value"));
}
}
/// <summary>
/// Gets or sets the value of this property. Overriden from the generic property.
/// </summary>
/// <exception cref="InvalidCastException">Thrown if value is not of the right type.</exception>
object IProperty.Value
{
get
{
return _value;
}
set
{
this.Value = (T)value;
}
}
#endregion
#region Type property
/// <summary>
/// Gets the type of this property
/// </summary>
public Type Type
{
get
{
return typeof(T);
}
}
#endregion
#region Property changed event
/// <summary>
/// Triggered when a property changes
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
#endregion
#region Constructors
/// <summary>
/// Initializes this property
/// </summary>
/// <param name="name">Name of the property</param>
public Property(string name)
{
Name = name;
Value = default(T);
Children = new ObservableCollection<IProperty>();
}
/// <summary>
/// Initializes this property
/// </summary>
/// <param name="name">Name of the property</param>
/// <param name="value">Value of the property</param>
public Property(string name, T value)
{
Name = name;
Value = value;
Children = new ObservableCollection<IProperty>();
}
#endregion
/// <summary>
/// Gets the name of the property
/// </summary>
public string Name { get; private set; }
/// <summary>
/// Gets the children of this property
/// </summary>
public ObservableCollection<IProperty> Children { get; private set; }
}
}
}

View File

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
namespace RainmeterStudio.Core.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;
}
}
}

View File

@ -0,0 +1,157 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
namespace RainmeterStudio.Core.Model
{
public class Tree<T> : IList<Tree<T>>
{
public T Data { get; set; }
public ObservableCollection<Tree<T>> Children { get; private set; }
public Tree()
{
Children = new ObservableCollection<Tree<T>>();
Data = default(T);
}
public Tree(T data)
{
Children = new ObservableCollection<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;
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return Children.GetEnumerator();
}
}
}