mirror of
				https://github.com/chibicitiberiu/rainmeter-studio.git
				synced 2024-02-24 04:33:31 +00:00 
			
		
		
		
	Worked on CreateProjectDialog
This commit is contained in:
		@@ -107,8 +107,7 @@ namespace RainmeterStudio.UI.Controller
 | 
			
		||||
            // Create dialog
 | 
			
		||||
            var dialog = new CreateProjectDialog(this);
 | 
			
		||||
            dialog.Owner = OwnerWindow;
 | 
			
		||||
            dialog.SelectedLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Rainmeter Studio Projects");
 | 
			
		||||
 | 
			
		||||
            
 | 
			
		||||
            if (name != null) 
 | 
			
		||||
                dialog.Name = name;
 | 
			
		||||
            
 | 
			
		||||
 
 | 
			
		||||
@@ -2,9 +2,11 @@
 | 
			
		||||
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 | 
			
		||||
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
        xmlns:r="clr-namespace:RainmeterStudio.Resources"
 | 
			
		||||
        Title="{x:Static r:Strings.CreateProjectDialog_Title}" Height="320" Width="480"
 | 
			
		||||
        xmlns:p="clr-namespace:RainmeterStudio.Properties"
 | 
			
		||||
        Title="{x:Static r:Strings.CreateProjectDialog_Title}" Width="600" Height="400" 
 | 
			
		||||
        WindowStartupLocation="CenterOwner"
 | 
			
		||||
        WindowStyle="ToolWindow" ShowInTaskbar="False">
 | 
			
		||||
        WindowStyle="ToolWindow" ShowInTaskbar="False"
 | 
			
		||||
        Closed="Window_Closed">
 | 
			
		||||
 | 
			
		||||
    <Grid Background="WhiteSmoke">
 | 
			
		||||
        <Grid.RowDefinitions>
 | 
			
		||||
@@ -53,8 +55,10 @@
 | 
			
		||||
            
 | 
			
		||||
            <!-- Location -->
 | 
			
		||||
            <TextBlock Grid.Row="1" Text="{x:Static r:Strings.CreateProjectDialog_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" 
 | 
			
		||||
@@ -63,14 +67,13 @@
 | 
			
		||||
 | 
			
		||||
            <!-- Path -->
 | 
			
		||||
            <TextBlock Grid.Row="2" Text="{x:Static r:Strings.CreateProjectDialog_Path}"/>
 | 
			
		||||
            <ComboBox Name="textPath" 
 | 
			
		||||
                      IsEditable="True"
 | 
			
		||||
                     Grid.Row="2" Grid.Column="1" />
 | 
			
		||||
            <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="True"
 | 
			
		||||
                      IsChecked="{Binding Source={x:Static p:Settings.Default}, Path=CreateProjectDialog_CreateDirectoryCheckbox, Mode=TwoWay}"
 | 
			
		||||
                      Checked="checkCreateDirectory_CheckChanged"
 | 
			
		||||
                      Unchecked="checkCreateDirectory_CheckChanged"
 | 
			
		||||
                      VerticalAlignment="Center"/>
 | 
			
		||||
@@ -79,8 +82,8 @@
 | 
			
		||||
 | 
			
		||||
        <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}" />
 | 
			
		||||
            <Button Name="buttonCreate" IsDefault="True" Content="{x:Static r:Strings.Dialog_Create}" Click="buttonCreate_Click"/>
 | 
			
		||||
            <Button Name="buttonCancel" IsCancel="True" Content="{x:Static r:Strings.Dialog_Cancel}" Click="buttonCancel_Click" />
 | 
			
		||||
        </StackPanel>
 | 
			
		||||
 | 
			
		||||
    </Grid>
 | 
			
		||||
 
 | 
			
		||||
@@ -14,6 +14,8 @@ using System.Windows.Shapes;
 | 
			
		||||
using RainmeterStudio.Business;
 | 
			
		||||
using RainmeterStudio.Core.Documents;
 | 
			
		||||
using RainmeterStudio.Core.Model;
 | 
			
		||||
using RainmeterStudio.Core.Utils;
 | 
			
		||||
using RainmeterStudio.Properties;
 | 
			
		||||
using RainmeterStudio.UI.Controller;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.UI.Dialogs
 | 
			
		||||
@@ -23,34 +25,6 @@ namespace RainmeterStudio.UI.Dialogs
 | 
			
		||||
    /// </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>
 | 
			
		||||
@@ -120,45 +94,62 @@ namespace RainmeterStudio.UI.Dialogs
 | 
			
		||||
 | 
			
		||||
        private bool _pathUserSet = false;
 | 
			
		||||
        private bool _ignoreNextChange = false;
 | 
			
		||||
        private ProjectController _projectController;
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes the create project dialog
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="projectController">Project controller</param>
 | 
			
		||||
        public CreateProjectDialog(ProjectController projectController)
 | 
			
		||||
        {
 | 
			
		||||
            InitializeComponent();
 | 
			
		||||
 | 
			
		||||
            _projectController = projectController;
 | 
			
		||||
 | 
			
		||||
            // Add event handlers
 | 
			
		||||
            textLocation.AddHandler(TextBoxBase.TextChangedEvent, new TextChangedEventHandler(textLocation_TextChanged));
 | 
			
		||||
            textPath.AddHandler(TextBoxBase.TextChangedEvent, new TextChangedEventHandler(textPath_TextChanged));
 | 
			
		||||
 | 
			
		||||
            // Set data context
 | 
			
		||||
            DataContext = this;
 | 
			
		||||
 | 
			
		||||
            // Populate templates
 | 
			
		||||
            // Populate controls
 | 
			
		||||
            listTemplates.ItemsSource = projectController.ProjectTemplates.OrderBy(x => x.DisplayText);
 | 
			
		||||
 | 
			
		||||
            textLocation.ItemsSource = GetRecentLocations().OrderBy(x => x);
 | 
			
		||||
 | 
			
		||||
            textLocation.Text = GetLocation();
 | 
			
		||||
 | 
			
		||||
            Validate();
 | 
			
		||||
 | 
			
		||||
            // Focus on name textbox
 | 
			
		||||
            textName.Focus();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void Create()
 | 
			
		||||
        private string GetLocation()
 | 
			
		||||
        {
 | 
			
		||||
            DialogResult = true;
 | 
			
		||||
            Close();
 | 
			
		||||
            // Get setting
 | 
			
		||||
            string location = Settings.Default.CreateProjectDialog_SavedLocation;
 | 
			
		||||
 | 
			
		||||
            // No location provided, use default
 | 
			
		||||
            if (String.IsNullOrEmpty(location))
 | 
			
		||||
                return System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Rainmeter Studio Projects");
 | 
			
		||||
 | 
			
		||||
            return location;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void Cancel()
 | 
			
		||||
        private IEnumerable<string> GetRecentLocations()
 | 
			
		||||
        {
 | 
			
		||||
            DialogResult = false;
 | 
			
		||||
            Close();
 | 
			
		||||
            return Settings.Default.CreateProjectDialog_RecentLocations
 | 
			
		||||
                .Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private bool Validate()
 | 
			
		||||
        private void Validate()
 | 
			
		||||
        {
 | 
			
		||||
            bool res = true;
 | 
			
		||||
            res &= (listTemplates.SelectedItem != null); 
 | 
			
		||||
            res &= !String.IsNullOrWhiteSpace(textPath.Text);
 | 
			
		||||
            res &= (listTemplates.SelectedItem != null);
 | 
			
		||||
            return res;
 | 
			
		||||
            res &= PathHelper.IsPathValid(textPath.Text);
 | 
			
		||||
            
 | 
			
		||||
            buttonCreate.IsEnabled = res;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void UpdatePath()
 | 
			
		||||
@@ -206,7 +197,15 @@ namespace RainmeterStudio.UI.Dialogs
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                _pathUserSet = true;
 | 
			
		||||
 | 
			
		||||
                try
 | 
			
		||||
                {
 | 
			
		||||
                    textLocation.Text = System.IO.Path.GetDirectoryName(textPath.Text);
 | 
			
		||||
                }
 | 
			
		||||
                catch { }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            Validate();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void checkCreateDirectory_CheckChanged(object sender, RoutedEventArgs e)
 | 
			
		||||
@@ -216,6 +215,44 @@ namespace RainmeterStudio.UI.Dialogs
 | 
			
		||||
 | 
			
		||||
        private void listTemplates_SelectionChanged(object sender, SelectionChangedEventArgs e)
 | 
			
		||||
        {
 | 
			
		||||
            Validate();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void buttonCreate_Click(object sender, RoutedEventArgs e)
 | 
			
		||||
        {
 | 
			
		||||
            DialogResult = true;
 | 
			
		||||
            Close();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void buttonCancel_Click(object sender, RoutedEventArgs e)
 | 
			
		||||
        {
 | 
			
		||||
            DialogResult = false;
 | 
			
		||||
            Close();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void Window_Closed(object sender, EventArgs e)
 | 
			
		||||
        {
 | 
			
		||||
            // Save settings
 | 
			
		||||
            if (DialogResult.HasValue && DialogResult.Value)
 | 
			
		||||
            {
 | 
			
		||||
                // Save recent locations
 | 
			
		||||
                IEnumerable<string> recentLocations = GetRecentLocations();
 | 
			
		||||
                if (!recentLocations.Contains(SelectedLocation))
 | 
			
		||||
                {
 | 
			
		||||
                    if (recentLocations.Count() > 5)
 | 
			
		||||
                        recentLocations = recentLocations.Skip(1);
 | 
			
		||||
 | 
			
		||||
                    recentLocations = recentLocations.Append(SelectedLocation);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                Settings.Default.CreateProjectDialog_RecentLocations = recentLocations.Aggregate((first, second) => first + "|" + second);
 | 
			
		||||
 | 
			
		||||
                // Save location
 | 
			
		||||
                if (checkLocationDefault.IsChecked.HasValue && checkLocationDefault.IsChecked.Value)
 | 
			
		||||
                {
 | 
			
		||||
                    Settings.Default.CreateProjectDialog_SavedLocation = SelectedLocation;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user