| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. |
| 2 | |
| 3 | namespace WixToolset.Data |
| 4 | { |
| 5 | using System; |
| 6 | using SimpleJson; |
| 7 | |
| 8 | public class LocalizedControl |
| 9 | { |
| 10 | public LocalizedControl(string dialog, string control, int x, int y, int width, int height, bool rightToLeft, bool rightAligned, bool leftScroll, string text) |
| 11 | { |
| 12 | this.Dialog = dialog; |
| 13 | this.Control = control; |
| 14 | this.X = x; |
| 15 | this.Y = y; |
| 16 | this.Width = width; |
| 17 | this.Height = height; |
| 18 | this.RightToLeft = rightToLeft; |
| 19 | this.RightAligned = rightAligned; |
| 20 | this.LeftScroll = leftScroll; |
| 21 | this.Text = text; |
| 22 | } |
| 23 | |
| 24 | public string Dialog { get; } |
| 25 | |
| 26 | public string Control { get; } |
| 27 | |
| 28 | public int X { get; } |
| 29 | |
| 30 | public int Y { get; } |
| 31 | |
| 32 | public int Width { get; } |
| 33 | |
| 34 | public int Height { get; } |
| 35 | |
| 36 | public bool RightToLeft { get; } |
| 37 | |
| 38 | public bool RightAligned { get; } |
| 39 | |
| 40 | public bool LeftScroll { get; } |
| 41 | |
| 42 | public string Text { get; } |
| 43 | |
| 44 | /// <summary> |
| 45 | /// Get key for a localized control. |
| 46 | /// </summary> |
| 47 | /// <returns>The localized control id.</returns> |
| 48 | public string GetKey() |
| 49 | { |
| 50 | return LocalizedControl.GetKey(this.Dialog, this.Control); |
| 51 | } |
| 52 | |
| 53 | /// <summary> |
| 54 | /// Get key for a localized control. |
| 55 | /// </summary> |
| 56 | /// <param name="dialog">The optional id of the control's dialog.</param> |
| 57 | /// <param name="control">The id of the control.</param> |
| 58 | /// <returns>The localized control id.</returns> |
| 59 | public static string GetKey(string dialog, string control) |
| 60 | { |
| 61 | return String.Concat(dialog, "/", control); |
| 62 | } |
| 63 | |
| 64 | internal JsonObject Serialize() |
| 65 | { |
| 66 | var jsonObject = new JsonObject |
| 67 | { |
| 68 | { "dialog", this.Dialog }, |
| 69 | }; |
| 70 | |
| 71 | jsonObject.AddIsNotNullOrEmpty("control", this.Control); |
| 72 | jsonObject.AddNonDefaultValue("x", this.X); |
| 73 | jsonObject.AddNonDefaultValue("y", this.Y); |
| 74 | jsonObject.AddNonDefaultValue("width", this.Width); |
| 75 | jsonObject.AddNonDefaultValue("height", this.Height); |
| 76 | jsonObject.AddNonDefaultValue("rightToLeft", this.RightToLeft); |
| 77 | jsonObject.AddNonDefaultValue("rightAligned", this.RightAligned); |
| 78 | jsonObject.AddNonDefaultValue("leftScroll", this.LeftScroll); |
| 79 | jsonObject.AddIsNotNullOrEmpty("text", this.Text); |
| 80 | |
| 81 | return jsonObject; |
| 82 | } |
| 83 | |
| 84 | internal static LocalizedControl Deserialize(JsonObject jsonObject) |
| 85 | { |
| 86 | var dialog = jsonObject.GetValueOrDefault<string>("dialog"); |
| 87 | var control = jsonObject.GetValueOrDefault<string>("control"); |
| 88 | var x = jsonObject.GetValueOrDefault("x", 0); |
| 89 | var y = jsonObject.GetValueOrDefault("y", 0); |
| 90 | var width = jsonObject.GetValueOrDefault("width", 0); |
| 91 | var height = jsonObject.GetValueOrDefault("height", 0); |
| 92 | var rightToLeft = jsonObject.GetValueOrDefault("rightToLeft", false); |
| 93 | var rightAligned = jsonObject.GetValueOrDefault("rightAligned", false); |
| 94 | var leftScroll = jsonObject.GetValueOrDefault("leftScroll", false); |
| 95 | var text = jsonObject.GetValueOrDefault<string>("text"); |
| 96 | |
| 97 | return new LocalizedControl(dialog, control, x, y, width, height, rightToLeft, rightAligned, leftScroll, text); |
| 98 | } |
| 99 | } |
| 100 | } |