mirror of
				https://github.com/chibicitiberiu/rainmeter-studio.git
				synced 2024-02-24 04:33:31 +00:00 
			
		
		
		
	Fixes for project manager
This commit is contained in:
		@@ -51,14 +51,14 @@ namespace RainmeterStudio.Business
 | 
				
			|||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        /// <param name="name">Name of project</param>
 | 
					        /// <param name="name">Name of project</param>
 | 
				
			||||||
        /// <param name="path">Path of project file</param>
 | 
					        /// <param name="path">Path of project file</param>
 | 
				
			||||||
        public void CreateProject(string name, string path)
 | 
					        public void CreateProject(string name, string path, IProjectTemplate template)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            // If there is an opened project, close it
 | 
					            // If there is an opened project, close it
 | 
				
			||||||
            if (ActiveProject != null)
 | 
					            if (ActiveProject != null)
 | 
				
			||||||
                Close();
 | 
					                Close();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Create project object
 | 
					            // Create project object
 | 
				
			||||||
            ActiveProject = new Project();
 | 
					            ActiveProject = template.CreateProject();
 | 
				
			||||||
            ActiveProject.Name = name;
 | 
					            ActiveProject.Name = name;
 | 
				
			||||||
            ActiveProject.Path = path;
 | 
					            ActiveProject.Path = path;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										6
									
								
								RainmeterStudio/Properties/Settings.Designer.cs
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										6
									
								
								RainmeterStudio/Properties/Settings.Designer.cs
									
									
									
										generated
									
									
									
								
							@@ -163,12 +163,12 @@ namespace RainmeterStudio.Properties {
 | 
				
			|||||||
        [global::System.Configuration.UserScopedSettingAttribute()]
 | 
					        [global::System.Configuration.UserScopedSettingAttribute()]
 | 
				
			||||||
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
 | 
					        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
 | 
				
			||||||
        [global::System.Configuration.DefaultSettingValueAttribute("")]
 | 
					        [global::System.Configuration.DefaultSettingValueAttribute("")]
 | 
				
			||||||
        public string CreateProjectDialog_SavedLocation {
 | 
					        public string Project_SavedLocation {
 | 
				
			||||||
            get {
 | 
					            get {
 | 
				
			||||||
                return ((string)(this["CreateProjectDialog_SavedLocation"]));
 | 
					                return ((string)(this["Project_SavedLocation"]));
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            set {
 | 
					            set {
 | 
				
			||||||
                this["CreateProjectDialog_SavedLocation"] = value;
 | 
					                this["Project_SavedLocation"] = value;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -35,7 +35,7 @@
 | 
				
			|||||||
    <Setting Name="CreateProjectDialog_RecentLocations" Type="System.String" Scope="User">
 | 
					    <Setting Name="CreateProjectDialog_RecentLocations" Type="System.String" Scope="User">
 | 
				
			||||||
      <Value Profile="(Default)" />
 | 
					      <Value Profile="(Default)" />
 | 
				
			||||||
    </Setting>
 | 
					    </Setting>
 | 
				
			||||||
    <Setting Name="CreateProjectDialog_SavedLocation" Type="System.String" Scope="User">
 | 
					    <Setting Name="Project_SavedLocation" Type="System.String" Scope="User">
 | 
				
			||||||
      <Value Profile="(Default)" />
 | 
					      <Value Profile="(Default)" />
 | 
				
			||||||
    </Setting>
 | 
					    </Setting>
 | 
				
			||||||
    <Setting Name="CreateProjectDialog_CreateDirectoryCheckbox" Type="System.Boolean" Scope="User">
 | 
					    <Setting Name="CreateProjectDialog_CreateDirectoryCheckbox" Type="System.Boolean" Scope="User">
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -31,6 +31,8 @@ namespace RainmeterStudio.UI.Controller
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        public Command DocumentCreateCommand { get; private set; }
 | 
					        public Command DocumentCreateCommand { get; private set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public Command DocumentOpenCommand { get; private set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        #endregion
 | 
					        #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
@@ -58,25 +60,22 @@ namespace RainmeterStudio.UI.Controller
 | 
				
			|||||||
            DocumentManager = documentManager;
 | 
					            DocumentManager = documentManager;
 | 
				
			||||||
            ProjectManager = projectManager;
 | 
					            ProjectManager = projectManager;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            DocumentCreateCommand = new Command("DocumentCreateCommand", () => CreateWindow());
 | 
					            DocumentCreateCommand = new Command("DocumentCreateCommand", () => Create(), () => ProjectManager.ActiveProject != null);
 | 
				
			||||||
 | 
					            ProjectManager.ActiveProjectChanged += new EventHandler((obj, e) => DocumentCreateCommand.NotifyCanExecuteChanged());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public void CreateWindow(IDocumentTemplate defaultFormat = null, string defaultPath = "")
 | 
					        public void Create()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            // Show dialog
 | 
					            // Show dialog
 | 
				
			||||||
            var dialog = new CreateDocumentDialog(this)
 | 
					            var dialog = new CreateDocumentDialog(this);
 | 
				
			||||||
            {
 | 
					            dialog.Owner = OwnerWindow;
 | 
				
			||||||
                Owner = OwnerWindow,
 | 
					 | 
				
			||||||
                SelectedTemplate = new DocumentTemplateViewModel(defaultFormat),
 | 
					 | 
				
			||||||
                SelectedPath = defaultPath
 | 
					 | 
				
			||||||
            };
 | 
					 | 
				
			||||||
            bool? res = dialog.ShowDialog();
 | 
					            bool? res = dialog.ShowDialog();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (!res.HasValue || !res.Value)
 | 
					            if (!res.HasValue || !res.Value)
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var format = dialog.SelectedTemplate;
 | 
					            var format = dialog.SelectedTemplate;
 | 
				
			||||||
            var path = dialog.SelectedPath;
 | 
					            var path = dialog.SelectedName;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Call manager
 | 
					            // Call manager
 | 
				
			||||||
            DocumentManager.Create(format.Template);
 | 
					            DocumentManager.Create(format.Template);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,6 +8,7 @@ using RainmeterStudio.Business;
 | 
				
			|||||||
using RainmeterStudio.Core.Model;
 | 
					using RainmeterStudio.Core.Model;
 | 
				
			||||||
using RainmeterStudio.UI.Dialogs;
 | 
					using RainmeterStudio.UI.Dialogs;
 | 
				
			||||||
using RainmeterStudio.UI.ViewModel;
 | 
					using RainmeterStudio.UI.ViewModel;
 | 
				
			||||||
 | 
					using RainmeterStudio.Properties;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace RainmeterStudio.UI.Controller
 | 
					namespace RainmeterStudio.UI.Controller
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -115,9 +116,10 @@ namespace RainmeterStudio.UI.Controller
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            string selectedName = dialog.SelectedName;
 | 
					            string selectedName = dialog.SelectedName;
 | 
				
			||||||
            string selectedPath = dialog.SelectedPath;
 | 
					            string selectedPath = dialog.SelectedPath;
 | 
				
			||||||
 | 
					            IProjectTemplate selectedTemplate = dialog.SelectedTemplate;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Call manager
 | 
					            // Call manager
 | 
				
			||||||
            Manager.CreateProject(selectedName, selectedPath);
 | 
					            Manager.CreateProject(selectedName, selectedPath, selectedTemplate);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
@@ -132,6 +134,7 @@ namespace RainmeterStudio.UI.Controller
 | 
				
			|||||||
                + Resources.Strings.Dialog_FileType_AllFiles + "|*.*";
 | 
					                + Resources.Strings.Dialog_FileType_AllFiles + "|*.*";
 | 
				
			||||||
            dialog.Title = Resources.Strings.Dialog_OpenProject_Title;
 | 
					            dialog.Title = Resources.Strings.Dialog_OpenProject_Title;
 | 
				
			||||||
            dialog.Multiselect = false;
 | 
					            dialog.Multiselect = false;
 | 
				
			||||||
 | 
					            dialog.InitialDirectory = Settings.Default.Project_SavedLocation;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Show dialog
 | 
					            // Show dialog
 | 
				
			||||||
            bool? res = dialog.ShowDialog(OwnerWindow);
 | 
					            bool? res = dialog.ShowDialog(OwnerWindow);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -34,7 +34,6 @@
 | 
				
			|||||||
        <Grid Grid.Row="1">
 | 
					        <Grid Grid.Row="1">
 | 
				
			||||||
            <Grid.RowDefinitions>
 | 
					            <Grid.RowDefinitions>
 | 
				
			||||||
                <RowDefinition />
 | 
					                <RowDefinition />
 | 
				
			||||||
                <RowDefinition />
 | 
					 | 
				
			||||||
            </Grid.RowDefinitions>
 | 
					            </Grid.RowDefinitions>
 | 
				
			||||||
            <Grid.ColumnDefinitions>
 | 
					            <Grid.ColumnDefinitions>
 | 
				
			||||||
                <ColumnDefinition Width="Auto" />
 | 
					                <ColumnDefinition Width="Auto" />
 | 
				
			||||||
@@ -43,18 +42,14 @@
 | 
				
			|||||||
            </Grid.ColumnDefinitions>
 | 
					            </Grid.ColumnDefinitions>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            <TextBlock Grid.Row="0" Text="{x:Static r:Strings.CreateDocumentDialog_Name}" />
 | 
					            <TextBlock Grid.Row="0" Text="{x:Static r:Strings.CreateDocumentDialog_Name}" />
 | 
				
			||||||
            <TextBox Name="textPath" Grid.Row="0" Grid.Column="1" Margin="1px"></TextBox>
 | 
					            <TextBox Name="textName" Grid.Row="0" Grid.Column="1" Margin="1px" TextChanged="textName_TextChanged"/>
 | 
				
			||||||
 | 
					 | 
				
			||||||
            <TextBlock Grid.Row="1">Path:</TextBlock>
 | 
					 | 
				
			||||||
            <TextBox Name="textPath1" Grid.Row="1" Grid.Column="1" Margin="1px"></TextBox>
 | 
					 | 
				
			||||||
            <Button Grid.Row="1" Grid.Column="2">...</Button>
 | 
					 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
        </Grid>
 | 
					        </Grid>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <StackPanel Grid.Row="2" Orientation="Horizontal"
 | 
					        <StackPanel Grid.Row="2" Orientation="Horizontal"
 | 
				
			||||||
                    HorizontalAlignment="Right">
 | 
					                    HorizontalAlignment="Right">
 | 
				
			||||||
            <Button Name="buttonCreate" Click="buttonCreate_Click" IsDefault="True" Margin="1px">Create</Button>
 | 
					            <Button Name="buttonCreate" Content="{x:Static r:Strings.Dialog_Create}" IsDefault="True" Margin="1px" Click="buttonCreate_Click" />
 | 
				
			||||||
            <Button Name="buttonCancel" Click="buttonCancel_Click" IsCancel="True" Margin="1px">Cancel</Button>
 | 
					            <Button Name="buttonCancel" Content="{x:Static r:Strings.Dialog_Cancel}" IsCancel="True" Margin="1px" Click="buttonCancel_Click" />
 | 
				
			||||||
        </StackPanel>
 | 
					        </StackPanel>
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
    </Grid>
 | 
					    </Grid>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,6 +2,7 @@
 | 
				
			|||||||
using System.Linq;
 | 
					using System.Linq;
 | 
				
			||||||
using System.Windows;
 | 
					using System.Windows;
 | 
				
			||||||
using System.Windows.Controls;
 | 
					using System.Windows.Controls;
 | 
				
			||||||
 | 
					using RainmeterStudio.Core.Utils;
 | 
				
			||||||
using RainmeterStudio.UI.Controller;
 | 
					using RainmeterStudio.UI.Controller;
 | 
				
			||||||
using RainmeterStudio.UI.ViewModel;
 | 
					using RainmeterStudio.UI.ViewModel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -32,15 +33,15 @@ namespace RainmeterStudio.UI.Dialogs
 | 
				
			|||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Gets or sets the path
 | 
					        /// Gets or sets the path
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        public string SelectedPath
 | 
					        public string SelectedName
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            get
 | 
					            get
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                return textPath.Text;
 | 
					                return textName.Text;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            set
 | 
					            set
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                textPath.Text = value;
 | 
					                textName.Text = value;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -52,13 +53,9 @@ namespace RainmeterStudio.UI.Dialogs
 | 
				
			|||||||
            InitializeComponent();
 | 
					            InitializeComponent();
 | 
				
			||||||
            _documentController = docCtrl;
 | 
					            _documentController = docCtrl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            PopulateFormats();
 | 
					            listTemplates.ItemsSource = _documentController.DocumentTemplates.OrderBy(x => x.DisplayText);
 | 
				
			||||||
            Validate();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void PopulateFormats()
 | 
					            Validate();
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            listTemplates.ItemsSource = _documentController.DocumentTemplates;
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void buttonCreate_Click(object sender, RoutedEventArgs e)
 | 
					        private void buttonCreate_Click(object sender, RoutedEventArgs e)
 | 
				
			||||||
@@ -77,9 +74,8 @@ namespace RainmeterStudio.UI.Dialogs
 | 
				
			|||||||
        {
 | 
					        {
 | 
				
			||||||
            bool res = true;
 | 
					            bool res = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            res &= !String.IsNullOrWhiteSpace(textPath.Text);
 | 
					 | 
				
			||||||
            res &= !textPath.Text.Intersect(System.IO.Path.GetInvalidFileNameChars()).Any();
 | 
					 | 
				
			||||||
            res &= (listTemplates.SelectedItem != null);
 | 
					            res &= (listTemplates.SelectedItem != null);
 | 
				
			||||||
 | 
					            res &= PathHelper.IsFileNameValid(SelectedName);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            buttonCreate.IsEnabled = res;
 | 
					            buttonCreate.IsEnabled = res;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -88,5 +84,10 @@ namespace RainmeterStudio.UI.Dialogs
 | 
				
			|||||||
        {
 | 
					        {
 | 
				
			||||||
            Validate();
 | 
					            Validate();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private void textName_TextChanged(object sender, TextChangedEventArgs e)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            Validate();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -32,11 +32,11 @@ namespace RainmeterStudio.UI.Dialogs
 | 
				
			|||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Gets or sets the currently selected file format
 | 
					        /// Gets or sets the currently selected file format
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
        public IDocumentTemplate SelectedTemplate
 | 
					        public IProjectTemplate SelectedTemplate
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            get
 | 
					            get
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                return listTemplates.SelectedItem as IDocumentTemplate;
 | 
					                return listTemplates.SelectedItem as IProjectTemplate;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            set
 | 
					            set
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
@@ -125,7 +125,7 @@ namespace RainmeterStudio.UI.Dialogs
 | 
				
			|||||||
        private string GetLocation()
 | 
					        private string GetLocation()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            // Get setting
 | 
					            // Get setting
 | 
				
			||||||
            string location = Settings.Default.CreateProjectDialog_SavedLocation;
 | 
					            string location = Settings.Default.Project_SavedLocation;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // No location provided, use default
 | 
					            // No location provided, use default
 | 
				
			||||||
            if (String.IsNullOrEmpty(location))
 | 
					            if (String.IsNullOrEmpty(location))
 | 
				
			||||||
@@ -197,7 +197,7 @@ namespace RainmeterStudio.UI.Dialogs
 | 
				
			|||||||
                // Save location
 | 
					                // Save location
 | 
				
			||||||
                if (checkLocationDefault.IsChecked.HasValue && checkLocationDefault.IsChecked.Value)
 | 
					                if (checkLocationDefault.IsChecked.HasValue && checkLocationDefault.IsChecked.Value)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    Settings.Default.CreateProjectDialog_SavedLocation = SelectedLocation;
 | 
					                    Settings.Default.Project_SavedLocation = SelectedLocation;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -41,7 +41,7 @@
 | 
				
			|||||||
            <setting name="CreateProjectDialog_RecentLocations" serializeAs="String">
 | 
					            <setting name="CreateProjectDialog_RecentLocations" serializeAs="String">
 | 
				
			||||||
                <value />
 | 
					                <value />
 | 
				
			||||||
            </setting>
 | 
					            </setting>
 | 
				
			||||||
            <setting name="CreateProjectDialog_SavedLocation" serializeAs="String">
 | 
					            <setting name="Project_SavedLocation" serializeAs="String">
 | 
				
			||||||
                <value />
 | 
					                <value />
 | 
				
			||||||
            </setting>
 | 
					            </setting>
 | 
				
			||||||
            <setting name="CreateProjectDialog_CreateDirectoryCheckbox" serializeAs="String">
 | 
					            <setting name="CreateProjectDialog_CreateDirectoryCheckbox" serializeAs="String">
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user