mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
[FancyZones] Clasify strings in FancyZones to localizable and non-localizable (#5315)
* Clasify strings in FancyZones to localizable and non-localizable * Address PR comments * Better handling of FirePropertyChanged event * Address PR comments * Update properties
This commit is contained in:
@@ -13,6 +13,9 @@ namespace FancyZonesEditor
|
||||
/// </summary>
|
||||
public partial class CanvasEditor : UserControl
|
||||
{
|
||||
// Non-localizable strings
|
||||
private const string PropertyUpdateLayoutID = "UpdateLayout";
|
||||
|
||||
private CanvasLayoutModel _model;
|
||||
|
||||
public CanvasEditor()
|
||||
@@ -35,7 +38,7 @@ namespace FancyZonesEditor
|
||||
|
||||
private void OnModelChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == "Zones")
|
||||
if (e.PropertyName == PropertyUpdateLayoutID)
|
||||
{
|
||||
UpdateZoneRects();
|
||||
}
|
||||
|
||||
@@ -16,7 +16,12 @@ namespace FancyZonesEditor
|
||||
/// </summary>
|
||||
public partial class GridEditor : UserControl
|
||||
{
|
||||
public static readonly DependencyProperty ModelProperty = DependencyProperty.Register("Model", typeof(GridLayoutModel), typeof(GridEditor), new PropertyMetadata(null, OnGridDimensionsChanged));
|
||||
// Non-localizable strings
|
||||
private const string PropertyRowsChangedID = "Rows";
|
||||
private const string PropertyColumnsChangedID = "Columns";
|
||||
private const string ObjectDependencyID = "Model";
|
||||
|
||||
public static readonly DependencyProperty ModelProperty = DependencyProperty.Register(ObjectDependencyID, typeof(GridLayoutModel), typeof(GridEditor), new PropertyMetadata(null, OnGridDimensionsChanged));
|
||||
|
||||
private static int gridEditorUniqueIdCounter = 0;
|
||||
|
||||
@@ -336,7 +341,7 @@ namespace FancyZonesEditor
|
||||
private void OnGridDimensionsChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
// Only enter if this is the newest instance
|
||||
if (((e.PropertyName == "Rows") || (e.PropertyName == "Columns")) && gridEditorUniqueId == gridEditorUniqueIdCounter)
|
||||
if (((e.PropertyName == PropertyRowsChangedID) || (e.PropertyName == PropertyColumnsChangedID)) && gridEditorUniqueId == gridEditorUniqueIdCounter)
|
||||
{
|
||||
OnGridDimensionsChanged();
|
||||
}
|
||||
|
||||
@@ -17,7 +17,12 @@ namespace FancyZonesEditor
|
||||
/// </summary>
|
||||
public partial class GridZone : UserControl
|
||||
{
|
||||
public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(GridZone), new PropertyMetadata(false, OnSelectionChanged));
|
||||
// Non-localizable strings
|
||||
private const string ObjectDependencyID = "IsSelected";
|
||||
private const string GridZoneBackgroundBrushID = "GridZoneBackgroundBrush";
|
||||
private const string PropertyIsShiftKeyPressedID = "IsShiftKeyPressed";
|
||||
|
||||
public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register(ObjectDependencyID, typeof(bool), typeof(GridZone), new PropertyMetadata(false, OnSelectionChanged));
|
||||
|
||||
public event SplitEventHandler Split;
|
||||
|
||||
@@ -45,7 +50,7 @@ namespace FancyZonesEditor
|
||||
|
||||
private void OnSelectionChanged()
|
||||
{
|
||||
Background = IsSelected ? SystemParameters.WindowGlassBrush : App.Current.Resources["GridZoneBackgroundBrush"] as SolidColorBrush;
|
||||
Background = IsSelected ? SystemParameters.WindowGlassBrush : App.Current.Resources[GridZoneBackgroundBrushID] as SolidColorBrush;
|
||||
}
|
||||
|
||||
public bool IsSelected
|
||||
@@ -69,7 +74,7 @@ namespace FancyZonesEditor
|
||||
|
||||
private void ZoneSettings_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == "IsShiftKeyPressed")
|
||||
if (e.PropertyName == PropertyIsShiftKeyPressedID)
|
||||
{
|
||||
_switchOrientation = ((App)Application.Current).ZoneSettings.IsShiftKeyPressed;
|
||||
if (_lastPos.X != -1)
|
||||
|
||||
@@ -17,7 +17,13 @@ namespace FancyZonesEditor
|
||||
/// </summary>
|
||||
public partial class LayoutPreview : UserControl
|
||||
{
|
||||
public static readonly DependencyProperty IsActualSizeProperty = DependencyProperty.Register("IsActualSize", typeof(bool), typeof(LayoutPreview), new PropertyMetadata(false));
|
||||
// Non-localizable strings
|
||||
private const string PropertyZoneCountID = "ZoneCount";
|
||||
private const string PropertyShowSpacingID = "ShowSpacing";
|
||||
private const string PropertySpacingID = "Spacing";
|
||||
private const string ObjectDependencyID = "IsActualSize";
|
||||
|
||||
public static readonly DependencyProperty IsActualSizeProperty = DependencyProperty.Register(ObjectDependencyID, typeof(bool), typeof(LayoutPreview), new PropertyMetadata(false));
|
||||
|
||||
private LayoutModel _model;
|
||||
private List<Int32Rect> _zones = new List<Int32Rect>();
|
||||
@@ -43,11 +49,11 @@ namespace FancyZonesEditor
|
||||
|
||||
private void ZoneSettings_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == "ZoneCount")
|
||||
if (e.PropertyName == PropertyZoneCountID)
|
||||
{
|
||||
RenderPreview();
|
||||
}
|
||||
else if ((e.PropertyName == "ShowSpacing") || (e.PropertyName == "Spacing"))
|
||||
else if ((e.PropertyName == PropertyShowSpacingID) || (e.PropertyName == PropertySpacingID))
|
||||
{
|
||||
if (_model is GridLayoutModel)
|
||||
{
|
||||
|
||||
@@ -20,6 +20,8 @@ namespace FancyZonesEditor
|
||||
// TODO: share the constants b/w C# Editor and FancyZoneLib
|
||||
public const int MaxZones = 40;
|
||||
private readonly Settings _settings = ((App)Application.Current).ZoneSettings;
|
||||
|
||||
// Localizable string
|
||||
private static readonly string _defaultNamePrefix = "Custom Layout ";
|
||||
|
||||
public int WrapPanelItemSize { get; set; } = 262;
|
||||
|
||||
@@ -14,6 +14,12 @@ namespace FancyZonesEditor.Models
|
||||
// Free form Layout Model, which specifies independent zone rects
|
||||
public class CanvasLayoutModel : LayoutModel
|
||||
{
|
||||
// Localizable strings
|
||||
private const string ErrorPersistingCanvasLayout = "Error persisting canvas layout";
|
||||
|
||||
// Non-localizable strings
|
||||
private const string ModelTypeID = "canvas";
|
||||
|
||||
public CanvasLayoutModel(string uuid, string name, LayoutType type, IList<Int32Rect> zones, int workAreaWidth, int workAreaHeight)
|
||||
: base(uuid, name, type)
|
||||
{
|
||||
@@ -56,7 +62,7 @@ namespace FancyZonesEditor.Models
|
||||
public void RemoveZoneAt(int index)
|
||||
{
|
||||
Zones.RemoveAt(index);
|
||||
FirePropertyChanged("Zones");
|
||||
UpdateLayout();
|
||||
}
|
||||
|
||||
// AddZone
|
||||
@@ -64,7 +70,12 @@ namespace FancyZonesEditor.Models
|
||||
public void AddZone(Int32Rect zone)
|
||||
{
|
||||
Zones.Add(zone);
|
||||
FirePropertyChanged("Zones");
|
||||
UpdateLayout();
|
||||
}
|
||||
|
||||
private void UpdateLayout()
|
||||
{
|
||||
FirePropertyChanged();
|
||||
}
|
||||
|
||||
// Clone
|
||||
@@ -178,7 +189,7 @@ namespace FancyZonesEditor.Models
|
||||
{
|
||||
Uuid = "{" + Guid.ToString().ToUpper() + "}",
|
||||
Name = Name,
|
||||
Type = "canvas",
|
||||
Type = ModelTypeID,
|
||||
Info = layoutInfo,
|
||||
};
|
||||
|
||||
@@ -194,7 +205,7 @@ namespace FancyZonesEditor.Models
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ShowExceptionMessageBox("Error persisting canvas layout", ex);
|
||||
ShowExceptionMessageBox(ErrorPersistingCanvasLayout, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,12 @@ namespace FancyZonesEditor.Models
|
||||
// Grid-styled Layout Model, which specifies rows, columns, percentage sizes, and row/column spans
|
||||
public class GridLayoutModel : LayoutModel
|
||||
{
|
||||
// Localizable strings
|
||||
private const string ErrorPersistingGridLayout = "Error persisting grid layout";
|
||||
|
||||
// Non-localizable strings
|
||||
private const string ModelTypeID = "grid";
|
||||
|
||||
// Rows - number of rows in the Grid
|
||||
public int Rows
|
||||
{
|
||||
@@ -220,7 +226,7 @@ namespace FancyZonesEditor.Models
|
||||
{
|
||||
Uuid = "{" + Guid.ToString().ToUpper() + "}",
|
||||
Name = Name,
|
||||
Type = "grid",
|
||||
Type = ModelTypeID,
|
||||
Info = layoutInfo,
|
||||
};
|
||||
JsonSerializerOptions options = new JsonSerializerOptions
|
||||
@@ -235,7 +241,7 @@ namespace FancyZonesEditor.Models
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ShowExceptionMessageBox("Error persisting grid layout", ex);
|
||||
ShowExceptionMessageBox(ErrorPersistingGridLayout, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,9 +61,11 @@ namespace FancyZonesEditor.Models
|
||||
private const string PriorityGridJsonTag = "priority-grid";
|
||||
private const string CustomJsonTag = "custom";
|
||||
|
||||
private const string PowerToysIssuesLink = "https://aka.ms/powerToysReportBug";
|
||||
|
||||
public static void ShowExceptionMessageBox(string message, Exception exception = null)
|
||||
{
|
||||
string fullMessage = ErrorMessageBoxMessage + "https://aka.ms/powerToysReportBug \n" + message;
|
||||
string fullMessage = ErrorMessageBoxMessage + PowerToysIssuesLink + " \n" + message;
|
||||
if (exception != null)
|
||||
{
|
||||
fullMessage += ": " + exception.Message;
|
||||
|
||||
@@ -60,9 +60,19 @@ namespace FancyZonesEditor
|
||||
private const string ErrorInvalidArgs = "FancyZones Editor arguments are invalid.";
|
||||
private const string ErrorNonStandaloneApp = "FancyZones Editor should not be run as standalone application.";
|
||||
|
||||
// Non-localizable strings
|
||||
private const string ZonesSettingsFile = "\\Microsoft\\PowerToys\\FancyZones\\zones-settings.json";
|
||||
// Displayed layout names are localizable strings, but their underlying json tags are not.
|
||||
private const string FocusLayoutID = "Focus";
|
||||
private const string ColumnsLayoutID = "Columns";
|
||||
private const string RowsLayoutID = "Rows";
|
||||
private const string GridLayoutID = "Grid";
|
||||
private const string PriorityGridLayoutID = "Priority Grid";
|
||||
private const string CreateNewCustomLabel = "Create new custom";
|
||||
|
||||
// Non-localizable strings
|
||||
public static readonly string RegistryPath = "SOFTWARE\\SuperFancyZones";
|
||||
public static readonly string FullRegistryPath = "HKEY_CURRENT_USER\\" + RegistryPath;
|
||||
|
||||
private const string ZonesSettingsFile = "\\Microsoft\\PowerToys\\FancyZones\\zones-settings.json";
|
||||
private const string ActiveZoneSetsTmpFileName = "FancyZonesActiveZoneSets.json";
|
||||
private const string AppliedZoneSetsTmpFileName = "FancyZonesAppliedZoneSets.json";
|
||||
private const string DeletedCustomZoneSetsTmpFileName = "FancyZonesDeletedCustomZoneSets.json";
|
||||
@@ -79,6 +89,15 @@ namespace FancyZonesEditor
|
||||
private const string EditorSpacingJsonTag = "editor-spacing";
|
||||
private const string EditorZoneCountJsonTag = "editor-zone-count";
|
||||
|
||||
private const string FocusJsonTag = "focus";
|
||||
private const string ColumnsJsonTag = "columns";
|
||||
private const string RowsJsonTag = "rows";
|
||||
private const string GridJsonTag = "grid";
|
||||
private const string PriorityGridJsonTag = "priority-grid";
|
||||
private const string CustomJsonTag = "custom";
|
||||
|
||||
private const string DebugMode = "Debug";
|
||||
|
||||
// hard coded data for all the "Priority Grid" configurations that are unique to "Grid"
|
||||
private static readonly byte[][] _priorityData = new byte[][]
|
||||
{
|
||||
@@ -128,30 +147,30 @@ namespace FancyZonesEditor
|
||||
|
||||
// Initialize the five default layout models: Focus, Columns, Rows, Grid, and PriorityGrid
|
||||
DefaultModels = new List<LayoutModel>(5);
|
||||
_focusModel = new CanvasLayoutModel("Focus", LayoutType.Focus);
|
||||
_focusModel = new CanvasLayoutModel(FocusLayoutID, LayoutType.Focus);
|
||||
DefaultModels.Add(_focusModel);
|
||||
|
||||
_columnsModel = new GridLayoutModel("Columns", LayoutType.Columns)
|
||||
_columnsModel = new GridLayoutModel(ColumnsLayoutID, LayoutType.Columns)
|
||||
{
|
||||
Rows = 1,
|
||||
RowPercents = new List<int>(1) { _multiplier },
|
||||
};
|
||||
DefaultModels.Add(_columnsModel);
|
||||
|
||||
_rowsModel = new GridLayoutModel("Rows", LayoutType.Rows)
|
||||
_rowsModel = new GridLayoutModel(RowsLayoutID, LayoutType.Rows)
|
||||
{
|
||||
Columns = 1,
|
||||
ColumnPercents = new List<int>(1) { _multiplier },
|
||||
};
|
||||
DefaultModels.Add(_rowsModel);
|
||||
|
||||
_gridModel = new GridLayoutModel("Grid", LayoutType.Grid);
|
||||
_gridModel = new GridLayoutModel(GridLayoutID, LayoutType.Grid);
|
||||
DefaultModels.Add(_gridModel);
|
||||
|
||||
_priorityGridModel = new GridLayoutModel("Priority Grid", LayoutType.PriorityGrid);
|
||||
_priorityGridModel = new GridLayoutModel(PriorityGridLayoutID, LayoutType.PriorityGrid);
|
||||
DefaultModels.Add(_priorityGridModel);
|
||||
|
||||
_blankCustomModel = new CanvasLayoutModel("Create new custom", LayoutType.Blank);
|
||||
_blankCustomModel = new CanvasLayoutModel(CreateNewCustomLabel, LayoutType.Blank);
|
||||
|
||||
UpdateLayoutModels();
|
||||
}
|
||||
@@ -421,22 +440,22 @@ namespace FancyZonesEditor
|
||||
{
|
||||
switch (layoutType)
|
||||
{
|
||||
case "focus":
|
||||
case FocusJsonTag:
|
||||
ActiveZoneSetLayoutType = LayoutType.Focus;
|
||||
break;
|
||||
case "columns":
|
||||
case ColumnsJsonTag:
|
||||
ActiveZoneSetLayoutType = LayoutType.Columns;
|
||||
break;
|
||||
case "rows":
|
||||
case RowsJsonTag:
|
||||
ActiveZoneSetLayoutType = LayoutType.Rows;
|
||||
break;
|
||||
case "grid":
|
||||
case GridJsonTag:
|
||||
ActiveZoneSetLayoutType = LayoutType.Grid;
|
||||
break;
|
||||
case "priority-grid":
|
||||
case PriorityGridJsonTag:
|
||||
ActiveZoneSetLayoutType = LayoutType.PriorityGrid;
|
||||
break;
|
||||
case "custom":
|
||||
case CustomJsonTag:
|
||||
ActiveZoneSetLayoutType = LayoutType.Custom;
|
||||
break;
|
||||
}
|
||||
@@ -461,7 +480,7 @@ namespace FancyZonesEditor
|
||||
|
||||
if (args.Length == 2)
|
||||
{
|
||||
if (args[1].Equals("Debug"))
|
||||
if (args[1].Equals(DebugMode))
|
||||
{
|
||||
ParseDeviceInfoData(ParseDeviceMode.Debug);
|
||||
}
|
||||
@@ -529,9 +548,6 @@ namespace FancyZonesEditor
|
||||
|
||||
private static ObservableCollection<LayoutModel> _customModels;
|
||||
|
||||
public static readonly string RegistryPath = "SOFTWARE\\SuperFancyZones";
|
||||
public static readonly string FullRegistryPath = "HKEY_CURRENT_USER\\" + RegistryPath;
|
||||
|
||||
public static bool IsPredefinedLayout(LayoutModel model)
|
||||
{
|
||||
return model.Type != LayoutType.Custom;
|
||||
|
||||
Reference in New Issue
Block a user