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,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("RainmeterStudio.TextEditor")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RainmeterStudio.TextEditor")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("61e147ab-2bdd-4f7a-a610-60617d7e31d3")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9A644478-2F1B-4145-8B31-6F8DBD42EC38}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>RainmeterStudio.TextEditorPlugin</RootNamespace>
<AssemblyName>RainmeterStudio.TextEditorPlugin</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\Plugins\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\Plugins\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TextDocument.cs" />
<Compile Include="TextDocumentTemplate.cs" />
<Compile Include="TextEditor.cs" />
<Compile Include="TextEditorControl.xaml.cs">
<DependentUpon>TextEditorControl.xaml</DependentUpon>
</Compile>
<Compile Include="TextEditorFactory.cs" />
<Compile Include="TextStorage.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RainmeterStudio.Core\RainmeterStudio.Core.csproj">
<Project>{1d2a4896-af31-4e82-a84f-4e218067701f}</Project>
<Name>RainmeterStudio.Core</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Page Include="TextEditorControl.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</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.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.ComponentModel;
using RainmeterStudio.Core.Model;
namespace RainmeterStudio.TextEditorPlugin
{
public class TextDocument : IDocument
{
private Reference _reference;
private bool _isDirty;
/// <summary>
/// Gets or sets the text associated with this document
/// </summary>
public List<string> Lines
{
get; private 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()
{
Lines = new List<string>();
}
}
}

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RainmeterStudio.Core;
using RainmeterStudio.Core.Documents;
using RainmeterStudio.Core.Model;
namespace RainmeterStudio.TextEditorPlugin
{
/// <summary>
/// A blank text document template
/// </summary>
[PluginExport]
public class TextDocumentTemplate : DocumentTemplate
{
public TextDocumentTemplate()
: base("TextDocument", "txt")
{
}
public override IDocument CreateDocument()
{
return new TextDocument();
}
}
}

View File

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using RainmeterStudio.Core.Documents;
using RainmeterStudio.Core.Model;
namespace RainmeterStudio.TextEditorPlugin
{
public class TextEditor : IDocumentEditor
{
private TextDocument _document;
private TextEditorControl _control;
public TextEditor(TextDocument document)
{
_document = document;
_control = new TextEditorControl(document);
}
public IDocument AttachedDocument
{
get { return _document; }
}
public System.Windows.UIElement EditorUI
{
get { return _control; }
}
}
}

View File

@ -0,0 +1,11 @@
<UserControl x:Class="RainmeterStudio.TextEditorPlugin.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 RainmeterStudio.TextEditorPlugin
{
/// <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.Lines.Aggregate((a, b) => a + "\n" + b);
}
}
}

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using RainmeterStudio.Core;
using RainmeterStudio.Core.Documents;
using RainmeterStudio.Core.Model;
namespace RainmeterStudio.TextEditorPlugin
{
[PluginExport]
public class TextEditorFactory : IDocumentEditorFactory
{
public IDocumentEditor CreateEditor(IDocument document)
{
return new TextEditor((TextDocument)document);
}
public bool CanEdit(Type type)
{
return type.Equals(typeof(TextDocument));
}
}
}

View File

@ -0,0 +1,73 @@
using System;
using System.IO;
using RainmeterStudio.Core;
using RainmeterStudio.Core.Model;
using RainmeterStudio.Core.Storage;
namespace RainmeterStudio.TextEditorPlugin
{
/// <summary>
/// Storage for text files
/// </summary>
[PluginExport]
public class TextStorage : IDocumentStorage
{
/// <inheritdoc />
IDocument IDocumentStorage.Read(string path)
{
TextDocument document = new TextDocument();
document.Reference.Path = path;
document.Reference.Name = Path.GetFileName(path);
document.Lines.AddRange(File.ReadAllLines(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.WriteAllLines(path, textDocument.Lines);
}
/// <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;
}
public bool CanWrite(Type documentType)
{
return documentType.Equals(typeof(TextDocument));
}
}
}