[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:
Garrett Vernon
2023-10-18 04:14:16 -06:00
committed by GitHub
parent 50cb279d2a
commit 6a9d44fb4d
4 changed files with 12 additions and 19 deletions

View File

@@ -12,7 +12,7 @@ namespace FancyZonesEditor
{
private LayoutModel _backup;
private string _hotkeyBackup;
private List<LayoutModel> _defaultLayoutsBackup;
private Dictionary<MonitorConfigurationType, LayoutModel> _defaultLayoutsBackup;
public LayoutBackup()
{
@@ -30,7 +30,7 @@ namespace FancyZonesEditor
}
_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)

View File

@@ -13,7 +13,7 @@ namespace FancyZonesEditor.Models
{
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()
{
@@ -36,12 +36,12 @@ namespace FancyZonesEditor.Models
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);
}
if (Layouts[(int)MonitorConfigurationType.Vertical].Uuid == uuid)
if (Layouts[MonitorConfigurationType.Vertical].Uuid == uuid)
{
Set(MainWindowSettingsModel.TemplateModels[(int)LayoutType.Rows], MonitorConfigurationType.Vertical);
}
@@ -49,23 +49,16 @@ namespace FancyZonesEditor.Models
public void Set(LayoutModel layout, MonitorConfigurationType type)
{
if (Layouts.Count <= (int)type)
{
Layouts.Insert((int)type, layout);
}
else
{
Layouts[(int)type] = layout;
}
Layouts[type] = layout;
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);
}
}

View File

@@ -166,7 +166,7 @@ namespace FancyZonesEditor.Models
{
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
{
return MainWindowSettingsModel.DefaultLayouts.Layouts[(int)MonitorConfigurationType.Vertical].Uuid != this.Uuid;
return MainWindowSettingsModel.DefaultLayouts.Layouts[MonitorConfigurationType.Vertical].Uuid != this.Uuid;
}
}

View File

@@ -80,8 +80,8 @@ namespace FancyZonesEditor
TemplateModels.Insert((int)LayoutType.PriorityGrid, priorityGridModel);
// set default layouts
DefaultLayouts.Set(priorityGridModel, MonitorConfigurationType.Horizontal);
DefaultLayouts.Set(rowsModel, MonitorConfigurationType.Vertical);
DefaultLayouts.Set(priorityGridModel, MonitorConfigurationType.Horizontal);
}
// IsShiftKeyPressed - is the shift key currently being held down