From 1f87bfe6c599e3c0e471096600a38647da263fa9 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 4 Feb 2017 11:47:43 -0500 Subject: [PATCH] Finish name changer UI --- .../Applications/NameChanger.Designer.cs | 5 ++ ShiftOS.WinForms/Applications/NameChanger.cs | 86 ++++++++++++++++++- 2 files changed, 90 insertions(+), 1 deletion(-) diff --git a/ShiftOS.WinForms/Applications/NameChanger.Designer.cs b/ShiftOS.WinForms/Applications/NameChanger.Designer.cs index c507ace..ec1cecd 100644 --- a/ShiftOS.WinForms/Applications/NameChanger.Designer.cs +++ b/ShiftOS.WinForms/Applications/NameChanger.Designer.cs @@ -105,6 +105,7 @@ namespace ShiftOS.WinForms.Applications { this.btnclose.TabIndex = 0; this.btnclose.Text = "Close"; this.btnclose.UseVisualStyleBackColor = true; + this.btnclose.Click += new System.EventHandler(this.btnclose_Click); // // btnloaddefault // @@ -116,6 +117,7 @@ namespace ShiftOS.WinForms.Applications { this.btnloaddefault.TabIndex = 1; this.btnloaddefault.Text = "Load default"; this.btnloaddefault.UseVisualStyleBackColor = true; + this.btnloaddefault.Click += new System.EventHandler(this.btnloaddefault_Click); // // btnimport // @@ -127,6 +129,7 @@ namespace ShiftOS.WinForms.Applications { this.btnimport.TabIndex = 2; this.btnimport.Text = "Import"; this.btnimport.UseVisualStyleBackColor = true; + this.btnimport.Click += new System.EventHandler(this.btnimport_Click); // // btnexport // @@ -138,6 +141,7 @@ namespace ShiftOS.WinForms.Applications { this.btnexport.TabIndex = 3; this.btnexport.Text = "Export"; this.btnexport.UseVisualStyleBackColor = true; + this.btnexport.Click += new System.EventHandler(this.btnexport_Click); // // btnapply // @@ -149,6 +153,7 @@ namespace ShiftOS.WinForms.Applications { this.btnapply.TabIndex = 4; this.btnapply.Text = "Apply"; this.btnapply.UseVisualStyleBackColor = true; + this.btnapply.Click += new System.EventHandler(this.btnapply_Click); // // NameChanger // diff --git a/ShiftOS.WinForms/Applications/NameChanger.cs b/ShiftOS.WinForms/Applications/NameChanger.cs index 605ba3b..c983841 100644 --- a/ShiftOS.WinForms/Applications/NameChanger.cs +++ b/ShiftOS.WinForms/Applications/NameChanger.cs @@ -31,7 +31,10 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Newtonsoft.Json; using ShiftOS.Engine; +using ShiftOS.Objects.ShiftFS; +using ShiftOS.WinForms.Tools; namespace ShiftOS.WinForms.Applications { @@ -46,8 +49,49 @@ namespace ShiftOS.WinForms.Applications { InitializeComponent(); } + private Dictionary names = new Dictionary(); + public void OnLoad() { + names = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(NameChangerBackend.GetCurrent())); + SetupUI(); + } + + public void SetupUI() + { + flnames.Controls.Clear(); + foreach(var name in names) + { + var pnl = new Panel(); + var lbl = new Label(); + var txt = new TextBox(); + pnl.Controls.Add(lbl); + lbl.Show(); + pnl.Controls.Add(txt); + txt.Show(); + + ControlManager.SetupControls(pnl); + + pnl.Width = flnames.Width - 10; + pnl.Height = 50; + lbl.Left = 10; + lbl.Width = (pnl.Width / 4) - 10; + lbl.Text = name.Key; + lbl.Top = (pnl.Height - lbl.Height) / 2; + lbl.TextAlign = ContentAlignment.MiddleLeft; + + txt.Text = name.Value; + + txt.TextChanged += (o, a) => + { + names[name.Key] = txt.Text; + }; + txt.Width = pnl.Width - (pnl.Width / 4) - 20; + txt.Left = lbl.Width + 20; + txt.Top = (pnl.Height - txt.Height) / 2; + flnames.Controls.Add(pnl); + pnl.Show(); + } } public void OnSkinLoad() @@ -67,7 +111,40 @@ namespace ShiftOS.WinForms.Applications { { } - + + private void btnclose_Click(object sender, EventArgs e) + { + this.Close(); + } + + private void btnloaddefault_Click(object sender, EventArgs e) + { + names = NameChangerBackend.GetDefault(); + SetupUI(); + } + + private void btnimport_Click(object sender, EventArgs e) + { + FileSkimmerBackend.GetFile(new[] { ".nme" }, FileOpenerStyle.Open, new Action((path) => + { + names = JsonConvert.DeserializeObject>(Utils.ReadAllText(path)); + })); + } + + private void btnexport_Click(object sender, EventArgs e) + { + FileSkimmerBackend.GetFile(new[] { ".nme" }, FileOpenerStyle.Save, new Action((path) => + { + Utils.WriteAllText(path, JsonConvert.SerializeObject(names)); + })); + } + + private void btnapply_Click(object sender, EventArgs e) + { + SkinEngine.LoadedSkin.AppNames = names; + Utils.WriteAllText(Paths.GetPath("skin.json"), SkinEngine.LoadedSkin.ToString()); + SkinEngine.LoadSkin(); + } } public static class NameChangerBackend @@ -92,6 +169,13 @@ namespace ShiftOS.WinForms.Applications { if (SkinEngine.LoadedSkin.AppNames == null) SkinEngine.LoadedSkin.AppNames = GetDefault(); + + foreach(var def in GetDefault()) + { + if (!SkinEngine.LoadedSkin.AppNames.ContainsKey(def.Key)) + SkinEngine.LoadedSkin.AppNames.Add(def.Key, def.Value); + } + return SkinEngine.LoadedSkin.AppNames; }