Fix LastSelected and LastSelectedElement properties.
This commit is contained in:
parent
5fe7250b53
commit
8d6ed32a84
@ -33,7 +33,21 @@ namespace zaaReloaded2.ViewModels
|
|||||||
|
|
||||||
public ObservableCollection<SettingsViewModel> SettingsList { get; private set; }
|
public ObservableCollection<SettingsViewModel> SettingsList { get; private set; }
|
||||||
|
|
||||||
public SettingsViewModel Selected { get; private set; }
|
/// <summary>
|
||||||
|
/// Gets the SettingsViewModel that was most recently selected. Whether
|
||||||
|
/// this view model is still selected can be found out be getting the
|
||||||
|
/// view model's IsSelected property.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Due to the way the WPF ListBox (for example) is implemented, selecting
|
||||||
|
/// a list item will trigger an PropertyChanged event twice: Once for the
|
||||||
|
/// item being selected, and once for the item being deselected. Thus we
|
||||||
|
/// can only capture the last item that actually was selected. We cannot
|
||||||
|
/// howeve capture if an item was deselected without a new selection,
|
||||||
|
/// because we cannot logicaly connect two occurrences of the same event
|
||||||
|
/// from different objects.
|
||||||
|
/// </remarks>
|
||||||
|
public SettingsViewModel LastSelected { get; private set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -195,23 +209,23 @@ namespace zaaReloaded2.ViewModels
|
|||||||
{
|
{
|
||||||
if (CanEditSettings())
|
if (CanEditSettings())
|
||||||
{
|
{
|
||||||
EditSettingsMessage.Send(new ViewModelMessageContent(Selected));
|
EditSettingsMessage.Send(new ViewModelMessageContent(LastSelected));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CanEditSettings()
|
bool CanEditSettings()
|
||||||
{
|
{
|
||||||
return Selected != null && !IsDefaultSettings();
|
return LastSelected != null && LastSelected.IsSelected && !IsDefaultSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoUseSettings()
|
void DoUseSettings()
|
||||||
{
|
{
|
||||||
UseSettingsMessage.Send(new ViewModelMessageContent(Selected));
|
UseSettingsMessage.Send(new ViewModelMessageContent(LastSelected));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CanUseSettings()
|
bool CanUseSettings()
|
||||||
{
|
{
|
||||||
return Selected != null;
|
return LastSelected != null && LastSelected.IsSelected;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoAddSettings()
|
void DoAddSettings()
|
||||||
@ -225,7 +239,7 @@ namespace zaaReloaded2.ViewModels
|
|||||||
|
|
||||||
bool CanDeleteSettings()
|
bool CanDeleteSettings()
|
||||||
{
|
{
|
||||||
return Selected != null && !IsDefaultSettings();
|
return LastSelected != null && LastSelected.IsSelected && !IsDefaultSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoDeleteSettings()
|
void DoDeleteSettings()
|
||||||
@ -233,7 +247,7 @@ namespace zaaReloaded2.ViewModels
|
|||||||
if (CanDeleteSettings())
|
if (CanDeleteSettings())
|
||||||
{
|
{
|
||||||
ConfirmDeleteSettingsMessage.Send(
|
ConfirmDeleteSettingsMessage.Send(
|
||||||
new ViewModelMessageContent(Selected),
|
new ViewModelMessageContent(LastSelected),
|
||||||
param => ConfirmDeleteSettings(param));
|
param => ConfirmDeleteSettings(param));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -265,12 +279,12 @@ namespace zaaReloaded2.ViewModels
|
|||||||
|
|
||||||
void DoCopySettings()
|
void DoCopySettings()
|
||||||
{
|
{
|
||||||
if (Selected != null)
|
if (LastSelected != null)
|
||||||
{
|
{
|
||||||
SettingsViewModel copy = Selected.Clone() as SettingsViewModel;
|
SettingsViewModel copy = LastSelected.Clone() as SettingsViewModel;
|
||||||
_repository.SettingsList.Add(copy.RevealModelObject() as Settings);
|
_repository.SettingsList.Add(copy.RevealModelObject() as Settings);
|
||||||
AddSettingsViewModel(copy);
|
AddSettingsViewModel(copy);
|
||||||
Selected.IsSelected = false;
|
LastSelected.IsSelected = false;
|
||||||
copy.IsSelected = true;
|
copy.IsSelected = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -280,7 +294,7 @@ namespace zaaReloaded2.ViewModels
|
|||||||
SettingsViewModel vm = sender as SettingsViewModel;
|
SettingsViewModel vm = sender as SettingsViewModel;
|
||||||
if (vm != null && e.PropertyName == "IsSelected")
|
if (vm != null && e.PropertyName == "IsSelected")
|
||||||
{
|
{
|
||||||
Selected = vm.IsSelected ? vm : null;
|
if (vm.IsSelected) LastSelected = vm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,11 +304,11 @@ namespace zaaReloaded2.ViewModels
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
bool IsDefaultSettings()
|
bool IsDefaultSettings()
|
||||||
{
|
{
|
||||||
if (Selected != null)
|
if (LastSelected != null)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
(Selected.Name == zaaReloaded2.Properties.Settings.Default.SettingsNameClinic
|
(LastSelected.Name == zaaReloaded2.Properties.Settings.Default.SettingsNameClinic
|
||||||
|| Selected.Name == zaaReloaded2.Properties.Settings.Default.SettingsNameWard);
|
|| LastSelected.Name == zaaReloaded2.Properties.Settings.Default.SettingsNameWard);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -76,7 +76,16 @@ namespace zaaReloaded2.ViewModels
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the currently selected element.
|
/// Gets or sets the currently selected element.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ElementViewModel SelectedElement
|
/// <remarks>
|
||||||
|
/// Due to the way the WPF ListBox (for example) is implemented, selecting
|
||||||
|
/// a list item will trigger an PropertyChanged event twice: Once for the
|
||||||
|
/// item being selected, and once for the item being deselected. Thus we
|
||||||
|
/// can only capture the last item that actually was selected. We cannot
|
||||||
|
/// howeve capture if an item was deselected without a new selection,
|
||||||
|
/// because we cannot logicaly connect two occurrences of the same event
|
||||||
|
/// from different objects.
|
||||||
|
/// </remarks>
|
||||||
|
public ElementViewModel LastSelectedElement
|
||||||
{
|
{
|
||||||
get { return _selectedElement; }
|
get { return _selectedElement; }
|
||||||
set
|
set
|
||||||
@ -279,7 +288,7 @@ namespace zaaReloaded2.ViewModels
|
|||||||
picker.ElementChosenMessage.Sent += (sender, args) =>
|
picker.ElementChosenMessage.Sent += (sender, args) =>
|
||||||
{
|
{
|
||||||
FormatElementViewModel newVM = args.Content.ViewModel as FormatElementViewModel;
|
FormatElementViewModel newVM = args.Content.ViewModel as FormatElementViewModel;
|
||||||
AddChildElementViewModel(SelectedElement as ControlElementViewModel, newVM);
|
AddChildElementViewModel(LastSelectedElement as ControlElementViewModel, newVM);
|
||||||
};
|
};
|
||||||
AddChildElementMessage.Send(new ViewModelMessageContent(picker));
|
AddChildElementMessage.Send(new ViewModelMessageContent(picker));
|
||||||
}
|
}
|
||||||
@ -287,27 +296,30 @@ namespace zaaReloaded2.ViewModels
|
|||||||
|
|
||||||
bool CanAddChildElement()
|
bool CanAddChildElement()
|
||||||
{
|
{
|
||||||
return SelectedElement is ControlElementViewModel;
|
return LastSelectedElement is ControlElementViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoDeleteElement() { }
|
void DoDeleteElement() { }
|
||||||
|
|
||||||
bool CanDeleteElement() { return _selectedElement != null; }
|
bool CanDeleteElement() { return LastSelectedElement != null && LastSelectedElement.IsSelected; }
|
||||||
|
|
||||||
void DoCopyElement() { }
|
void DoCopyElement() { }
|
||||||
|
|
||||||
bool CanCopyElement() { return _selectedElement != null; }
|
bool CanCopyElement() { return LastSelectedElement != null && LastSelectedElement.IsSelected; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets or unsets the SelectedElement property whenever the IsSelected
|
/// Sets LastSelectedElement property whenever the IsSelected
|
||||||
/// property of an ElementViewModel changes.
|
/// property of an ElementViewModel changes
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Please see the remarks on the LastSelectedElement property.
|
||||||
|
/// </remarks>
|
||||||
void ElementViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
void ElementViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
ElementViewModel vm = sender as ElementViewModel;
|
ElementViewModel vm = sender as ElementViewModel;
|
||||||
if (vm != null && e.PropertyName == "IsSelected")
|
if (vm != null && e.PropertyName == "IsSelected")
|
||||||
{
|
{
|
||||||
SelectedElement = vm.IsSelected ? vm : null;
|
if (vm.IsSelected) LastSelectedElement = vm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user