Implement reset settings feature.

- NEU: Auf Werkseinstellungen zurücksetzen.
This commit is contained in:
Daniel Kraus 2015-08-11 21:39:21 +02:00
parent 0708f2a2b3
commit 5a0923e8e8
3 changed files with 36 additions and 31 deletions

View File

@ -167,25 +167,10 @@ namespace zaaReloaded2.Controller
return SettingsList.FirstOrDefault(s => s.Uid == uid);
}
/// <summary>
/// Imports one Settings object by deserialization
/// from a stream.
/// </summary>
/// <param name="s">Stream to read from.</param>
/// <returns>True if the import was successful.</returns>
bool Import(Stream s)
public static bool IsDefaultSettings(Settings settings)
{
XmlSerializer ser = new XmlSerializer(typeof(Settings));
Settings settings = ser.Deserialize(s) as Settings;
if (settings != null)
{
SettingsList.Add(settings);
return true;
}
else
{
return false;
}
return (settings.Name == Properties.Settings.Default.SettingsNameClinic + BUILTIN_LABEL ||
settings.Name == Properties.Settings.Default.SettingsNameWard + BUILTIN_LABEL);
}
#endregion
@ -223,7 +208,7 @@ namespace zaaReloaded2.Controller
// Configure the settings for the ward
SettingsList.Add(
new Settings(
def.SettingsNameWard,
def.SettingsNameWard + BUILTIN_LABEL,
new List<ElementBase>()
{
new TwoColumns(),
@ -238,7 +223,7 @@ namespace zaaReloaded2.Controller
// Configure the settings for the outpatient clinic
SettingsList.Add(
new Settings(
def.SettingsNameClinic,
def.SettingsNameClinic + BUILTIN_LABEL,
new List<ElementBase>()
{
new SelectEachDay(defaultItems),
@ -250,7 +235,12 @@ namespace zaaReloaded2.Controller
#endregion
#region Private constants
#region Constants
/// <summary>
/// Label that is appended to the default Settings' names.
/// </summary>
public const string BUILTIN_LABEL = " (eingebaut)";
/// <summary>
/// Constant GUID for the first default Settings.

View File

@ -149,6 +149,7 @@ namespace zaaReloaded2.ViewModels
return _exportSettingsCommand;
}
}
public DelegatingCommand ImportSettingsCommand
{
get
@ -270,12 +271,7 @@ namespace zaaReloaded2.ViewModels
public SettingsRepositoryViewModel(SettingsRepository repository)
{
_repository = repository;
SettingsList = new ObservableCollection<SettingsViewModel>();
foreach (Settings s in repository.SettingsList)
{
SettingsViewModel vm = new SettingsViewModel(s);
AddSettingsViewModel(vm);
}
BuildSettingsList();
RequestCloseView += (sender, args) =>
{
_repository.Store();
@ -286,6 +282,17 @@ namespace zaaReloaded2.ViewModels
#region Private methods
void BuildSettingsList()
{
SettingsList = new ObservableCollection<SettingsViewModel>();
foreach (Settings s in _repository.SettingsList)
{
SettingsViewModel vm = new SettingsViewModel(s);
AddSettingsViewModel(vm);
}
OnPropertyChanged("SettingsList");
}
void DoEditSettings()
{
if (CanEditSettings())
@ -356,7 +363,8 @@ namespace zaaReloaded2.ViewModels
{
if (content.Confirmed)
{
_repository = new SettingsRepository();
BuildSettingsList();
}
}
@ -365,6 +373,10 @@ namespace zaaReloaded2.ViewModels
if (LastSelected != null)
{
SettingsViewModel copy = LastSelected.Clone() as SettingsViewModel;
if (IsDefaultSettings())
{
copy.Name = copy.Name.Replace(SettingsRepository.BUILTIN_LABEL, String.Empty);
}
_repository.SettingsList.Add(copy.RevealModelObject() as Settings);
AddSettingsViewModel(copy);
LastSelected.IsSelected = false;
@ -390,9 +402,7 @@ namespace zaaReloaded2.ViewModels
{
if (LastSelected != null)
{
return
(LastSelected.Name == zaaReloaded2.Properties.Settings.Default.SettingsNameClinic
|| LastSelected.Name == zaaReloaded2.Properties.Settings.Default.SettingsNameWard);
return SettingsRepository.IsDefaultSettings(LastSelected.RevealModelObject() as Settings);
}
else
{

View File

@ -38,6 +38,10 @@
<action:ConfirmationAction Caption="Stil entfernen" OkButtonLabel="Ja" CancelButtonLabel="Nein"
Message="Soll dieser Stil wirklich unwiederbringlich entfernt werden?" />
</i:EventTrigger>
<i:EventTrigger SourceObject="{Binding ConfirmResetSettingsMessage}" EventName="Sent">
<action:ConfirmationAction Caption="Stile zurücksetzen" OkButtonLabel="Ja" CancelButtonLabel="Nein"
Message="Sollen alle Stile gelöscht und die eingebauten Stile geladen werden?" />
</i:EventTrigger>
<i:EventTrigger SourceObject="{Binding ChooseExportFileNameMessage}" EventName="Sent">
<action:ChooseFileSaveAction Caption="Stil exportieren" Message="Bitte Dateinamen für den Export angeben." />
</i:EventTrigger>
@ -62,6 +66,7 @@
<Button Command="{Binding CopySettingsCommand}" Content="Kopieren" Margin="0 0 0 5" />
<Button Command="{Binding ExportSettingsCommand}" Content="Exportieren" Margin="0 5 0 5" />
<Button Command="{Binding ImportSettingsCommand}" Content="Importieren" Margin="0 0 0 5" />
<Button Command="{Binding ResetSettingsCommand}" Content="Werkseinstellungen" Margin="0 0 0 5" />
</StackPanel>
<UniformGrid DockPanel.Dock="Bottom" Margin="0 10 0 0" Columns="2" Rows="1" HorizontalAlignment="Right">
<Button Command="{Binding UseSettingsCommand}" Content="Auswählen" IsDefault="True" Margin="0 0 5 0" />