mirror of
				https://github.com/chibicitiberiu/rainmeter-studio.git
				synced 2024-02-24 04:33:31 +00:00 
			
		
		
		
	Implemented project manager
This commit is contained in:
		@@ -16,7 +16,25 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
    {
 | 
			
		||||
        #region Commands
 | 
			
		||||
 | 
			
		||||
        public Command DocumentCreateCommand { get; private set; }
 | 
			
		||||
        public Command _documentCreateCommand;
 | 
			
		||||
        public Command DocumentCreateCommand
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                if (_documentCreateCommand == null)
 | 
			
		||||
                {
 | 
			
		||||
                    _documentCreateCommand = new Command("DocumentCreateCommand", () => CreateWindow())
 | 
			
		||||
                    {
 | 
			
		||||
                        DisplayText = Resources.Strings.DocumentCreateCommand_DisplayText,
 | 
			
		||||
                        Tooltip = Resources.Strings.DocumentCreateCommand_ToolTip,
 | 
			
		||||
                        Icon = new BitmapImage(new Uri(Resources.Icons.DocumentCreateCommand_Icon, UriKind.RelativeOrAbsolute)),
 | 
			
		||||
                        Shortcut = new KeyGesture(Key.N, ModifierKeys.Control)
 | 
			
		||||
                    };
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                return _documentCreateCommand;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
@@ -37,16 +55,9 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
 | 
			
		||||
        public DocumentController()
 | 
			
		||||
        {
 | 
			
		||||
            DocumentCreateCommand = new Command("DocumentCreateCommand", () => CreateWindow())
 | 
			
		||||
            {
 | 
			
		||||
                DisplayText = Resources.Strings.DocumentCreateCommand_DisplayText,
 | 
			
		||||
                Tooltip = Resources.Strings.DocumentCreateCommand_ToolTip,
 | 
			
		||||
                Icon = new BitmapImage(new Uri("/Resources/Icons/page_white_star_16.png", UriKind.RelativeOrAbsolute)),
 | 
			
		||||
                Shortcut = new KeyGesture(Key.N, ModifierKeys.Control)
 | 
			
		||||
            };
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void CreateWindow(DocumentFormat defaultFormat = null, string defaultPath = "")
 | 
			
		||||
        public void CreateWindow(DocumentTemplate defaultFormat = null, string defaultPath = "")
 | 
			
		||||
        {
 | 
			
		||||
            // Show dialog
 | 
			
		||||
            var dialog = new CreateDocumentDialog()
 | 
			
		||||
@@ -67,7 +78,7 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
            DocumentManager.Instance.Create(format, path);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void Create(DocumentFormat format, string path)
 | 
			
		||||
        public void Create(DocumentTemplate format, string path)
 | 
			
		||||
        {
 | 
			
		||||
            // Call manager
 | 
			
		||||
            DocumentManager.Instance.Create(format, path);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										148
									
								
								RainmeterStudio/UI/Controller/ProjectController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										148
									
								
								RainmeterStudio/UI/Controller/ProjectController.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,148 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Windows;
 | 
			
		||||
using System.Windows.Input;
 | 
			
		||||
using System.Windows.Media.Imaging;
 | 
			
		||||
using RainmeterStudio.Business;
 | 
			
		||||
using RainmeterStudio.Model;
 | 
			
		||||
using RainmeterStudio.UI.Dialogs;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.UI.Controller
 | 
			
		||||
{
 | 
			
		||||
    public class ProjectController
 | 
			
		||||
    {
 | 
			
		||||
        #region Properties
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the project manager
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        protected ProjectManager Manager { get; private set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the owner window. Used for creating dialogs.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public Window OwnerWindow { get; set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the active project
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public Project ActiveProject
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return Manager.ActiveProject;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the active project path
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string ActiveProjectPath
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return Manager.ActiveProjectPath;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        #region Callbacks
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Called when a project is opened or the active project closes.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public event EventHandler ActiveProjectChanged
 | 
			
		||||
        {
 | 
			
		||||
            add
 | 
			
		||||
            {
 | 
			
		||||
                Manager.ActiveProjectChanged += value;
 | 
			
		||||
            }
 | 
			
		||||
            remove
 | 
			
		||||
            {
 | 
			
		||||
                Manager.ActiveProjectChanged -= value;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        #region Commands
 | 
			
		||||
 | 
			
		||||
        private Command _projectCreateCommand;
 | 
			
		||||
        public Command ProjectCreateCommand
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                if (_projectCreateCommand == null)
 | 
			
		||||
                {
 | 
			
		||||
                    _projectCreateCommand = new Command("ProjectCreateComand", () => CreateProject())
 | 
			
		||||
                    {
 | 
			
		||||
                        DisplayText = Resources.Strings.ProjectCreateCommand_DisplayText,
 | 
			
		||||
                        Tooltip = Resources.Strings.ProjectCreateCommand_ToolTip,
 | 
			
		||||
                        Icon = new BitmapImage(new Uri(Resources.Icons.ProjectCreateCommand_Icon, UriKind.RelativeOrAbsolute)),
 | 
			
		||||
                        Shortcut = new KeyGesture(Key.N, ModifierKeys.Control | ModifierKeys.Shift)
 | 
			
		||||
                    };
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                return _projectCreateCommand;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes the project controller
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="manager">Project manager</param>
 | 
			
		||||
        public ProjectController(ProjectManager manager)
 | 
			
		||||
        {
 | 
			
		||||
            Manager = manager;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Displays the 'create project' dialog and creates a new project
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public void CreateProject(string name = null, string path = null)
 | 
			
		||||
        {
 | 
			
		||||
            // Create dialog
 | 
			
		||||
            var dialog = new CreateProjectDialog();
 | 
			
		||||
            dialog.Owner = OwnerWindow;
 | 
			
		||||
            dialog.SelectedLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Rainmeter Studio Projects");
 | 
			
		||||
 | 
			
		||||
            if (name != null) 
 | 
			
		||||
                dialog.Name = name;
 | 
			
		||||
            
 | 
			
		||||
            if (path != null) 
 | 
			
		||||
                dialog.SelectedPath = path;
 | 
			
		||||
            
 | 
			
		||||
            // Display
 | 
			
		||||
            bool? res = dialog.ShowDialog();
 | 
			
		||||
            if (!res.HasValue || !res.Value)
 | 
			
		||||
                return;
 | 
			
		||||
 | 
			
		||||
            string selectedPath = dialog.SelectedPath;
 | 
			
		||||
 | 
			
		||||
            // Call manager
 | 
			
		||||
            Manager.CreateProject(name, selectedPath); // TODO
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Displays an 'open file' dialog and opens an existing project
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="path"></param>
 | 
			
		||||
        public void OpenProject(string path = null)
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Closes the active project
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public void CloseProject()
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user