mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 03:36:44 +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:
@@ -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