mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
[FancyZones] Customize default layouts (#21156)
This commit is contained in:
@@ -113,6 +113,13 @@ namespace FancyZonesEditor
|
||||
MessageBox.Show(parseResult.Message, FancyZonesEditor.Properties.Resources.Error_Parsing_Data_Title, MessageBoxButton.OK);
|
||||
}
|
||||
|
||||
parseResult = FancyZonesEditorIO.ParseDefaultLayouts();
|
||||
if (!parseResult.Result)
|
||||
{
|
||||
Logger.LogError(ParsingErrorReportTag + ": " + parseResult.Message + "; " + ParsingErrorDataTag + ": " + parseResult.MalformedData);
|
||||
MessageBox.Show(parseResult.Message, FancyZonesEditor.Properties.Resources.Error_Parsing_Data_Title, MessageBoxButton.OK);
|
||||
}
|
||||
|
||||
MainWindowSettingsModel settings = ((App)Current).MainWindowSettings;
|
||||
settings.UpdateSelectedLayoutModel();
|
||||
|
||||
|
||||
@@ -202,7 +202,7 @@
|
||||
FontWeight="SemiBold"
|
||||
FontSize="24" />
|
||||
|
||||
<ui:GridView ItemsSource="{Binding DefaultModels}"
|
||||
<ui:GridView ItemsSource="{Binding TemplateModels}"
|
||||
Grid.Row="1"
|
||||
ItemTemplate="{StaticResource LayoutItemTemplate}"
|
||||
AutomationProperties.LabeledBy="{Binding ElementName=TemplatesHeaderBlock}"
|
||||
@@ -589,9 +589,6 @@
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
|
||||
|
||||
|
||||
<StackPanel Margin="0, 12, 0, 0">
|
||||
<TextBlock Text="{x:Static props:Resources.Distance_adjacent_zones}"
|
||||
x:Name="distanceTitle"
|
||||
@@ -635,6 +632,97 @@
|
||||
VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal"
|
||||
HorizontalAlignment="Left"
|
||||
Margin="0,16,0,0"
|
||||
Visibility="{Binding Path=Type, Converter={StaticResource LayoutTypeTemplateToVisibilityConverter}}">
|
||||
|
||||
<TextBlock FontFamily="Segoe MDL2 Assets"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="16"
|
||||
Margin="0,16,0,0"
|
||||
AutomationProperties.Name="{x:Static props:Resources.Number_of_zones}"
|
||||
ToolTip="{x:Static props:Resources.Number_of_zones}"
|
||||
Text="" />
|
||||
|
||||
<ui:NumberBox Minimum="1"
|
||||
Maximum="128"
|
||||
Width="216"
|
||||
KeyDown="EditDialogNumberBox_KeyDown"
|
||||
Margin="12,0,0,0"
|
||||
Header="{x:Static props:Resources.Number_of_zones}"
|
||||
Loaded="NumberBox_Loaded"
|
||||
AutomationProperties.Name="{x:Static props:Resources.Number_of_zones}"
|
||||
SpinButtonPlacementMode="Compact"
|
||||
Text="{Binding TemplateZoneCount}" />
|
||||
</StackPanel>
|
||||
|
||||
|
||||
|
||||
<StackPanel Orientation="Vertical"
|
||||
HorizontalAlignment="Left"
|
||||
Margin="0,16,0,0">
|
||||
|
||||
<Button x:Name="SetLayoutAsHorizontalDefaultButton"
|
||||
Click="SetLayoutAsHorizontalDefaultButton_Click"
|
||||
AutomationProperties.Name="{x:Static props:Resources.Set_Layout_As_Horizontal_Default}"
|
||||
ToolTip="{x:Static props:Resources.Set_Layout_As_Horizontal_Default}"
|
||||
Style="{StaticResource IconOnlyButtonStyle}"
|
||||
Visibility="{Binding CanBeSetAsHorizontalDefault, Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||
<Button.Content>
|
||||
<TextBlock AutomationProperties.Name="{x:Static props:Resources.Set_Layout_As_Horizontal_Default}"
|
||||
FontSize="14">
|
||||
<Run Text="" FontFamily="Segoe MDL2 Assets"/>
|
||||
<Run Text="{x:Static props:Resources.Default_Layout_Horizontal}"/>
|
||||
</TextBlock>
|
||||
</Button.Content>
|
||||
</Button>
|
||||
<Button x:Name="HorizontalDefaultLayoutButton"
|
||||
Click="HorizontalDefaultLayoutButton_Click"
|
||||
ToolTip="{x:Static props:Resources.Default_Layout_Horizontal}"
|
||||
AutomationProperties.Name="{x:Static props:Resources.Default_Layout_Horizontal}"
|
||||
Style="{StaticResource IconOnlyButtonStyle}"
|
||||
Visibility="{Binding IsHorizontalDefault, Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||
<Button.Content>
|
||||
<TextBlock AutomationProperties.Name="{x:Static props:Resources.Default_Layout_Horizontal}"
|
||||
FontSize="14">
|
||||
<Run Text="" FontFamily="Segoe MDL2 Assets"/>
|
||||
<Run Text="{x:Static props:Resources.Default_Layout_Horizontal}"/>
|
||||
</TextBlock>
|
||||
</Button.Content>
|
||||
</Button>
|
||||
|
||||
<Button x:Name="SetLayoutAsVerticalDefaultButton"
|
||||
Click="SetLayoutAsVerticalDefaultButton_Click"
|
||||
AutomationProperties.Name="{x:Static props:Resources.Set_Layout_As_Vertical_Default}"
|
||||
ToolTip="{x:Static props:Resources.Set_Layout_As_Vertical_Default}"
|
||||
Style="{StaticResource IconOnlyButtonStyle}"
|
||||
Visibility="{Binding CanBeSetAsVerticalDefault, Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||
<Button.Content>
|
||||
<TextBlock AutomationProperties.Name="{x:Static props:Resources.Set_Layout_As_Vertical_Default}"
|
||||
FontSize="14">
|
||||
<Run Text="" FontFamily="Segoe MDL2 Assets"/>
|
||||
<Run Text="{x:Static props:Resources.Default_Layout_Vertical}"/>
|
||||
</TextBlock>
|
||||
</Button.Content>
|
||||
</Button>
|
||||
<Button x:Name="VerticalDefaultLayoutButton"
|
||||
Click="VerticalDefaultLayoutButton_Click"
|
||||
ToolTip="{x:Static props:Resources.Default_Layout_Vertical}"
|
||||
AutomationProperties.Name="{x:Static props:Resources.Default_Layout_Vertical}"
|
||||
Style="{StaticResource IconOnlyButtonStyle}"
|
||||
Visibility="{Binding IsVerticalDefault, Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||
<Button.Content>
|
||||
<TextBlock AutomationProperties.Name="{x:Static props:Resources.Default_Layout_Vertical}"
|
||||
FontSize="14">
|
||||
<Run Text="" FontFamily="Segoe MDL2 Assets"/>
|
||||
<Run Text="{x:Static props:Resources.Default_Layout_Vertical}"/>
|
||||
</TextBlock>
|
||||
</Button.Content>
|
||||
</Button>
|
||||
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</ui:ContentDialog>
|
||||
|
||||
@@ -29,6 +29,7 @@ namespace FancyZonesEditor
|
||||
|
||||
private readonly MainWindowSettingsModel _settings = ((App)Application.Current).MainWindowSettings;
|
||||
private LayoutModel _backup;
|
||||
private List<LayoutModel> _defaultLayoutsBackup;
|
||||
|
||||
private ContentDialog _openedDialog;
|
||||
private TextBlock _createLayoutAnnounce;
|
||||
@@ -322,6 +323,8 @@ namespace FancyZonesEditor
|
||||
_backup = new CanvasLayoutModel(canvas);
|
||||
}
|
||||
|
||||
_defaultLayoutsBackup = new List<LayoutModel>(MainWindowSettingsModel.DefaultLayouts.DefaultLayouts);
|
||||
|
||||
Keyboard.ClearFocus();
|
||||
EditLayoutDialogTitle.Text = string.Format(CultureInfo.CurrentCulture, Properties.Resources.Edit_Template, ((LayoutModel)dataContext).Name);
|
||||
await EditLayoutDialog.ShowAsync();
|
||||
@@ -424,6 +427,7 @@ namespace FancyZonesEditor
|
||||
}
|
||||
|
||||
_backup = null;
|
||||
_defaultLayoutsBackup = null;
|
||||
|
||||
// update current settings
|
||||
if (model == _settings.AppliedModel)
|
||||
@@ -464,6 +468,8 @@ namespace FancyZonesEditor
|
||||
_backup = null;
|
||||
}
|
||||
|
||||
MainWindowSettingsModel.DefaultLayouts.Reset(model.Uuid);
|
||||
|
||||
if (model == _settings.AppliedModel)
|
||||
{
|
||||
_settings.SetAppliedModel(_settings.BlankModel);
|
||||
@@ -480,6 +486,7 @@ namespace FancyZonesEditor
|
||||
|
||||
App.FancyZonesEditorIO.SerializeAppliedLayouts();
|
||||
App.FancyZonesEditorIO.SerializeCustomLayouts();
|
||||
App.FancyZonesEditorIO.SerializeDefaultLayouts();
|
||||
model.Delete();
|
||||
}
|
||||
}
|
||||
@@ -543,6 +550,12 @@ namespace FancyZonesEditor
|
||||
_settings.RestoreSelectedModel(_backup);
|
||||
_backup = null;
|
||||
}
|
||||
|
||||
if (_defaultLayoutsBackup != null)
|
||||
{
|
||||
MainWindowSettingsModel.DefaultLayouts.Restore(_defaultLayoutsBackup);
|
||||
_defaultLayoutsBackup = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void NumberBox_Loaded(object sender, RoutedEventArgs e)
|
||||
@@ -586,5 +599,45 @@ namespace FancyZonesEditor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetLayoutAsVerticalDefaultButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var dataContext = ((FrameworkElement)sender).DataContext;
|
||||
if (dataContext is LayoutModel model)
|
||||
{
|
||||
MainWindowSettingsModel.DefaultLayouts.Set(model, MonitorConfigurationType.Vertical);
|
||||
App.FancyZonesEditorIO.SerializeDefaultLayouts();
|
||||
}
|
||||
}
|
||||
|
||||
private void SetLayoutAsHorizontalDefaultButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var dataContext = ((FrameworkElement)sender).DataContext;
|
||||
if (dataContext is LayoutModel model)
|
||||
{
|
||||
MainWindowSettingsModel.DefaultLayouts.Set(model, MonitorConfigurationType.Horizontal);
|
||||
App.FancyZonesEditorIO.SerializeDefaultLayouts();
|
||||
}
|
||||
}
|
||||
|
||||
private void HorizontalDefaultLayoutButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var dataContext = ((FrameworkElement)sender).DataContext;
|
||||
if (dataContext is LayoutModel model)
|
||||
{
|
||||
MainWindowSettingsModel.DefaultLayouts.Reset(MonitorConfigurationType.Horizontal);
|
||||
App.FancyZonesEditorIO.SerializeDefaultLayouts();
|
||||
}
|
||||
}
|
||||
|
||||
private void VerticalDefaultLayoutButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var dataContext = ((FrameworkElement)sender).DataContext;
|
||||
if (dataContext is LayoutModel model)
|
||||
{
|
||||
MainWindowSettingsModel.DefaultLayouts.Reset(MonitorConfigurationType.Vertical);
|
||||
App.FancyZonesEditorIO.SerializeDefaultLayouts();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
// 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;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace FancyZonesEditor.Models
|
||||
{
|
||||
public class DefaultLayoutsModel : INotifyPropertyChanged
|
||||
{
|
||||
private static int Count { get; } = Enum.GetValues(typeof(MonitorConfigurationType)).Length;
|
||||
|
||||
public List<LayoutModel> DefaultLayouts { get; } = new List<LayoutModel>(Count);
|
||||
|
||||
public DefaultLayoutsModel()
|
||||
{
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public void Reset(MonitorConfigurationType type)
|
||||
{
|
||||
Set(MainWindowSettingsModel.TemplateModels[(int)LayoutType.PriorityGrid], type);
|
||||
}
|
||||
|
||||
public void Reset(string uuid)
|
||||
{
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (DefaultLayouts[i].Uuid == uuid)
|
||||
{
|
||||
Set(MainWindowSettingsModel.TemplateModels[(int)LayoutType.PriorityGrid], (MonitorConfigurationType)i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Set(LayoutModel layout, MonitorConfigurationType type)
|
||||
{
|
||||
if (DefaultLayouts.Count <= (int)type)
|
||||
{
|
||||
DefaultLayouts.Insert((int)type, layout);
|
||||
}
|
||||
else
|
||||
{
|
||||
DefaultLayouts[(int)type] = layout;
|
||||
}
|
||||
|
||||
FirePropertyChanged();
|
||||
}
|
||||
|
||||
public void Restore(List<LayoutModel> layouts)
|
||||
{
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
Set(layouts[i], (MonitorConfigurationType)i);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void FirePropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,8 @@ namespace FancyZonesEditor.Models
|
||||
{
|
||||
_guid = Guid.NewGuid();
|
||||
Type = LayoutType.Custom;
|
||||
|
||||
MainWindowSettingsModel.DefaultLayouts.PropertyChanged += DefaultLayouts_PropertyChanged;
|
||||
}
|
||||
|
||||
protected LayoutModel(string name)
|
||||
@@ -144,6 +146,38 @@ namespace FancyZonesEditor.Models
|
||||
|
||||
private bool _isApplied;
|
||||
|
||||
public bool IsHorizontalDefault
|
||||
{
|
||||
get
|
||||
{
|
||||
return MainWindowSettingsModel.DefaultLayouts.DefaultLayouts[(int)MonitorConfigurationType.Horizontal].Uuid == this.Uuid;
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanBeSetAsHorizontalDefault
|
||||
{
|
||||
get
|
||||
{
|
||||
return MainWindowSettingsModel.DefaultLayouts.DefaultLayouts[(int)MonitorConfigurationType.Horizontal].Uuid != this.Uuid;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsVerticalDefault
|
||||
{
|
||||
get
|
||||
{
|
||||
return MainWindowSettingsModel.DefaultLayouts.DefaultLayouts[(int)MonitorConfigurationType.Vertical].Uuid == this.Uuid;
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanBeSetAsVerticalDefault
|
||||
{
|
||||
get
|
||||
{
|
||||
return MainWindowSettingsModel.DefaultLayouts.DefaultLayouts[(int)MonitorConfigurationType.Vertical].Uuid != this.Uuid;
|
||||
}
|
||||
}
|
||||
|
||||
public int SensitivityRadius
|
||||
{
|
||||
get
|
||||
@@ -334,5 +368,13 @@ namespace FancyZonesEditor.Models
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DefaultLayouts_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
FirePropertyChanged(nameof(IsHorizontalDefault));
|
||||
FirePropertyChanged(nameof(IsVerticalDefault));
|
||||
FirePropertyChanged(nameof(CanBeSetAsHorizontalDefault));
|
||||
FirePropertyChanged(nameof(CanBeSetAsVerticalDefault));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,10 +23,6 @@ namespace FancyZonesEditor
|
||||
VirtualDesktopId,
|
||||
}
|
||||
|
||||
// Non-localizable strings
|
||||
public static readonly string RegistryPath = "SOFTWARE\\SuperFancyZones";
|
||||
public static readonly string FullRegistryPath = "HKEY_CURRENT_USER\\" + RegistryPath;
|
||||
|
||||
public bool IsCustomLayoutActive
|
||||
{
|
||||
get
|
||||
@@ -43,6 +39,8 @@ namespace FancyZonesEditor
|
||||
}
|
||||
}
|
||||
|
||||
public static DefaultLayoutsModel DefaultLayouts { get; } = new DefaultLayoutsModel();
|
||||
|
||||
public MainWindowSettingsModel()
|
||||
{
|
||||
// Initialize default layout models: Blank, Focus, Columns, Rows, Grid, and PriorityGrid
|
||||
@@ -51,11 +49,11 @@ namespace FancyZonesEditor
|
||||
TemplateZoneCount = 0,
|
||||
SensitivityRadius = 0,
|
||||
};
|
||||
DefaultModels.Insert((int)LayoutType.Blank, blankModel);
|
||||
TemplateModels.Insert((int)LayoutType.Blank, blankModel);
|
||||
|
||||
var focusModel = new CanvasLayoutModel(Properties.Resources.Template_Layout_Focus, LayoutType.Focus);
|
||||
focusModel.InitTemplateZones();
|
||||
DefaultModels.Insert((int)LayoutType.Focus, focusModel);
|
||||
TemplateModels.Insert((int)LayoutType.Focus, focusModel);
|
||||
|
||||
var columnsModel = new GridLayoutModel(Properties.Resources.Template_Layout_Columns, LayoutType.Columns)
|
||||
{
|
||||
@@ -63,7 +61,7 @@ namespace FancyZonesEditor
|
||||
RowPercents = new List<int>(1) { GridLayoutModel.GridMultiplier },
|
||||
};
|
||||
columnsModel.InitTemplateZones();
|
||||
DefaultModels.Insert((int)LayoutType.Columns, columnsModel);
|
||||
TemplateModels.Insert((int)LayoutType.Columns, columnsModel);
|
||||
|
||||
var rowsModel = new GridLayoutModel(Properties.Resources.Template_Layout_Rows, LayoutType.Rows)
|
||||
{
|
||||
@@ -71,15 +69,19 @@ namespace FancyZonesEditor
|
||||
ColumnPercents = new List<int>(1) { GridLayoutModel.GridMultiplier },
|
||||
};
|
||||
rowsModel.InitTemplateZones();
|
||||
DefaultModels.Insert((int)LayoutType.Rows, rowsModel);
|
||||
TemplateModels.Insert((int)LayoutType.Rows, rowsModel);
|
||||
|
||||
var gridModel = new GridLayoutModel(Properties.Resources.Template_Layout_Grid, LayoutType.Grid);
|
||||
gridModel.InitTemplateZones();
|
||||
DefaultModels.Insert((int)LayoutType.Grid, gridModel);
|
||||
TemplateModels.Insert((int)LayoutType.Grid, gridModel);
|
||||
|
||||
var priorityGridModel = new GridLayoutModel(Properties.Resources.Template_Layout_Priority_Grid, LayoutType.PriorityGrid);
|
||||
priorityGridModel.InitTemplateZones();
|
||||
DefaultModels.Insert((int)LayoutType.PriorityGrid, priorityGridModel);
|
||||
TemplateModels.Insert((int)LayoutType.PriorityGrid, priorityGridModel);
|
||||
|
||||
// set default layouts
|
||||
DefaultLayouts.Set(priorityGridModel, MonitorConfigurationType.Horizontal);
|
||||
DefaultLayouts.Set(priorityGridModel, MonitorConfigurationType.Vertical);
|
||||
}
|
||||
|
||||
// IsShiftKeyPressed - is the shift key currently being held down
|
||||
@@ -126,11 +128,11 @@ namespace FancyZonesEditor
|
||||
{
|
||||
get
|
||||
{
|
||||
return DefaultModels[(int)LayoutType.Blank];
|
||||
return TemplateModels[(int)LayoutType.Blank];
|
||||
}
|
||||
}
|
||||
|
||||
public static IList<LayoutModel> DefaultModels { get; } = new List<LayoutModel>(6);
|
||||
public static IList<LayoutModel> TemplateModels { get; } = new List<LayoutModel>(6);
|
||||
|
||||
public static ObservableCollection<LayoutModel> CustomModels
|
||||
{
|
||||
@@ -213,7 +215,7 @@ namespace FancyZonesEditor
|
||||
|
||||
public void InitModels()
|
||||
{
|
||||
foreach (var model in DefaultModels)
|
||||
foreach (var model in TemplateModels)
|
||||
{
|
||||
model.InitTemplateZones();
|
||||
}
|
||||
@@ -239,7 +241,7 @@ namespace FancyZonesEditor
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (LayoutModel model in DefaultModels)
|
||||
foreach (LayoutModel model in TemplateModels)
|
||||
{
|
||||
if (model.Type == currentApplied.Type)
|
||||
{
|
||||
@@ -261,7 +263,7 @@ namespace FancyZonesEditor
|
||||
|
||||
if (foundModel == null)
|
||||
{
|
||||
foundModel = DefaultModels[(int)LayoutType.PriorityGrid];
|
||||
foundModel = TemplateModels[(int)LayoutType.PriorityGrid];
|
||||
}
|
||||
|
||||
SetSelectedModel(foundModel);
|
||||
@@ -321,9 +323,9 @@ namespace FancyZonesEditor
|
||||
AppliedModel = model;
|
||||
}
|
||||
|
||||
public void UpdateDefaultModels()
|
||||
public void UpdateTemplateModels()
|
||||
{
|
||||
foreach (LayoutModel model in DefaultModels)
|
||||
foreach (LayoutModel model in TemplateModels)
|
||||
{
|
||||
if (App.Overlay.CurrentLayoutSettings.Type == model.Type && App.Overlay.CurrentLayoutSettings.ZoneCount != model.TemplateZoneCount)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// 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.
|
||||
|
||||
namespace FancyZonesEditor.Models
|
||||
{
|
||||
public enum MonitorConfigurationType
|
||||
{
|
||||
Horizontal = 0,
|
||||
Vertical,
|
||||
}
|
||||
}
|
||||
@@ -107,7 +107,7 @@ namespace FancyZonesEditor
|
||||
if (settings != null)
|
||||
{
|
||||
settings.SetAppliedModel(null);
|
||||
settings.UpdateDefaultModels();
|
||||
settings.UpdateTemplateModels();
|
||||
}
|
||||
|
||||
Update();
|
||||
|
||||
@@ -222,6 +222,24 @@ namespace FancyZonesEditor.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Default layout for horizontal monitor orientation.
|
||||
/// </summary>
|
||||
public static string Default_Layout_Horizontal {
|
||||
get {
|
||||
return ResourceManager.GetString("Default_Layout_Horizontal", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Default layout for vertical monitor orientation.
|
||||
/// </summary>
|
||||
public static string Default_Layout_Vertical {
|
||||
get {
|
||||
return ResourceManager.GetString("Default_Layout_Vertical", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Delete.
|
||||
/// </summary>
|
||||
@@ -451,6 +469,15 @@ namespace FancyZonesEditor.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to An error occurred while parsing default layouts..
|
||||
/// </summary>
|
||||
public static string Error_Parsing_Default_Layouts_Message {
|
||||
get {
|
||||
return ResourceManager.GetString("Error_Parsing_Default_Layouts_Message", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Error parsing device info data..
|
||||
/// </summary>
|
||||
@@ -762,6 +789,24 @@ namespace FancyZonesEditor.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Set layout as a default for horizontal monitor orientation.
|
||||
/// </summary>
|
||||
public static string Set_Layout_As_Horizontal_Default {
|
||||
get {
|
||||
return ResourceManager.GetString("Set_Layout_As_Horizontal_Default", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Set layout as a default for vertical monitor orientation.
|
||||
/// </summary>
|
||||
public static string Set_Layout_As_Vertical_Default {
|
||||
get {
|
||||
return ResourceManager.GetString("Set_Layout_As_Vertical_Default", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Template settings.
|
||||
/// </summary>
|
||||
|
||||
@@ -414,4 +414,19 @@
|
||||
<data name="Slider_Value" xml:space="preserve">
|
||||
<value>{0} pixels</value>
|
||||
</data>
|
||||
<data name="Default_Layout_Horizontal" xml:space="preserve">
|
||||
<value>Default layout for horizontal monitor orientation</value>
|
||||
</data>
|
||||
<data name="Set_Layout_As_Horizontal_Default" xml:space="preserve">
|
||||
<value>Set layout as a default for horizontal monitor orientation</value>
|
||||
</data>
|
||||
<data name="Error_Parsing_Default_Layouts_Message" xml:space="preserve">
|
||||
<value>An error occurred while parsing default layouts.</value>
|
||||
</data>
|
||||
<data name="Default_Layout_Vertical" xml:space="preserve">
|
||||
<value>Default layout for vertical monitor orientation</value>
|
||||
</data>
|
||||
<data name="Set_Layout_As_Vertical_Default" xml:space="preserve">
|
||||
<value>Set layout as a default for vertical monitor orientation</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -27,12 +27,15 @@ namespace FancyZonesEditor.Utils
|
||||
private const string GridJsonTag = "grid";
|
||||
private const string PriorityGridJsonTag = "priority-grid";
|
||||
private const string CustomJsonTag = "custom";
|
||||
private const string HorizontalJsonTag = "horizontal";
|
||||
private const string VerticalJsonTag = "vertical";
|
||||
|
||||
// Non-localizable strings: Files
|
||||
private const string AppliedLayoutsFile = "\\Microsoft\\PowerToys\\FancyZones\\applied-layouts.json";
|
||||
private const string LayoutHotkeysFile = "\\Microsoft\\PowerToys\\FancyZones\\layout-hotkeys.json";
|
||||
private const string LayoutTemplatesFile = "\\Microsoft\\PowerToys\\FancyZones\\layout-templates.json";
|
||||
private const string CustomLayoutsFile = "\\Microsoft\\PowerToys\\FancyZones\\custom-layouts.json";
|
||||
private const string DefaultLayoutsFile = "\\Microsoft\\PowerToys\\FancyZones\\default-layouts.json";
|
||||
private const string ParamsFile = "\\Microsoft\\PowerToys\\FancyZones\\editor-parameters.json";
|
||||
|
||||
// Non-localizable string: default virtual desktop id
|
||||
@@ -56,6 +59,8 @@ namespace FancyZonesEditor.Utils
|
||||
|
||||
public string FancyZonesCustomLayoutsFile { get; private set; }
|
||||
|
||||
public string FancyZonesDefaultLayoutsFile { get; private set; }
|
||||
|
||||
public string FancyZonesEditorParamsFile { get; private set; }
|
||||
|
||||
private enum CmdArgs
|
||||
@@ -264,6 +269,35 @@ namespace FancyZonesEditor.Utils
|
||||
public List<LayoutHotkeyWrapper> LayoutHotkeys { get; set; }
|
||||
}
|
||||
|
||||
// default-layouts.json
|
||||
private struct DefaultLayoutWrapper
|
||||
{
|
||||
public struct LayoutWrapper
|
||||
{
|
||||
public string Uuid { get; set; }
|
||||
|
||||
public string Type { get; set; }
|
||||
|
||||
public bool ShowSpacing { get; set; }
|
||||
|
||||
public int Spacing { get; set; }
|
||||
|
||||
public int ZoneCount { get; set; }
|
||||
|
||||
public int SensitivityRadius { get; set; }
|
||||
}
|
||||
|
||||
public string MonitorConfiguration { get; set; }
|
||||
|
||||
public LayoutWrapper Layout { get; set; }
|
||||
}
|
||||
|
||||
// default-layouts.json
|
||||
private struct DefaultLayoutsListWrapper
|
||||
{
|
||||
public List<DefaultLayoutWrapper> DefaultLayouts { get; set; }
|
||||
}
|
||||
|
||||
private struct EditorParams
|
||||
{
|
||||
public int ProcessId { get; set; }
|
||||
@@ -296,6 +330,7 @@ namespace FancyZonesEditor.Utils
|
||||
FancyZonesLayoutHotkeysFile = localAppDataDir + LayoutHotkeysFile;
|
||||
FancyZonesLayoutTemplatesFile = localAppDataDir + LayoutTemplatesFile;
|
||||
FancyZonesCustomLayoutsFile = localAppDataDir + CustomLayoutsFile;
|
||||
FancyZonesDefaultLayoutsFile = localAppDataDir + DefaultLayoutsFile;
|
||||
FancyZonesEditorParamsFile = localAppDataDir + ParamsFile;
|
||||
}
|
||||
|
||||
@@ -558,6 +593,46 @@ namespace FancyZonesEditor.Utils
|
||||
return new ParsingResult(true);
|
||||
}
|
||||
|
||||
public ParsingResult ParseDefaultLayouts()
|
||||
{
|
||||
Logger.LogTrace();
|
||||
|
||||
if (_fileSystem.File.Exists(FancyZonesDefaultLayoutsFile))
|
||||
{
|
||||
DefaultLayoutsListWrapper wrapper;
|
||||
string dataString = string.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
dataString = ReadFile(FancyZonesDefaultLayoutsFile);
|
||||
wrapper = JsonSerializer.Deserialize<DefaultLayoutsListWrapper>(dataString, _options);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError("Default layouts parsing error", ex);
|
||||
return new ParsingResult(false, ex.Message, dataString);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
bool parsingResult = SetDefaultLayouts(wrapper.DefaultLayouts);
|
||||
if (parsingResult)
|
||||
{
|
||||
return new ParsingResult(true);
|
||||
}
|
||||
|
||||
return new ParsingResult(false, FancyZonesEditor.Properties.Resources.Error_Parsing_Default_Layouts_Message, dataString);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError("Default layouts parsing error", ex);
|
||||
return new ParsingResult(false, ex.Message, dataString);
|
||||
}
|
||||
}
|
||||
|
||||
return new ParsingResult(true);
|
||||
}
|
||||
|
||||
public void SerializeAppliedLayouts()
|
||||
{
|
||||
Logger.LogTrace();
|
||||
@@ -658,7 +733,7 @@ namespace FancyZonesEditor.Utils
|
||||
TemplateLayoutsListWrapper templates = new TemplateLayoutsListWrapper { };
|
||||
templates.LayoutTemplates = new List<TemplateLayoutWrapper>();
|
||||
|
||||
foreach (LayoutModel layout in MainWindowSettingsModel.DefaultModels)
|
||||
foreach (LayoutModel layout in MainWindowSettingsModel.TemplateModels)
|
||||
{
|
||||
TemplateLayoutWrapper wrapper = new TemplateLayoutWrapper
|
||||
{
|
||||
@@ -790,6 +865,107 @@ namespace FancyZonesEditor.Utils
|
||||
}
|
||||
}
|
||||
|
||||
public void SerializeDefaultLayouts()
|
||||
{
|
||||
DefaultLayoutsListWrapper layouts = new DefaultLayoutsListWrapper { };
|
||||
layouts.DefaultLayouts = new List<DefaultLayoutWrapper>();
|
||||
|
||||
foreach (LayoutModel layout in MainWindowSettingsModel.TemplateModels)
|
||||
{
|
||||
if (layout.IsHorizontalDefault || layout.IsVerticalDefault)
|
||||
{
|
||||
DefaultLayoutWrapper.LayoutWrapper layoutWrapper = new DefaultLayoutWrapper.LayoutWrapper
|
||||
{
|
||||
Uuid = string.Empty,
|
||||
Type = LayoutTypeToJsonTag(layout.Type),
|
||||
SensitivityRadius = layout.SensitivityRadius,
|
||||
ZoneCount = layout.TemplateZoneCount,
|
||||
};
|
||||
|
||||
if (layout is GridLayoutModel grid)
|
||||
{
|
||||
layoutWrapper.ShowSpacing = grid.ShowSpacing;
|
||||
layoutWrapper.Spacing = grid.Spacing;
|
||||
}
|
||||
|
||||
// can be both horizontal and vertical, so check separately
|
||||
if (layout.IsHorizontalDefault)
|
||||
{
|
||||
DefaultLayoutWrapper wrapper = new DefaultLayoutWrapper
|
||||
{
|
||||
MonitorConfiguration = MonitorConfigurationTypeToJsonTag(MonitorConfigurationType.Horizontal),
|
||||
Layout = layoutWrapper,
|
||||
};
|
||||
|
||||
layouts.DefaultLayouts.Add(wrapper);
|
||||
}
|
||||
|
||||
if (layout.IsVerticalDefault)
|
||||
{
|
||||
DefaultLayoutWrapper wrapper = new DefaultLayoutWrapper
|
||||
{
|
||||
MonitorConfiguration = MonitorConfigurationTypeToJsonTag(MonitorConfigurationType.Vertical),
|
||||
Layout = layoutWrapper,
|
||||
};
|
||||
|
||||
layouts.DefaultLayouts.Add(wrapper);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (LayoutModel layout in MainWindowSettingsModel.CustomModels)
|
||||
{
|
||||
if (layout.IsHorizontalDefault || layout.IsVerticalDefault)
|
||||
{
|
||||
DefaultLayoutWrapper.LayoutWrapper layoutWrapper = new DefaultLayoutWrapper.LayoutWrapper
|
||||
{
|
||||
Uuid = layout.Uuid,
|
||||
Type = LayoutTypeToJsonTag(LayoutType.Custom),
|
||||
};
|
||||
|
||||
if (layout is GridLayoutModel grid)
|
||||
{
|
||||
layoutWrapper.ShowSpacing = grid.ShowSpacing;
|
||||
layoutWrapper.Spacing = grid.Spacing;
|
||||
}
|
||||
|
||||
// can be both horizontal and vertical, so check separately
|
||||
if (layout.IsHorizontalDefault)
|
||||
{
|
||||
DefaultLayoutWrapper wrapper = new DefaultLayoutWrapper
|
||||
{
|
||||
MonitorConfiguration = MonitorConfigurationTypeToJsonTag(MonitorConfigurationType.Horizontal),
|
||||
Layout = layoutWrapper,
|
||||
};
|
||||
|
||||
layouts.DefaultLayouts.Add(wrapper);
|
||||
}
|
||||
|
||||
if (layout.IsVerticalDefault)
|
||||
{
|
||||
DefaultLayoutWrapper wrapper = new DefaultLayoutWrapper
|
||||
{
|
||||
MonitorConfiguration = MonitorConfigurationTypeToJsonTag(MonitorConfigurationType.Vertical),
|
||||
Layout = layoutWrapper,
|
||||
};
|
||||
|
||||
layouts.DefaultLayouts.Add(wrapper);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
string jsonString = JsonSerializer.Serialize(layouts, _options);
|
||||
_fileSystem.File.WriteAllText(FancyZonesDefaultLayoutsFile, jsonString);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError("Serialize default layout error", ex);
|
||||
App.ShowExceptionMessageBox(Properties.Resources.Error_Applying_Layout, ex);
|
||||
}
|
||||
}
|
||||
|
||||
private string ReadFile(string fileName)
|
||||
{
|
||||
Logger.LogTrace();
|
||||
@@ -942,7 +1118,7 @@ namespace FancyZonesEditor.Utils
|
||||
foreach (var wrapper in templateLayouts)
|
||||
{
|
||||
LayoutType type = JsonTagToLayoutType(wrapper.Type);
|
||||
LayoutModel layout = MainWindowSettingsModel.DefaultModels[(int)type];
|
||||
LayoutModel layout = MainWindowSettingsModel.TemplateModels[(int)type];
|
||||
|
||||
layout.SensitivityRadius = wrapper.SensitivityRadius;
|
||||
layout.TemplateZoneCount = wrapper.ZoneCount;
|
||||
@@ -972,6 +1148,41 @@ namespace FancyZonesEditor.Utils
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool SetDefaultLayouts(List<DefaultLayoutWrapper> layouts)
|
||||
{
|
||||
Logger.LogTrace();
|
||||
|
||||
if (layouts == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var layout in layouts)
|
||||
{
|
||||
if (layout.Layout.Uuid != null && layout.Layout.Uuid != string.Empty)
|
||||
{
|
||||
MonitorConfigurationType type = JsonTagToMonitorConfigurationType(layout.MonitorConfiguration);
|
||||
|
||||
foreach (var customLayout in MainWindowSettingsModel.CustomModels)
|
||||
{
|
||||
if (customLayout.Uuid == layout.Layout.Uuid)
|
||||
{
|
||||
MainWindowSettingsModel.DefaultLayouts.Set(customLayout, type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LayoutType layoutType = JsonTagToLayoutType(layout.Layout.Type);
|
||||
MonitorConfigurationType type = JsonTagToMonitorConfigurationType(layout.MonitorConfiguration);
|
||||
MainWindowSettingsModel.DefaultLayouts.Set(MainWindowSettingsModel.TemplateModels[(int)layoutType], type);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private CanvasLayoutModel ParseCanvasInfo(CustomLayoutWrapper wrapper)
|
||||
{
|
||||
var info = JsonSerializer.Deserialize<CanvasInfoWrapper>(wrapper.Info.GetRawText(), _options);
|
||||
@@ -1089,5 +1300,31 @@ namespace FancyZonesEditor.Utils
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
private MonitorConfigurationType JsonTagToMonitorConfigurationType(string tag)
|
||||
{
|
||||
switch (tag)
|
||||
{
|
||||
case HorizontalJsonTag:
|
||||
return MonitorConfigurationType.Horizontal;
|
||||
case VerticalJsonTag:
|
||||
return MonitorConfigurationType.Vertical;
|
||||
}
|
||||
|
||||
return MonitorConfigurationType.Horizontal;
|
||||
}
|
||||
|
||||
private string MonitorConfigurationTypeToJsonTag(MonitorConfigurationType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case MonitorConfigurationType.Horizontal:
|
||||
return HorizontalJsonTag;
|
||||
case MonitorConfigurationType.Vertical:
|
||||
return VerticalJsonTag;
|
||||
}
|
||||
|
||||
return HorizontalJsonTag;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user