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:
@ -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