diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml b/src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml
index bd3108e023a3..295deb5498c7 100644
--- a/src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml
+++ b/src/modules/fancyzones/editor/FancyZonesEditor/MainWindow.xaml
@@ -356,6 +356,7 @@
PrimaryButtonClick="EditLayoutDialog_PrimaryButtonClick"
SecondaryButtonClick="EditLayoutDialog_SecondaryButtonClick"
Title="{x:Static props:Resources.Edit_Layout}"
+ ScrollViewer.VerticalScrollBarVisibility="Auto"
Opened="Dialog_Opened"
Closed="Dialog_Closed">
-
-
-
+
-
-
+
+
+
+
+
+
+
diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Models/FastAccessKeysModel.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Models/FastAccessKeysModel.cs
deleted file mode 100644
index 604979499f99..000000000000
--- a/src/modules/fancyzones/editor/FancyZonesEditor/Models/FastAccessKeysModel.cs
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright (c) Microsoft Corporation
-// The Microsoft Corporation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Collections.Generic;
-using System.Linq;
-
-namespace FancyZonesEditor.Models
-{
- public class FastAccessKeysModel
- {
- public static SortedDictionary SelectedKeys { get; } = new SortedDictionary()
- {
- { 0, string.Empty },
- { 1, string.Empty },
- { 2, string.Empty },
- { 3, string.Empty },
- { 4, string.Empty },
- { 5, string.Empty },
- { 6, string.Empty },
- { 7, string.Empty },
- { 8, string.Empty },
- { 9, string.Empty },
- };
-
- public FastAccessKeysModel()
- {
- }
-
- public static void FreeKey(int key)
- {
- if (SelectedKeys.ContainsKey(key))
- {
- SelectedKeys[key] = string.Empty;
- }
- }
-
- public static bool SelectKey(int key, string uuid)
- {
- if (!SelectedKeys.ContainsKey(key))
- {
- return false;
- }
-
- SelectedKeys[key] = uuid;
- return true;
- }
-
- public static void CleanUp()
- {
- var keys = SelectedKeys.Keys.ToList();
- foreach (var key in keys)
- {
- SelectedKeys[key] = string.Empty;
- }
- }
- }
-}
diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Models/LayoutModel.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Models/LayoutModel.cs
index 11981ee22cf8..2dd8fdd021ad 100644
--- a/src/modules/fancyzones/editor/FancyZonesEditor/Models/LayoutModel.cs
+++ b/src/modules/fancyzones/editor/FancyZonesEditor/Models/LayoutModel.cs
@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
+using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
@@ -16,6 +17,8 @@ protected LayoutModel()
{
_guid = Guid.NewGuid();
Type = LayoutType.Custom;
+
+ MainWindowSettingsModel.QuickKeys.PropertyChanged += FastAccessKeys_PropertyChanged;
}
protected LayoutModel(string name)
@@ -27,7 +30,7 @@ protected LayoutModel(string name)
protected LayoutModel(string uuid, string name, LayoutType type)
: this()
{
- _guid = Guid.Parse(uuid);
+ Uuid = uuid;
Name = name;
Type = type;
}
@@ -48,6 +51,9 @@ protected LayoutModel(LayoutModel other)
_isApplied = other._isApplied;
_sensitivityRadius = other._sensitivityRadius;
_zoneCount = other._zoneCount;
+ _quickKey = other._quickKey;
+
+ MainWindowSettingsModel.QuickKeys.PropertyChanged += FastAccessKeys_PropertyChanged;
}
// Name - the display name for this layout model - is also used as the key in the registry
@@ -88,6 +94,17 @@ public string Uuid
{
return "{" + Guid.ToString().ToUpperInvariant() + "}";
}
+
+ set
+ {
+ try
+ {
+ _guid = Guid.Parse(value);
+ }
+ catch (Exception)
+ {
+ }
+ }
}
public bool IsCustom
@@ -158,6 +175,55 @@ public int SensitivityRadius
private int _sensitivityRadius = LayoutSettings.DefaultSensitivityRadius;
+ public List QuickKeysAvailable
+ {
+ get
+ {
+ List result = new List();
+ foreach (var pair in MainWindowSettingsModel.QuickKeys.SelectedKeys)
+ {
+ if (pair.Value == string.Empty || pair.Value == Uuid)
+ {
+ result.Add(pair.Key);
+ }
+ }
+
+ return result;
+ }
+ }
+
+ public string QuickKey
+ {
+ get
+ {
+ return _quickKey == -1 ? Properties.Resources.Quick_Key_None : _quickKey.ToString();
+ }
+
+ set
+ {
+ string none = Properties.Resources.Quick_Key_None;
+ var intValue = value == none ? -1 : int.Parse(value);
+ if (intValue != _quickKey)
+ {
+ string prev = _quickKey == -1 ? none : _quickKey.ToString();
+ _quickKey = intValue;
+
+ if (intValue != -1)
+ {
+ MainWindowSettingsModel.QuickKeys.SelectKey(value, Uuid);
+ }
+ else
+ {
+ MainWindowSettingsModel.QuickKeys.FreeKey(prev);
+ }
+
+ FirePropertyChanged(nameof(QuickKey));
+ }
+ }
+ }
+
+ private int _quickKey = -1;
+
// TemplateZoneCount - number of zones selected in the picker window for template layouts
public int TemplateZoneCount
{
@@ -200,6 +266,11 @@ protected virtual void FirePropertyChanged([CallerMemberName] string propertyNam
// Removes this Layout from the registry and the loaded CustomModels list
public void Delete()
{
+ if (_quickKey != -1)
+ {
+ MainWindowSettingsModel.QuickKeys.FreeKey(QuickKey);
+ }
+
var customModels = MainWindowSettingsModel.CustomModels;
int i = customModels.IndexOf(this);
if (i != -1)
@@ -241,5 +312,17 @@ public void Persist()
{
PersistData();
}
+
+ private void FastAccessKeys_PropertyChanged(object sender, PropertyChangedEventArgs e)
+ {
+ foreach (var pair in MainWindowSettingsModel.QuickKeys.SelectedKeys)
+ {
+ if (pair.Value == Uuid)
+ {
+ QuickKey = pair.Key.ToString();
+ break;
+ }
+ }
+ }
}
}
diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Models/LayoutType.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Models/LayoutType.cs
index d9a51bc0f658..2d514449ecc9 100644
--- a/src/modules/fancyzones/editor/FancyZonesEditor/Models/LayoutType.cs
+++ b/src/modules/fancyzones/editor/FancyZonesEditor/Models/LayoutType.cs
@@ -6,7 +6,7 @@ namespace FancyZonesEditor.Models
{
public enum LayoutType
{
- Blank = -1,
+ Blank = 0,
Focus,
Columns,
Rows,
diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Models/MainWindowSettingsModel.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Models/MainWindowSettingsModel.cs
index a23e1d8fd8c3..794575d7f69b 100644
--- a/src/modules/fancyzones/editor/FancyZonesEditor/Models/MainWindowSettingsModel.cs
+++ b/src/modules/fancyzones/editor/FancyZonesEditor/Models/MainWindowSettingsModel.cs
@@ -23,13 +23,6 @@ private enum DeviceIdParts
VirtualDesktopId,
}
- private readonly CanvasLayoutModel _blankModel;
- private readonly CanvasLayoutModel _focusModel;
- private readonly GridLayoutModel _rowsModel;
- private readonly GridLayoutModel _columnsModel;
- private readonly GridLayoutModel _gridModel;
- private readonly GridLayoutModel _priorityGridModel;
-
// Non-localizable strings
public static readonly string RegistryPath = "SOFTWARE\\SuperFancyZones";
public static readonly string FullRegistryPath = "HKEY_CURRENT_USER\\" + RegistryPath;
@@ -53,40 +46,40 @@ public bool IsCustomLayoutActive
public MainWindowSettingsModel()
{
// Initialize default layout models: Blank, Focus, Columns, Rows, Grid, and PriorityGrid
- _blankModel = new CanvasLayoutModel(Properties.Resources.Template_Layout_Blank, LayoutType.Blank)
+ var blankModel = new CanvasLayoutModel(Properties.Resources.Template_Layout_Blank, LayoutType.Blank)
{
TemplateZoneCount = 0,
SensitivityRadius = 0,
};
- DefaultModels.Add(_blankModel);
+ DefaultModels.Insert((int)LayoutType.Blank, blankModel);
- _focusModel = new CanvasLayoutModel(Properties.Resources.Template_Layout_Focus, LayoutType.Focus);
- _focusModel.InitTemplateZones();
- DefaultModels.Add(_focusModel);
+ var focusModel = new CanvasLayoutModel(Properties.Resources.Template_Layout_Focus, LayoutType.Focus);
+ focusModel.InitTemplateZones();
+ DefaultModels.Insert((int)LayoutType.Focus, focusModel);
- _columnsModel = new GridLayoutModel(Properties.Resources.Template_Layout_Columns, LayoutType.Columns)
+ var columnsModel = new GridLayoutModel(Properties.Resources.Template_Layout_Columns, LayoutType.Columns)
{
Rows = 1,
RowPercents = new List(1) { GridLayoutModel.GridMultiplier },
};
- _columnsModel.InitTemplateZones();
- DefaultModels.Add(_columnsModel);
+ columnsModel.InitTemplateZones();
+ DefaultModels.Insert((int)LayoutType.Columns, columnsModel);
- _rowsModel = new GridLayoutModel(Properties.Resources.Template_Layout_Rows, LayoutType.Rows)
+ var rowsModel = new GridLayoutModel(Properties.Resources.Template_Layout_Rows, LayoutType.Rows)
{
Columns = 1,
ColumnPercents = new List(1) { GridLayoutModel.GridMultiplier },
};
- _rowsModel.InitTemplateZones();
- DefaultModels.Add(_rowsModel);
+ rowsModel.InitTemplateZones();
+ DefaultModels.Insert((int)LayoutType.Rows, rowsModel);
- _gridModel = new GridLayoutModel(Properties.Resources.Template_Layout_Grid, LayoutType.Grid);
- _gridModel.InitTemplateZones();
- DefaultModels.Add(_gridModel);
+ var gridModel = new GridLayoutModel(Properties.Resources.Template_Layout_Grid, LayoutType.Grid);
+ gridModel.InitTemplateZones();
+ DefaultModels.Insert((int)LayoutType.Grid, gridModel);
- _priorityGridModel = new GridLayoutModel(Properties.Resources.Template_Layout_Priority_Grid, LayoutType.PriorityGrid);
- _priorityGridModel.InitTemplateZones();
- DefaultModels.Add(_priorityGridModel);
+ var priorityGridModel = new GridLayoutModel(Properties.Resources.Template_Layout_Priority_Grid, LayoutType.PriorityGrid);
+ priorityGridModel.InitTemplateZones();
+ DefaultModels.Insert((int)LayoutType.PriorityGrid, priorityGridModel);
}
// IsShiftKeyPressed - is the shift key currently being held down
@@ -133,7 +126,7 @@ public LayoutModel BlankModel
{
get
{
- return _blankModel;
+ return DefaultModels[(int)LayoutType.Blank];
}
}
@@ -149,6 +142,8 @@ public static ObservableCollection CustomModels
private static ObservableCollection _customModels = new ObservableCollection();
+ public static QuickKeysModel QuickKeys { get; } = new QuickKeysModel();
+
public LayoutModel SelectedModel
{
get
@@ -202,7 +197,7 @@ public LayoutModel UpdateSelectedLayoutModel()
{
foreach (LayoutModel model in CustomModels)
{
- if ("{" + model.Guid.ToString().ToUpperInvariant() + "}" == currentApplied.ZonesetUuid.ToUpperInvariant())
+ if (model.Uuid == currentApplied.ZonesetUuid.ToUpperInvariant())
{
// found match
foundModel = model;
@@ -234,7 +229,7 @@ public LayoutModel UpdateSelectedLayoutModel()
if (foundModel == null)
{
- foundModel = _priorityGridModel;
+ foundModel = DefaultModels[(int)LayoutType.PriorityGrid];
}
SetSelectedModel(foundModel);
@@ -255,6 +250,7 @@ public void RestoreSelectedModel(LayoutModel model)
SelectedModel.IsSelected = model.IsSelected;
SelectedModel.IsApplied = model.IsApplied;
SelectedModel.Name = model.Name;
+ SelectedModel.QuickKey = model.QuickKey;
if (model is GridLayoutModel grid)
{
diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Models/QuickKeysModel.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Models/QuickKeysModel.cs
new file mode 100644
index 000000000000..e1fc706b190e
--- /dev/null
+++ b/src/modules/fancyzones/editor/FancyZonesEditor/Models/QuickKeysModel.cs
@@ -0,0 +1,87 @@
+// Copyright (c) Microsoft Corporation
+// The Microsoft Corporation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Runtime.CompilerServices;
+
+namespace FancyZonesEditor.Models
+{
+ public class QuickKeysModel : INotifyPropertyChanged
+ {
+ public SortedDictionary SelectedKeys { get; } = new SortedDictionary()
+ {
+ { Properties.Resources.Quick_Key_None, string.Empty },
+ { "0", string.Empty },
+ { "1", string.Empty },
+ { "2", string.Empty },
+ { "3", string.Empty },
+ { "4", string.Empty },
+ { "5", string.Empty },
+ { "6", string.Empty },
+ { "7", string.Empty },
+ { "8", string.Empty },
+ { "9", string.Empty },
+ };
+
+ public QuickKeysModel()
+ {
+ }
+
+ public event PropertyChangedEventHandler PropertyChanged;
+
+ public void FreeKey(string key)
+ {
+ if (SelectedKeys.ContainsKey(key))
+ {
+ SelectedKeys[key] = string.Empty;
+ FirePropertyChanged();
+ }
+ }
+
+ public bool SelectKey(string key, string uuid)
+ {
+ if (!SelectedKeys.ContainsKey(key))
+ {
+ return false;
+ }
+
+ if (SelectedKeys[key] == uuid)
+ {
+ return true;
+ }
+
+ // clean previous value
+ foreach (var pair in SelectedKeys)
+ {
+ if (pair.Value == uuid)
+ {
+ SelectedKeys[pair.Key] = string.Empty;
+ break;
+ }
+ }
+
+ SelectedKeys[key] = uuid;
+ FirePropertyChanged();
+ return true;
+ }
+
+ public void CleanUp()
+ {
+ var keys = SelectedKeys.Keys.ToList();
+ foreach (var key in keys)
+ {
+ SelectedKeys[key] = string.Empty;
+ }
+
+ FirePropertyChanged();
+ }
+
+ protected virtual void FirePropertyChanged([CallerMemberName] string propertyName = null)
+ {
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+ }
+ }
+}
diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Properties/Resources.Designer.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Properties/Resources.Designer.cs
index 7e6b14a20e3c..6a44078f17b7 100644
--- a/src/modules/fancyzones/editor/FancyZonesEditor/Properties/Resources.Designer.cs
+++ b/src/modules/fancyzones/editor/FancyZonesEditor/Properties/Resources.Designer.cs
@@ -1,4 +1,4 @@
-//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
//
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
@@ -547,6 +547,24 @@ public static string NumberOfZones {
}
}
+ ///
+ /// Looks up a localized string similar to None.
+ ///
+ public static string Quick_Key_None {
+ get {
+ return ResourceManager.GetString("Quick_Key_None", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Select a key to quickly apply the layout (Win + Alt + key).
+ ///
+ public static string QuickKey_Select {
+ get {
+ return ResourceManager.GetString("QuickKey_Select", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Reset layout.
///
diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Properties/Resources.resx b/src/modules/fancyzones/editor/FancyZonesEditor/Properties/Resources.resx
index 46f43279abf1..4eb776ae40f8 100644
--- a/src/modules/fancyzones/editor/FancyZonesEditor/Properties/Resources.resx
+++ b/src/modules/fancyzones/editor/FancyZonesEditor/Properties/Resources.resx
@@ -334,4 +334,10 @@ To merge zones, hold down the left mouse button, drag the mouse to the zone to m
Custom layout
+
+ Select a key to quickly apply the layout (Win + Alt + key)
+
+
+ None
+
\ No newline at end of file
diff --git a/src/modules/fancyzones/editor/FancyZonesEditor/Utils/FancyZonesEditorIO.cs b/src/modules/fancyzones/editor/FancyZonesEditor/Utils/FancyZonesEditorIO.cs
index 781ef11f7abb..5652b700a4ac 100644
--- a/src/modules/fancyzones/editor/FancyZonesEditor/Utils/FancyZonesEditorIO.cs
+++ b/src/modules/fancyzones/editor/FancyZonesEditor/Utils/FancyZonesEditorIO.cs
@@ -169,6 +169,8 @@ private struct CustomLayoutWrapper
// zones-settings: templates
private struct TemplateLayoutWrapper
{
+ public string Uuid { get; set; }
+
public string Type { get; set; }
public bool ShowSpacing { get; set; }
@@ -180,8 +182,8 @@ private struct TemplateLayoutWrapper
public int SensitivityRadius { get; set; }
}
- // zones-settings: fast-access-layout-keys-wrapper
- private struct FastAccessLayoutKeysWrapper
+ // zones-settings: quick-layout-keys-wrapper
+ private struct QuickLayoutKeysWrapper
{
public int Key { get; set; }
@@ -197,7 +199,7 @@ private struct ZoneSettingsWrapper
public List Templates { get; set; }
- public List FastAccessLayoutKeys { get; set; }
+ public List QuickLayoutKeys { get; set; }
}
private struct EditorParams
@@ -545,7 +547,7 @@ public ParsingResult ParseZoneSettings()
bool devicesParsingResult = SetDevices(zoneSettings.Devices);
bool customZonesParsingResult = SetCustomLayouts(zoneSettings.CustomZoneSets);
bool templatesParsingResult = SetTemplateLayouts(zoneSettings.Templates);
- bool fastAccessKeysParsingResult = SetFastAccessKeys(zoneSettings.FastAccessLayoutKeys);
+ bool fastAccessKeysParsingResult = SetFastAccessKeys(zoneSettings.QuickLayoutKeys);
if (!devicesParsingResult || !customZonesParsingResult)
{
@@ -567,7 +569,7 @@ public void SerializeZoneSettings()
zoneSettings.Devices = new List();
zoneSettings.CustomZoneSets = new List();
zoneSettings.Templates = new List();
- zoneSettings.FastAccessLayoutKeys = new List();
+ zoneSettings.QuickLayoutKeys = new List();
// Serialize used devices
foreach (var monitor in App.Overlay.Monitors)
@@ -690,6 +692,7 @@ public void SerializeZoneSettings()
{
TemplateLayoutWrapper wrapper = new TemplateLayoutWrapper
{
+ Uuid = layout.Uuid,
Type = LayoutTypeToJsonTag(layout.Type),
SensitivityRadius = layout.SensitivityRadius,
ZoneCount = layout.TemplateZoneCount,
@@ -705,17 +708,23 @@ public void SerializeZoneSettings()
}
// Serialize fast access layout keys
- foreach (var pair in FastAccessKeysModel.SelectedKeys)
+ foreach (var pair in MainWindowSettingsModel.QuickKeys.SelectedKeys)
{
if (pair.Value != string.Empty)
{
- FastAccessLayoutKeysWrapper wrapper = new FastAccessLayoutKeysWrapper
+ try
{
- Key = pair.Key,
- Uuid = pair.Value,
- };
+ QuickLayoutKeysWrapper wrapper = new QuickLayoutKeysWrapper
+ {
+ Key = int.Parse(pair.Key),
+ Uuid = pair.Value,
+ };
- zoneSettings.FastAccessLayoutKeys.Add(wrapper);
+ zoneSettings.QuickLayoutKeys.Add(wrapper);
+ }
+ catch (Exception)
+ {
+ }
}
}
@@ -857,40 +866,36 @@ private bool SetTemplateLayouts(List templateLayouts)
foreach (var wrapper in templateLayouts)
{
- var type = JsonTagToLayoutType(wrapper.Type);
+ LayoutType type = JsonTagToLayoutType(wrapper.Type);
+ LayoutModel layout = MainWindowSettingsModel.DefaultModels[(int)type];
- foreach (var layout in MainWindowSettingsModel.DefaultModels)
- {
- if (layout.Type == type)
- {
- layout.SensitivityRadius = wrapper.SensitivityRadius;
- layout.TemplateZoneCount = wrapper.ZoneCount;
-
- if (layout is GridLayoutModel grid)
- {
- grid.ShowSpacing = wrapper.ShowSpacing;
- grid.Spacing = wrapper.Spacing;
- }
+ layout.Uuid = wrapper.Uuid;
+ layout.SensitivityRadius = wrapper.SensitivityRadius;
+ layout.TemplateZoneCount = wrapper.ZoneCount;
- layout.InitTemplateZones();
- }
+ if (layout is GridLayoutModel grid)
+ {
+ grid.ShowSpacing = wrapper.ShowSpacing;
+ grid.Spacing = wrapper.Spacing;
}
+
+ layout.InitTemplateZones();
}
return true;
}
- private bool SetFastAccessKeys(List fastAccessKeys)
+ private bool SetFastAccessKeys(List fastAccessKeys)
{
if (fastAccessKeys == null)
{
return false;
}
- FastAccessKeysModel.CleanUp();
+ MainWindowSettingsModel.QuickKeys.CleanUp();
foreach (var wrapper in fastAccessKeys)
{
- FastAccessKeysModel.SelectKey(wrapper.Key, wrapper.Uuid);
+ MainWindowSettingsModel.QuickKeys.SelectKey(wrapper.Key.ToString(), wrapper.Uuid);
}
return true;