mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Work on documents, separated UI from Main
This commit is contained in:
11
RainmeterStudio/Documents/AutoRegisterAttribute.cs
Normal file
11
RainmeterStudio/Documents/AutoRegisterAttribute.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace RainmeterStudio.Documents
|
||||
{
|
||||
public class AutoRegisterAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
@ -1,132 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
36
RainmeterStudio/Documents/DocumentTemplate_.cs
Normal file
36
RainmeterStudio/Documents/DocumentTemplate_.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using RainmeterStudio.Model;
|
||||
namespace RainmeterStudio.Documents
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a document template
|
||||
/// </summary>
|
||||
public abstract class DocumentTemplate
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the document template name
|
||||
/// </summary>
|
||||
public string Name { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default extension of this template
|
||||
/// </summary>
|
||||
public string DefaultExtension { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the document template
|
||||
/// </summary>
|
||||
/// <param name="name">Name of template</param>
|
||||
/// <param name="defaultExtension">Default extension</param>
|
||||
public DocumentTemplate(string name, string defaultExtension)
|
||||
{
|
||||
Name = name;
|
||||
DefaultExtension = defaultExtension;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a document using this template
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public abstract IDocument CreateDocument();
|
||||
}
|
||||
}
|
@ -16,9 +16,9 @@ namespace RainmeterStudio.Documents.Text
|
||||
/// <summary>
|
||||
/// Gets or sets the text associated with this document
|
||||
/// </summary>
|
||||
public string Text
|
||||
public List<string> Lines
|
||||
{
|
||||
get; set;
|
||||
get; private set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -67,7 +67,7 @@ namespace RainmeterStudio.Documents.Text
|
||||
/// </summary>
|
||||
public TextDocument()
|
||||
{
|
||||
Text = String.Empty;
|
||||
Lines = new List<string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
25
RainmeterStudio/Documents/Text/TextDocumentTemplate.cs
Normal file
25
RainmeterStudio/Documents/Text/TextDocumentTemplate.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using RainmeterStudio.Model;
|
||||
|
||||
namespace RainmeterStudio.Documents.Text
|
||||
{
|
||||
/// <summary>
|
||||
/// A blank text document template
|
||||
/// </summary>
|
||||
[AutoRegister]
|
||||
public class TextDocumentTemplate : DocumentTemplate
|
||||
{
|
||||
public TextDocumentTemplate()
|
||||
: base("TextDocument", "txt")
|
||||
{
|
||||
}
|
||||
|
||||
public override IDocument CreateDocument()
|
||||
{
|
||||
return new TextDocument();
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
@ -18,10 +18,14 @@ namespace RainmeterStudio.Documents.Text
|
||||
_control = new TextEditorControl(document);
|
||||
}
|
||||
|
||||
public override IDocument Document { get { return _document; } }
|
||||
public IDocument AttachedDocument
|
||||
{
|
||||
get { return _document; }
|
||||
}
|
||||
|
||||
public override string Title { get { return _document.Name; } }
|
||||
|
||||
public override System.Windows.UIElement EditorUI { get { return _control; } }
|
||||
}*/
|
||||
public System.Windows.UIElement EditorUI
|
||||
{
|
||||
get { return _control; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ namespace RainmeterStudio.Documents.Text
|
||||
InitializeComponent();
|
||||
|
||||
_document = document;
|
||||
text.Text = document.Text;
|
||||
text.Text = document.Lines.Aggregate((a, b) => a + "\n" + b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,51 +8,17 @@ using RainmeterStudio.Model;
|
||||
|
||||
namespace RainmeterStudio.Documents.Text
|
||||
{
|
||||
/*public class TextEditorFactory : IDocumentEditorFactory
|
||||
[AutoRegister]
|
||||
public class TextEditorFactory : IDocumentEditorFactory
|
||||
{
|
||||
private TextStorage _storage = new TextStorage();
|
||||
|
||||
/// <inheritdoc />
|
||||
public string EditorName
|
||||
{
|
||||
get { return Resources.Strings.DocumentEditor_Text_Name; }
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<DocumentTemplate> CreateDocumentFormats
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return new DocumentTemplate()
|
||||
{
|
||||
Name = Resources.Strings.DocumentFormat_TextFile_Name,
|
||||
Category = Resources.Strings.Category_Utility,
|
||||
DefaultExtension = ".txt",
|
||||
Description = Resources.Strings.DocumentFormat_TextFile_Description,
|
||||
Icon = new System.Windows.Media.Imaging.BitmapImage(new Uri(Resources.Icons.DocumentTemplate_Text, UriKind.RelativeOrAbsolute)),
|
||||
Factory = this
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public IDocumentEditor CreateEditor(IDocument document)
|
||||
{
|
||||
TextDocument textDocument = document as TextDocument;
|
||||
|
||||
if (textDocument == null)
|
||||
throw new ArgumentException("Cannot edit provided document.");
|
||||
|
||||
return new TextEditor(textDocument);
|
||||
return new TextEditor((TextDocument)document);
|
||||
}
|
||||
|
||||
public IDocumentStorage Storage { get { return _storage; } }
|
||||
|
||||
public IDocument CreateDocument(DocumentTemplate format, string path)
|
||||
public bool CanEdit(Type type)
|
||||
{
|
||||
var document = new TextDocument();
|
||||
document.FilePath = path;
|
||||
|
||||
return document;
|
||||
return type.Equals(typeof(TextDocument));
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,8 @@ namespace RainmeterStudio.Documents.Text
|
||||
{
|
||||
/// <summary>
|
||||
/// Storage for text files
|
||||
/// </summary>
|
||||
/// </summary>
|
||||
[AutoRegister]
|
||||
public class TextStorage : IDocumentStorage
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@ -15,7 +16,7 @@ namespace RainmeterStudio.Documents.Text
|
||||
TextDocument document = new TextDocument();
|
||||
document.Reference.Path = path;
|
||||
document.Reference.Name = Path.GetFileName(path);
|
||||
document.Text = File.ReadAllText(path);
|
||||
document.Lines.AddRange(File.ReadAllLines(path));
|
||||
|
||||
return document;
|
||||
}
|
||||
@ -28,7 +29,7 @@ namespace RainmeterStudio.Documents.Text
|
||||
if (textDocument == null)
|
||||
throw new ArgumentException("Provided document is not supported by this storage.");
|
||||
|
||||
File.WriteAllText(path, textDocument.Text);
|
||||
File.WriteAllLines(path, textDocument.Lines);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
Reference in New Issue
Block a user