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); return SettingsList.FirstOrDefault(s => s.Uid == uid);
} }
/// <summary> public static bool IsDefaultSettings(Settings settings)
/// 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)
{ {
XmlSerializer ser = new XmlSerializer(typeof(Settings)); return (settings.Name == Properties.Settings.Default.SettingsNameClinic + BUILTIN_LABEL ||
Settings settings = ser.Deserialize(s) as Settings; settings.Name == Properties.Settings.Default.SettingsNameWard + BUILTIN_LABEL);
if (settings != null)
{
SettingsList.Add(settings);
return true;
}
else
{
return false;
}
} }
#endregion #endregion
@ -223,7 +208,7 @@ namespace zaaReloaded2.Controller
// Configure the settings for the ward // Configure the settings for the ward
SettingsList.Add( SettingsList.Add(
new Settings( new Settings(
def.SettingsNameWard, def.SettingsNameWard + BUILTIN_LABEL,
new List<ElementBase>() new List<ElementBase>()
{ {
new TwoColumns(), new TwoColumns(),
@ -238,7 +223,7 @@ namespace zaaReloaded2.Controller
// Configure the settings for the outpatient clinic // Configure the settings for the outpatient clinic
SettingsList.Add( SettingsList.Add(
new Settings( new Settings(
def.SettingsNameClinic, def.SettingsNameClinic + BUILTIN_LABEL,
new List<ElementBase>() new List<ElementBase>()
{ {
new SelectEachDay(defaultItems), new SelectEachDay(defaultItems),
@ -250,7 +235,12 @@ namespace zaaReloaded2.Controller
#endregion #endregion
#region Private constants #region Constants
/// <summary>
/// Label that is appended to the default Settings' names.
/// </summary>
public const string BUILTIN_LABEL = " (eingebaut)";
/// <summary> /// <summary>
/// Constant GUID for the first default Settings. /// Constant GUID for the first default Settings.

View File

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

View File

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