[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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 77 additions and 20 deletions

View File

@ -90,7 +90,7 @@
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Background" Value="#767676"/>
<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="FocusVisualStyle" Value="{DynamicResource customButtonFocusVisualStyle}" />
<Setter Property="Template">
@ -117,7 +117,7 @@
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Background" Value="#0078D7"/>
<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="FocusVisualStyle" Value="{DynamicResource customButtonFocusVisualStyle}" />
<Setter Property="Template">
@ -445,6 +445,7 @@
</Grid>
<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="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();
App.Overlay.CloseLayoutWindow();
App.Current.Shutdown();
}
private void OnInitialized(object sender, EventArgs e)
@ -242,5 +243,28 @@ namespace FancyZonesEditor
{
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);
var canvasRect = CanvasRect;
if (canvasRect.Width == 0 || canvasRect.Height == 0)
{
canvasRect = App.Overlay.WorkArea;
}
CanvasLayoutInfo layoutInfo = new CanvasLayoutInfo
{
RefWidth = (int)CanvasRect.Width,
RefHeight = (int)CanvasRect.Height,
RefWidth = (int)canvasRect.Width,
RefHeight = (int)canvasRect.Height,
Zones = new Zone[Zones.Count],
};

View File

@ -2,6 +2,7 @@
// 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;
using FancyZonesEditor.Models;
namespace FancyZonesEditor
@ -16,8 +17,6 @@ namespace FancyZonesEditor
public static int DefaultSensitivityRadius => 20;
public string DeviceId { get; set; } = string.Empty;
public string ZonesetUuid { get; set; } = string.Empty;
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 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"
private static readonly byte[][] _priorityData = new byte[][]
{
@ -364,6 +361,16 @@ namespace FancyZonesEditor
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)
{
return model.Type != LayoutType.Custom;
@ -379,7 +386,11 @@ namespace FancyZonesEditor
LayoutSettings currentApplied = App.Overlay.CurrentLayoutSettings;
// 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)
{
@ -406,7 +417,7 @@ namespace FancyZonesEditor
if (foundModel == null)
{
foundModel = DefaultModels[0];
foundModel = DefaultModels[4]; // PriorityGrid
}
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>
/// Looks up a localized string similar to Save and apply.
/// </summary>

View File

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

View File

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

View File

@ -619,10 +619,7 @@ namespace JSONHelpers
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;

View File

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