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()
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -24,11 +24,11 @@ namespace RainmeterStudio.UI.Dialogs
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the currently selected file format
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public DocumentFormat SelectedFormat
 | 
			
		||||
        public DocumentTemplate SelectedFormat
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return listFormats.SelectedItem as DocumentFormat;
 | 
			
		||||
                return listFormats.SelectedItem as DocumentTemplate;
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										102
									
								
								RainmeterStudio/UI/Dialogs/CreateProjectDialog.xaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										102
									
								
								RainmeterStudio/UI/Dialogs/CreateProjectDialog.xaml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,102 @@
 | 
			
		||||
<Window x:Class="RainmeterStudio.UI.Dialogs.CreateProjectDialog"
 | 
			
		||||
        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">
 | 
			
		||||
 | 
			
		||||
    <Grid Background="WhiteSmoke">
 | 
			
		||||
        <Grid.RowDefinitions>
 | 
			
		||||
            <RowDefinition />
 | 
			
		||||
            <RowDefinition Height="Auto" />
 | 
			
		||||
            <RowDefinition Height="Auto" />
 | 
			
		||||
        </Grid.RowDefinitions>
 | 
			
		||||
 | 
			
		||||
        <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>
 | 
			
		||||
                    <DockPanel>
 | 
			
		||||
                        <Image DockPanel.Dock="Left" Source="{Binding Icon}" 
 | 
			
		||||
                               Width="32" Height="32" Margin="2"
 | 
			
		||||
                               Stretch="Uniform" VerticalAlignment="Top" />
 | 
			
		||||
                        <StackPanel Orientation="Vertical" VerticalAlignment="Center">
 | 
			
		||||
                            <TextBlock Text="{Binding Name}" FontWeight="Bold" />
 | 
			
		||||
                            <TextBlock Text="{Binding Description}" />
 | 
			
		||||
                        </StackPanel>
 | 
			
		||||
                    </DockPanel>
 | 
			
		||||
                </DataTemplate>
 | 
			
		||||
            </ListView.ItemTemplate>
 | 
			
		||||
            <ListView.GroupStyle>
 | 
			
		||||
                <GroupStyle>
 | 
			
		||||
                    <GroupStyle.HeaderTemplate>
 | 
			
		||||
                        <DataTemplate>
 | 
			
		||||
                            <TextBlock FontWeight="Bold" FontSize="13pt" Text="{Binding Name}" />
 | 
			
		||||
                        </DataTemplate>
 | 
			
		||||
                    </GroupStyle.HeaderTemplate>
 | 
			
		||||
                </GroupStyle>
 | 
			
		||||
            </ListView.GroupStyle>
 | 
			
		||||
        </ListView>
 | 
			
		||||
 | 
			
		||||
        <Grid Grid.Row="1">
 | 
			
		||||
            <Grid.RowDefinitions>
 | 
			
		||||
                <RowDefinition />
 | 
			
		||||
                <RowDefinition />
 | 
			
		||||
                <RowDefinition />
 | 
			
		||||
                <RowDefinition />
 | 
			
		||||
            </Grid.RowDefinitions>
 | 
			
		||||
            <Grid.ColumnDefinitions>
 | 
			
		||||
                <ColumnDefinition Width="Auto" />
 | 
			
		||||
                <ColumnDefinition />
 | 
			
		||||
                <ColumnDefinition Width="Auto" />
 | 
			
		||||
                <ColumnDefinition Width="Auto" />
 | 
			
		||||
            </Grid.ColumnDefinitions>
 | 
			
		||||
 | 
			
		||||
            <!-- Name -->
 | 
			
		||||
            <TextBlock Grid.Row="0" Text="{x:Static r:Strings.ProjectCreateDialog_Name}" />
 | 
			
		||||
 | 
			
		||||
            <TextBox Name="textName" 
 | 
			
		||||
                     Grid.Row="0" Grid.Column="1"
 | 
			
		||||
                     TextChanged="textName_TextChanged"/>
 | 
			
		||||
            
 | 
			
		||||
            <!-- Location -->
 | 
			
		||||
            <TextBlock Grid.Row="1" Text="{x:Static r:Strings.ProjectCreateDialog_Location}" />
 | 
			
		||||
            <ComboBox Name="textLocation" IsEditable="True"
 | 
			
		||||
                      Grid.Row="1" Grid.Column="1" />
 | 
			
		||||
            <Button Grid.Row="1" Grid.Column="2" Content="{x:Static r:Strings.Dialog_Browse}"/>
 | 
			
		||||
            <CheckBox Name="checkLocationDefault" 
 | 
			
		||||
                      Grid.Row="1" Grid.Column="3" 
 | 
			
		||||
                      Content="{x:Static r:Strings.ProjectCreateDialog_LocationDefault}" 
 | 
			
		||||
                      VerticalAlignment="Center"/>
 | 
			
		||||
 | 
			
		||||
            <!-- Path -->
 | 
			
		||||
            <TextBlock Grid.Row="2" Text="{x:Static r:Strings.ProjectCreateDialog_Path}"/>
 | 
			
		||||
            <ComboBox Name="textPath" 
 | 
			
		||||
                      IsEditable="True"
 | 
			
		||||
                     Grid.Row="2" Grid.Column="1" />
 | 
			
		||||
            <Button Grid.Row="2" Grid.Column="2" Content="{x:Static r:Strings.Dialog_Browse}" />
 | 
			
		||||
            <CheckBox Name="checkCreateDirectory" 
 | 
			
		||||
                      Grid.Row="2" Grid.Column="3" 
 | 
			
		||||
                      Content="{x:Static r:Strings.ProjectCreateDialog_PathCreateFolder}"
 | 
			
		||||
                      IsChecked="True"
 | 
			
		||||
                      Checked="checkCreateDirectory_CheckChanged"
 | 
			
		||||
                      Unchecked="checkCreateDirectory_CheckChanged"
 | 
			
		||||
                      VerticalAlignment="Center"/>
 | 
			
		||||
 | 
			
		||||
        </Grid>
 | 
			
		||||
 | 
			
		||||
        <StackPanel Grid.Row="2" Orientation="Horizontal"
 | 
			
		||||
                    HorizontalAlignment="Right">
 | 
			
		||||
            <Button Command="{Binding CreateCommand}" IsDefault="True" Content="{x:Static r:Strings.Dialog_Create}" />
 | 
			
		||||
            <Button Command="{Binding CancelCommand}" IsCancel="True" Content="{x:Static r:Strings.Dialog_Cancel}" />
 | 
			
		||||
        </StackPanel>
 | 
			
		||||
 | 
			
		||||
    </Grid>
 | 
			
		||||
</Window>
 | 
			
		||||
							
								
								
									
										207
									
								
								RainmeterStudio/UI/Dialogs/CreateProjectDialog.xaml.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										207
									
								
								RainmeterStudio/UI/Dialogs/CreateProjectDialog.xaml.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,207 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Windows;
 | 
			
		||||
using System.Windows.Controls;
 | 
			
		||||
using System.Windows.Controls.Primitives;
 | 
			
		||||
using System.Windows.Data;
 | 
			
		||||
using System.Windows.Documents;
 | 
			
		||||
using System.Windows.Input;
 | 
			
		||||
using System.Windows.Media;
 | 
			
		||||
using System.Windows.Media.Imaging;
 | 
			
		||||
using System.Windows.Shapes;
 | 
			
		||||
using RainmeterStudio.Business;
 | 
			
		||||
using RainmeterStudio.Model;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.UI.Dialogs
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Interaction logic for CreateProjectDialog.xaml
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public partial class CreateProjectDialog : Window
 | 
			
		||||
    {
 | 
			
		||||
        #region Commands
 | 
			
		||||
 | 
			
		||||
        private Command _createCommand;
 | 
			
		||||
        public Command CreateCommand
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                if (_createCommand == null)
 | 
			
		||||
                    _createCommand = new Command("CreateCommand", Create, Validate);
 | 
			
		||||
 | 
			
		||||
                return _createCommand;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private Command _cancelCommand;
 | 
			
		||||
        public Command CancelCommand
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                if (_cancelCommand == null)
 | 
			
		||||
                    _cancelCommand = new Command("CancelCommand", Cancel);
 | 
			
		||||
 | 
			
		||||
                return _cancelCommand;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        #region Properties
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the currently selected file format
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public DocumentTemplate SelectedTemplate
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return listTemplates.SelectedItem as DocumentTemplate;
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                listTemplates.SelectedItem = value;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the path
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string SelectedName
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return textName.Text;
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                textName.Text = value;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the path
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string SelectedLocation
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return textLocation.Text;
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                textLocation.Text = value;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the path
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string SelectedPath
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return textPath.Text;
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                textPath.Text = value;
 | 
			
		||||
                _pathUserSet = true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        #region Private fields
 | 
			
		||||
 | 
			
		||||
        private bool _pathUserSet = false;
 | 
			
		||||
        private bool _ignoreNextChange = false;
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        public CreateProjectDialog()
 | 
			
		||||
        {
 | 
			
		||||
            InitializeComponent();
 | 
			
		||||
 | 
			
		||||
            textLocation.AddHandler(TextBoxBase.TextChangedEvent, new TextChangedEventHandler(textLocation_TextChanged));
 | 
			
		||||
            textPath.AddHandler(TextBoxBase.TextChangedEvent, new TextChangedEventHandler(textPath_TextChanged));
 | 
			
		||||
 | 
			
		||||
            DataContext = this;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void Create()
 | 
			
		||||
        {
 | 
			
		||||
            DialogResult = true;
 | 
			
		||||
            Close();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void Cancel()
 | 
			
		||||
        {
 | 
			
		||||
            DialogResult = false;
 | 
			
		||||
            Close();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private bool Validate()
 | 
			
		||||
        {
 | 
			
		||||
            bool res = true;
 | 
			
		||||
            res &= !String.IsNullOrWhiteSpace(textPath.Text);
 | 
			
		||||
            res &= (listTemplates.SelectedItem != null);
 | 
			
		||||
            return res;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void UpdatePath()
 | 
			
		||||
        {
 | 
			
		||||
            if (!_pathUserSet)
 | 
			
		||||
            {
 | 
			
		||||
                // Start with location
 | 
			
		||||
                string path = textLocation.Text;
 | 
			
		||||
 | 
			
		||||
                try
 | 
			
		||||
                {
 | 
			
		||||
                    // Combine with project directory
 | 
			
		||||
                    if (checkCreateDirectory.IsChecked.HasValue && checkCreateDirectory.IsChecked.Value)
 | 
			
		||||
                        path = System.IO.Path.Combine(path, textName.Text);
 | 
			
		||||
 | 
			
		||||
                    // Combine with project file name
 | 
			
		||||
                    path = System.IO.Path.Combine(path, textName.Text + ".rsproj");
 | 
			
		||||
 | 
			
		||||
                    // Set new value
 | 
			
		||||
                    _ignoreNextChange = true;
 | 
			
		||||
                    textPath.Text = path;
 | 
			
		||||
                }
 | 
			
		||||
                catch (ArgumentException)
 | 
			
		||||
                {
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void textName_TextChanged(object sender, TextChangedEventArgs e)
 | 
			
		||||
        {
 | 
			
		||||
            UpdatePath();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void textLocation_TextChanged(object sender, TextChangedEventArgs e)
 | 
			
		||||
        {
 | 
			
		||||
            UpdatePath();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void textPath_TextChanged(object sender, TextChangedEventArgs e)
 | 
			
		||||
        {
 | 
			
		||||
            if (_ignoreNextChange)
 | 
			
		||||
            {
 | 
			
		||||
                _ignoreNextChange = false;
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                _pathUserSet = true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void checkCreateDirectory_CheckChanged(object sender, RoutedEventArgs e)
 | 
			
		||||
        {
 | 
			
		||||
            UpdatePath();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -6,11 +6,27 @@
 | 
			
		||||
        xmlns:adlayout="clr-namespace:Xceed.Wpf.AvalonDock.Layout;assembly=Xceed.Wpf.AvalonDock"
 | 
			
		||||
        Title="Rainmeter Studio" Height="350" Width="525"
 | 
			
		||||
        ResizeMode="CanResizeWithGrip" >
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    <Window.Resources>
 | 
			
		||||
        
 | 
			
		||||
        <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="Button">
 | 
			
		||||
            <Setter Property="Command" Value="{Binding}" />
 | 
			
		||||
            <Setter Property="ToolTip" Value="{Binding Tooltip}" />
 | 
			
		||||
            <Setter Property="ContentTemplate">
 | 
			
		||||
                <Setter.Value>
 | 
			
		||||
                    <DataTemplate>
 | 
			
		||||
                        <Image Width="16" Height="16" Source="{Binding Icon}" />
 | 
			
		||||
                    </DataTemplate>
 | 
			
		||||
                </Setter.Value>
 | 
			
		||||
            </Setter>
 | 
			
		||||
        </Style>
 | 
			
		||||
    </Window.Resources>
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    <Grid>
 | 
			
		||||
        <Grid.RowDefinitions>
 | 
			
		||||
            <RowDefinition Height="Auto" />
 | 
			
		||||
@@ -27,19 +43,20 @@
 | 
			
		||||
        <Menu Grid.Row="0" Grid.ColumnSpan="10">
 | 
			
		||||
            <MenuItem Header="_File">
 | 
			
		||||
                <MenuItem Header="_New">
 | 
			
		||||
                    <MenuItem DataContext="{Binding DocumentCreateCommand}"
 | 
			
		||||
                              Command="{Binding}" Header="{Binding DisplayText}" ToolTip="{Binding Tooltip}"
 | 
			
		||||
                              InputGestureText="{Binding ShortcutText}">
 | 
			
		||||
                    <MenuItem DataContext="{Binding DocumentController.DocumentCreateCommand}"
 | 
			
		||||
                              Style="{StaticResource CommandMenuItemStyle}" >
 | 
			
		||||
                        <MenuItem.Icon>
 | 
			
		||||
                            <Image Source="{Binding Icon}" />
 | 
			
		||||
                        </MenuItem.Icon>
 | 
			
		||||
                    </MenuItem>
 | 
			
		||||
                    <MenuItem Header="_Project..." Command="{Binding DocumentCreateCommand}">
 | 
			
		||||
                    <MenuItem DataContext="{Binding ProjectController.ProjectCreateCommand}"
 | 
			
		||||
                              Style="{StaticResource CommandMenuItemStyle}">
 | 
			
		||||
                        <MenuItem.Icon>
 | 
			
		||||
                            <Image Source="/Resources/Icons/project_star_16.png" />
 | 
			
		||||
                            <Image Source="{Binding Icon}" />
 | 
			
		||||
                        </MenuItem.Icon>
 | 
			
		||||
                    </MenuItem>
 | 
			
		||||
                </MenuItem>
 | 
			
		||||
                <Separator />
 | 
			
		||||
                <MenuItem Header="_Open..." />
 | 
			
		||||
                <Separator />
 | 
			
		||||
                <MenuItem Header="_Close" />
 | 
			
		||||
@@ -59,10 +76,8 @@
 | 
			
		||||
                    <Image Width="16" Height="16" Source="/Resources/Icons/arrow_forward_16.png" />
 | 
			
		||||
                </Button>
 | 
			
		||||
                <Separator />
 | 
			
		||||
                <Button DataContext="{Binding DocumentCreateCommand}"
 | 
			
		||||
                        Command="{Binding}" ToolTip="{Binding Tooltip}">
 | 
			
		||||
                    <Image Source="{Binding Icon}" />
 | 
			
		||||
                </Button>
 | 
			
		||||
                <Button DataContext="{Binding DocumentController.DocumentCreateCommand}"
 | 
			
		||||
                        Style="{StaticResource CommandButtonStyle}" />
 | 
			
		||||
            </ToolBar>
 | 
			
		||||
        </ToolBarTray>
 | 
			
		||||
 | 
			
		||||
@@ -109,7 +124,7 @@
 | 
			
		||||
                         Width="64" Height="8" 
 | 
			
		||||
                         IsIndeterminate="True" 
 | 
			
		||||
                         Visibility="Collapsed" />
 | 
			
		||||
            
 | 
			
		||||
 | 
			
		||||
            <TextBlock Name="statusMessage">Ready</TextBlock>
 | 
			
		||||
        </StatusBar>
 | 
			
		||||
    </Grid>
 | 
			
		||||
 
 | 
			
		||||
@@ -11,7 +11,9 @@ using System.Windows.Media;
 | 
			
		||||
using System.Windows.Media.Imaging;
 | 
			
		||||
using System.Windows.Navigation;
 | 
			
		||||
using System.Windows.Shapes;
 | 
			
		||||
using RainmeterStudio.Business;
 | 
			
		||||
using RainmeterStudio.Model.Events;
 | 
			
		||||
using RainmeterStudio.Storage;
 | 
			
		||||
using RainmeterStudio.UI.Controller;
 | 
			
		||||
using Xceed.Wpf.AvalonDock.Layout;
 | 
			
		||||
 | 
			
		||||
@@ -22,9 +24,8 @@ namespace RainmeterStudio.UI
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public partial class MainWindow : Window
 | 
			
		||||
    {
 | 
			
		||||
        private DocumentController documentController;
 | 
			
		||||
 | 
			
		||||
        public Command DocumentCreateCommand { get { return documentController.DocumentCreateCommand; } }
 | 
			
		||||
        public DocumentController DocumentController { get; set; }
 | 
			
		||||
        public ProjectController ProjectController { get; set; }
 | 
			
		||||
 | 
			
		||||
        public MainWindow()
 | 
			
		||||
        {
 | 
			
		||||
@@ -32,10 +33,19 @@ namespace RainmeterStudio.UI
 | 
			
		||||
 | 
			
		||||
            this.DataContext = this;
 | 
			
		||||
 | 
			
		||||
            documentController = new DocumentController();
 | 
			
		||||
            documentController.OwnerWindow = this;
 | 
			
		||||
            documentController.DocumentOpened += documentController_DocumentOpened;
 | 
			
		||||
            AddKeyBinding(documentController.DocumentCreateCommand);
 | 
			
		||||
            // 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;
 | 
			
		||||
            AddKeyBinding(ProjectController.ProjectCreateCommand);
 | 
			
		||||
 | 
			
		||||
            // Initialize document controller
 | 
			
		||||
            DocumentController = new DocumentController();
 | 
			
		||||
            DocumentController.OwnerWindow = this;
 | 
			
		||||
            DocumentController.DocumentOpened += documentController_DocumentOpened;
 | 
			
		||||
            AddKeyBinding(DocumentController.DocumentCreateCommand);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void AddKeyBinding(Command c)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user