[ColorPicker] Order colors with up/down buttons. (#10392)

This commit is contained in:
Seraphima Zykova
2021-03-24 19:36:25 +03:00
committed by GitHub
parent 3ae5135f67
commit fd55026fba
5 changed files with 148 additions and 6 deletions

View File

@@ -12,6 +12,8 @@ namespace Microsoft.PowerToys.Settings.UI.Library
private string _name;
private string _example;
private bool _isShown;
private bool _canMoveUp = true;
private bool _canMoveDown = true;
public ColorFormatModel(string name, string example, bool isShown)
{
@@ -62,6 +64,34 @@ namespace Microsoft.PowerToys.Settings.UI.Library
}
}
public bool CanMoveUp
{
get
{
return _canMoveUp;
}
set
{
_canMoveUp = value;
OnPropertyChanged();
}
}
public bool CanMoveDown
{
get
{
return _canMoveDown;
}
set
{
_canMoveDown = value;
OnPropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged([CallerMemberName] string propertyName = null)

View File

@@ -247,11 +247,28 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
ColorFormats.Add(remainingColorFormat);
}
// Reordering colors with buttons: disable first and last buttons
ColorFormats[0].CanMoveUp = false;
ColorFormats[ColorFormats.Count - 1].CanMoveDown = false;
ColorFormats.CollectionChanged += ColorFormats_CollectionChanged;
}
private void ColorFormats_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
// Reordering colors with buttons: update buttons availability depending on order
if (ColorFormats.Count > 0)
{
foreach (var color in ColorFormats)
{
color.CanMoveUp = true;
color.CanMoveDown = true;
}
ColorFormats[0].CanMoveUp = false;
ColorFormats[ColorFormats.Count - 1].CanMoveDown = false;
}
UpdateColorFormats();
ScheduleSavingOfSettings();
}