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:
parent
5dc71eca92
commit
c933b96347
@ -67,6 +67,7 @@
|
||||
<Compile Include="Utils\InputHelper.cs" />
|
||||
<Compile Include="Utils\LinqExtension.cs" />
|
||||
<Compile Include="Utils\BitmapHelper.cs" />
|
||||
<Compile Include="Utils\PathHelper.cs" />
|
||||
<Compile Include="Utils\TreeExtensions.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
@ -21,5 +21,19 @@ namespace RainmeterStudio.Core.Utils
|
||||
foreach (var obj in container)
|
||||
action(obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Appends an item at the end of the container
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Enumerable type</typeparam>
|
||||
/// <param name="container">Container</param>
|
||||
/// <param name="item">Item to append</param>
|
||||
public static IEnumerable<T> Append<T> (this IEnumerable<T> container, T item)
|
||||
{
|
||||
foreach (var i in container)
|
||||
yield return i;
|
||||
|
||||
yield return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
25
RainmeterStudio.Core/Utils/PathHelper.cs
Normal file
25
RainmeterStudio.Core/Utils/PathHelper.cs
Normal file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Validates a path
|
||||
/// </summary>
|
||||
/// <param name="path">The path</param>
|
||||
/// <returns>True if the path is valid</returns>
|
||||
public static bool IsPathValid(string path)
|
||||
{
|
||||
// Check for invalid characters
|
||||
if (Path.GetInvalidPathChars().Intersect(path).Any())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
36
RainmeterStudio/Properties/Settings.Designer.cs
generated
36
RainmeterStudio/Properties/Settings.Designer.cs
generated
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,5 +32,14 @@
|
||||
<Setting Name="MainWindow_Top" Type="System.Double" Scope="User">
|
||||
<Value Profile="(Default)">10</Value>
|
||||
</Setting>
|
||||
<Setting Name="CreateProjectDialog_RecentLocations" Type="System.String" Scope="User">
|
||||
<Value Profile="(Default)" />
|
||||
</Setting>
|
||||
<Setting Name="CreateProjectDialog_SavedLocation" Type="System.String" Scope="User">
|
||||
<Value Profile="(Default)" />
|
||||
</Setting>
|
||||
<Setting Name="CreateProjectDialog_CreateDirectoryCheckbox" Type="System.Boolean" Scope="User">
|
||||
<Value Profile="(Default)">True</Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,15 @@
|
||||
<setting name="MainWindow_Top" serializeAs="String">
|
||||
<value>10</value>
|
||||
</setting>
|
||||
<setting name="CreateProjectDialog_RecentLocations" serializeAs="String">
|
||||
<value />
|
||||
</setting>
|
||||
<setting name="CreateProjectDialog_SavedLocation" serializeAs="String">
|
||||
<value />
|
||||
</setting>
|
||||
<setting name="CreateProjectDialog_CreateDirectoryCheckbox" serializeAs="String">
|
||||
<value>True</value>
|
||||
</setting>
|
||||
</RainmeterStudio.Properties.Settings>
|
||||
</userSettings>
|
||||
</configuration>
|
||||
|
Loading…
Reference in New Issue
Block a user