Work on document manager

This commit is contained in:
Tiberiu Chibici 2014-07-23 23:27:14 +03:00
parent 1cf00049d2
commit 50e6e27cd6
33 changed files with 1204 additions and 6 deletions

View File

@ -1,7 +1,8 @@
<Application x:Class="RainmeterEditor.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="UI/MainWindow.xaml">
StartupUri="UI/MainWindow.xaml"
Startup="Application_Startup">
<Application.Resources>
</Application.Resources>

View File

@ -4,6 +4,8 @@ using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using RainmeterEditor.Business;
using RainmeterEditor.Documents.Text;
namespace RainmeterEditor
{
@ -12,5 +14,9 @@ namespace RainmeterEditor
/// </summary>
public partial class App : Application
{
private void Application_Startup(object sender, StartupEventArgs e)
{
DocumentManager.Instance.RegisterEditorFactory(new TextEditorFactory());
}
}
}

View File

@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RainmeterEditor.Model;
using RainmeterEditor.Model.Events;
namespace RainmeterEditor.Business
{
public class DocumentManager
{
#region Singleton instance
private static DocumentManager _instance = null;
/// <summary>
/// Gets the instance of DocumentManager
/// </summary>
public static DocumentManager Instance
{
get
{
if (_instance == null)
_instance = new DocumentManager();
return _instance;
}
}
#endregion
private DocumentManager()
{
}
List<IDocumentEditorFactory> _factories = new List<IDocumentEditorFactory>();
List<IDocumentEditor> _editors = new List<IDocumentEditor>();
public event EventHandler<DocumentOpenedEventArgs> DocumentOpened;
/// <summary>
/// Registers a document editor factory
/// </summary>
/// <param name="factory">Document editor factory</param>
public void RegisterEditorFactory(IDocumentEditorFactory factory)
{
_factories.Add(factory);
}
/// <summary>
/// Creates a new document in the specified path, with the specified format, and opens it
/// </summary>
/// <param name="format"></param>
/// <param name="path"></param>
public void Create(DocumentFormat format, string path)
{
// Create document
var document = format.Factory.CreateDocument(format, path);
// Create editor
var editor = format.Factory.CreateEditor(document);
_editors.Add(editor);
// Trigger event
if (DocumentOpened != null)
DocumentOpened(this, new DocumentOpenedEventArgs(editor));
}
public IEnumerable<DocumentFormat> DocumentFormats
{
get
{
foreach (var f in _factories)
foreach (var df in f.CreateDocumentFormats)
yield return df;
}
}
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RainmeterEditor.Model;
namespace RainmeterEditor.Documents.Ini
{
/*public class IniDocument : IDocument
{
}*/
}

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RainmeterEditor.Model;
namespace RainmeterEditor.Documents.Ini
{
/*public class IniSkinDesigner : IDocumentEditor
{
public override IDocument Document
{
get { throw new NotImplementedException(); }
}
public override string Title
{
get { throw new NotImplementedException(); }
}
public override System.Windows.UIElement EditorUI
{
get { throw new NotImplementedException(); }
}
public override EventHandler SelectionChanged
{
get { throw new NotImplementedException(); }
}
}*/
}

View File

@ -0,0 +1,11 @@
<UserControl x:Class="RainmeterEditor.Documents.Ini.IniSkinDesignerControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
</Grid>
</UserControl>

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace RainmeterEditor.Documents.Ini
{
/// <summary>
/// Interaction logic for IniSkinDesignerControl.xaml
/// </summary>
public partial class IniSkinDesignerControl : UserControl
{
public IniSkinDesignerControl()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using RainmeterEditor.Model;
namespace RainmeterEditor.Documents.Ini
{
/*public class IniSkinDesignerFactory : IDocumentEditorFactory
{
}*/
}

View File

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using RainmeterEditor.Model;
namespace RainmeterEditor.Documents.Text
{
public class TextDocument : IDocument
{
public string Name
{
get
{
return Path.GetFileName(FilePath);
}
}
public string FilePath
{
get; set;
}
public string Text
{
get; set;
}
public TextDocument()
{
Text = String.Empty;
}
}
}

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using RainmeterEditor.Model;
namespace RainmeterEditor.Documents.Text
{
public class TextEditor : IDocumentEditor
{
private TextDocument _document;
private TextEditorControl _control;
public TextEditor(TextDocument document)
{
_document = document;
_control = new TextEditorControl(document);
}
public override IDocument Document { get { return _document; } }
public override string Title { get { return _document.Name; } }
public override System.Windows.UIElement EditorUI { get { return _control; } }
}
}

View File

@ -0,0 +1,11 @@
<UserControl x:Class="RainmeterEditor.Documents.Text.TextEditorControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<TextBox Name="text" AcceptsReturn="True" />
</Grid>
</UserControl>

View File

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace RainmeterEditor.Documents.Text
{
/// <summary>
/// Interaction logic for TextEditorControl.xaml
/// </summary>
public partial class TextEditorControl : UserControl
{
private TextDocument _document;
public TextEditorControl(TextDocument document)
{
InitializeComponent();
_document = document;
text.Text = document.Text;
}
}
}

View File

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using RainmeterEditor.Business;
using RainmeterEditor.Model;
namespace RainmeterEditor.Documents.Text
{
public class TextEditorFactory : IDocumentEditorFactory
{
private TextStorage _storage = new TextStorage();
/// <inheritdoc />
public string EditorName
{
get { return Resources.Strings.DocumentEditor_Text_Name; }
}
/// <inheritdoc />
public IEnumerable<DocumentFormat> CreateDocumentFormats
{
get
{
yield return new DocumentFormat()
{
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/text-x-generic-32.png", 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);
}
public IDocumentStorage Storage { get { return _storage; } }
public IDocument CreateDocument(DocumentFormat format, string path)
{
var document = new TextDocument();
document.FilePath = path;
return document;
}
}
}

View File

@ -0,0 +1,64 @@
using System;
using System.IO;
using RainmeterEditor.Model;
namespace RainmeterEditor.Documents.Text
{
/// <summary>
/// Storage for text files
/// </summary>
public class TextStorage : IDocumentStorage
{
/// <inheritdoc />
IDocument IDocumentStorage.Read(string path)
{
TextDocument document = new TextDocument();
document.FilePath = path;
document.Text = File.ReadAllText(path);
return document;
}
/// <inheritdoc />
public void Write(string path, IDocument document)
{
TextDocument textDocument = document as TextDocument;
if (textDocument == null)
throw new ArgumentException("Provided document is not supported by this storage.");
File.WriteAllText(path, textDocument.Text);
}
/// <inheritdoc />
public bool CanRead(string path)
{
// Open the file
FileStream file = File.OpenRead(path);
// Read a small chunk (1kb should be enough)
byte[] buffer = new byte[1024];
int read = file.Read(buffer, 0, buffer.Length);
// Close file
file.Close();
// Find 4 consecutive zero bytes
int cnt = 0;
for (int i = 0; i < read; i++)
{
// Count zero bytes
if (buffer[i] == 0)
++cnt;
else cnt = 0;
// Found > 4? Most likely binary file
if (cnt >= 4)
return false;
}
// Not found, probably text file
return true;
}
}
}

View File

@ -0,0 +1,14 @@
using System.Windows.Media;
namespace RainmeterEditor.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; }
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RainmeterEditor.Model.Events
{
public class DocumentOpenedEventArgs : EventArgs
{
public IDocumentEditor Editor { get; private set; }
public DocumentOpenedEventArgs(IDocumentEditor editor)
{
Editor = editor;
}
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RainmeterEditor.Model
{
public interface IDocument
{
string Name { get; }
string FilePath { get; }
}
}

View File

@ -0,0 +1,136 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
namespace RainmeterEditor.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
}
}

View File

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RainmeterEditor.Storage;
namespace RainmeterEditor.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; }
}
}

View File

@ -0,0 +1,26 @@
namespace RainmeterEditor.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);
}
}

View File

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RainmeterEditor.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;
}
}

View File

@ -69,13 +69,55 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Business\DocumentManager.cs" />
<Compile Include="Documents\Text\TextDocument.cs" />
<Compile Include="Documents\Text\TextEditorControl.xaml.cs">
<DependentUpon>TextEditorControl.xaml</DependentUpon>
</Compile>
<Compile Include="Documents\Text\TextStorage.cs" />
<Compile Include="Model\DocumentFormat.cs" />
<Compile Include="Model\IDocument.cs" />
<Compile Include="Model\IDocumentEditor.cs" />
<Compile Include="Model\IDocumentEditorFactory.cs" />
<Compile Include="Documents\Ini\IniDocument.cs" />
<Compile Include="Documents\Ini\IniSkinDesigner.cs" />
<Compile Include="Documents\Ini\IniSkinDesignerControl.xaml.cs">
<DependentUpon>IniSkinDesignerControl.xaml</DependentUpon>
</Compile>
<Compile Include="Documents\Ini\IniSkinDesignerFactory.cs" />
<Compile Include="Documents\Text\TextEditor.cs" />
<Compile Include="Documents\Text\TextEditorFactory.cs" />
<Compile Include="Interop\NativeLibrary.cs" />
<Compile Include="Model\Property.cs" />
<Compile Include="Model\RainmeterConfig.cs" />
<Compile Include="Rainmeter.cs" />
<Compile Include="Resources\Strings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Strings.resx</DependentUpon>
</Compile>
<Compile Include="Model\IDocumentStorage.cs" />
<Compile Include="Storage\SkinDirectory.cs" />
<Compile Include="UI\Dialogs\CreateDocumentDialog.xaml.cs">
<DependentUpon>CreateDocumentDialog.xaml</DependentUpon>
</Compile>
<Compile Include="UI\Controller\DocumentController.cs" />
<Compile Include="Model\Events\DocumentOpenedEventArgs.cs" />
<Compile Include="UI\SkinsPanel.xaml.cs">
<DependentUpon>SkinsPanel.xaml</DependentUpon>
</Compile>
<Page Include="Documents\Ini\IniSkinDesignerControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Documents\Text\TextEditorControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UI\Dialogs\CreateDocumentDialog.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UI\MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
@ -111,6 +153,10 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="Resources\Strings.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Strings.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="app.config" />
<None Include="LICENSE" />
<None Include="packages.config" />
@ -120,6 +166,12 @@
</None>
<AppDesigner Include="Properties\" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Icons\page_white_text.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Icons\text-x-generic-32.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

Binary file not shown.

After

Width:  |  Height:  |  Size: 342 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -0,0 +1,99 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.34014
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace RainmeterEditor.Resources {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Strings {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Strings() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("RainmeterEditor.Resources.Strings", typeof(Strings).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to Utility.
/// </summary>
internal static string Category_Utility {
get {
return ResourceManager.GetString("Category_Utility", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Text Editor.
/// </summary>
internal static string DocumentEditor_Text_Name {
get {
return ResourceManager.GetString("DocumentEditor_Text_Name", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Blank text file.
/// </summary>
internal static string DocumentFormat_TextFile_Description {
get {
return ResourceManager.GetString("DocumentFormat_TextFile_Description", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Text file.
/// </summary>
internal static string DocumentFormat_TextFile_Name {
get {
return ResourceManager.GetString("DocumentFormat_TextFile_Name", resourceCulture);
}
}
}
}

View File

@ -0,0 +1,132 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Category_Utility" xml:space="preserve">
<value>Utility</value>
</data>
<data name="DocumentEditor_Text_Name" xml:space="preserve">
<value>Text Editor</value>
</data>
<data name="DocumentFormat_TextFile_Description" xml:space="preserve">
<value>Blank text file</value>
</data>
<data name="DocumentFormat_TextFile_Name" xml:space="preserve">
<value>Text file</value>
</data>
</root>

View File

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RainmeterEditor.Business;
using RainmeterEditor.UI.Dialogs;
using RainmeterEditor.Model.Events;
using RainmeterEditor.Model;
namespace RainmeterEditor.UI.Controller
{
public class DocumentController
{
public event EventHandler<DocumentOpenedEventArgs> DocumentOpened
{
add
{
DocumentManager.Instance.DocumentOpened += value;
}
remove
{
DocumentManager.Instance.DocumentOpened -= value;
}
}
public event EventHandler DocumentClosed;
public DocumentController()
{
}
public void Create()
{
// Show dialog
var dialog = new CreateDocumentDialog();
bool? res = dialog.ShowDialog();
if (!res.HasValue || !res.Value)
return;
var format = dialog.SelectedFormat;
var path = dialog.SelectedPath;
// Call manager
DocumentManager.Instance.Create(format, path);
}
}
}

View File

@ -0,0 +1,61 @@
<Window x:Class="RainmeterEditor.UI.Dialogs.CreateDocumentDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="CreateDocumentDialog" Height="250" Width="400">
<Grid Background="WhiteSmoke">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ListView Name="listFormats" Grid.Row="0">
<ListView.ItemTemplate>
<DataTemplate>
<DockPanel>
<Image DockPanel.Dock="Left" Source="{Binding Icon}"
Width="32" Height="32" Margin="2"
Stretch="Uniform" VerticalAlignment="Top" />
<StackPanel Orientation="Vertical" VerticalAlignment="Center">
<TextBlock Text="{Binding Name}" FontWeight="Bold" />
<TextBlock Text="{Binding Description}" />
</StackPanel>
</DockPanel>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock FontWeight="Bold" FontSize="13pt" Text="{Binding Name}" />
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListView.GroupStyle>
</ListView>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0">Path:</TextBlock>
<TextBox Name="textPath" Grid.Row="0" Grid.Column="1"></TextBox>
<Button Grid.Row="0" Grid.Column="2">...</Button>
</Grid>
<StackPanel Grid.Row="2" Orientation="Horizontal"
HorizontalAlignment="Right">
<Button Name="buttonCreate" Click="buttonCreate_Click" IsDefault="True">Create</Button>
<Button Name="buttonCancel" Click="buttonCancel_Click" IsCancel="True">Cancel</Button>
</StackPanel>
</Grid>
</Window>

View File

@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using RainmeterEditor.Business;
using RainmeterEditor.Model;
namespace RainmeterEditor.UI.Dialogs
{
/// <summary>
/// Interaction logic for CreateDocumentDialog.xaml
/// </summary>
public partial class CreateDocumentDialog : Window
{
/// <summary>
/// Gets or sets the currently selected file format
/// </summary>
public DocumentFormat SelectedFormat
{
get
{
return listFormats.SelectedItem as DocumentFormat;
}
set
{
listFormats.SelectedItem = value;
}
}
/// <summary>
/// Gets or sets the path
/// </summary>
public string SelectedPath
{
get
{
return textPath.Text;
}
set
{
textPath.Text = value;
}
}
/// <summary>
/// Creates a new instance of CreateDocumentDialog
/// </summary>
public CreateDocumentDialog()
{
InitializeComponent();
PopulateFormats();
}
private void PopulateFormats()
{
listFormats.ItemsSource = DocumentManager.Instance.DocumentFormats;
CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(listFormats.ItemsSource);
view.GroupDescriptions.Add(new PropertyGroupDescription("Category"));
}
private void buttonCreate_Click(object sender, RoutedEventArgs e)
{
DialogResult = true;
Close();
}
private void buttonCancel_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
Close();
}
}
}

View File

@ -4,7 +4,7 @@
xmlns:ui="clr-namespace:RainmeterEditor.UI"
xmlns:ad="clr-namespace:Xceed.Wpf.AvalonDock;assembly=Xceed.Wpf.AvalonDock"
xmlns:adlayout="clr-namespace:Xceed.Wpf.AvalonDock.Layout;assembly=Xceed.Wpf.AvalonDock"
Title="MainWindow" Height="350" Width="525">
Title="Rainmeter Studio" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
@ -20,7 +20,7 @@
<!-- Menu bar -->
<Menu Grid.Row="0" Grid.ColumnSpan="10">
<MenuItem Header="_File">
<MenuItem Header="_New Item..." />
<MenuItem Header="_New Item..." Click="File_New_Click"/>
<MenuItem Header="_Open..." />
<Separator />
<MenuItem Header="_Close" />

View File

@ -11,6 +11,9 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using RainmeterEditor.Model.Events;
using RainmeterEditor.UI.Controller;
using Xceed.Wpf.AvalonDock.Layout;
namespace RainmeterEditor
{
@ -19,9 +22,46 @@ namespace RainmeterEditor
/// </summary>
public partial class MainWindow : Window
{
DocumentController documentController = new DocumentController();
public MainWindow()
{
InitializeComponent();
documentController.DocumentOpened += documentController_DocumentOpened;
}
void documentController_DocumentOpened(object sender, DocumentOpenedEventArgs e)
{
// Spawn a new window
LayoutDocument document = new LayoutDocument();
document.Content = e.Editor.EditorUI;
document.Title = e.Editor.Title;
document.Closing += document_Closing;
documentPane.Children.Add(document);
documentPane.SelectedContentIndex = documentPane.IndexOf(document);
}
void document_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
switch (MessageBox.Show("Are you sure?", "", MessageBoxButton.YesNoCancel, MessageBoxImage.Question))
{
case MessageBoxResult.Yes:
break;
case MessageBoxResult.No:
break;
default:
e.Cancel = true;
return;
}
}
private void File_New_Click(object sender, RoutedEventArgs e)
{
documentController.Create();
}
}
}

View File

@ -25,7 +25,7 @@ namespace RainmeterEditor.UI
{
InitializeComponent();
var x = Rainmeter.Instance.Handle;
//var x = Rainmeter.Instance.Handle;
}
}
}

View File

@ -72,7 +72,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PluginWin7Audio", "Plugins\
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PluginWindowMessage", "Plugins\PluginWindowMessage\PluginWindowMessage.vcxproj", "{B9184DBA-C6B7-44FE-8BBD-0852DB22D2E4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RainmeterEditor", "RainmeterEditor\RainmeterEditor.csproj", "{438D0136-4A27-4E4D-A617-FFACE4554236}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RainmeterStudio", "RainmeterEditor\RainmeterStudio.csproj", "{438D0136-4A27-4E4D-A617-FFACE4554236}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution