Fix views and view models.

This commit is contained in:
Daniel Kraus 2015-08-07 21:37:14 +02:00
parent edaf88c4cd
commit bde85e5651
14 changed files with 419 additions and 19 deletions

View File

@ -0,0 +1,53 @@
/* SettingsTest.cs
* part of zaaReloaded2
*
* Copyright 2015 Daniel Kraus
*
* 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.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using zaaReloaded2.Controller;
using zaaReloaded2.Controller.Elements;
namespace Tests.Controller
{
[TestFixture]
class SettingsTest
{
[Test]
public void CloneSettings()
{
SelectEachDay selectEachDay = new SelectEachDay();
Items items = new Items("some text");
Settings source = new Settings(
"hello world",
new List<ElementBase>() { selectEachDay, items });
source.ReferenceStyle = zaaReloaded2.Formatter.ReferenceStyle.IfSpecialOrAbnormal;
Settings clone = source.Clone() as Settings;
Assert.AreNotSame(source, clone);
Assert.AreEqual("Kopie von " + source.Name, clone.Name,
"Name");
Assert.AreNotSame(source.Elements, clone.Elements);
Assert.AreEqual(source.ReferenceStyle, clone.ReferenceStyle,
"ReferenceStyle");
Assert.AreEqual(
((Items)source.Elements[1]).Content,
((Items)clone.Elements[1]).Content,
"Items content");
}
}
}

View File

@ -79,6 +79,7 @@
</Choose>
<ItemGroup>
<Compile Include="Controller\SettingsRepositoryTest.cs" />
<Compile Include="Controller\SettingsTest.cs" />
<Compile Include="Formatter\DocumentWriterTest.cs" />
<Compile Include="Thesaurus\ThesaurusTest.cs" />
<Compile Include="Controller\Elements\ItemsTest.cs" />

View File

@ -9,9 +9,9 @@ using System.Security;
[assembly: AssemblyTitle("zaaReloaded2")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyCompany("Daniel Kraus")]
[assembly: AssemblyProduct("zaaReloaded2")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2015")]
[assembly: AssemblyCopyright("Copyright © Daniel Kraus 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: InternalsVisibleTo("Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010061ecc0718277dee13e7dae2dad33787a981c9883ba80a659bebbdbec76563e201a7a3a6a5852e01bb5eb328d24d5889244b4626da9af9f93db663565441a3120e3985789e6f2a39289f4eed063725b84152cbef472d9dd2f7495f51dad6c91f4dc6fb7c72cb6bd9381335ac9878ec0a6369e880f35b8eca3063e16468d7704eb")]

View File

@ -202,10 +202,6 @@ namespace zaaReloaded2
Properties.Settings.Default.LastSettings = settings.Uid;
Properties.Settings.Default.Save();
};
vm.RequestCloseView += (sender, args) =>
{
repository.Save();
};
vm.InjectInto<SettingsRepositoryView>().ShowDialog();
}

View File

@ -96,7 +96,7 @@ namespace zaaReloaded2.ViewModels
Categories = new List<CategoryViewModel>();
if (allowControlElements)
{
Categories.Add(
AddCategory(
new CategoryViewModel(
"Kontroll-Elemente",
new Collection<ViewModelBase>()
@ -108,7 +108,7 @@ namespace zaaReloaded2.ViewModels
)
);
}
Categories.Add(
AddCategory(
new CategoryViewModel(
"Ausgabe-Elemente",
new Collection<ViewModelBase>()
@ -124,6 +124,12 @@ namespace zaaReloaded2.ViewModels
#region Private methods
void AddCategory(CategoryViewModel category)
{
category.PropertyChanged += ElementViewModel_PropertyChanged;
Categories.Add(category);
}
/// <summary>
/// Creates a new ControlElementViewModel that wraps a ControlElementBase
/// object. The display string of the ControlElementViewModel is taken
@ -152,13 +158,16 @@ namespace zaaReloaded2.ViewModels
void ElementViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "IsSelected")
// Casting sender as ElementViewModel may result in Null, but this
// is a desired effect because category headings may be selected
// in a view, but are not valid ElementViewModels that we could
// 'choose'. In addition, when an element is selected, another one
// is deselected, and the event triggers twice, once for the selected
// element and once for the deselected one.
ElementViewModel elementVM = sender as ElementViewModel;
if (elementVM != null && elementVM.IsSelected && e.PropertyName == "IsSelected")
{
// Casting sender as ElementViewModel may result in Null, but this
// is a desired effect because category headings may be selected
// in a view, but are not valid ElementViewModels that we could
// 'choose'.
Selected = sender as ElementViewModel;
Selected = elementVM;
}
}
@ -172,7 +181,7 @@ namespace zaaReloaded2.ViewModels
bool CanChooseElement()
{
return Selected != null;
return Selected != null && Selected.IsSelected == true;
}
#endregion

View File

@ -199,6 +199,10 @@ namespace zaaReloaded2.ViewModels
SettingsViewModel vm = new SettingsViewModel(s);
AddSettingsViewModel(vm);
}
RequestCloseView += (sender, args) =>
{
_repository.Store();
};
}
#endregion

View File

@ -0,0 +1,55 @@
<!--
ElementPickerView.xaml
part of zaaReloaded2
Copyright 2015 Daniel Kraus
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.
-->
<Window x:Class="zaaReloaded2.Views.ElementPickerView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:b="clr-namespace:Bovender.Mvvm.Views.Settings;assembly=Bovender"
SizeToContent="WidthAndHeight" ResizeMode="CanResizeWithGrip" ShowInTaskbar="False"
b:WindowState.CenterScreen="True" b:WindowState.Save="True"
Title="Neues Element auswählen"
>
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/zaaReloaded2;component/Style.xaml" />
<ResourceDictionary>
<DataTemplate x:Key="ChildElement">
<TextBlock Text="{Binding DisplayString}" />
</DataTemplate>
<HierarchicalDataTemplate x:Key="CategoriesTree"
ItemsSource="{Binding Children}"
ItemTemplate="{StaticResource ResourceKey=ChildElement}">
<TextBlock Text="{Binding DisplayString}" />
</HierarchicalDataTemplate>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<StackPanel Margin="10">
<Label Content="Verfügbare Elemente:" Target="{Binding ElementName=ElementsTreeView}" />
<!-- TODO: Expand tree by default. -->
<TreeView ItemsSource="{Binding Categories}" ItemTemplate="{StaticResource ResourceKey=CategoriesTree}"
Height="160" Width="240"/>
<UniformGrid HorizontalAlignment="Right" Columns="2" Rows="1" Margin="0 10 0 0">
<Button Content="OK" Command="{Binding ChooseElementCommand}" IsDefault="True" Margin="0 0 10 0" />
<Button Content="Abbrechen" Command="{Binding CloseViewCommand}" IsCancel="True" Margin="10 0 0 0" />
</UniformGrid>
</StackPanel>
</Window>

View File

@ -0,0 +1,33 @@
/* ElementPickerView.xaml.cs
* part of zaaReloaded2
*
* Copyright 2015 Daniel Kraus
*
* 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.
*/
using System.Windows;
namespace zaaReloaded2.Views
{
/// <summary>
/// Interaction logic for ElementPickerView.xaml
/// </summary>
public partial class ElementPickerView : Window
{
public ElementPickerView()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,40 @@
<!--
ElementView.xaml
part of zaaReloaded2
Copyright 2015 Daniel Kraus
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.
-->
<Window x:Class="zaaReloaded2.Views.ElementView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:b="clr-namespace:Bovender.Mvvm.Views.Settings;assembly=Bovender"
SizeToContent="WidthAndHeight" ResizeMode="CanResizeWithGrip" ShowInTaskbar="False"
b:WindowState.CenterScreen="True" b:WindowState.Save="True"
Title="Element bearbeiten"
>
<Window.Resources>
<ResourceDictionary Source="/zaaReloaded2;component/Style.xaml" />
</Window.Resources>
<StackPanel Margin="20">
<Label Content="Inhalt:" Target="{Binding ElementName=ContentTextBox}" />
<TextBox Text="{Binding Content}" x:Name="ContentTextBox" Margin="0 0 0 5"
Width="300" Height="60" TextWrapping="Wrap" />
<UniformGrid HorizontalAlignment="Right" Columns="2" Rows="1" Margin="0 10 0 0">
<Button Content="OK" Command="{Binding SaveCommand}" IsDefault="True" Margin="0 0 5 0" />
<Button Content="Abbrechen" Command="{Binding CloseViewCommand}" IsCancel="True" Margin="5 0 0 0" />
</UniformGrid>
</StackPanel>
</Window>

View File

@ -0,0 +1,33 @@
/* ElementView.xaml.cs
* part of zaaReloaded2
*
* Copyright 2015 Daniel Kraus
*
* 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.
*/
using System.Windows;
namespace zaaReloaded2.Views
{
/// <summary>
/// Interaction logic for ElementView.xaml
/// </summary>
public partial class ElementView : Window
{
public ElementView()
{
InitializeComponent();
}
}
}

View File

@ -21,6 +21,8 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:b="clr-namespace:Bovender.Mvvm.Views.Settings;assembly=Bovender"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:action="clr-namespace:Bovender.Mvvm.Actions;assembly=Bovender"
SizeToContent="WidthAndHeight" ResizeMode="CanResizeWithGrip" ShowInTaskbar="False"
b:WindowState.CenterScreen="True" b:WindowState.Save="True"
Title="Stil auswählen"
@ -28,16 +30,21 @@
<Window.Resources>
<ResourceDictionary Source="/zaaReloaded2;component/style.xaml" />
</Window.Resources>
<i:Interaction.Triggers>
<i:EventTrigger SourceObject="{Binding EditSettingsMessage}" EventName="Sent">
<action:ShowViewAction View="zaaReloaded2.Views.SettingsView" Assembly="zaaReloaded2" />
</i:EventTrigger>
</i:Interaction.Triggers>
<StackPanel Margin="10">
<Label Target="{Binding ElementName=settingsList}">Bitte Stil auswählen:</Label>
<DockPanel Margin="0 5 0 0">
<StackPanel DockPanel.Dock="Right" Margin="10 0 0 0">
<Button Command="{Binding UseSettingsCommand}" Content="Wählen" Margin="0 0 0 5" />
<Button Command="{Binding UseSettingsCommand}" Content="Wählen" IsDefault="True" Margin="0 0 0 5" />
<Button Command="{Binding AddSettingsCommand}" Content="Hinzufügen" Margin="0 10 0 5" />
<Button Command="{Binding EditSettingsCommand}" Content="Bearbeiten" Margin="0 0 0 5" />
<Button Command="{Binding DeleteSettingsCommand}" Content="Entfernen" Margin="0 0 0 5" />
<Button Command="{Binding CopySettingsCommand}" Content="Kopieren" Margin="0 0 0 5" />
<Button Command="{Binding CloseViewCommand}" Content="Abbruch" Margin="0 10 0 0" IsCancel="True" />
<Button Command="{Binding CloseViewCommand}" Content="Schließen" Margin="0 10 0 0" IsCancel="True" />
</StackPanel>
<StackPanel>
<ListBox ItemsSource="{Binding SettingsList}"

View File

@ -0,0 +1,92 @@
<!--
SettingsView.xaml
part of zaaReloaded2
Copyright 2015 Daniel Kraus
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.
-->
<Window x:Class="zaaReloaded2.Views.SettingsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:b="clr-namespace:Bovender.Mvvm.Views.Settings;assembly=Bovender"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:action="clr-namespace:Bovender.Mvvm.Actions;assembly=Bovender"
SizeToContent="WidthAndHeight" ResizeMode="CanResizeWithGrip" ShowInTaskbar="False"
b:WindowState.CenterScreen="True" b:WindowState.Save="True"
Title="Stil bearbeiten"
>
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/zaaReloaded2;component/Style.xaml" />
<ResourceDictionary>
<DataTemplate x:Key="ChildElement">
<TextBlock Text="{Binding DisplayString}" />
</DataTemplate>
<HierarchicalDataTemplate x:Key="ElementsTree"
ItemsSource="{Binding Elements}"
ItemTemplate="{StaticResource ResourceKey=ChildElement}">
<TextBlock Text="{Binding DisplayString}" />
</HierarchicalDataTemplate>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<i:Interaction.Triggers>
<i:EventTrigger SourceObject="{Binding AddElementMessage}" EventName="Sent">
<action:ShowViewDialogAction View="zaaReloaded2.Views.ElementPickerView" Assembly="zaaReloaded2" />
</i:EventTrigger>
<i:EventTrigger SourceObject="{Binding AddChildElementMessage}" EventName="Sent">
<action:ShowViewDialogAction View="zaaReloaded2.Views.ElementPickerView" Assembly="zaaReloaded2" />
</i:EventTrigger>
<i:EventTrigger SourceObject="{Binding EditElementMessage}" EventName="Sent">
<action:ShowViewDialogAction View="zaaReloaded2.Views.ElementView" Assembly="zaaReloaded2" />
</i:EventTrigger>
</i:Interaction.Triggers>
<StackPanel Margin="10">
<DockPanel IsEnabled="{Binding IsNameEnabled}">
<Label DockPanel.Dock="Left" Content="Name:" Target="{Binding ElementName=NameTextBox}"
Margin="0 0 10 0"/>
<TextBox Text="{Binding Name}" x:Name="NameTextBox" HorizontalAlignment="Stretch" />
</DockPanel>
<DockPanel>
<Label DockPanel.Dock="Left" Content="Referenzwerte anzeigen:" Margin="0 0 10 0"
Target="{Binding ElementName=ReferenceStyleChooser}" />
<ComboBox ItemsSource="{Binding ReferenceStyle.Choices}"
ToolTip="{Binding ReferenceStyle.ToolTip}"
SelectedItem="{Binding ReferenceStyle.SelectedItem}"
x:Name="ReferenceStyleChooser" HorizontalAlignment="Stretch" />
</DockPanel>
<GroupBox Header="Elemente" Margin="0 10 0 0">
<DockPanel LastChildFill="True">
<StackPanel DockPanel.Dock="Right" Margin="10 0 0 0">
<Button Command="{Binding AddElementCommand}" Content="Neues Element" Margin="0 0 0 10"
x:Name="NewElementButton"/>
<Button Command="{Binding AddChildElementCommand}" Content="Neues Kindelement" Margin="0 0 0 10" />
<Button Command="{Binding EditElementCommand}" IsDefault="True" Content="Bearbeiten" Margin="0 0 0 10" />
<Button Command="{Binding CopyElementCommand}" Content="Kopieren" Margin="0 0 0 10" />
<Button Command="{Binding RemoveElementCommand}" Content="Entfernen" Margin="0 0 0 10" />
</StackPanel>
<TreeView ItemsSource="{Binding Elements}"
ItemTemplate="{StaticResource ResourceKey=ElementsTree}"
MinWidth="200"/>
</DockPanel>
</GroupBox>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button Command="{Binding CloseViewCommand}" Content="Schließen" IsCancel="True" Margin="0 10 0 0"
Width="{Binding ElementName=NewElementButton,Path=ActualWidth}"/>
</StackPanel>
</StackPanel>
</Window>

View File

@ -0,0 +1,33 @@
/* SettingsView.xaml.cs
* part of zaaReloaded2
*
* Copyright 2015 Daniel Kraus
*
* 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.
*/
using System.Windows;
namespace zaaReloaded2.Views
{
/// <summary>
/// Interaction logic for AboutView.xaml
/// </summary>
public partial class SettingsView : Window
{
public SettingsView()
{
InitializeComponent();
}
}
}

View File

@ -27,11 +27,24 @@
<NoStandardLibraries>false</NoStandardLibraries>
<RootNamespace>zaaReloaded2</RootNamespace>
<AssemblyName>zaaReloaded2</AssemblyName>
<LoadBehavior>3</LoadBehavior>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<DefineConstants>VSTO40</DefineConstants>
<BootstrapperEnabled>true</BootstrapperEnabled>
<BootstrapperComponentsLocation>HomeSite</BootstrapperComponentsLocation>
<PublishUrl>publish\</PublishUrl>
<InstallUrl />
<TargetCulture>en</TargetCulture>
<ApplicationVersion>1.0.0.0</ApplicationVersion>
<AutoIncrementApplicationRevision>true</AutoIncrementApplicationRevision>
<UpdateEnabled>true</UpdateEnabled>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>days</UpdateIntervalUnits>
<IsWebBootstrapper>False</IsWebBootstrapper>
<ProductName>zaaReloaded2</ProductName>
<PublisherName />
<SupportUrl />
<FriendlyName>zaaReloaded2</FriendlyName>
<OfficeApplicationDescription />
<LoadBehavior>3</LoadBehavior>
</PropertyGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0">
@ -39,6 +52,16 @@
<ProductName>Microsoft .NET Framework 4 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.VSTORuntime.4.0">
<Visible>False</Visible>
<ProductName>Microsoft Visual Studio 2010 Tools for Office Runtime %28x86 and x64%29</ProductName>
@ -226,6 +249,15 @@
<Compile Include="ViewModels\FormatElementViewModel.cs" />
<Compile Include="ViewModels\ControlElementViewModel.cs" />
<Compile Include="ViewModels\SettingsRepositoryViewModel.cs" />
<Compile Include="Views\ElementPickerView.xaml.cs">
<DependentUpon>ElementPickerView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\ElementView.xaml.cs">
<DependentUpon>ElementView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\SettingsView.xaml.cs">
<DependentUpon>SettingsView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\SettingsRepositoryView.xaml.cs">
<DependentUpon>SettingsRepositoryView.xaml</DependentUpon>
</Compile>
@ -297,6 +329,18 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Resource>
<Page Include="Views\ElementPickerView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\ElementView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\SettingsView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\SettingsRepositoryView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>