mirror of
https://github.com/microsoft/PowerToys
synced 2025-09-02 07:25:10 +00:00
[FZ Editor] Replace list with a dictionary for the DefaultLayouts (#29135)
* Dictionary Implementation to fix temporal coupling. Swapped the setting order as proof * changed Dictionary to use the monitor config and not int
This commit is contained in:
@@ -12,7 +12,7 @@ namespace FancyZonesEditor
|
|||||||
{
|
{
|
||||||
private LayoutModel _backup;
|
private LayoutModel _backup;
|
||||||
private string _hotkeyBackup;
|
private string _hotkeyBackup;
|
||||||
private List<LayoutModel> _defaultLayoutsBackup;
|
private Dictionary<MonitorConfigurationType, LayoutModel> _defaultLayoutsBackup;
|
||||||
|
|
||||||
public LayoutBackup()
|
public LayoutBackup()
|
||||||
{
|
{
|
||||||
@@ -30,7 +30,7 @@ namespace FancyZonesEditor
|
|||||||
}
|
}
|
||||||
|
|
||||||
_hotkeyBackup = MainWindowSettingsModel.LayoutHotkeys.Key(model.Uuid);
|
_hotkeyBackup = MainWindowSettingsModel.LayoutHotkeys.Key(model.Uuid);
|
||||||
_defaultLayoutsBackup = new List<LayoutModel>(MainWindowSettingsModel.DefaultLayouts.Layouts);
|
_defaultLayoutsBackup = new Dictionary<MonitorConfigurationType, LayoutModel>(MainWindowSettingsModel.DefaultLayouts.Layouts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Restore(LayoutModel layoutToRestore)
|
public void Restore(LayoutModel layoutToRestore)
|
||||||
|
@@ -13,7 +13,7 @@ namespace FancyZonesEditor.Models
|
|||||||
{
|
{
|
||||||
private static int Count { get; } = Enum.GetValues(typeof(MonitorConfigurationType)).Length;
|
private static int Count { get; } = Enum.GetValues(typeof(MonitorConfigurationType)).Length;
|
||||||
|
|
||||||
public List<LayoutModel> Layouts { get; } = new List<LayoutModel>(Count);
|
public Dictionary<MonitorConfigurationType, LayoutModel> Layouts { get; } = new Dictionary<MonitorConfigurationType, LayoutModel>(Count);
|
||||||
|
|
||||||
public DefaultLayoutsModel()
|
public DefaultLayoutsModel()
|
||||||
{
|
{
|
||||||
@@ -36,12 +36,12 @@ namespace FancyZonesEditor.Models
|
|||||||
|
|
||||||
public void Reset(string uuid)
|
public void Reset(string uuid)
|
||||||
{
|
{
|
||||||
if (Layouts[(int)MonitorConfigurationType.Horizontal].Uuid == uuid)
|
if (Layouts[MonitorConfigurationType.Horizontal].Uuid == uuid)
|
||||||
{
|
{
|
||||||
Set(MainWindowSettingsModel.TemplateModels[(int)LayoutType.PriorityGrid], MonitorConfigurationType.Horizontal);
|
Set(MainWindowSettingsModel.TemplateModels[(int)LayoutType.PriorityGrid], MonitorConfigurationType.Horizontal);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Layouts[(int)MonitorConfigurationType.Vertical].Uuid == uuid)
|
if (Layouts[MonitorConfigurationType.Vertical].Uuid == uuid)
|
||||||
{
|
{
|
||||||
Set(MainWindowSettingsModel.TemplateModels[(int)LayoutType.Rows], MonitorConfigurationType.Vertical);
|
Set(MainWindowSettingsModel.TemplateModels[(int)LayoutType.Rows], MonitorConfigurationType.Vertical);
|
||||||
}
|
}
|
||||||
@@ -49,23 +49,16 @@ namespace FancyZonesEditor.Models
|
|||||||
|
|
||||||
public void Set(LayoutModel layout, MonitorConfigurationType type)
|
public void Set(LayoutModel layout, MonitorConfigurationType type)
|
||||||
{
|
{
|
||||||
if (Layouts.Count <= (int)type)
|
Layouts[type] = layout;
|
||||||
{
|
|
||||||
Layouts.Insert((int)type, layout);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Layouts[(int)type] = layout;
|
|
||||||
}
|
|
||||||
|
|
||||||
FirePropertyChanged();
|
FirePropertyChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Restore(List<LayoutModel> layouts)
|
public void Restore(Dictionary<MonitorConfigurationType, LayoutModel> layouts)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < Count; i++)
|
foreach (var monitorConfigurationType in layouts.Keys)
|
||||||
{
|
{
|
||||||
Set(layouts[i], (MonitorConfigurationType)i);
|
Set(layouts[monitorConfigurationType], monitorConfigurationType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -166,7 +166,7 @@ namespace FancyZonesEditor.Models
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return MainWindowSettingsModel.DefaultLayouts.Layouts[(int)MonitorConfigurationType.Vertical].Uuid == this.Uuid;
|
return MainWindowSettingsModel.DefaultLayouts.Layouts[MonitorConfigurationType.Vertical].Uuid == this.Uuid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,7 +174,7 @@ namespace FancyZonesEditor.Models
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return MainWindowSettingsModel.DefaultLayouts.Layouts[(int)MonitorConfigurationType.Vertical].Uuid != this.Uuid;
|
return MainWindowSettingsModel.DefaultLayouts.Layouts[MonitorConfigurationType.Vertical].Uuid != this.Uuid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -80,8 +80,8 @@ namespace FancyZonesEditor
|
|||||||
TemplateModels.Insert((int)LayoutType.PriorityGrid, priorityGridModel);
|
TemplateModels.Insert((int)LayoutType.PriorityGrid, priorityGridModel);
|
||||||
|
|
||||||
// set default layouts
|
// set default layouts
|
||||||
DefaultLayouts.Set(priorityGridModel, MonitorConfigurationType.Horizontal);
|
|
||||||
DefaultLayouts.Set(rowsModel, MonitorConfigurationType.Vertical);
|
DefaultLayouts.Set(rowsModel, MonitorConfigurationType.Vertical);
|
||||||
|
DefaultLayouts.Set(priorityGridModel, MonitorConfigurationType.Horizontal);
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsShiftKeyPressed - is the shift key currently being held down
|
// IsShiftKeyPressed - is the shift key currently being held down
|
||||||
|
Reference in New Issue
Block a user