mirror of
				https://github.com/chibicitiberiu/rainmeter-studio.git
				synced 2024-02-24 04:33:31 +00:00 
			
		
		
		
	Finished create project dialog
This commit is contained in:
		@@ -102,18 +102,12 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Displays the 'create project' dialog and creates a new project
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public void CreateProject(string name = null, string path = null)
 | 
			
		||||
        public void CreateProject()
 | 
			
		||||
        {
 | 
			
		||||
            // Create dialog
 | 
			
		||||
            var dialog = new CreateProjectDialog(this);
 | 
			
		||||
            dialog.Owner = OwnerWindow;
 | 
			
		||||
            
 | 
			
		||||
            if (name != null) 
 | 
			
		||||
                dialog.Name = name;
 | 
			
		||||
            
 | 
			
		||||
            if (path != null) 
 | 
			
		||||
                dialog.SelectedPath = path;
 | 
			
		||||
            
 | 
			
		||||
            // Display
 | 
			
		||||
            bool? res = dialog.ShowDialog();
 | 
			
		||||
            if (!res.HasValue || !res.Value)
 | 
			
		||||
 
 | 
			
		||||
@@ -59,23 +59,21 @@
 | 
			
		||||
            <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}"/>
 | 
			
		||||
            <Button Name="buttonBrowse"
 | 
			
		||||
                    Grid.Row="1" Grid.Column="2" 
 | 
			
		||||
                    Content="{x:Static r:Strings.Dialog_Browse}"
 | 
			
		||||
                    Click="buttonBrowse_Click" />
 | 
			
		||||
            
 | 
			
		||||
            <CheckBox Name="checkLocationDefault" 
 | 
			
		||||
                      Grid.Row="1" Grid.Column="3" 
 | 
			
		||||
                      Content="{x:Static r:Strings.CreateProjectDialog_LocationDefault}" 
 | 
			
		||||
                      VerticalAlignment="Center"/>
 | 
			
		||||
 | 
			
		||||
            <!-- Path -->
 | 
			
		||||
            <TextBlock Grid.Row="2" Text="{x:Static r:Strings.CreateProjectDialog_Path}"/>
 | 
			
		||||
            <TextBox Name="textPath" 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.CreateProjectDialog_PathCreateFolder}"
 | 
			
		||||
                      IsChecked="{Binding Source={x:Static p:Settings.Default}, Path=CreateProjectDialog_CreateDirectoryCheckbox, Mode=TwoWay}"
 | 
			
		||||
                      Checked="checkCreateDirectory_CheckChanged"
 | 
			
		||||
                      Unchecked="checkCreateDirectory_CheckChanged"
 | 
			
		||||
                      VerticalAlignment="Center"/>
 | 
			
		||||
 | 
			
		||||
        </Grid>
 | 
			
		||||
 
 | 
			
		||||
@@ -11,11 +11,13 @@ using System.Windows.Input;
 | 
			
		||||
using System.Windows.Media;
 | 
			
		||||
using System.Windows.Media.Imaging;
 | 
			
		||||
using System.Windows.Shapes;
 | 
			
		||||
using Microsoft.Win32;
 | 
			
		||||
using RainmeterStudio.Business;
 | 
			
		||||
using RainmeterStudio.Core.Documents;
 | 
			
		||||
using RainmeterStudio.Core.Model;
 | 
			
		||||
using RainmeterStudio.Core.Utils;
 | 
			
		||||
using RainmeterStudio.Properties;
 | 
			
		||||
using RainmeterStudio.Resources;
 | 
			
		||||
using RainmeterStudio.UI.Controller;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.UI.Dialogs
 | 
			
		||||
@@ -73,18 +75,18 @@ namespace RainmeterStudio.UI.Dialogs
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the path
 | 
			
		||||
        /// Gets the selected path
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string SelectedPath
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return textPath.Text;
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                textPath.Text = value;
 | 
			
		||||
                _pathUserSet = true;
 | 
			
		||||
                string path = SelectedLocation;
 | 
			
		||||
 | 
			
		||||
                if (checkCreateDirectory.IsChecked.HasValue && checkCreateDirectory.IsChecked.Value)
 | 
			
		||||
                    path = System.IO.Path.Combine(path, SelectedName);
 | 
			
		||||
 | 
			
		||||
                return System.IO.Path.Combine(path, SelectedName + ".rsproj");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -92,8 +94,6 @@ namespace RainmeterStudio.UI.Dialogs
 | 
			
		||||
 | 
			
		||||
        #region Private fields
 | 
			
		||||
 | 
			
		||||
        private bool _pathUserSet = false;
 | 
			
		||||
        private bool _ignoreNextChange = false;
 | 
			
		||||
        private ProjectController _projectController;
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
@@ -146,73 +146,20 @@ namespace RainmeterStudio.UI.Dialogs
 | 
			
		||||
        {
 | 
			
		||||
            bool res = true;
 | 
			
		||||
            res &= (listTemplates.SelectedItem != null); 
 | 
			
		||||
            res &= !String.IsNullOrWhiteSpace(textPath.Text);
 | 
			
		||||
            res &= PathHelper.IsPathValid(textPath.Text);
 | 
			
		||||
            
 | 
			
		||||
           
 | 
			
		||||
            buttonCreate.IsEnabled = 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();
 | 
			
		||||
            Validate();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void textLocation_TextChanged(object sender, TextChangedEventArgs e)
 | 
			
		||||
        {
 | 
			
		||||
            UpdatePath();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void textPath_TextChanged(object sender, TextChangedEventArgs e)
 | 
			
		||||
        {
 | 
			
		||||
            if (_ignoreNextChange)
 | 
			
		||||
            {
 | 
			
		||||
                _ignoreNextChange = false;
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                _pathUserSet = true;
 | 
			
		||||
 | 
			
		||||
                try
 | 
			
		||||
                {
 | 
			
		||||
                    textLocation.Text = System.IO.Path.GetDirectoryName(textPath.Text);
 | 
			
		||||
                }
 | 
			
		||||
                catch { }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            Validate();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void checkCreateDirectory_CheckChanged(object sender, RoutedEventArgs e)
 | 
			
		||||
        {
 | 
			
		||||
            UpdatePath();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void listTemplates_SelectionChanged(object sender, SelectionChangedEventArgs e)
 | 
			
		||||
        {
 | 
			
		||||
            Validate();
 | 
			
		||||
@@ -254,5 +201,23 @@ namespace RainmeterStudio.UI.Dialogs
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void buttonBrowse_Click(object sender, RoutedEventArgs e)
 | 
			
		||||
        {
 | 
			
		||||
            // Show dialog
 | 
			
		||||
            SaveFileDialog dialog = new SaveFileDialog();
 | 
			
		||||
            dialog.Title = Strings.CreateProjectDialog_Browse_Title;
 | 
			
		||||
            dialog.AddExtension = true;
 | 
			
		||||
            dialog.Filter = Strings.Dialog_FileType_Project + "|*.rsproj|" + Strings.Dialog_FileType_AllFiles + "|*.*";
 | 
			
		||||
            dialog.InitialDirectory = SelectedLocation;
 | 
			
		||||
            dialog.FileName = SelectedName;
 | 
			
		||||
            bool? res = dialog.ShowDialog();
 | 
			
		||||
 | 
			
		||||
            if (res.HasValue && res.Value)
 | 
			
		||||
            {
 | 
			
		||||
                SelectedName = System.IO.Path.GetFileNameWithoutExtension(dialog.FileName);
 | 
			
		||||
                SelectedLocation = System.IO.Path.GetDirectoryName(dialog.FileName);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user