diff --git a/RainmeterStudio.Core/RainmeterStudio.Core.csproj b/RainmeterStudio.Core/RainmeterStudio.Core.csproj
index b57220d8..aa876854 100644
--- a/RainmeterStudio.Core/RainmeterStudio.Core.csproj
+++ b/RainmeterStudio.Core/RainmeterStudio.Core.csproj
@@ -67,6 +67,7 @@
+
diff --git a/RainmeterStudio.Core/Utils/LinqExtension.cs b/RainmeterStudio.Core/Utils/LinqExtension.cs
index b0dda7bb..5538c31d 100644
--- a/RainmeterStudio.Core/Utils/LinqExtension.cs
+++ b/RainmeterStudio.Core/Utils/LinqExtension.cs
@@ -21,5 +21,19 @@ namespace RainmeterStudio.Core.Utils
foreach (var obj in container)
action(obj);
}
+
+ ///
+ /// Appends an item at the end of the container
+ ///
+ /// Enumerable type
+ /// Container
+ /// Item to append
+ public static IEnumerable Append (this IEnumerable container, T item)
+ {
+ foreach (var i in container)
+ yield return i;
+
+ yield return item;
+ }
}
}
diff --git a/RainmeterStudio.Core/Utils/PathHelper.cs b/RainmeterStudio.Core/Utils/PathHelper.cs
new file mode 100644
index 00000000..0323365a
--- /dev/null
+++ b/RainmeterStudio.Core/Utils/PathHelper.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+
+namespace RainmeterStudio.Core.Utils
+{
+ public static class PathHelper
+ {
+ ///
+ /// Validates a path
+ ///
+ /// The path
+ /// True if the path is valid
+ public static bool IsPathValid(string path)
+ {
+ // Check for invalid characters
+ if (Path.GetInvalidPathChars().Intersect(path).Any())
+ return false;
+
+ return true;
+ }
+ }
+}
diff --git a/RainmeterStudio/Properties/Settings.Designer.cs b/RainmeterStudio/Properties/Settings.Designer.cs
index d8922d43..8586ff67 100644
--- a/RainmeterStudio/Properties/Settings.Designer.cs
+++ b/RainmeterStudio/Properties/Settings.Designer.cs
@@ -147,5 +147,41 @@ namespace RainmeterStudio.Properties {
this["MainWindow_Top"] = value;
}
}
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("")]
+ public string CreateProjectDialog_RecentLocations {
+ get {
+ return ((string)(this["CreateProjectDialog_RecentLocations"]));
+ }
+ set {
+ this["CreateProjectDialog_RecentLocations"] = value;
+ }
+ }
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("")]
+ public string CreateProjectDialog_SavedLocation {
+ get {
+ return ((string)(this["CreateProjectDialog_SavedLocation"]));
+ }
+ set {
+ this["CreateProjectDialog_SavedLocation"] = value;
+ }
+ }
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("True")]
+ public bool CreateProjectDialog_CreateDirectoryCheckbox {
+ get {
+ return ((bool)(this["CreateProjectDialog_CreateDirectoryCheckbox"]));
+ }
+ set {
+ this["CreateProjectDialog_CreateDirectoryCheckbox"] = value;
+ }
+ }
}
}
diff --git a/RainmeterStudio/Properties/Settings.settings b/RainmeterStudio/Properties/Settings.settings
index 2e4c6840..af3b6bf2 100644
--- a/RainmeterStudio/Properties/Settings.settings
+++ b/RainmeterStudio/Properties/Settings.settings
@@ -32,5 +32,14 @@
10
+
+
+
+
+
+
+
+ True
+
\ No newline at end of file
diff --git a/RainmeterStudio/UI/Controller/ProjectController.cs b/RainmeterStudio/UI/Controller/ProjectController.cs
index 6b2ce95e..d1577fde 100644
--- a/RainmeterStudio/UI/Controller/ProjectController.cs
+++ b/RainmeterStudio/UI/Controller/ProjectController.cs
@@ -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;
diff --git a/RainmeterStudio/UI/Dialogs/CreateProjectDialog.xaml b/RainmeterStudio/UI/Dialogs/CreateProjectDialog.xaml
index abe8c19d..27efe9ff 100644
--- a/RainmeterStudio/UI/Dialogs/CreateProjectDialog.xaml
+++ b/RainmeterStudio/UI/Dialogs/CreateProjectDialog.xaml
@@ -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">
@@ -53,8 +55,10 @@
+
+
-
+
+
@@ -79,8 +82,8 @@
-
-
+
+
diff --git a/RainmeterStudio/UI/Dialogs/CreateProjectDialog.xaml.cs b/RainmeterStudio/UI/Dialogs/CreateProjectDialog.xaml.cs
index 0d212ea7..e358c4bf 100644
--- a/RainmeterStudio/UI/Dialogs/CreateProjectDialog.xaml.cs
+++ b/RainmeterStudio/UI/Dialogs/CreateProjectDialog.xaml.cs
@@ -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
///
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
///
@@ -120,45 +94,62 @@ namespace RainmeterStudio.UI.Dialogs
private bool _pathUserSet = false;
private bool _ignoreNextChange = false;
+ private ProjectController _projectController;
#endregion
+ ///
+ /// Initializes the create project dialog
+ ///
+ /// Project controller
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 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 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;
+ }
+ }
}
}
}
diff --git a/RainmeterStudio/app.config b/RainmeterStudio/app.config
index 9842eb68..7de0c84f 100644
--- a/RainmeterStudio/app.config
+++ b/RainmeterStudio/app.config
@@ -38,6 +38,15 @@
10
+
+
+
+
+
+
+
+ True
+