[FancyZones Editor] Reset layout (#8114)

Co-authored-by: Enrico Giordani <enricogior@users.noreply.github.com>
This commit is contained in:
Seraphima Zykova
2020-11-19 10:03:22 +03:00
committed by GitHub
parent 1735be1cc2
commit 854ea0e5ac
10 changed files with 77 additions and 20 deletions

View File

@@ -90,7 +90,7 @@
<Setter Property="BorderThickness" Value="0"/> <Setter Property="BorderThickness" Value="0"/>
<Setter Property="Background" Value="#767676"/> <Setter Property="Background" Value="#767676"/>
<Setter Property="Margin" Value="16,0,0,0" /> <Setter Property="Margin" Value="16,0,0,0" />
<Setter Property="Width" Value="245"/> <Setter Property="Width" Value="200"/>
<Setter Property="Height" Value="32"/> <Setter Property="Height" Value="32"/>
<Setter Property="FocusVisualStyle" Value="{DynamicResource customButtonFocusVisualStyle}" /> <Setter Property="FocusVisualStyle" Value="{DynamicResource customButtonFocusVisualStyle}" />
<Setter Property="Template"> <Setter Property="Template">
@@ -117,7 +117,7 @@
<Setter Property="BorderThickness" Value="0"/> <Setter Property="BorderThickness" Value="0"/>
<Setter Property="Background" Value="#0078D7"/> <Setter Property="Background" Value="#0078D7"/>
<Setter Property="Margin" Value="16,0,0,0" /> <Setter Property="Margin" Value="16,0,0,0" />
<Setter Property="Width" Value="245"/> <Setter Property="Width" Value="220"/>
<Setter Property="Height" Value="32"/> <Setter Property="Height" Value="32"/>
<Setter Property="FocusVisualStyle" Value="{DynamicResource customButtonFocusVisualStyle}" /> <Setter Property="FocusVisualStyle" Value="{DynamicResource customButtonFocusVisualStyle}" />
<Setter Property="Template"> <Setter Property="Template">
@@ -445,6 +445,7 @@
</Grid> </Grid>
<StackPanel Orientation="Horizontal" Margin="0,10,0,16"> <StackPanel Orientation="Horizontal" Margin="0,10,0,16">
<Button x:Name="ResetButton" Content="{x:Static props:Resources.Reset_Layout}" Padding="8" Style="{StaticResource secondaryButton}" Click="Reset_Click"/>
<Button x:Name="EditCustomButton" Content="{x:Static props:Resources.Edit_Selected_Layout}" Padding="8" Style="{StaticResource secondaryButton}" Click="EditLayout_Click"/> <Button x:Name="EditCustomButton" Content="{x:Static props:Resources.Edit_Selected_Layout}" Padding="8" Style="{StaticResource secondaryButton}" Click="EditLayout_Click"/>
<Button x:Name="ApplyCustomButton" Content="{x:Static props:Resources.Apply}" Padding="8" Style="{StaticResource primaryButton}" Click="Apply_Click"/> <Button x:Name="ApplyCustomButton" Content="{x:Static props:Resources.Apply}" Padding="8" Style="{StaticResource primaryButton}" Click="Apply_Click"/>

View File

@@ -193,6 +193,7 @@ namespace FancyZonesEditor
{ {
LayoutModel.SerializeDeletedCustomZoneSets(); LayoutModel.SerializeDeletedCustomZoneSets();
App.Overlay.CloseLayoutWindow(); App.Overlay.CloseLayoutWindow();
App.Current.Shutdown();
} }
private void OnInitialized(object sender, EventArgs e) private void OnInitialized(object sender, EventArgs e)
@@ -242,5 +243,28 @@ namespace FancyZonesEditor
{ {
this.Close(); this.Close();
} }
private void Reset_Click(object sender, RoutedEventArgs e)
{
var overlay = App.Overlay;
MainWindowSettingsModel settings = ((App)Application.Current).MainWindowSettings;
if (overlay.CurrentDataContext is LayoutModel model)
{
model.IsSelected = false;
model.IsApplied = false;
}
overlay.CurrentLayoutSettings.ZonesetUuid = settings.BlankModel.Uuid;
overlay.CurrentLayoutSettings.Type = LayoutType.Blank;
overlay.CurrentDataContext = settings.BlankModel;
App.FancyZonesEditorIO.SerializeAppliedLayouts();
if (!overlay.MultiMonitorMode)
{
Close();
}
}
} }
} }

View File

@@ -120,10 +120,16 @@ namespace FancyZonesEditor.Models
{ {
AddCustomLayout(this); AddCustomLayout(this);
var canvasRect = CanvasRect;
if (canvasRect.Width == 0 || canvasRect.Height == 0)
{
canvasRect = App.Overlay.WorkArea;
}
CanvasLayoutInfo layoutInfo = new CanvasLayoutInfo CanvasLayoutInfo layoutInfo = new CanvasLayoutInfo
{ {
RefWidth = (int)CanvasRect.Width, RefWidth = (int)canvasRect.Width,
RefHeight = (int)CanvasRect.Height, RefHeight = (int)canvasRect.Height,
Zones = new Zone[Zones.Count], Zones = new Zone[Zones.Count],
}; };

View File

@@ -2,6 +2,7 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System;
using FancyZonesEditor.Models; using FancyZonesEditor.Models;
namespace FancyZonesEditor namespace FancyZonesEditor
@@ -16,8 +17,6 @@ namespace FancyZonesEditor
public static int DefaultSensitivityRadius => 20; public static int DefaultSensitivityRadius => 20;
public string DeviceId { get; set; } = string.Empty;
public string ZonesetUuid { get; set; } = string.Empty; public string ZonesetUuid { get; set; } = string.Empty;
public LayoutType Type { get; set; } = LayoutType.PriorityGrid; public LayoutType Type { get; set; } = LayoutType.PriorityGrid;

View File

@@ -46,9 +46,6 @@ namespace FancyZonesEditor
public static readonly string RegistryPath = "SOFTWARE\\SuperFancyZones"; public static readonly string RegistryPath = "SOFTWARE\\SuperFancyZones";
public static readonly string FullRegistryPath = "HKEY_CURRENT_USER\\" + RegistryPath; public static readonly string FullRegistryPath = "HKEY_CURRENT_USER\\" + RegistryPath;
private const string LayoutTypeBlankStr = "blank";
private const string NullUuidStr = "null";
// hard coded data for all the "Priority Grid" configurations that are unique to "Grid" // hard coded data for all the "Priority Grid" configurations that are unique to "Grid"
private static readonly byte[][] _priorityData = new byte[][] private static readonly byte[][] _priorityData = new byte[][]
{ {
@@ -364,6 +361,16 @@ namespace FancyZonesEditor
private static ObservableCollection<LayoutModel> _customModels; private static ObservableCollection<LayoutModel> _customModels;
public CanvasLayoutModel BlankModel
{
get
{
return _blankModel;
}
}
private CanvasLayoutModel _blankModel = new CanvasLayoutModel(string.Empty, LayoutType.Blank);
public static bool IsPredefinedLayout(LayoutModel model) public static bool IsPredefinedLayout(LayoutModel model)
{ {
return model.Type != LayoutType.Custom; return model.Type != LayoutType.Custom;
@@ -379,7 +386,11 @@ namespace FancyZonesEditor
LayoutSettings currentApplied = App.Overlay.CurrentLayoutSettings; LayoutSettings currentApplied = App.Overlay.CurrentLayoutSettings;
// set new layout // set new layout
if (currentApplied.Type == LayoutType.Custom) if (currentApplied.Type == LayoutType.Blank)
{
foundModel = BlankModel;
}
else if (currentApplied.Type == LayoutType.Custom)
{ {
foreach (LayoutModel model in MainWindowSettingsModel.CustomModels) foreach (LayoutModel model in MainWindowSettingsModel.CustomModels)
{ {
@@ -406,7 +417,7 @@ namespace FancyZonesEditor
if (foundModel == null) if (foundModel == null)
{ {
foundModel = DefaultModels[0]; foundModel = DefaultModels[4]; // PriorityGrid
} }
foundModel.IsSelected = true; foundModel.IsSelected = true;

View File

@@ -348,6 +348,15 @@ namespace FancyZonesEditor.Properties {
} }
} }
/// <summary>
/// Looks up a localized string similar to Reset layout.
/// </summary>
public static string Reset_Layout {
get {
return ResourceManager.GetString("Reset_Layout", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Save and apply. /// Looks up a localized string similar to Save and apply.
/// </summary> /// </summary>

View File

@@ -253,4 +253,8 @@
<data name="Error_Monitor_Match_Not_Found" xml:space="preserve"> <data name="Error_Monitor_Match_Not_Found" xml:space="preserve">
<value>Match not found ({0})</value> <value>Match not found ({0})</value>
</data> </data>
<data name="Reset_Layout" xml:space="preserve">
<value>Reset layout</value>
<comment>as in Reset to a blank value</comment>
</data>
</root> </root>

View File

@@ -28,6 +28,7 @@ namespace FancyZonesEditor.Utils
private const string EditorZoneCountJsonTag = "editor-zone-count"; private const string EditorZoneCountJsonTag = "editor-zone-count";
private const string EditorSensitivityRadiusJsonTag = "editor-sensitivity-radius"; private const string EditorSensitivityRadiusJsonTag = "editor-sensitivity-radius";
private const string BlankJsonTag = "blank";
private const string FocusJsonTag = "focus"; private const string FocusJsonTag = "focus";
private const string ColumnsJsonTag = "columns"; private const string ColumnsJsonTag = "columns";
private const string RowsJsonTag = "rows"; private const string RowsJsonTag = "rows";
@@ -56,6 +57,9 @@ namespace FancyZonesEditor.Utils
private const string AppliedZoneSetsTmpFileName = "FancyZonesAppliedZoneSets.json"; private const string AppliedZoneSetsTmpFileName = "FancyZonesAppliedZoneSets.json";
private const string DeletedCustomZoneSetsTmpFileName = "FancyZonesDeletedCustomZoneSets.json"; private const string DeletedCustomZoneSetsTmpFileName = "FancyZonesDeletedCustomZoneSets.json";
// Non-localizable string: Multi-monitor id
private const string MultiMonitorId = "FancyZones#MultiMonitorDevice";
private readonly IFileSystem _fileSystem = new FileSystem(); private readonly IFileSystem _fileSystem = new FileSystem();
private JsonSerializerOptions _options = new JsonSerializerOptions private JsonSerializerOptions _options = new JsonSerializerOptions
@@ -319,7 +323,6 @@ namespace FancyZonesEditor.Utils
{ {
monitors[monitorIndex].Settings = new LayoutSettings monitors[monitorIndex].Settings = new LayoutSettings
{ {
DeviceId = deviceId,
ZonesetUuid = zonesetData.GetProperty(ActiveZoneSetJsonTag).GetProperty(UuidJsonTag).GetString(), ZonesetUuid = zonesetData.GetProperty(ActiveZoneSetJsonTag).GetProperty(UuidJsonTag).GetString(),
ShowSpacing = zonesetData.GetProperty(EditorShowSpacingJsonTag).GetBoolean(), ShowSpacing = zonesetData.GetProperty(EditorShowSpacingJsonTag).GetBoolean(),
Spacing = zonesetData.GetProperty(EditorSpacingJsonTag).GetInt32(), Spacing = zonesetData.GetProperty(EditorSpacingJsonTag).GetInt32(),
@@ -334,13 +337,12 @@ namespace FancyZonesEditor.Utils
} }
else else
{ {
bool isLayoutMultiMonitor = deviceId.StartsWith("FancyZones#MultiMonitorDevice"); bool isLayoutMultiMonitor = deviceId.StartsWith(MultiMonitorId);
if (isLayoutMultiMonitor) if (isLayoutMultiMonitor)
{ {
// one zoneset for all desktops // one zoneset for all desktops
App.Overlay.Monitors[App.Overlay.CurrentDesktop].Settings = new LayoutSettings App.Overlay.Monitors[App.Overlay.CurrentDesktop].Settings = new LayoutSettings
{ {
DeviceId = deviceId,
ZonesetUuid = zonesetData.GetProperty(ActiveZoneSetJsonTag).GetProperty(UuidJsonTag).GetString(), ZonesetUuid = zonesetData.GetProperty(ActiveZoneSetJsonTag).GetProperty(UuidJsonTag).GetString(),
ShowSpacing = zonesetData.GetProperty(EditorShowSpacingJsonTag).GetBoolean(), ShowSpacing = zonesetData.GetProperty(EditorShowSpacingJsonTag).GetBoolean(),
Spacing = zonesetData.GetProperty(EditorSpacingJsonTag).GetInt32(), Spacing = zonesetData.GetProperty(EditorSpacingJsonTag).GetInt32(),
@@ -349,6 +351,8 @@ namespace FancyZonesEditor.Utils
SensitivityRadius = zonesetData.GetProperty(EditorSensitivityRadiusJsonTag).GetInt32(), SensitivityRadius = zonesetData.GetProperty(EditorSensitivityRadiusJsonTag).GetInt32(),
}; };
App.Overlay.Monitors[App.Overlay.CurrentDesktop].Device.Id = deviceId;
break; break;
} }
} }
@@ -527,7 +531,7 @@ namespace FancyZonesEditor.Utils
applied.AppliedZonesets.Add(new AppliedZoneSet applied.AppliedZonesets.Add(new AppliedZoneSet
{ {
DeviceId = zoneset.DeviceId, DeviceId = monitor.Device.Id,
ActiveZoneset = activeZoneSet, ActiveZoneset = activeZoneSet,
EditorShowSpacing = zoneset.ShowSpacing, EditorShowSpacing = zoneset.ShowSpacing,
EditorSpacing = zoneset.Spacing, EditorSpacing = zoneset.Spacing,
@@ -615,6 +619,8 @@ namespace FancyZonesEditor.Utils
{ {
switch (type) switch (type)
{ {
case LayoutType.Blank:
return BlankJsonTag;
case LayoutType.Focus: case LayoutType.Focus:
return FocusJsonTag; return FocusJsonTag;
case LayoutType.Rows: case LayoutType.Rows:

View File

@@ -619,10 +619,7 @@ namespace JSONHelpers
for (const auto& [deviceID, deviceData] : deviceInfoMap) for (const auto& [deviceID, deviceData] : deviceInfoMap)
{ {
if (deviceData.activeZoneSet.type != FancyZonesDataTypes::ZoneSetLayoutType::Blank) DeviceInfosJSON.Append(DeviceInfoJSON::DeviceInfoJSON::ToJson(DeviceInfoJSON{ deviceID, deviceData }));
{
DeviceInfosJSON.Append(DeviceInfoJSON::DeviceInfoJSON::ToJson(DeviceInfoJSON{ deviceID, deviceData }));
}
} }
return DeviceInfosJSON; return DeviceInfosJSON;

View File

@@ -390,7 +390,7 @@ void ZoneWindow::CalculateZoneSet() noexcept
const auto& activeZoneSet = deviceInfoData->activeZoneSet; const auto& activeZoneSet = deviceInfoData->activeZoneSet;
if (activeZoneSet.uuid.empty() || activeZoneSet.type == FancyZonesDataTypes::ZoneSetLayoutType::Blank) if (activeZoneSet.uuid.empty())
{ {
return; return;
} }