Work on document manager

This commit is contained in:
2014-07-29 19:42:52 +03:00
parent 1c4c7ccfb0
commit 09224d9af7
29 changed files with 798 additions and 280 deletions

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RainmeterStudio.Documents.DocumentEditorFeatures
{
public interface ICustomDocumentTitleProvider
{
string Title { get; }
event EventHandler TitleChanged;
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RainmeterStudio.Model;
namespace RainmeterStudio.Documents.DocumentEditorFeatures
{
interface ISelectionPropertiesProvider
{
string SelectionName { get; }
IEnumerable<Property> SelectionProperties { get; }
event EventHandler SelectionChanged;
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RainmeterStudio.Documents.DocumentEditorFeatures
{
public interface IToolboxProvider
{
bool SupportsToolboxDrop { get; }
IEnumerable<string> ToolboxItems { get; }
event EventHandler ToolboxItemsChanged;
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RainmeterStudio.Documents.DocumentEditorFeatures
{
public interface IUndoSupport
{
// TODO
}
}

View File

@ -0,0 +1,132 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
using RainmeterStudio.Model;
using RainmeterStudio.UI.Controller;
namespace RainmeterStudio.Documents
{
/// <summary>
/// Represents a document template
/// </summary>
public class DocumentTemplate<T> where T : IDocument
{
#region Private fields
private Func<T> _createFunction;
#endregion
/// <summary>
/// Gets the document template name
/// </summary>
public string Name { get; private set; }
#region Icon property
private ImageSource _icon = null;
/// <summary>
/// Gets or sets the template's icon
/// </summary>
public virtual ImageSource Icon
{
get
{
if (_icon == null)
return IconProvider.GetIcon("Template_" + Name);
return _icon;
}
set
{
_icon = value;
}
}
#endregion
#region Display text property
private string _displayText = null;
/// <summary>
/// Gets or sets the display text
/// </summary>
public virtual string DisplayText
{
get
{
if (_displayText == null)
return Resources.Strings.ResourceManager.GetString("Template_" + Name + "_DisplayText");
return _displayText;
}
set
{
_displayText = value;
}
}
#endregion
#region Description property
private string _description = null;
/// <summary>
/// Gets or sets the description
/// </summary>
public virtual string Description
{
get
{
if (_description == null)
return Resources.Strings.ResourceManager.GetString("Template_" + Name + "_Description");
return _description;
}
set
{
_description = value;
}
}
#endregion
/// <summary>
/// Gets or sets the default extension of this template
/// </summary>
public string DefaultExtension { get; set; }
/// <summary>
/// Gets or sets the category in which this template belongs
/// </summary>
public virtual string Category { get; set; }
/// <summary>
/// Initializes the document template
/// </summary>
/// <param name="name">Name of document template</param>
public DocumentTemplate(string name, string defaultExtension = null, string category = null, Func<T> createDocument = null)
{
Name = name;
DefaultExtension = defaultExtension;
_createFunction = createDocument;
}
/// <summary>
/// Creates a document of type T
/// </summary>
/// <returns></returns>
public virtual T CreateDocument()
{
if (_createFunction != null)
return _createFunction();
return default(T);
}
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using RainmeterStudio.Model;
namespace RainmeterStudio.Documents
{
public interface IDocumentEditor
{
IDocument AttachedDocument { get; }
UIElement EditorUI { get; }
}
}

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RainmeterStudio.Model;
namespace RainmeterStudio.Documents
{
public interface IDocumentEditorFactory
{
/// <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>
/// Tests if this editor can edit this document type
/// </summary>
/// <param name="type">Document type</param>
/// <returns>True if the editor can edit the document type</returns>
bool CanEdit(Type type);
}
}

View File

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RainmeterStudio.Model;
namespace RainmeterStudio.Documents
{
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);
/// <summary>
/// Tests if the document can be written by this storage
/// </summary>
/// <param name="documentType">Document type</param>
/// <returns>True if the document can be written</returns>
bool CanWrite(Type documentType);
}
}

View File

@ -4,29 +4,67 @@ using System.IO;
using System.Linq;
using System.Text;
using RainmeterStudio.Model;
using System.ComponentModel;
namespace RainmeterStudio.Documents.Text
{
public class TextDocument : IDocument
{
public string Name
{
get
{
return Path.GetFileName(FilePath);
}
}
public string FilePath
{
get; set;
}
private Reference _reference;
private bool _isDirty;
/// <summary>
/// Gets or sets the text associated with this document
/// </summary>
public string Text
{
get; set;
}
/// <summary>
/// Gets or sets the reference of this document
/// </summary>
public Reference Reference
{
get
{
return _reference;
}
set
{
_reference = value;
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("Reference"));
}
}
/// <summary>
/// Gets a property indicating if this file was modified and not saved
/// </summary>
public bool IsDirty
{
get
{
return _isDirty;
}
set
{
_isDirty = value;
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("IsDirty"));
}
}
/// <summary>
/// Triggered when the value of a property changes
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Initializes the text document
/// </summary>
public TextDocument()
{
Text = String.Empty;

View File

@ -7,7 +7,7 @@ using RainmeterStudio.Model;
namespace RainmeterStudio.Documents.Text
{
public class TextEditor : IDocumentEditor
/*public class TextEditor : IDocumentEditor
{
private TextDocument _document;
private TextEditorControl _control;
@ -23,5 +23,5 @@ namespace RainmeterStudio.Documents.Text
public override string Title { get { return _document.Name; } }
public override System.Windows.UIElement EditorUI { get { return _control; } }
}
}*/
}

View File

@ -8,7 +8,7 @@ using RainmeterStudio.Model;
namespace RainmeterStudio.Documents.Text
{
public class TextEditorFactory : IDocumentEditorFactory
/*public class TextEditorFactory : IDocumentEditorFactory
{
private TextStorage _storage = new TextStorage();
@ -35,7 +35,6 @@ namespace RainmeterStudio.Documents.Text
}
}
public IDocumentEditor CreateEditor(IDocument document)
{
TextDocument textDocument = document as TextDocument;
@ -55,5 +54,5 @@ namespace RainmeterStudio.Documents.Text
return document;
}
}
}*/
}

View File

@ -13,7 +13,8 @@ namespace RainmeterStudio.Documents.Text
IDocument IDocumentStorage.Read(string path)
{
TextDocument document = new TextDocument();
document.FilePath = path;
document.Reference.Path = path;
document.Reference.Name = Path.GetFileName(path);
document.Text = File.ReadAllText(path);
return document;
@ -60,5 +61,10 @@ namespace RainmeterStudio.Documents.Text
// Not found, probably text file
return true;
}
public bool CanWrite(Type documentType)
{
return documentType.Equals(typeof(TextDocument));
}
}
}