Implemented project manager

This commit is contained in:
2014-07-26 13:49:11 +03:00
parent 6eec29a3a7
commit 48972dfb52
18 changed files with 1028 additions and 52 deletions

View File

@ -24,11 +24,11 @@ namespace RainmeterStudio.UI.Dialogs
/// <summary>
/// Gets or sets the currently selected file format
/// </summary>
public DocumentFormat SelectedFormat
public DocumentTemplate SelectedFormat
{
get
{
return listFormats.SelectedItem as DocumentFormat;
return listFormats.SelectedItem as DocumentTemplate;
}
set
{

View File

@ -0,0 +1,102 @@
<Window x:Class="RainmeterStudio.UI.Dialogs.CreateProjectDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:r="clr-namespace:RainmeterStudio.Resources"
xmlns:toremove="clr-namespace:RainmeterStudio.Model"
Title="{x:Static r:Strings.ProjectCreateDialog_Title}" Height="320" Width="480"
WindowStartupLocation="CenterOwner"
WindowStyle="ToolWindow" ShowInTaskbar="False">
<Grid Background="WhiteSmoke">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ListView Name="listTemplates" Grid.Row="0" SelectedIndex="0"
IsEnabled="False">
<!-- TODO: remove -->
<toremove:DocumentTemplate Name="Empty project"
Description="Create a new empty project" >
</toremove:DocumentTemplate>
<ListView.ItemTemplate>
<DataTemplate>
<DockPanel>
<Image DockPanel.Dock="Left" Source="{Binding Icon}"
Width="32" Height="32" Margin="2"
Stretch="Uniform" VerticalAlignment="Top" />
<StackPanel Orientation="Vertical" VerticalAlignment="Center">
<TextBlock Text="{Binding Name}" FontWeight="Bold" />
<TextBlock Text="{Binding Description}" />
</StackPanel>
</DockPanel>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock FontWeight="Bold" FontSize="13pt" Text="{Binding Name}" />
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListView.GroupStyle>
</ListView>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!-- Name -->
<TextBlock Grid.Row="0" Text="{x:Static r:Strings.ProjectCreateDialog_Name}" />
<TextBox Name="textName"
Grid.Row="0" Grid.Column="1"
TextChanged="textName_TextChanged"/>
<!-- Location -->
<TextBlock Grid.Row="1" Text="{x:Static r:Strings.ProjectCreateDialog_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"
Content="{x:Static r:Strings.ProjectCreateDialog_LocationDefault}"
VerticalAlignment="Center"/>
<!-- Path -->
<TextBlock Grid.Row="2" Text="{x:Static r:Strings.ProjectCreateDialog_Path}"/>
<ComboBox Name="textPath"
IsEditable="True"
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.ProjectCreateDialog_PathCreateFolder}"
IsChecked="True"
Checked="checkCreateDirectory_CheckChanged"
Unchecked="checkCreateDirectory_CheckChanged"
VerticalAlignment="Center"/>
</Grid>
<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}" />
</StackPanel>
</Grid>
</Window>

View File

@ -0,0 +1,207 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using RainmeterStudio.Business;
using RainmeterStudio.Model;
namespace RainmeterStudio.UI.Dialogs
{
/// <summary>
/// Interaction logic for CreateProjectDialog.xaml
/// </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>
/// Gets or sets the currently selected file format
/// </summary>
public DocumentTemplate SelectedTemplate
{
get
{
return listTemplates.SelectedItem as DocumentTemplate;
}
set
{
listTemplates.SelectedItem = value;
}
}
/// <summary>
/// Gets or sets the path
/// </summary>
public string SelectedName
{
get
{
return textName.Text;
}
set
{
textName.Text = value;
}
}
/// <summary>
/// Gets or sets the path
/// </summary>
public string SelectedLocation
{
get
{
return textLocation.Text;
}
set
{
textLocation.Text = value;
}
}
/// <summary>
/// Gets or sets the path
/// </summary>
public string SelectedPath
{
get
{
return textPath.Text;
}
set
{
textPath.Text = value;
_pathUserSet = true;
}
}
#endregion
#region Private fields
private bool _pathUserSet = false;
private bool _ignoreNextChange = false;
#endregion
public CreateProjectDialog()
{
InitializeComponent();
textLocation.AddHandler(TextBoxBase.TextChangedEvent, new TextChangedEventHandler(textLocation_TextChanged));
textPath.AddHandler(TextBoxBase.TextChangedEvent, new TextChangedEventHandler(textPath_TextChanged));
DataContext = this;
}
private void Create()
{
DialogResult = true;
Close();
}
private void Cancel()
{
DialogResult = false;
Close();
}
private bool Validate()
{
bool res = true;
res &= !String.IsNullOrWhiteSpace(textPath.Text);
res &= (listTemplates.SelectedItem != null);
return 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();
}
private void textLocation_TextChanged(object sender, TextChangedEventArgs e)
{
UpdatePath();
}
private void textPath_TextChanged(object sender, TextChangedEventArgs e)
{
if (_ignoreNextChange)
{
_ignoreNextChange = false;
}
else
{
_pathUserSet = true;
}
}
private void checkCreateDirectory_CheckChanged(object sender, RoutedEventArgs e)
{
UpdatePath();
}
}
}