From 28a087d2d4961fd80d827df968de0f6f63da07eb Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 4 Feb 2017 11:14:39 -0500 Subject: Add name changer backend You can use the DefaultTitleAttribute on an IShiftOSWindow to specify a default title for the window and name changer entry. --- .../Applications/NameChanger.Designer.cs | 125 +++++++++++++++++++-- 1 file changed, 113 insertions(+), 12 deletions(-) (limited to 'ShiftOS.WinForms/Applications/NameChanger.Designer.cs') diff --git a/ShiftOS.WinForms/Applications/NameChanger.Designer.cs b/ShiftOS.WinForms/Applications/NameChanger.Designer.cs index b51822f..c507ace 100644 --- a/ShiftOS.WinForms/Applications/NameChanger.Designer.cs +++ b/ShiftOS.WinForms/Applications/NameChanger.Designer.cs @@ -47,33 +47,134 @@ namespace ShiftOS.WinForms.Applications { /// the contents of this method with the code editor. /// private void InitializeComponent() { - this.listBox1 = new System.Windows.Forms.ListBox(); + this.panel1 = new System.Windows.Forms.Panel(); + this.flnames = new System.Windows.Forms.FlowLayoutPanel(); + this.flbuttons = new System.Windows.Forms.FlowLayoutPanel(); + this.btnclose = new System.Windows.Forms.Button(); + this.btnloaddefault = new System.Windows.Forms.Button(); + this.btnimport = new System.Windows.Forms.Button(); + this.btnexport = new System.Windows.Forms.Button(); + this.btnapply = new System.Windows.Forms.Button(); + this.panel1.SuspendLayout(); + this.flbuttons.SuspendLayout(); this.SuspendLayout(); // - // listBox1 + // panel1 // - this.listBox1.FormattingEnabled = true; - this.listBox1.Location = new System.Drawing.Point(3, 3); - this.listBox1.Name = "listBox1"; - this.listBox1.Size = new System.Drawing.Size(138, 342); - this.listBox1.TabIndex = 0; - this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged); + this.panel1.Controls.Add(this.flnames); + this.panel1.Controls.Add(this.flbuttons); + this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.panel1.Location = new System.Drawing.Point(0, 0); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(354, 349); + this.panel1.TabIndex = 0; + // + // flnames + // + this.flnames.AutoScroll = true; + this.flnames.Dock = System.Windows.Forms.DockStyle.Fill; + this.flnames.FlowDirection = System.Windows.Forms.FlowDirection.TopDown; + this.flnames.Location = new System.Drawing.Point(0, 0); + this.flnames.Name = "flnames"; + this.flnames.Size = new System.Drawing.Size(354, 320); + this.flnames.TabIndex = 0; + this.flnames.WrapContents = false; + // + // flbuttons + // + this.flbuttons.AutoSize = true; + this.flbuttons.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.flbuttons.Controls.Add(this.btnclose); + this.flbuttons.Controls.Add(this.btnloaddefault); + this.flbuttons.Controls.Add(this.btnimport); + this.flbuttons.Controls.Add(this.btnexport); + this.flbuttons.Controls.Add(this.btnapply); + this.flbuttons.Dock = System.Windows.Forms.DockStyle.Bottom; + this.flbuttons.Location = new System.Drawing.Point(0, 320); + this.flbuttons.Name = "flbuttons"; + this.flbuttons.Size = new System.Drawing.Size(354, 29); + this.flbuttons.TabIndex = 0; + // + // btnclose + // + this.btnclose.AutoSize = true; + this.btnclose.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.btnclose.Location = new System.Drawing.Point(3, 3); + this.btnclose.Name = "btnclose"; + this.btnclose.Size = new System.Drawing.Size(43, 23); + this.btnclose.TabIndex = 0; + this.btnclose.Text = "Close"; + this.btnclose.UseVisualStyleBackColor = true; + // + // btnloaddefault + // + this.btnloaddefault.AutoSize = true; + this.btnloaddefault.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.btnloaddefault.Location = new System.Drawing.Point(52, 3); + this.btnloaddefault.Name = "btnloaddefault"; + this.btnloaddefault.Size = new System.Drawing.Size(76, 23); + this.btnloaddefault.TabIndex = 1; + this.btnloaddefault.Text = "Load default"; + this.btnloaddefault.UseVisualStyleBackColor = true; + // + // btnimport + // + this.btnimport.AutoSize = true; + this.btnimport.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.btnimport.Location = new System.Drawing.Point(134, 3); + this.btnimport.Name = "btnimport"; + this.btnimport.Size = new System.Drawing.Size(46, 23); + this.btnimport.TabIndex = 2; + this.btnimport.Text = "Import"; + this.btnimport.UseVisualStyleBackColor = true; + // + // btnexport + // + this.btnexport.AutoSize = true; + this.btnexport.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.btnexport.Location = new System.Drawing.Point(186, 3); + this.btnexport.Name = "btnexport"; + this.btnexport.Size = new System.Drawing.Size(47, 23); + this.btnexport.TabIndex = 3; + this.btnexport.Text = "Export"; + this.btnexport.UseVisualStyleBackColor = true; + // + // btnapply + // + this.btnapply.AutoSize = true; + this.btnapply.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.btnapply.Location = new System.Drawing.Point(239, 3); + this.btnapply.Name = "btnapply"; + this.btnapply.Size = new System.Drawing.Size(43, 23); + this.btnapply.TabIndex = 4; + this.btnapply.Text = "Apply"; + this.btnapply.UseVisualStyleBackColor = true; // // NameChanger // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.listBox1); + this.Controls.Add(this.panel1); this.Name = "NameChanger"; - this.Text = "Name Changer"; - this.Size = new System.Drawing.Size(459, 406); + this.Size = new System.Drawing.Size(354, 349); this.Load += new System.EventHandler(this.NameChanger_Load); + this.panel1.ResumeLayout(false); + this.panel1.PerformLayout(); + this.flbuttons.ResumeLayout(false); + this.flbuttons.PerformLayout(); this.ResumeLayout(false); } #endregion - private System.Windows.Forms.ListBox listBox1; + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.FlowLayoutPanel flnames; + private System.Windows.Forms.FlowLayoutPanel flbuttons; + private System.Windows.Forms.Button btnclose; + private System.Windows.Forms.Button btnloaddefault; + private System.Windows.Forms.Button btnimport; + private System.Windows.Forms.Button btnexport; + private System.Windows.Forms.Button btnapply; } } \ No newline at end of file -- cgit v1.2.3 From 1f87bfe6c599e3c0e471096600a38647da263fa9 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 4 Feb 2017 11:47:43 -0500 Subject: Finish name changer UI --- .../Applications/NameChanger.Designer.cs | 5 ++ ShiftOS.WinForms/Applications/NameChanger.cs | 86 +++++++++++++++++++++- 2 files changed, 90 insertions(+), 1 deletion(-) (limited to 'ShiftOS.WinForms/Applications/NameChanger.Designer.cs') 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; } -- cgit v1.2.3