Work on project editor

This commit is contained in:
2014-09-12 13:19:01 +03:00
parent b6d8730783
commit 51e0b0d612
16 changed files with 354 additions and 127 deletions

View File

@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RainmeterStudio.Core.Model;
namespace RainmeterStudio.Editor.ProjectEditor
{
/// <summary>
/// A project document
/// </summary>
/// <remarks>Unlike the Project class, this class implements the 'IDocument'
/// interface. This is a proxy class for the actual project.</remarks>
public class ProjectDocument : IDocument
{
private Reference _reference;
private bool _isDirty = false;
/// <summary>
/// Gets or sets the reference of the document
/// </summary>
public Reference Reference
{
get
{
return _reference;
}
set
{
_reference = value;
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("Reference"));
}
}
/// <inheritdoc />
public bool IsDirty
{
get
{
return _isDirty;
}
set
{
_isDirty = value;
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("IsDirty"));
}
}
/// <summary>
/// Gets the project this project document is linked to
/// </summary>
public Project Project { get; private set; }
/// <summary>
/// Event triggered when a property changes value
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Initializes this project document
/// </summary>
/// <param name="project">The actual project this document is linked to</param>
public ProjectDocument(Project project)
{
Project = project;
}
}
}

View File

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RainmeterStudio.Core;
using RainmeterStudio.Core.Documents;
using RainmeterStudio.Core.Model;
namespace RainmeterStudio.Editor.ProjectEditor
{
/// <summary>
/// Project editor factory
/// </summary>
[PluginExport]
public class ProjectEditorFactory : IDocumentEditorFactory
{
/// <summary>
/// Creates a new project editor
/// </summary>
/// <param name="document">The project document</param>
/// <returns>Created editor</returns>
public IDocumentEditor CreateEditor(IDocument document)
{
return new ProjectEditorUI((ProjectDocument)document);
}
/// <summary>
/// Checks if this editor can edit documents of given type
/// </summary>
/// <param name="type">Type</param>
/// <returns>True if the project editor can edit that kind of document</returns>
public bool CanEdit(Type type)
{
return (type.Equals(typeof(ProjectDocument)));
}
}
}

View File

@ -0,0 +1,31 @@
<UserControl x:Class="RainmeterStudio.Editor.ProjectEditor.ProjectEditorUI"
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"
xmlns:r="clr-namespace:RainmeterStudio.Resources"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<ScrollViewer VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Disabled">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0">Name:</TextBlock>
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Name, Mode=TwoWay}" />
<TextBlock Grid.Row="1" Grid.Column="0">Author:</TextBlock>
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Author, Mode=TwoWay}" />
</Grid>
</ScrollViewer>
</UserControl>

View File

@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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;
using RainmeterStudio.Core.Documents;
using RainmeterStudio.Core.Model;
namespace RainmeterStudio.Editor.ProjectEditor
{
/// <summary>
/// Interaction logic for ProjectEditorUI.xaml
/// </summary>
public partial class ProjectEditorUI : UserControl, IDocumentEditor
{
/// <summary>
/// Gets the attached project document being edited
/// </summary>
public ProjectDocument Document { get; private set; }
/// <summary>
/// Gets the attached document
/// </summary>
public IDocument AttachedDocument
{
get { return Document; }
}
/// <summary>
/// Gets the UI element to be displayed in the document window
/// </summary>
public UIElement EditorUI
{
get { return this; }
}
/// <summary>
/// Initializes this project editor UI
/// </summary>
/// <param name="document"></param>
public ProjectEditorUI(ProjectDocument document)
{
InitializeComponent();
Document = document;
Document.Project.PropertyChanged += Project_PropertyChanged;
DataContext = Document.Project;
}
private void Project_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
Document.IsDirty = true;
}
}
}