Skip to content

Commit

Permalink
[FancyZones] Clasify strings in FancyZones to localizable and non-loc…
Browse files Browse the repository at this point in the history
…alizable (#5315)

* Clasify strings in FancyZones to localizable and non-localizable

* Address PR comments

* Better handling of FirePropertyChanged event

* Address PR comments

* Update properties
  • Loading branch information
vldmr11080 committed Aug 11, 2020
1 parent b8b6dbe commit 145347f
Show file tree
Hide file tree
Showing 22 changed files with 361 additions and 189 deletions.
10 changes: 8 additions & 2 deletions src/modules/fancyzones/dll/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ class FancyZonesModule : public PowertoyModuleIface
s_llKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, GetModuleHandle(NULL), NULL);
if (!s_llKeyboardHook)
{
MessageBoxW(NULL, L"Cannot install keyboard listener.", L"PowerToys - FancyZones", MB_OK | MB_ICONERROR);
MessageBoxW(NULL,
GET_RESOURCE_STRING(IDS_KEYBOARD_LISTENER_ERROR).c_str(),
GET_RESOURCE_STRING(IDS_POWERTOYS_FANCYZONES).c_str(),
MB_OK | MB_ICONERROR);
}
}

Expand All @@ -103,7 +106,10 @@ class FancyZonesModule : public PowertoyModuleIface
}
else
{
MessageBoxW(NULL, L"Cannot install Windows event listener.", L"PowerToys - FancyZones", MB_OK | MB_ICONERROR);
MessageBoxW(NULL,
GET_RESOURCE_STRING(IDS_WINDOW_EVENT_LISTENER_ERROR).c_str(),
GET_RESOURCE_STRING(IDS_POWERTOYS_FANCYZONES).c_str(),
MB_OK | MB_ICONERROR);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -35,7 +38,7 @@ private void OnLoaded(object sender, RoutedEventArgs e)

private void OnModelChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "Zones")
if (e.PropertyName == PropertyUpdateLayoutID)
{
UpdateZoneRects();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -336,7 +341,7 @@ private int AddZone()
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();
}
Expand Down
11 changes: 8 additions & 3 deletions src/modules/fancyzones/editor/FancyZonesEditor/GridZone.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -45,7 +50,7 @@ private static void OnSelectionChanged(DependencyObject d, DependencyPropertyCha

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
Expand All @@ -69,7 +74,7 @@ public GridZone()

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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
Expand All @@ -43,11 +49,11 @@ public bool IsActualSize

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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public partial class MainWindow : MetroWindow
// 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -56,15 +62,20 @@ public CanvasLayoutModel(string name)
public void RemoveZoneAt(int index)
{
Zones.RemoveAt(index);
FirePropertyChanged("Zones");
UpdateLayout();
}

// AddZone
// Adds the specified Zone to the end of the Zones list, and fires a property changed notification for the Zones property
public void AddZone(Int32Rect zone)
{
Zones.Add(zone);
FirePropertyChanged("Zones");
UpdateLayout();
}

private void UpdateLayout()
{
FirePropertyChanged();
}

// Clone
Expand Down Expand Up @@ -178,7 +189,7 @@ protected override void PersistData()
{
Uuid = "{" + Guid.ToString().ToUpper() + "}",
Name = Name,
Type = "canvas",
Type = ModelTypeID,
Info = layoutInfo,
};

Expand All @@ -194,7 +205,7 @@ protected override void PersistData()
}
catch (Exception ex)
{
ShowExceptionMessageBox("Error persisting canvas layout", ex);
ShowExceptionMessageBox(ErrorPersistingCanvasLayout, ex);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -220,7 +226,7 @@ protected override void PersistData()
{
Uuid = "{" + Guid.ToString().ToUpper() + "}",
Name = Name,
Type = "grid",
Type = ModelTypeID,
Info = layoutInfo,
};
JsonSerializerOptions options = new JsonSerializerOptions
Expand All @@ -235,7 +241,7 @@ protected override void PersistData()
}
catch (Exception ex)
{
ShowExceptionMessageBox("Error persisting grid layout", ex);
ShowExceptionMessageBox(ErrorPersistingGridLayout, ex);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ public abstract class LayoutModel : INotifyPropertyChanged
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;
Expand Down
50 changes: 33 additions & 17 deletions src/modules/fancyzones/editor/FancyZonesEditor/Models/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,19 @@ private enum ParseDeviceMode
private const string ErrorInvalidArgs = "FancyZones Editor arguments are invalid.";
private const string ErrorNonStandaloneApp = "FancyZones Editor should not be run as standalone application.";

// 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
private const string ZonesSettingsFile = "\\Microsoft\\PowerToys\\FancyZones\\zones-settings.json";
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";
Expand All @@ -79,6 +89,15 @@ private enum ParseDeviceMode
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[][]
{
Expand Down Expand Up @@ -128,30 +147,30 @@ public Settings()

// 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();
}
Expand Down Expand Up @@ -421,22 +440,22 @@ private void ParseDeviceInfoData(ParseDeviceMode mode = ParseDeviceMode.Prod)
{
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;
}
Expand All @@ -461,7 +480,7 @@ private void ParseCommandLineArgs()

if (args.Length == 2)
{
if (args[1].Equals("Debug"))
if (args[1].Equals(DebugMode))
{
ParseDeviceInfoData(ParseDeviceMode.Debug);
}
Expand Down Expand Up @@ -529,9 +548,6 @@ public static ObservableCollection<LayoutModel> CustomModels

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;
Expand Down

0 comments on commit 145347f

Please sign in to comment.