mirror of
				https://github.com/chibicitiberiu/rainmeter-studio.git
				synced 2024-02-24 04:33:31 +00:00 
			
		
		
		
	Work on project editor
This commit is contained in:
		
							
								
								
									
										75
									
								
								RainmeterStudio/Editor/ProjectEditor/ProjectDocument.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										75
									
								
								RainmeterStudio/Editor/ProjectEditor/ProjectDocument.cs
									
									
									
									
									
										Normal 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;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										38
									
								
								RainmeterStudio/Editor/ProjectEditor/ProjectEditorFactory.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								RainmeterStudio/Editor/ProjectEditor/ProjectEditorFactory.cs
									
									
									
									
									
										Normal 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)));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										31
									
								
								RainmeterStudio/Editor/ProjectEditor/ProjectEditorUI.xaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								RainmeterStudio/Editor/ProjectEditor/ProjectEditorUI.xaml
									
									
									
									
									
										Normal 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>
 | 
			
		||||
							
								
								
									
										63
									
								
								RainmeterStudio/Editor/ProjectEditor/ProjectEditorUI.xaml.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								RainmeterStudio/Editor/ProjectEditor/ProjectEditorUI.xaml.cs
									
									
									
									
									
										Normal 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;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user