mirror of
				https://github.com/chibicitiberiu/rainmeter-studio.git
				synced 2024-02-24 04:33:31 +00:00 
			
		
		
		
	Work on documents, separated UI from Main
This commit is contained in:
		
							
								
								
									
										44
									
								
								RainmeterStudio/UI/App.xaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								RainmeterStudio/UI/App.xaml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,44 @@
 | 
			
		||||
<Application x:Class="RainmeterStudio.UI.App"
 | 
			
		||||
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 | 
			
		||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
 | 
			
		||||
    <Application.Resources>
 | 
			
		||||
        <ResourceDictionary>
 | 
			
		||||
            <ResourceDictionary.MergedDictionaries>
 | 
			
		||||
                <ResourceDictionary Source="Styles/Common.xaml" />
 | 
			
		||||
            </ResourceDictionary.MergedDictionaries>
 | 
			
		||||
 | 
			
		||||
            <Style TargetType="ToolBar">
 | 
			
		||||
                <Setter Property="Background" Value="Transparent" />
 | 
			
		||||
            </Style>
 | 
			
		||||
            <Style TargetType="ToolBarTray">
 | 
			
		||||
                <Setter Property="Background" Value="Transparent" />
 | 
			
		||||
            </Style>
 | 
			
		||||
            
 | 
			
		||||
            <Style x:Key="CommandMenuItemStyle" TargetType="MenuItem">
 | 
			
		||||
                <Setter Property="Command" Value="{Binding}" />
 | 
			
		||||
                <Setter Property="Header" Value="{Binding DisplayText}" />
 | 
			
		||||
                <Setter Property="ToolTip" Value="{Binding ToolTip}" />
 | 
			
		||||
                <Setter Property="InputGestureText" Value="{Binding ShortcutText}" />
 | 
			
		||||
            </Style>
 | 
			
		||||
            
 | 
			
		||||
            <Style x:Key="CommandButtonStyle" TargetType="ButtonBase">
 | 
			
		||||
                <Setter Property="Command" Value="{Binding}" />
 | 
			
		||||
                <Setter Property="ToolTip" Value="{Binding ToolTip}" />
 | 
			
		||||
                <Style.Triggers>
 | 
			
		||||
                    <Trigger Property="IsEnabled" Value="False">
 | 
			
		||||
                        <Setter Property="Opacity" Value=".5" />
 | 
			
		||||
                    </Trigger>
 | 
			
		||||
                </Style.Triggers>
 | 
			
		||||
            </Style>
 | 
			
		||||
 | 
			
		||||
            <Style x:Key="CommandAutoHideButtonStyle" TargetType="ButtonBase" BasedOn="{StaticResource CommandButtonStyle}">
 | 
			
		||||
                <Style.Triggers>
 | 
			
		||||
                    <Trigger Property="IsEnabled" Value="False">
 | 
			
		||||
                        <Setter Property="Visibility" Value="Collapsed" />
 | 
			
		||||
                    </Trigger>
 | 
			
		||||
                </Style.Triggers>
 | 
			
		||||
            </Style>
 | 
			
		||||
 | 
			
		||||
        </ResourceDictionary>
 | 
			
		||||
    </Application.Resources>
 | 
			
		||||
</Application>
 | 
			
		||||
							
								
								
									
										22
									
								
								RainmeterStudio/UI/App.xaml.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								RainmeterStudio/UI/App.xaml.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Configuration;
 | 
			
		||||
using System.Data;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Windows;
 | 
			
		||||
using RainmeterStudio.Business;
 | 
			
		||||
using RainmeterStudio.Documents.Text;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.UI
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Interaction logic for App.xaml
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public partial class App : Application
 | 
			
		||||
    {
 | 
			
		||||
        public App()
 | 
			
		||||
        {
 | 
			
		||||
            InitializeComponent();   
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -9,6 +9,7 @@ using RainmeterStudio.Model;
 | 
			
		||||
using System.Windows;
 | 
			
		||||
using System.Windows.Input;
 | 
			
		||||
using System.Windows.Media.Imaging;
 | 
			
		||||
using RainmeterStudio.Documents;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.UI.Controller
 | 
			
		||||
{
 | 
			
		||||
@@ -34,18 +35,23 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Triggered when a document is opened
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public event EventHandler<DocumentOpenedEventArgs> DocumentOpened
 | 
			
		||||
        {
 | 
			
		||||
            add
 | 
			
		||||
            {
 | 
			
		||||
                DocumentManager.DocumentOpened += value;
 | 
			
		||||
            }
 | 
			
		||||
            remove
 | 
			
		||||
            {
 | 
			
		||||
                DocumentManager.DocumentOpened -= value;
 | 
			
		||||
            }
 | 
			
		||||
            add { DocumentManager.DocumentOpened += value; }
 | 
			
		||||
            remove { DocumentManager.DocumentOpened -= value; }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Triggered when a document is closed
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public event EventHandler<DocumentClosedEventArgs> DocumentClosed
 | 
			
		||||
        {
 | 
			
		||||
            add { DocumentManager.DocumentClosed += value; }
 | 
			
		||||
            remove { DocumentManager.DocumentClosed -= value; }
 | 
			
		||||
        }
 | 
			
		||||
        public event EventHandler DocumentClosed;
 | 
			
		||||
 | 
			
		||||
        public Window OwnerWindow { get; set; }
 | 
			
		||||
 | 
			
		||||
@@ -63,7 +69,7 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
            var dialog = new CreateDocumentDialog()
 | 
			
		||||
            {
 | 
			
		||||
                Owner = OwnerWindow,
 | 
			
		||||
                SelectedFormat = defaultFormat,
 | 
			
		||||
                SelectedTemplate = defaultFormat,
 | 
			
		||||
                SelectedPath = defaultPath
 | 
			
		||||
            };
 | 
			
		||||
            bool? res = dialog.ShowDialog();
 | 
			
		||||
@@ -71,7 +77,7 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
            if (!res.HasValue || !res.Value)
 | 
			
		||||
                return;
 | 
			
		||||
 | 
			
		||||
            var format = dialog.SelectedFormat;
 | 
			
		||||
            var format = dialog.SelectedTemplate;
 | 
			
		||||
            var path = dialog.SelectedPath;
 | 
			
		||||
 | 
			
		||||
            // Call manager
 | 
			
		||||
 
 | 
			
		||||
@@ -12,6 +12,7 @@ using System.Windows.Media;
 | 
			
		||||
using System.Windows.Media.Imaging;
 | 
			
		||||
using System.Windows.Shapes;
 | 
			
		||||
using RainmeterStudio.Business;
 | 
			
		||||
using RainmeterStudio.Documents;
 | 
			
		||||
using RainmeterStudio.Model;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.UI.Dialogs
 | 
			
		||||
@@ -24,7 +25,7 @@ namespace RainmeterStudio.UI.Dialogs
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the currently selected file format
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public DocumentTemplate SelectedFormat
 | 
			
		||||
        public DocumentTemplate SelectedTemplate
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
 
 | 
			
		||||
@@ -12,6 +12,7 @@ using System.Windows.Media;
 | 
			
		||||
using System.Windows.Media.Imaging;
 | 
			
		||||
using System.Windows.Shapes;
 | 
			
		||||
using RainmeterStudio.Business;
 | 
			
		||||
using RainmeterStudio.Documents;
 | 
			
		||||
using RainmeterStudio.Model;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.UI.Dialogs
 | 
			
		||||
 
 | 
			
		||||
@@ -27,26 +27,21 @@ namespace RainmeterStudio.UI
 | 
			
		||||
        public DocumentController DocumentController { get; set; }
 | 
			
		||||
        public ProjectController ProjectController { get; set; }
 | 
			
		||||
 | 
			
		||||
        public MainWindow()
 | 
			
		||||
        public MainWindow(ProjectController projCtrl, DocumentController docCtrl)
 | 
			
		||||
        {
 | 
			
		||||
            InitializeComponent();
 | 
			
		||||
 | 
			
		||||
            this.DataContext = this;
 | 
			
		||||
            // Set fields
 | 
			
		||||
            DataContext = this;
 | 
			
		||||
            DocumentController = docCtrl;
 | 
			
		||||
            ProjectController = projCtrl;
 | 
			
		||||
 | 
			
		||||
            // Initialize project controller
 | 
			
		||||
            // TODO: put this in main
 | 
			
		||||
            ProjectStorage projectStorage = new ProjectStorage();
 | 
			
		||||
            ProjectManager projectManager = new ProjectManager(projectStorage);
 | 
			
		||||
            ProjectController = new Controller.ProjectController(projectManager);
 | 
			
		||||
            ProjectController.OwnerWindow = this;
 | 
			
		||||
            // Add key bindings
 | 
			
		||||
            this.AddKeyBinding(ProjectController.ProjectCreateCommand);
 | 
			
		||||
            
 | 
			
		||||
            // Initialize document controller
 | 
			
		||||
            DocumentManager documentManager = new DocumentManager();
 | 
			
		||||
            DocumentController = new DocumentController(documentManager, projectManager);
 | 
			
		||||
            DocumentController.OwnerWindow = this;
 | 
			
		||||
            DocumentController.DocumentOpened += documentController_DocumentOpened;
 | 
			
		||||
            this.AddKeyBinding(DocumentController.DocumentCreateCommand);
 | 
			
		||||
            
 | 
			
		||||
            // Subscribe to events
 | 
			
		||||
            DocumentController.DocumentOpened += documentController_DocumentOpened;
 | 
			
		||||
 | 
			
		||||
            // Initialize panels
 | 
			
		||||
            projectPanel.Controller = ProjectController;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										58
									
								
								RainmeterStudio/UI/UIManager.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								RainmeterStudio/UI/UIManager.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,58 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using RainmeterStudio.Business;
 | 
			
		||||
using RainmeterStudio.UI.Controller;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.UI
 | 
			
		||||
{
 | 
			
		||||
    public class UIManager
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the WPF app
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        protected App App {get; private set;}
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the project manager
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        protected ProjectManager ProjectManager { get; private set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the document manager
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        protected DocumentManager DocumentManager { get; private set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes the UI manager
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="projectManager">Project manager</param>
 | 
			
		||||
        /// <param name="documentManager">Document manager</param>
 | 
			
		||||
        public UIManager(ProjectManager projectManager, DocumentManager documentManager)
 | 
			
		||||
        {
 | 
			
		||||
            App = new UI.App();
 | 
			
		||||
            ProjectManager = projectManager;
 | 
			
		||||
            DocumentManager = documentManager;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Runs the UI thread
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public void Run()
 | 
			
		||||
        {
 | 
			
		||||
            // Create controllers
 | 
			
		||||
            ProjectController projectController = new ProjectController(ProjectManager);
 | 
			
		||||
            DocumentController documentController = new DocumentController(DocumentManager, ProjectManager);
 | 
			
		||||
 | 
			
		||||
            // Create and set up main window
 | 
			
		||||
            MainWindow mainWindow = new MainWindow(projectController, documentController);
 | 
			
		||||
            projectController.OwnerWindow = mainWindow;
 | 
			
		||||
            documentController.OwnerWindow = mainWindow;
 | 
			
		||||
            mainWindow.Show();
 | 
			
		||||
 | 
			
		||||
            // Run app
 | 
			
		||||
            App.Run();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Windows.Media;
 | 
			
		||||
using RainmeterStudio.Documents;
 | 
			
		||||
using RainmeterStudio.Model;
 | 
			
		||||
using RainmeterStudio.UI.Controller;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user