Begin implemenation of format and choose style commands.

This commit is contained in:
Daniel Kraus 2015-08-04 02:43:17 +02:00
parent b6209731ec
commit 41b155e8be
13 changed files with 239 additions and 36 deletions

View File

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

View File

@ -233,5 +233,17 @@ namespace zaaReloaded2.Properties {
return ((string)(this["DefaultItemsDrugs"])); 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"> <Setting Name="DefaultItemsDrugs" Type="System.String" Scope="Application">
<Value Profile="(Default)">Medikamente: TAC, CSA, SIR, Vancomycin, Gentamicin, Tobramicin</Value> <Value Profile="(Default)">Medikamente: TAC, CSA, SIR, Vancomycin, Gentamicin, Tobramicin</Value>
</Setting> </Setting>
<Setting Name="LastSettings" Type="System.Guid" Scope="User">
<Value Profile="(Default)">00000000-0000-0000-0000-000000000000</Value>
</Setting>
</Settings> </Settings>
</SettingsFile> </SettingsFile>

View File

@ -26,6 +26,11 @@ using System.Windows;
using System.Drawing; using System.Drawing;
using System.Windows.Resources; using System.Windows.Resources;
using Office = Microsoft.Office.Core; 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: // TODO: Follow these steps to enable the Ribbon (XML) item:
@ -51,12 +56,14 @@ namespace zaaReloaded2
[ComVisible(true)] [ComVisible(true)]
public class Ribbon : Office.IRibbonExtensibility public class Ribbon : Office.IRibbonExtensibility
{ {
private Office.IRibbonUI ribbon; #region Constructor
public Ribbon() public Ribbon()
{ {
} }
#endregion
#region IRibbonExtensibility Members #region IRibbonExtensibility Members
public string GetCustomUI(string ribbonID) public string GetCustomUI(string ribbonID)
@ -71,7 +78,8 @@ namespace zaaReloaded2
public void Ribbon_Load(Office.IRibbonUI ribbonUI) public void Ribbon_Load(Office.IRibbonUI ribbonUI)
{ {
this.ribbon = ribbonUI; _ribbon = ribbonUI;
Globals.ThisAddIn.Application.WindowSelectionChange += Application_WindowSelectionChange;
} }
/// <summary> /// <summary>
@ -86,6 +94,12 @@ namespace zaaReloaded2
{ {
switch (control.Id) switch (control.Id)
{ {
case "zrlFormat":
DoFormat();
break;
case "zrlSettings":
DoChooseSettings();
break;
case "zrlAbout": case "zrlAbout":
ViewModels.AboutViewModel vm = new ViewModels.AboutViewModel(); ViewModels.AboutViewModel vm = new ViewModels.AboutViewModel();
vm.InjectInto<Views.AboutView>().ShowDialog(); vm.InjectInto<Views.AboutView>().ShowDialog();
@ -138,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 #endregion
#region Helpers #region Helpers
@ -163,5 +238,11 @@ namespace zaaReloaded2
} }
#endregion #endregion
#region Fields
private Office.IRibbonUI _ribbon;
#endregion
} }
} }

View File

@ -25,8 +25,9 @@
<tab id="zaaReloaded2" label="zaaReloaded2"> <tab id="zaaReloaded2" label="zaaReloaded2">
<group id="zrlFormatGroup" label="Formatieren"> <group id="zrlFormatGroup" label="Formatieren">
<button id="zrlFormat" label="Formatieren" image="f.png" onAction="Ribbon_Click" size="large" <button id="zrlFormat" label="Formatieren" image="f.png" onAction="Ribbon_Click" size="large"
supertip="Formatiert den ausgewählten Bereich mit dem zuletzt verwendeten Stil." /> supertip="Formatiert den ausgewählten Bereich mit dem zuletzt verwendeten Stil."
<button id="zrlChooseFormat" label="Stilauswahl" image="fff.png" onAction="Ribbon_Click" size="large" 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." /> 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" <button id="zrlDaniel" label="Daniels Spezial" image="dk.png" onAction="Ribbon_Click" size="large"
getVisible="Daniel_GetVisible"/> getVisible="Daniel_GetVisible"/>

View File

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

View File

@ -45,6 +45,14 @@ namespace zaaReloaded2.ViewModels
: base(controlElement) : base(controlElement)
{ {
Elements = new ObservableCollection<ElementViewModel>(); Elements = new ObservableCollection<ElementViewModel>();
if (controlElement != null)
{
foreach (FormatElementBase childElement in controlElement.FormatElements)
{
FormatElementViewModel childVM = new FormatElementViewModel(childElement);
Elements.Add(childVM);
}
}
} }
#endregion #endregion

View File

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

View File

@ -71,14 +71,7 @@ namespace zaaReloaded2.ViewModels
/// <summary> /// <summary>
/// Gets a list of element view models. /// Gets a list of element view models.
/// </summary> /// </summary>
public IList<ElementViewModel> Elements public IList<ElementViewModel> Elements { get; private set; }
{
get
{
if (_elements == null) { _elements = new List<ElementViewModel>(); }
return _elements;
}
}
/// <summary> /// <summary>
/// Gets or sets the currently selected element. /// Gets or sets the currently selected element.
@ -120,7 +113,7 @@ namespace zaaReloaded2.ViewModels
: base() : base()
{ {
_settings = settings; _settings = settings;
_elements = new List<ElementViewModel>(); Elements = new List<ElementViewModel>();
foreach (ElementBase element in settings.Elements) foreach (ElementBase element in settings.Elements)
{ {
ElementViewModel vm; ElementViewModel vm;
@ -131,13 +124,18 @@ namespace zaaReloaded2.ViewModels
else if (element is ControlElementBase) else if (element is ControlElementBase)
{ {
vm = new ControlElementViewModel(element as ControlElementBase); vm = new ControlElementViewModel(element as ControlElementBase);
foreach (FormatElementViewModel childVM in ((ControlElementViewModel)vm).Elements)
{
childVM.PropertyChanged += ElementViewModel_PropertyChanged;
}
} }
else else
{ {
throw new InvalidOperationException( throw new InvalidOperationException(
"Cannot create ViewModel for " + element.GetType().ToString()); "Cannot create ViewModel for " + element.GetType().ToString());
} }
AddElementViewModel(vm); vm.PropertyChanged += ElementViewModel_PropertyChanged;
Elements.Add(vm);
} }
} }
@ -342,7 +340,6 @@ namespace zaaReloaded2.ViewModels
DelegatingCommand _copyElementCommand; DelegatingCommand _copyElementCommand;
Message<ViewModelMessageContent> _addElementMessage; Message<ViewModelMessageContent> _addElementMessage;
Message<ViewModelMessageContent> _addChildElementMessage; Message<ViewModelMessageContent> _addChildElementMessage;
List<ElementViewModel> _elements;
ElementViewModel _selectedElement; ElementViewModel _selectedElement;
EnumProvider<ReferenceStyle> _referenceStyle; 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"> <setting name="LastUpdateCheck" serializeAs="String">
<value /> <value />
</setting> </setting>
<setting name="LastSettings" serializeAs="String">
<value>00000000-0000-0000-0000-000000000000</value>
</setting>
</zaaReloaded2.Properties.Settings> </zaaReloaded2.Properties.Settings>
</userSettings> </userSettings>
</configuration> </configuration>

View File

@ -226,6 +226,9 @@
<Compile Include="ViewModels\FormatElementViewModel.cs" /> <Compile Include="ViewModels\FormatElementViewModel.cs" />
<Compile Include="ViewModels\ControlElementViewModel.cs" /> <Compile Include="ViewModels\ControlElementViewModel.cs" />
<Compile Include="ViewModels\SettingsRepositoryViewModel.cs" /> <Compile Include="ViewModels\SettingsRepositoryViewModel.cs" />
<Compile Include="Views\SettingsRepositoryView.xaml.cs">
<DependentUpon>SettingsRepositoryView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\AboutView.xaml.cs"> <Compile Include="Views\AboutView.xaml.cs">
<DependentUpon>AboutView.xaml</DependentUpon> <DependentUpon>AboutView.xaml</DependentUpon>
</Compile> </Compile>
@ -294,6 +297,10 @@
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Resource> </Resource>
<Page Include="Views\SettingsRepositoryView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\AboutView.xaml"> <Page Include="Views\AboutView.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>