mirror of
				https://github.com/chibicitiberiu/rainmeter-studio.git
				synced 2024-02-24 04:33:31 +00:00 
			
		
		
		
	Work on document manager
This commit is contained in:
		@@ -14,21 +14,23 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
{
 | 
			
		||||
    public class DocumentController
 | 
			
		||||
    {
 | 
			
		||||
        #region Managers
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the document manager
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        protected DocumentManager DocumentManager { get; private set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the project manager
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        protected ProjectManager ProjectManager { get; private set; }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        #region Commands
 | 
			
		||||
 | 
			
		||||
        public Command _documentCreateCommand;
 | 
			
		||||
        public Command DocumentCreateCommand
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                if (_documentCreateCommand == null)
 | 
			
		||||
                {
 | 
			
		||||
                    _documentCreateCommand = new Command("DocumentCreateCommand", () => CreateWindow());
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                return _documentCreateCommand;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        public Command DocumentCreateCommand { get; private set; }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
@@ -36,19 +38,23 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
        {
 | 
			
		||||
            add
 | 
			
		||||
            {
 | 
			
		||||
                DocumentManager.Instance.DocumentOpened += value;
 | 
			
		||||
                DocumentManager.DocumentOpened += value;
 | 
			
		||||
            }
 | 
			
		||||
            remove
 | 
			
		||||
            {
 | 
			
		||||
                DocumentManager.Instance.DocumentOpened -= value;
 | 
			
		||||
                DocumentManager.DocumentOpened -= value;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        public event EventHandler DocumentClosed;
 | 
			
		||||
 | 
			
		||||
        public Window OwnerWindow { get; set; }
 | 
			
		||||
 | 
			
		||||
        public DocumentController()
 | 
			
		||||
        public DocumentController(DocumentManager documentManager, ProjectManager projectManager)
 | 
			
		||||
        {
 | 
			
		||||
            DocumentManager = documentManager;
 | 
			
		||||
            ProjectManager = projectManager;
 | 
			
		||||
 | 
			
		||||
            DocumentCreateCommand = new Command("DocumentCreateCommand", () => CreateWindow());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void CreateWindow(DocumentTemplate defaultFormat = null, string defaultPath = "")
 | 
			
		||||
@@ -69,13 +75,13 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
            var path = dialog.SelectedPath;
 | 
			
		||||
 | 
			
		||||
            // Call manager
 | 
			
		||||
            DocumentManager.Instance.Create(format, path);
 | 
			
		||||
            DocumentManager.Create(format);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void Create(DocumentTemplate format, string path)
 | 
			
		||||
        public void Create(DocumentTemplate format)
 | 
			
		||||
        {
 | 
			
		||||
            // Call manager
 | 
			
		||||
            DocumentManager.Instance.Create(format, path);
 | 
			
		||||
            DocumentManager.Create(format);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -64,7 +64,8 @@ namespace RainmeterStudio.UI.Dialogs
 | 
			
		||||
 | 
			
		||||
        private void PopulateFormats()
 | 
			
		||||
        {
 | 
			
		||||
            listFormats.ItemsSource = DocumentManager.Instance.DocumentFormats;
 | 
			
		||||
            //listFormats.ItemsSource = DocumentManager.Instance.DocumentFormats;
 | 
			
		||||
 | 
			
		||||
            CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(listFormats.ItemsSource);
 | 
			
		||||
            view.GroupDescriptions.Add(new PropertyGroupDescription("Category"));
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,6 @@
 | 
			
		||||
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 | 
			
		||||
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
        xmlns:r="clr-namespace:RainmeterStudio.Resources"
 | 
			
		||||
        xmlns:toremove="clr-namespace:RainmeterStudio.Model"
 | 
			
		||||
        Title="{x:Static r:Strings.ProjectCreateDialog_Title}" Height="320" Width="480"
 | 
			
		||||
        WindowStartupLocation="CenterOwner"
 | 
			
		||||
        WindowStyle="ToolWindow" ShowInTaskbar="False">
 | 
			
		||||
@@ -16,10 +15,6 @@
 | 
			
		||||
 | 
			
		||||
        <ListView Name="listTemplates" Grid.Row="0" SelectedIndex="0"
 | 
			
		||||
                  IsEnabled="False">
 | 
			
		||||
            <!-- TODO: remove -->
 | 
			
		||||
            <toremove:DocumentTemplate Name="Empty project" 
 | 
			
		||||
                                       Description="Create a new empty project" >
 | 
			
		||||
            </toremove:DocumentTemplate>
 | 
			
		||||
            
 | 
			
		||||
            <ListView.ItemTemplate>
 | 
			
		||||
                <DataTemplate>
 | 
			
		||||
 
 | 
			
		||||
@@ -42,7 +42,8 @@ namespace RainmeterStudio.UI
 | 
			
		||||
            this.AddKeyBinding(ProjectController.ProjectCreateCommand);
 | 
			
		||||
            
 | 
			
		||||
            // Initialize document controller
 | 
			
		||||
            DocumentController = new DocumentController();
 | 
			
		||||
            DocumentManager documentManager = new DocumentManager();
 | 
			
		||||
            DocumentController = new DocumentController(documentManager, projectManager);
 | 
			
		||||
            DocumentController.OwnerWindow = this;
 | 
			
		||||
            DocumentController.DocumentOpened += documentController_DocumentOpened;
 | 
			
		||||
            this.AddKeyBinding(DocumentController.DocumentCreateCommand);
 | 
			
		||||
@@ -56,7 +57,7 @@ namespace RainmeterStudio.UI
 | 
			
		||||
            // Spawn a new window
 | 
			
		||||
            LayoutDocument document = new LayoutDocument();
 | 
			
		||||
            document.Content = e.Editor.EditorUI;
 | 
			
		||||
            document.Title = e.Editor.Title;
 | 
			
		||||
            document.Title = e.Editor.AttachedDocument.Reference.Name;
 | 
			
		||||
            document.Closing += document_Closing;
 | 
			
		||||
 | 
			
		||||
            documentPane.Children.Add(document);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										128
									
								
								RainmeterStudio/UI/ViewModel/DocumentTemplateViewModel.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										128
									
								
								RainmeterStudio/UI/ViewModel/DocumentTemplateViewModel.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,128 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Windows.Media;
 | 
			
		||||
using RainmeterStudio.Model;
 | 
			
		||||
using RainmeterStudio.UI.Controller;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.UI.ViewModel
 | 
			
		||||
{
 | 
			
		||||
    public class DocumentTemplateViewModel
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the document template
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public DocumentTemplate Template { get; private set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the document template name
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string Name { get { return Template.Name; } }
 | 
			
		||||
 | 
			
		||||
        #region Icon property
 | 
			
		||||
 | 
			
		||||
        private ImageSource _icon = null;
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the icon of this document template
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public virtual ImageSource Icon
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                if (_icon == null)
 | 
			
		||||
                    return IconProvider.GetIcon("Template_" + Name);
 | 
			
		||||
 | 
			
		||||
                return _icon;
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                _icon = value;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        #region Display text property
 | 
			
		||||
 | 
			
		||||
        private string _displayText = null;
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the display text
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string DisplayText
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                if (_displayText == null)
 | 
			
		||||
                    return Resources.Strings.ResourceManager.GetString("Template_" + Name + "_DisplayText");
 | 
			
		||||
 | 
			
		||||
                return _displayText;
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                _displayText = value;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        #region Description property
 | 
			
		||||
 | 
			
		||||
        private string _description = null;
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the description of this document template
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string Description
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                if (_description == null)
 | 
			
		||||
                    return Resources.Strings.ResourceManager.GetString("Template_" + Name + "_Description");
 | 
			
		||||
 | 
			
		||||
                return _description;
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                _description = value;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        #region Category property
 | 
			
		||||
 | 
			
		||||
        private string _category = null;
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the category of this template
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string Category
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                if (_category == null)
 | 
			
		||||
                    return Resources.Strings.ResourceManager.GetString("Template_" + Name + "_Category");
 | 
			
		||||
 | 
			
		||||
                return _category;
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                _category = value;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes the document template view model
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="template">The document template</param>
 | 
			
		||||
        public DocumentTemplateViewModel(DocumentTemplate template)
 | 
			
		||||
        {
 | 
			
		||||
            this.Template = template;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user