Merge branch 'release-2.0.0-alpha.5'

This commit is contained in:
Daniel Kraus 2015-08-04 02:46:21 +02:00
commit 34006ba1e9
27 changed files with 600 additions and 68 deletions

View File

@ -1,3 +1,12 @@
Version 2.0.0-alpha.5 (2015-08-04)
========================================================================
- FIX: Daniels Spezial löscht nicht mehr die Unterschriften.
- NEU: Eingebautes Demo-Dokument zum Ausprobieren.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Version 2.0.0-alpha.3 (2015-07-31)
========================================================================

View File

@ -91,6 +91,7 @@
<Compile Include="Thesaurus\TestThesaurus.cs" />
<Compile Include="Importer\ZaaImporter\TimePointTest.cs" />
<Compile Include="TestHelpers.cs" />
<Compile Include="ViewModels\ElementPickerViewModelTest.cs" />
<Compile Include="ViewModels\SettingsRepositoryViewModelTest.cs" />
<Compile Include="ViewModels\SettingsViewModelTest.cs" />
</ItemGroup>

View File

@ -0,0 +1,54 @@
/* ElementPickerViewModelTest.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 Bovender.Mvvm.ViewModels;
using zaaReloaded2.ViewModels;
namespace Tests.ViewModels
{
[TestFixture]
class ElementPickerViewModelTest
{
[Test]
public void ChooseElement()
{
ElementPickerViewModel vm = new ElementPickerViewModel(true);
ViewModelBase elementVM = vm.Categories.First().Children.First();
elementVM.IsSelected = true;
string expectedLabel = elementVM.DisplayString;
Assert.IsTrue(vm.ChooseElementCommand.CanExecute(null),
"Cannot execute ChooseElementCommand");
bool messageSent = false;
vm.ElementChosenMessage.Sent += (sender, args) =>
{
messageSent = true;
ViewModelBase messageContentVM = args.Content.ViewModel as ViewModelBase;
Assert.AreEqual(expectedLabel, messageContentVM.DisplayString);
};
vm.ChooseElementCommand.Execute(null);
Assert.IsTrue(messageSent, "No message was sent when element was chosen");
}
}
}

View File

@ -40,13 +40,52 @@ namespace Tests.ViewModels
[Test]
public void AddElement()
{
bool messageSent = false;
Settings model = _settingsVM.RevealModelObject() as Settings;
int oldViewModelElementCount = _settingsVM.Elements.Count;
int oldModelElementCount = model.Elements.Count;
_settingsVM.AddElementMessage.Sent += (sender, args) =>
{
messageSent = true;
ElementPickerViewModel picker = args.Content.ViewModel as ElementPickerViewModel;
Assert.IsNotNull(picker, "ViewModel in MessageContent is not an ElementPickerViewModel");
picker.Categories.First().Children.First().IsSelected = true;
picker.ChooseElementCommand.Execute(null);
};
_settingsVM.AddElementCommand.Execute(null);
Assert.IsTrue(messageSent, "Message was not sent");
Assert.AreEqual(oldViewModelElementCount + 1, _settingsVM.Elements.Count,
"Count of elements in ViewModel was not increased by 1");
Assert.AreEqual(oldModelElementCount + 1, model.Elements.Count,
"Count of elements in settings Model was not increased by 1");
}
[Test]
public void AddChildElement()
{
bool messageSent = false;
SelectEachDay model = new SelectEachDay();
ControlElementViewModel viewModel = new ControlElementViewModel(model);
_settingsVM.AddElementViewModel(viewModel);
viewModel.IsSelected = true;
int oldViewModelChildrenCount = viewModel.Elements.Count;
int oldModelChildrenCount = model.FormatElements.Count;
_settingsVM.AddChildElementMessage.Sent += (sender, args) =>
{
messageSent = true;
ElementPickerViewModel picker = args.Content.ViewModel as ElementPickerViewModel;
Assert.IsNotNull(picker, "ViewModel in MessageContent is not an ElementPickerViewModel");
picker.Categories.First().Children.First().IsSelected = true;
Assert.IsTrue(picker.ChooseElementCommand.CanExecute(null),
"Cannot execute element picker's ChooseElementCommand.");
picker.ChooseElementCommand.Execute(null);
};
_settingsVM.AddChildElementCommand.Execute(null);
Assert.IsTrue(messageSent, "Message was not sent");
Assert.AreEqual(oldViewModelChildrenCount + 1, viewModel.Elements.Count,
"Count of children in ViewModel was not increased by 1");
Assert.AreEqual(oldModelChildrenCount + 1, model.FormatElements.Count,
"Count of children in Model was not increased by 1");
}
[Test]
@ -58,7 +97,7 @@ namespace Tests.ViewModels
parent.IsSelected = true;
Assert.IsTrue(_settingsVM.AddChildElementCommand.CanExecute(null));
FormatElementViewModel child = new FormatElementViewModel(new Items());
parent.AddChildElement(child);
_settingsVM.AddChildElementViewModel(parent, child);
parent.IsSelected = false;
child.IsSelected = true;
Assert.IsFalse(_settingsVM.AddChildElementCommand.CanExecute(null));
@ -67,13 +106,13 @@ namespace Tests.ViewModels
[Test]
public void DeleteElement()
{
throw new NotImplementedException();
}
[Test]
public void CopyElement()
{
throw new NotImplementedException();
}
}
}

BIN
gimp/d.xcf Normal file

Binary file not shown.

View File

@ -1,4 +1,4 @@
2.0.0-alpha.4
http://zaa.nephrowiki.de/downloads/zaaReloaded-2.0.0-alpha.4.exe
3f511ac90dbfbb14318948a3be1d1f9d2eb059d1 publish/release/zaaReloaded-2.0.0-alpha.4.exe
2.0.0-alpha.5
http://zaa.nephrowiki.de/downloads/zaaReloaded-2.0.0-alpha.5.exe
423cbe81b42ddfc293cf5b387c1d8d269dce3f61 publish/release/zaaReloaded-2.0.0-alpha.5.exe

View File

@ -31,7 +31,9 @@ namespace zaaReloaded2.Controller.Elements
/// </summary>
public IList<FormatElementBase> FormatElements { get; private set; }
public ControlElementBase() { }
public ControlElementBase()
: this(new List<FormatElementBase>())
{ }
public ControlElementBase(IList<FormatElementBase> formatElements)
{

View File

@ -58,16 +58,12 @@ namespace zaaReloaded2.Controller
#region Constructors
public Settings()
{
Elements = new List<ElementBase>();
Uid = Guid.NewGuid();
}
: this(string.Empty, new List<ElementBase>())
{ }
public Settings(string name)
: this()
{
Name = name;
}
: this(name, null)
{ }
/// <summary>
/// Creates a new Settings object with an initial
@ -76,9 +72,8 @@ namespace zaaReloaded2.Controller
/// <param name="initialElements">Set of ElementBase
/// object (or derived ones).</param>
public Settings(IList<ElementBase> initialElements)
{
Elements = initialElements;
}
: this(String.Empty, initialElements)
{ }
/// <summary>
/// Creates a new Settings object with an initial
@ -88,9 +83,10 @@ namespace zaaReloaded2.Controller
/// object (or derived ones).</param>
/// <param name="name">Name of these settings.</param>
public Settings(string name, IList<ElementBase> initialElements)
: this(initialElements)
{
Uid = Guid.NewGuid();
Name = name;
Elements = initialElements;
}
#endregion

75
zaaReloaded2/Demo/Demo.cs Executable file
View File

@ -0,0 +1,75 @@
/* Demo.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.IO;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Word;
namespace zaaReloaded2.Demo
{
/// <summary>
/// Static class that serves to load an embedded Word document
/// into a temporary file and open that temporary file in Word.
/// </summary>
static class Demo
{
#region Public methods
/// <summary>
/// Opens a demo document. The document's Saved property is set to
/// false so that a user who wants to save changes will be prompted
/// for a file name.
/// </summary>
public static void OpenDemoDocument()
{
string tempFile = CreateTempFileFromResource();
Document demoDoc = Globals.ThisAddIn.Application.Documents
.Add(Template: tempFile);
File.Delete(tempFile);
}
#endregion
#region Private methods
/// <summary>
/// Copies the built-in demo file from a resource stream to a
/// temporary file and returns the path to that file.
/// </summary>
/// <returns>Path to the newly created temporary file.</returns>
static string CreateTempFileFromResource()
{
string resourceName = "zaaReloaded2.Demo.Demo.docx";
Stream resourceStream = typeof(Demo).Assembly
.GetManifestResourceStream(resourceName);
if (resourceStream == null)
{
throw new IOException("Unable to open stream " + resourceName);
}
string fileName = Path.GetTempFileName() + ".docx";
Stream tempStream = File.Create(fileName);
resourceStream.CopyTo(tempStream);
tempStream.Close();
return fileName;
}
#endregion
}
}

BIN
zaaReloaded2/Demo/Demo.docx Executable file

Binary file not shown.

View File

@ -79,8 +79,8 @@ namespace zaaReloaded2.Formatter
static void FixSalutation(Document document)
{
Regex sal = new Regex(@"^Mit.*(freundl|kolleg)");
Regex med = new Regex(@"^((Häusl|Empf).*Medikat)|Therapieempf");
Regex sal = new Regex(@"^Mit.*?Grüßen");
Regex med = new Regex(@"^((Häusl|Empf).*?Medikat)|Therapieempf");
foreach (Paragraph p in document.Paragraphs)
{
if (sal.IsMatch(p.Range.Text)) p.Range.Text = "Mit freundlichen, kollegialen Grüßen,";

BIN
zaaReloaded2/Icons/d.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1012 B

View File

@ -233,5 +233,17 @@ namespace zaaReloaded2.Properties {
return ((string)(this["DefaultItemsDrugs"]));
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("00000000-0000-0000-0000-000000000000")]
public global::System.Guid LastSettings {
get {
return ((global::System.Guid)(this["LastSettings"]));
}
set {
this["LastSettings"] = value;
}
}
}
}

View File

@ -71,5 +71,8 @@
<Setting Name="DefaultItemsDrugs" Type="System.String" Scope="Application">
<Value Profile="(Default)">Medikamente: TAC, CSA, SIR, Vancomycin, Gentamicin, Tobramicin</Value>
</Setting>
<Setting Name="LastSettings" Type="System.Guid" Scope="User">
<Value Profile="(Default)">00000000-0000-0000-0000-000000000000</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@ -26,6 +26,11 @@ using System.Windows;
using System.Drawing;
using System.Windows.Resources;
using Office = Microsoft.Office.Core;
using zaaReloaded2.Views;
using zaaReloaded2.ViewModels;
using zaaReloaded2.Importer.ZaaImporter;
using zaaReloaded2.Formatter;
using zaaReloaded2.Controller;
// TODO: Follow these steps to enable the Ribbon (XML) item:
@ -51,12 +56,14 @@ namespace zaaReloaded2
[ComVisible(true)]
public class Ribbon : Office.IRibbonExtensibility
{
private Office.IRibbonUI ribbon;
#region Constructor
public Ribbon()
{
}
#endregion
#region IRibbonExtensibility Members
public string GetCustomUI(string ribbonID)
@ -71,7 +78,8 @@ namespace zaaReloaded2
public void Ribbon_Load(Office.IRibbonUI ribbonUI)
{
this.ribbon = ribbonUI;
_ribbon = ribbonUI;
Globals.ThisAddIn.Application.WindowSelectionChange += Application_WindowSelectionChange;
}
/// <summary>
@ -86,6 +94,12 @@ namespace zaaReloaded2
{
switch (control.Id)
{
case "zrlFormat":
DoFormat();
break;
case "zrlSettings":
DoChooseSettings();
break;
case "zrlAbout":
ViewModels.AboutViewModel vm = new ViewModels.AboutViewModel();
vm.InjectInto<Views.AboutView>().ShowDialog();
@ -95,6 +109,9 @@ namespace zaaReloaded2
Globals.ThisAddIn.Application.ActiveDocument,
Globals.ThisAddIn.Application.Selection);
break;
case "zrlDemo":
Demo.Demo.OpenDemoDocument();
break;
default:
throw new InvalidOperationException("No operation defined for " + control.Id);
}
@ -135,6 +152,67 @@ namespace zaaReloaded2
}
}
public bool CanFormat(Office.IRibbonControl control)
{
return Globals.ThisAddIn.Application.Selection.Paragraphs.Count > 0;
}
#endregion
#region Private methods
void DoFormat()
{
if (CanFormat(null))
{
SettingsRepository repository = SettingsRepository.Load();
Guid lastSettingsUid = Properties.Settings.Default.LastSettings;
Settings lastSettings = repository.FindByGuid(lastSettingsUid);
if (lastSettings != null)
{
DoFormat(lastSettings);
}
else
{
DoChooseSettings();
}
}
}
void DoFormat(Settings settings)
{
ZaaImporter importer = new ZaaImporter();
importer.Import(Globals.ThisAddIn.Application.Selection.Text);
Formatter.Formatter formatter =new Formatter.Formatter(
Globals.ThisAddIn.Application.ActiveDocument);
formatter.Settings = settings;
formatter.Laboratory = importer.Laboratory;
formatter.Run();
}
void DoChooseSettings()
{
SettingsRepository repository = SettingsRepository.Load();
SettingsRepositoryViewModel vm = new SettingsRepositoryViewModel(repository);
vm.UseSettingsMessage.Sent += (sender, args) =>
{
SettingsViewModel settingsVM = args.Content.ViewModel as SettingsViewModel;
Settings settings = settingsVM.RevealModelObject() as Settings;
DoFormat(settings);
Properties.Settings.Default.LastSettings = settings.Uid;
};
vm.RequestCloseView += (sender, args) =>
{
repository.Save();
};
vm.InjectInto<SettingsRepositoryView>().ShowDialog();
}
public void Application_WindowSelectionChange(Microsoft.Office.Interop.Word.Selection Sel)
{
_ribbon.Invalidate();
}
#endregion
#region Helpers
@ -160,5 +238,11 @@ namespace zaaReloaded2
}
#endregion
#region Fields
private Office.IRibbonUI _ribbon;
#endregion
}
}

View File

@ -25,13 +25,17 @@
<tab id="zaaReloaded2" label="zaaReloaded2">
<group id="zrlFormatGroup" label="Formatieren">
<button id="zrlFormat" label="Formatieren" image="f.png" onAction="Ribbon_Click" size="large"
supertip="Formatiert den ausgewählten Bereich mit dem zuletzt verwendeten Stil." />
<button id="zrlChooseFormat" label="Stilauswahl" image="fff.png" onAction="Ribbon_Click" size="large"
supertip="Formatiert den ausgewählten Bereich mit dem zuletzt verwendeten Stil."
getEnabled="CanFormat" />
<button id="zrlSettings" label="Stilauswahl" image="fff.png" onAction="Ribbon_Click" size="large"
supertip="Zeigt eine Liste vorhandener Stile an. Stile können bearbeitet, hinzugefügt, gelöscht werden." />
<button id="zrlDaniel" label="Daniels Spezial" image="dk.png" onAction="Ribbon_Click" size="large"
getVisible="Daniel_GetVisible"/>
</group>
<group id="zrlInfoGroup" label="Info">
<button id="zrlDemo" label="Demo" image="d.png" onAction="Ribbon_Click" size="large"
screentip="Demo-Dokument öffnen"
supertip="Öffnet ein eingebautes Demo-Dokument, das zum Ausprobieren verwendet werden kann." />
<button id="zrlAbout" label="Über..." image="i.png" onAction="Ribbon_Click" size="large"
screentip="Über zaaReloaded"
supertip="Zeigt Informationen über das Add-in an." />

View File

@ -119,6 +119,7 @@ namespace zaaReloaded2
ExceptionViewModel vm = new ExceptionViewModel(e.Exception);
vm.InjectInto<ExceptionView>().ShowDialog();
}
#endregion
#region Private fields

View File

@ -1,2 +1,2 @@
2.0.0-alpha.4
2.0.0.4
2.0.0-alpha.5
2.0.0.5

View File

@ -26,24 +26,34 @@ using System.Collections.ObjectModel;
namespace zaaReloaded2.ViewModels
{
class ControlElementViewModel : ElementViewModel
public class ControlElementViewModel : ElementViewModel
{
#region Properties
public ObservableCollection<ElementViewModel> Elements
{
get { return null; }
}
/// <summary>
/// Gets a collection of child ElementViewModels.
/// </summary>
public ObservableCollection<ElementViewModel> Elements { get; protected set; }
#endregion
#region Constructors
public ControlElementViewModel() : base() { }
public ControlElementViewModel() : this(null) { }
public ControlElementViewModel(ControlElementBase controlElement)
: base(controlElement)
{ }
{
Elements = new ObservableCollection<ElementViewModel>();
if (controlElement != null)
{
foreach (FormatElementBase childElement in controlElement.FormatElements)
{
FormatElementViewModel childVM = new FormatElementViewModel(childElement);
Elements.Add(childVM);
}
}
}
#endregion

View File

@ -38,19 +38,65 @@ namespace zaaReloaded2.ViewModels
/// <summary>
/// A two-dimensional tree
/// </summary>
public IList<CategoryViewModel> AvailableElements { get; private set; }
public IList<CategoryViewModel> Categories { get; private set; }
/// <summary>
/// Gets the currently selected element, or null if no element is selected.
/// </summary>
/// <remarks>
/// TODO: Raise PropertyChanged event.
/// </remarks>
public ElementViewModel Selected { get; private set; }
#endregion
#region Commands
public DelegatingCommand ChooseElementCommand
{
get
{
if (_chooseElementCommand == null)
{
_chooseElementCommand = new DelegatingCommand(
param => DoChooseElement(),
param => CanChooseElement());
}
return _chooseElementCommand;
}
}
#endregion
#region Messages
/// <summary>
/// A message that is sent out when an element has been chosen;
/// the message content is the element's view model with the element
/// wrapped inside.
/// </summary>
public Message<ViewModelMessageContent> ElementChosenMessage
{
get
{
if (_elementChosenMessage == null)
{
_elementChosenMessage = new Message<ViewModelMessageContent>();
}
return _elementChosenMessage;
}
}
#endregion
#region Constructors
public ElementPickerViewModel(SettingsViewModel caller, bool allowControlElements)
public ElementPickerViewModel(bool allowControlElements)
{
_caller = caller;
AvailableElements = new List<CategoryViewModel>();
Categories = new List<CategoryViewModel>();
if (allowControlElements)
{
AvailableElements.Add(
Categories.Add(
new CategoryViewModel(
"Kontroll-Elemente",
new Collection<ViewModelBase>()
@ -62,7 +108,7 @@ namespace zaaReloaded2.ViewModels
)
);
}
AvailableElements.Add(
Categories.Add(
new CategoryViewModel(
"Ausgabe-Elemente",
new Collection<ViewModelBase>()
@ -87,6 +133,7 @@ namespace zaaReloaded2.ViewModels
{
ControlElementViewModel vm = new ControlElementViewModel(element);
vm.DisplayString = element.Label;
vm.PropertyChanged += ElementViewModel_PropertyChanged;
return vm;
}
@ -99,9 +146,35 @@ namespace zaaReloaded2.ViewModels
{
FormatElementViewModel vm = new FormatElementViewModel(element);
vm.DisplayString = name;
vm.PropertyChanged += ElementViewModel_PropertyChanged;
return vm;
}
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'.
Selected = sender as ElementViewModel;
}
}
void DoChooseElement()
{
if (CanChooseElement())
{
ElementChosenMessage.Send(new ViewModelMessageContent(Selected));
}
}
bool CanChooseElement()
{
return Selected != null;
}
#endregion
#region Implementation ov ViewModelBase
@ -115,7 +188,8 @@ namespace zaaReloaded2.ViewModels
#region Fields
SettingsViewModel _caller;
DelegatingCommand _chooseElementCommand;
Message<ViewModelMessageContent> _elementChosenMessage;
#endregion
}

View File

@ -24,7 +24,7 @@ using zaaReloaded2.Controller.Elements;
namespace zaaReloaded2.ViewModels
{
class FormatElementViewModel : ElementViewModel
public class FormatElementViewModel : ElementViewModel
{
#region Public properties

View File

@ -23,6 +23,7 @@ using Bovender.Mvvm;
using Bovender.Mvvm.ViewModels;
using Bovender.Mvvm.Messaging;
using zaaReloaded2.Controller;
using System.Collections.ObjectModel;
namespace zaaReloaded2.ViewModels
{
@ -30,7 +31,7 @@ namespace zaaReloaded2.ViewModels
{
#region Properties
public IList<SettingsViewModel> SettingsList { get; private set; }
public ObservableCollection<SettingsViewModel> SettingsList { get; private set; }
public SettingsViewModel Selected { get; private set; }
@ -123,7 +124,7 @@ namespace zaaReloaded2.ViewModels
#region Messages
Message<ViewModelMessageContent> EditSettingsMessage
public Message<ViewModelMessageContent> EditSettingsMessage
{
get
{
@ -134,8 +135,8 @@ namespace zaaReloaded2.ViewModels
return _editSettingsMessage;
}
}
Message<ViewModelMessageContent> UseSettingsMessage
public Message<ViewModelMessageContent> UseSettingsMessage
{
get
{
@ -146,8 +147,8 @@ namespace zaaReloaded2.ViewModels
return _useSettingsMessage;
}
}
Message<ViewModelMessageContent> ConfirmDeleteSettingsMessage
public Message<ViewModelMessageContent> ConfirmDeleteSettingsMessage
{
get
{
@ -158,8 +159,8 @@ namespace zaaReloaded2.ViewModels
return _confirmDeleteSettingsMessage;
}
}
Message<ViewModelMessageContent> ConfirmResetSettingsMessage
public Message<ViewModelMessageContent> ConfirmResetSettingsMessage
{
get
{
@ -178,7 +179,7 @@ namespace zaaReloaded2.ViewModels
public SettingsRepositoryViewModel(SettingsRepository repository)
{
_repository = repository;
SettingsList = new List<SettingsViewModel>();
SettingsList = new ObservableCollection<SettingsViewModel>();
foreach (Settings s in repository.SettingsList)
{
SettingsViewModel vm = new SettingsViewModel(s);

View File

@ -71,14 +71,7 @@ namespace zaaReloaded2.ViewModels
/// <summary>
/// Gets a list of element view models.
/// </summary>
public IList<ElementViewModel> Elements
{
get
{
if (_elements == null) { _elements = new List<ElementViewModel>(); }
return _elements;
}
}
public IList<ElementViewModel> Elements { get; private set; }
/// <summary>
/// Gets or sets the currently selected element.
@ -120,7 +113,7 @@ namespace zaaReloaded2.ViewModels
: base()
{
_settings = settings;
_elements = new List<ElementViewModel>();
Elements = new List<ElementViewModel>();
foreach (ElementBase element in settings.Elements)
{
ElementViewModel vm;
@ -131,13 +124,18 @@ namespace zaaReloaded2.ViewModels
else if (element is ControlElementBase)
{
vm = new ControlElementViewModel(element as ControlElementBase);
foreach (FormatElementViewModel childVM in ((ControlElementViewModel)vm).Elements)
{
childVM.PropertyChanged += ElementViewModel_PropertyChanged;
}
}
else
{
throw new InvalidOperationException(
"Cannot create ViewModel for " + element.GetType().ToString());
}
AddElementViewModel(vm);
vm.PropertyChanged += ElementViewModel_PropertyChanged;
Elements.Add(vm);
}
}
@ -145,6 +143,30 @@ namespace zaaReloaded2.ViewModels
#region Messages
public Message<ViewModelMessageContent> AddElementMessage
{
get
{
if (_addElementMessage == null)
{
_addElementMessage = new Message<ViewModelMessageContent>();
}
return _addElementMessage;
}
}
public Message<ViewModelMessageContent> AddChildElementMessage
{
get
{
if (_addChildElementMessage == null)
{
_addChildElementMessage = new Message<ViewModelMessageContent>();
}
return _addChildElementMessage;
}
}
#endregion
#region Commands
@ -216,15 +238,52 @@ namespace zaaReloaded2.ViewModels
{
elementViewModel.PropertyChanged += ElementViewModel_PropertyChanged;
Elements.Add(elementViewModel);
_settings.Elements.Add(elementViewModel.RevealModelObject() as ElementBase);
}
/// <summary>
/// Wires the OnProperty changed event of an ElementViewModel's
/// wrapped model and adds the view model as a child of another
/// view model.
/// </summary>
public void AddChildElementViewModel(ControlElementViewModel parent, FormatElementViewModel child)
{
child.PropertyChanged += ElementViewModel_PropertyChanged;
parent.AddChildElement(child);
}
#endregion
#region Private methods
void DoAddElement() { }
void DoAddElement()
{
// Create a new element picker; it will automatically create and
// send us a new element view model if one is chosen by the view.
ElementPickerViewModel picker = new ElementPickerViewModel(true);
picker.ElementChosenMessage.Sent += (sender, args) =>
{
ElementViewModel newVM = args.Content.ViewModel as ElementViewModel;
AddElementViewModel(newVM);
};
AddElementMessage.Send(new ViewModelMessageContent(picker));
}
void DoAddChildElement() { }
void DoAddChildElement()
{
if (CanAddChildElement())
{
// Create a new element picker; it will automatically create and
// send us a new element view model if one is chosen by the view.
ElementPickerViewModel picker = new ElementPickerViewModel(false);
picker.ElementChosenMessage.Sent += (sender, args) =>
{
FormatElementViewModel newVM = args.Content.ViewModel as FormatElementViewModel;
AddChildElementViewModel(SelectedElement as ControlElementViewModel, newVM);
};
AddChildElementMessage.Send(new ViewModelMessageContent(picker));
}
}
bool CanAddChildElement()
{
@ -246,7 +305,7 @@ namespace zaaReloaded2.ViewModels
void ElementViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
ElementViewModel vm = sender as ElementViewModel;
if (vm != null)
if (vm != null && e.PropertyName == "IsSelected")
{
SelectedElement = vm.IsSelected ? vm : null;
}
@ -279,8 +338,8 @@ namespace zaaReloaded2.ViewModels
DelegatingCommand _addChildElementCommand;
DelegatingCommand _deleteElementCommand;
DelegatingCommand _copyElementCommand;
List<ElementViewModel> _elements;
Message<ViewModelMessageContent> _addElementMessage;
Message<ViewModelMessageContent> _addChildElementMessage;
ElementViewModel _selectedElement;
EnumProvider<ReferenceStyle> _referenceStyle;

View File

@ -0,0 +1,60 @@
<!--
AboutView - Copy.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.SettingsRepositoryView"
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="Stil auswählen"
>
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/zaaReloaded2;component/style.xaml" />
<ResourceDictionary>
<Style x:Key="settingsListItem" TargetType="{x:Type ListBoxItem}">
<Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}" />
</Style>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<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 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" />
</StackPanel>
<StackPanel>
<ListBox ItemsSource="{Binding SettingsList}"
DisplayMemberPath="Name"
ItemContainerStyle="{StaticResource settingsListItem}"
x:Name="settingsList"
MinWidth="240" MinHeight="240" />
</StackPanel>
</DockPanel>
</StackPanel>
</Window>

View File

@ -0,0 +1,33 @@
/* SettingsRepositoryView.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 SettingsRepositoryView.xaml
/// </summary>
public partial class SettingsRepositoryView : Window
{
public SettingsRepositoryView()
{
InitializeComponent();
}
}
}

View File

@ -99,6 +99,9 @@
<setting name="LastUpdateCheck" serializeAs="String">
<value />
</setting>
<setting name="LastSettings" serializeAs="String">
<value>00000000-0000-0000-0000-000000000000</value>
</setting>
</zaaReloaded2.Properties.Settings>
</userSettings>
</configuration>

View File

@ -176,6 +176,7 @@
<Compile Include="Controller\Elements\CustomText.cs" />
<Compile Include="Controller\Settings.cs" />
<Compile Include="Controller\SettingsRepository.cs" />
<Compile Include="Demo\Demo.cs" />
<Compile Include="ExceptionHandler\ExceptionDetailView.xaml.cs" />
<Compile Include="ExceptionHandler\ExceptionView.xaml.cs" />
<Compile Include="ExceptionHandler\ExceptionViewModel.cs" />
@ -225,6 +226,9 @@
<Compile Include="ViewModels\FormatElementViewModel.cs" />
<Compile Include="ViewModels\ControlElementViewModel.cs" />
<Compile Include="ViewModels\SettingsRepositoryViewModel.cs" />
<Compile Include="Views\SettingsRepositoryView.xaml.cs">
<DependentUpon>SettingsRepositoryView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\AboutView.xaml.cs">
<DependentUpon>AboutView.xaml</DependentUpon>
</Compile>
@ -240,6 +244,7 @@
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="app.config" />
<EmbeddedResource Include="Demo\Demo.docx" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
@ -292,6 +297,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Resource>
<Page Include="Views\SettingsRepositoryView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\AboutView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@ -317,6 +326,9 @@
<ItemGroup>
<Resource Include="Icons\fff.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Icons\d.png" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>