Permalink
Browse files

Rework main window

  • Loading branch information...
1 parent d4fcf3a commit e2cc0a8002aeed533cea8d573d2f59bba5024978 @dirkrombauts committed Jun 15, 2012
@@ -0,0 +1,60 @@
+// #region License
+//
+//
+// /*
+// Copyright [2011] [Jeffrey Cameron]
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// http://www.apache.org/licenses/LICENSE-2.0
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+// */
+// #endregion
+
+using System;
+using System.ComponentModel;
+using System.Linq.Expressions;
+using System.Reflection;
+
+namespace Pickles.UserInterface
+{
+ public static class EventHandlerExtensions
+ {
+ public static void Raise(this EventHandler handler, object sender, EventArgs e)
+ {
+ if (handler != null)
+ {
+ handler(sender, e);
+ }
+ }
+
+ public static void Raise<TValue>(
+ this PropertyChangedEventHandler handler, object sender, Expression<Func<TValue>> selector)
+ {
+ if (handler != null)
+ {
+ handler(sender, new PropertyChangedEventArgs(GetProperty(selector).Name));
+ }
+ }
+
+ internal static PropertyInfo GetProperty(Expression expression)
+ {
+ if (expression is LambdaExpression)
+ {
+ expression = ((LambdaExpression)expression).Body;
+ }
+ switch (expression.NodeType)
+ {
+ case ExpressionType.MemberAccess:
+ return (PropertyInfo)((MemberExpression)expression).Member;
+ default:
+ throw new InvalidOperationException("Expression does not contain a property.");
+ }
+ }
+ }
+}
+
@@ -1,30 +1,89 @@
-<Window x:Class="Pickles.UserInterface.MainWindow"
+<mahapps:MetroWindow x:Class="Pickles.UserInterface.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Pickles.UserInterface"
+ xmlns:mahapps="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
Title="Pickles" Height="350" Width="525">
- <Window.DataContext>
+ <Window.Resources>
+ <ResourceDictionary>
+ <ResourceDictionary.MergedDictionaries>
+ <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" />
+ <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
+ <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
+ <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
+ <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
+ </ResourceDictionary.MergedDictionaries>
+ </ResourceDictionary>
+ </Window.Resources>
+ <Window.DataContext>
<local:MainWindowViewModel />
</Window.DataContext>
- <Grid>
- <Label Content="Feature Directory" Height="28" HorizontalAlignment="Left" Margin="12,12,0,0" Name="FeatureFolderLabel" VerticalAlignment="Top" Width="142" />
- <TextBox Text="{Binding FeatureFolder}" Height="23" HorizontalAlignment="Right" Margin="0,14,104,0" Name="FeatureFolder" VerticalAlignment="Top" Width="239" />
- <Label Content="Output Directory" Height="28" HorizontalAlignment="Left" Margin="12,46,0,0" Name="OutputFolderLabel" VerticalAlignment="Top" Width="142" />
- <TextBox Text="{Binding OutputFolder}" Height="23" HorizontalAlignment="Right" Margin="0,46,104,0" Name="OutputFolder" VerticalAlignment="Top" Width="239" />
- <Label Content="Documentation Format" Height="28" HorizontalAlignment="Left" Margin="12,80,0,0" Name="DocumentationFormatLabel" VerticalAlignment="Top" Width="142" />
- <ComboBox SelectedItem="{Binding SelectedDocumentationFormat}" ItemsSource="{Binding DocumentationFormatValues}" Height="23" HorizontalAlignment="Left" Margin="172,82,0,0" Name="DocumentationFormat" VerticalAlignment="Top" Width="75" />
- <Button Command="{Binding GeneratePickles}" Content="Generate" Height="23" HorizontalAlignment="Left" Margin="12,276,0,0" Name="GenerateButton" VerticalAlignment="Top" Width="75" />
- <Button Command="{Binding BrowseForFeatureFolder}" Content="Browse" Height="23" HorizontalAlignment="Left" Margin="416,14,0,0" Name="button1" VerticalAlignment="Top" Width="75" />
- <Button Command="{Binding BrowseForOutputFolder}" Content="Browse" Height="23" HorizontalAlignment="Left" Margin="416,46,0,0" Name="button2" VerticalAlignment="Top" Width="75" />
- <Label Content="Project Name" Height="28" HorizontalAlignment="Left" Margin="12,114,0,0" Name="ProjectNameLabel" VerticalAlignment="Top" Width="142" />
- <TextBox Height="23" HorizontalAlignment="Right" Margin="0,114,104,0" Name="ProjectName" Text="{Binding ProjectName}" VerticalAlignment="Top" Width="239" />
- <Label Content="Project Version" Height="28" HorizontalAlignment="Left" Margin="12,148,0,0" Name="ProjectVersionLabel" VerticalAlignment="Top" Width="142" />
- <TextBox Height="23" HorizontalAlignment="Right" Margin="0,148,104,0" Name="ProjectVersion" Text="{Binding ProjectVersion}" VerticalAlignment="Top" Width="239" />
- <Label Content="Test Results File" Height="28" HorizontalAlignment="Left" Margin="12,182,0,0" Name="label1" VerticalAlignment="Top" Width="142" />
- <TextBox Height="23" HorizontalAlignment="Right" Margin="0,182,104,0" Name="textBox1" Text="{Binding TestResultsFile}" VerticalAlignment="Top" Width="239" />
- <Button Command="{Binding BrowseForTestResultsFile}" Content="Browse" Height="23" HorizontalAlignment="Left" Margin="416,181,0,0" Name="button3" VerticalAlignment="Top" Width="75" />
- <Label Content="Test Results Format" Height="28" HorizontalAlignment="Left" Margin="12,216,0,0" Name="label2" VerticalAlignment="Top" Width="142" />
- <ComboBox Height="23" HorizontalAlignment="Left" ItemsSource="{Binding TestResultsFormatValues}" Margin="172,216,0,0" Name="comboBox1" SelectedItem="{Binding SelectedTestResultsFormat}" VerticalAlignment="Top" Width="75" />
- <Label Content="Language" Height="28" HorizontalAlignment="Left" Margin="12,245,0,0" Name="label3" VerticalAlignment="Top" Width="142" />
- <ComboBox Height="23" HorizontalAlignment="Left" ItemsSource="{Binding LanguageValues}" Margin="172,245,0,0" Name="comboBox2" SelectedItem="{Binding SelectedLanguage}" VerticalAlignment="Top" Width="75" />
+ <Grid Margin="0,0,0,20">
+ <Grid.RowDefinitions>
+ <RowDefinition />
+ <RowDefinition />
+ <RowDefinition />
+ <RowDefinition />
+ <RowDefinition />
+ <RowDefinition />
+ <RowDefinition />
+ <RowDefinition />
+ <RowDefinition />
+ </Grid.RowDefinitions>
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="Auto" />
+ <ColumnDefinition />
+ <ColumnDefinition Width="Auto" />
+ </Grid.ColumnDefinitions>
+
+ <Label Content="Feature Directory" Grid.Column="0" Grid.Row="0" />
+ <TextBox Text="{Binding FeatureFolder}" Grid.Column="1" Grid.Row="0" />
+ <Button Command="{Binding BrowseForFeatureFolder}" Content="Browse ..." Grid.Row="0" Grid.Column="2" />
+
+ <Label Content="Output Directory" Grid.Column="0" Grid.Row="1" />
+ <TextBox Text="{Binding OutputFolder}" Grid.Column="1" Grid.Row="1" />
+ <Button Command="{Binding BrowseForOutputFolder}" Content="Browse ..." Grid.Column="2" Grid.Row="1" />
+
+ <Label Content="Documentation Format" Grid.Column="0" Grid.Row="2" />
+ <ListBox ItemsSource="{Binding DocumentationFormatValues}" Grid.Column="1" Grid.Row="2" Grid.ColumnSpan="2">
+ <ListBox.ItemsPanel>
+ <ItemsPanelTemplate>
+ <StackPanel Orientation="Horizontal" />
+ </ItemsPanelTemplate>
+ </ListBox.ItemsPanel>
+ <ListBox.ItemTemplate>
+ <DataTemplate>
+ <RadioButton Content="{Binding Path=Item}" GroupName="documentationFormat" IsChecked="{Binding Path=IsSelected}"></RadioButton>
+ </DataTemplate>
+ </ListBox.ItemTemplate>
+ </ListBox>
+
+ <Label Content="Project Name" Grid.Column="0" Grid.Row="3" />
+ <TextBox Text="{Binding ProjectName}" Grid.Column="1" Grid.Row="3" Grid.ColumnSpan="2" />
+
+ <Label Content="Project Version" Grid.Column="0" Grid.Row="4" />
+ <TextBox Text="{Binding ProjectVersion}" Grid.Column="1" Grid.Row="4" Grid.ColumnSpan="2" />
+
+ <Label Content="Test Results File" Grid.Column="0" Grid.Row="5" />
+ <TextBox Text="{Binding TestResultsFile}" Grid.Column="1" Grid.Row="5" />
+ <Button Command="{Binding BrowseForTestResultsFile}" Content="Browse" Grid.Row="5" Grid.Column="2" />
+
+ <Label Content="Test Results Format" Grid.Column="0" Grid.Row="6"/>
+ <ListBox ItemsSource="{Binding TestResultsFormatValues}" Grid.Column="1" Grid.Row="6" Grid.ColumnSpan="2">
+ <ListBox.ItemsPanel>
+ <ItemsPanelTemplate>
+ <StackPanel Orientation="Horizontal" />
+ </ItemsPanelTemplate>
+ </ListBox.ItemsPanel>
+ <ListBox.ItemTemplate>
+ <DataTemplate>
+ <RadioButton Content="{Binding Path=Item}" GroupName="testResultsFormat" IsChecked="{Binding Path=IsSelected}"></RadioButton>
+ </DataTemplate>
+ </ListBox.ItemTemplate>
+ </ListBox>
+
+ <Label Content="Language" Grid.Column="0" Grid.Row="7" />
+ <ComboBox ItemsSource="{Binding LanguageValues}" Grid.Column="1" SelectedItem="{Binding SelectedLanguage}" Grid.Row="7" Grid.ColumnSpan="2"/>
+
+ <Button Command="{Binding GeneratePickles}" Content="Generate" Grid.Row="8" Grid.Column="2"/>
</Grid>
-</Window>
+</mahapps:MetroWindow>
@@ -1,23 +1,11 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
namespace Pickles.UserInterface
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
- public partial class MainWindow : Window
+ public partial class MainWindow
{
public MainWindow()
{
@@ -1,118 +1,92 @@
using System;
using System.Collections.Generic;
-using System.ComponentModel;
using System.IO;
using System.Linq;
-using System.Reflection;
-using System.Text;
using System.Windows.Input;
using Ninject;
using Pickles.Parser;
using System.Globalization;
namespace Pickles.UserInterface
{
- public class MainWindowViewModel : INotifyPropertyChanged
+ public class MainWindowViewModel : NotifyPropertyChanged
{
+ private readonly SelectableCollection<DocumentationFormat> documentationFormats;
+ private readonly SelectableCollection<TestResultsFormat> testResultsFormats;
private string picklesVersion = typeof(Feature).Assembly.GetName().Version.ToString();
private string featureFolder;
private string outputFolder;
- private DocumentationFormat selectedDocumentationFormat;
private string projectName;
private string projectVersion;
- private TestResultsFormat selectedTestResultsFormat;
private string testResultsFile;
private CultureInfo selectedLanguage = CultureInfo.CurrentUICulture;
+ public MainWindowViewModel()
+ {
+ this.documentationFormats = new SelectableCollection<DocumentationFormat>(Enum.GetValues(typeof(DocumentationFormat)).Cast<DocumentationFormat>());
+ this.documentationFormats.First().IsSelected = true;
+
+ this.testResultsFormats = new SelectableCollection<TestResultsFormat>(Enum.GetValues(typeof(TestResultsFormat)).Cast<TestResultsFormat>());
+ this.documentationFormats.First().IsSelected = true;
+ }
+
public string PicklesVersion
{
get { return picklesVersion; }
- set { picklesVersion = value; RaisePropertyChanged("PicklesVersion"); }
+ set { picklesVersion = value; this.RaisePropertyChanged(() => this.PicklesVersion); }
}
public string FeatureFolder
{
get { return featureFolder; }
- set { featureFolder = value; RaisePropertyChanged("FeatureFolder"); }
+ set { featureFolder = value; RaisePropertyChanged(() => this.FeatureFolder); }
}
public string OutputFolder
{
get { return outputFolder; }
- set { outputFolder = value; RaisePropertyChanged("OutputFolder"); }
+ set { outputFolder = value; RaisePropertyChanged(() => this.OutputFolder); }
}
- public DocumentationFormat SelectedDocumentationFormat
+ public SelectableCollection<DocumentationFormat> DocumentationFormatValues
{
- get { return selectedDocumentationFormat; }
- set { selectedDocumentationFormat = value; RaisePropertyChanged("SelectedDocumentationFormat"); }
- }
-
- public IEnumerable<DocumentationFormat> DocumentationFormatValues
- {
- get { return Enum.GetValues(typeof (DocumentationFormat)).Cast<DocumentationFormat>(); }
+ get { return this.documentationFormats; }
}
public string ProjectName
{
get { return projectName; }
- set { projectName = value; RaisePropertyChanged("ProjectName"); }
+ set { projectName = value; RaisePropertyChanged(() => ProjectName); }
}
public string ProjectVersion
{
get { return projectVersion; }
- set { projectVersion = value; RaisePropertyChanged("ProjectVersion"); }
+ set { projectVersion = value; RaisePropertyChanged(() => ProjectVersion); }
}
public string TestResultsFile
{
get { return testResultsFile; }
- set { testResultsFile = value; RaisePropertyChanged("TestResultsFile"); }
+ set { testResultsFile = value; RaisePropertyChanged(() => TestResultsFile); }
}
- public TestResultsFormat SelectedTestResultsFormat
+ public SelectableCollection<TestResultsFormat> TestResultsFormatValues
{
- get { return selectedTestResultsFormat; }
- set { selectedTestResultsFormat = value; RaisePropertyChanged("SelectedTestResultsFormat"); }
- }
-
- public IEnumerable<TestResultsFormat> TestResultsFormatValues
- {
- get { return Enum.GetValues(typeof(TestResultsFormat)).Cast<TestResultsFormat>(); }
+ get { return this.testResultsFormats; }
}
public CultureInfo SelectedLanguage
{
get { return selectedLanguage; }
- set { selectedLanguage = value; RaisePropertyChanged("SelectedLanguage"); }
+ set { selectedLanguage = value; RaisePropertyChanged(() => SelectedLanguage); }
}
public IEnumerable<CultureInfo> LanguageValues
{
get { return CultureInfo.GetCultures(CultureTypes.NeutralCultures); }
}
- #region Methods
-
- private void RaisePropertyChanged(string propertyName)
- {
- // take a copy to prevent thread issues
- PropertyChangedEventHandler handler = PropertyChanged;
- if (handler != null)
- {
- handler(this, new PropertyChangedEventArgs(propertyName));
- }
- }
-
- #endregion
-
- #region INotifyPropertyChanged Members
-
- public event PropertyChangedEventHandler PropertyChanged;
-
- #endregion
-
#region Commands
public ICommand GeneratePickles
@@ -126,11 +100,11 @@ public ICommand GeneratePickles
configuration.FeatureFolder = new DirectoryInfo(featureFolder);
configuration.OutputFolder = new DirectoryInfo(outputFolder);
- configuration.DocumentationFormat = selectedDocumentationFormat;
+ configuration.DocumentationFormat = this.documentationFormats.Selected;
configuration.SystemUnderTestName = projectName;
configuration.SystemUnderTestVersion = projectVersion;
configuration.TestResultsFile = testResultsFile != null ? new FileInfo(testResultsFile) : null;
- configuration.TestResultsFormat = selectedTestResultsFormat;
+ configuration.TestResultsFormat = this.testResultsFormats.Selected;
configuration.Language = selectedLanguage != null ? selectedLanguage.TwoLetterISOLanguageName : CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
var runner = kernel.Get<Runner>();
@@ -0,0 +1,24 @@
+using System;
+using System.ComponentModel;
+using System.Linq.Expressions;
+
+namespace Pickles.UserInterface
+{
+ /// <summary>
+ /// An implementation of <see cref="INotifyPropertyChanged"/>.
+ /// </summary>
+ public abstract class NotifyPropertyChanged : INotifyPropertyChanged
+ {
+ public event PropertyChangedEventHandler PropertyChanged;
+
+ /// <summary>
+ /// Raises the <see cref="PropertyChanged"/> event.
+ /// </summary>
+ /// <typeparam name="TValue">The type of the class that is raising the event.</typeparam>
+ /// <param name="selector">Contains the propery expression of the propery that changed.</param>
+ protected void RaisePropertyChanged<TValue>(Expression<Func<TValue>> selector)
+ {
+ this.PropertyChanged.Raise(this, selector);
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit e2cc0a8

Please sign in to comment.