diff --git a/ShiftOS.WinForms/Applications/WidgetManagerFrontend.Designer.cs b/ShiftOS.WinForms/Applications/WidgetManagerFrontend.Designer.cs new file mode 100644 index 0000000..9612b21 --- /dev/null +++ b/ShiftOS.WinForms/Applications/WidgetManagerFrontend.Designer.cs @@ -0,0 +1,164 @@ +namespace ShiftOS.WinForms.Applications +{ + partial class WidgetManagerFrontend + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.flbody = new System.Windows.Forms.FlowLayoutPanel(); + this.label1 = new System.Windows.Forms.Label(); + this.flowLayoutPanel1 = 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.flowLayoutPanel1.SuspendLayout(); + this.SuspendLayout(); + // + // flbody + // + this.flbody.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.flbody.Location = new System.Drawing.Point(22, 59); + this.flbody.Name = "flbody"; + this.flbody.Size = new System.Drawing.Size(463, 389); + this.flbody.TabIndex = 0; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(22, 14); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(89, 13); + this.label1.TabIndex = 1; + this.label1.Tag = "header1"; + this.label1.Text = "Desktop Widgets"; + // + // flowLayoutPanel1 + // + this.flowLayoutPanel1.AutoSize = true; + this.flowLayoutPanel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.flowLayoutPanel1.Controls.Add(this.btnclose); + this.flowLayoutPanel1.Controls.Add(this.btnloaddefault); + this.flowLayoutPanel1.Controls.Add(this.btnimport); + this.flowLayoutPanel1.Controls.Add(this.btnexport); + this.flowLayoutPanel1.Controls.Add(this.btnapply); + this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Bottom; + this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 461); + this.flowLayoutPanel1.Name = "flowLayoutPanel1"; + this.flowLayoutPanel1.Size = new System.Drawing.Size(517, 29); + this.flowLayoutPanel1.TabIndex = 2; + // + // 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; + this.btnclose.Click += new System.EventHandler(this.btnclose_Click); + // + // 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; + this.btnloaddefault.Click += new System.EventHandler(this.btnloaddefault_Click); + // + // 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; + this.btnimport.Click += new System.EventHandler(this.btnimport_Click); + // + // 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; + this.btnexport.Click += new System.EventHandler(this.btnexport_Click); + // + // 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; + this.btnapply.Click += new System.EventHandler(this.btnapply_Click); + // + // WidgetManagerFrontend + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.flowLayoutPanel1); + this.Controls.Add(this.label1); + this.Controls.Add(this.flbody); + this.Name = "WidgetManagerFrontend"; + this.Size = new System.Drawing.Size(517, 490); + this.flowLayoutPanel1.ResumeLayout(false); + this.flowLayoutPanel1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.FlowLayoutPanel flbody; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; + 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; + } +} diff --git a/ShiftOS.WinForms/Applications/WidgetManagerFrontend.cs b/ShiftOS.WinForms/Applications/WidgetManagerFrontend.cs new file mode 100644 index 0000000..6424710 --- /dev/null +++ b/ShiftOS.WinForms/Applications/WidgetManagerFrontend.cs @@ -0,0 +1,131 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using ShiftOS.Engine; +using ShiftOS.WinForms.Tools; +using Newtonsoft.Json; +using ShiftOS.Objects.ShiftFS; + +namespace ShiftOS.WinForms.Applications +{ + [WinOpen("desktop_widgets")] + [Launcher("Widget Manager", true, "al_widget_manager", "Customization")] + [DefaultTitle("Widget Manager")] + [RequiresUpgrade("desktop_widgets")] + public partial class WidgetManagerFrontend : UserControl, IShiftOSWindow + { + public WidgetManagerFrontend() + { + InitializeComponent(); + } + + Dictionary temp_details = null; + + public void SetupUI() + { + flbody.Controls.Clear(); + if(temp_details == null) + temp_details = new Dictionary(); + foreach(var widgetType in WidgetManager.GetAllWidgetTypes()) + { + + var details = WidgetManager.LoadDetails(widgetType.Value); + if (temp_details.ContainsKey(widgetType.Key.ToString())) + details = temp_details[widgetType.Key.ToString()]; + else + temp_details.Add(widgetType.Key.ToString(), details); + var cbox = new CheckBox(); + cbox.Checked = details.IsVisible; + cbox.Size = new Size(32, 32); + cbox.CheckedChanged += (o, a) => + { + details.IsVisible = cbox.Checked; + }; + flbody.Controls.Add(cbox); + cbox.Show(); + var title = new Label(); + title.Text = widgetType.Key.Name; + title.AutoSize = true; + title.Tag = "header3"; + ControlManager.SetupControl(title); + flbody.Controls.Add(title); + title.Show(); + var desc = new Label(); + desc.Text = widgetType.Key.Description; + flbody.Controls.Add(desc); + flbody.SetFlowBreak(desc, true); + flbody.SetFlowBreak(title, true); + desc.Show(); + } + } + + public void OnLoad() + { + SetupUI(); + } + + public void OnSkinLoad() + { + SetupUI(); + } + + public bool OnUnload() + { + return false; + } + + public void OnUpgrade() + { + SetupUI(); + } + + private void btnapply_Click(object sender, EventArgs e) + { + Utils.WriteAllText(Paths.GetPath("widgets.dat"), JsonConvert.SerializeObject(temp_details)); + Desktop.CurrentDesktop.SetupDesktop(); + } + + private void btnexport_Click(object sender, EventArgs e) + { + FileSkimmerBackend.GetFile(new[] { ".wid" }, FileOpenerStyle.Save, (path) => + { + Utils.WriteAllText(path, JsonConvert.SerializeObject(temp_details)); + }); + } + + private void btnimport_Click(object sender, EventArgs e) + { + FileSkimmerBackend.GetFile(new[] { ".wid" }, FileOpenerStyle.Open, (path) => + { + temp_details = JsonConvert.DeserializeObject>(Utils.ReadAllText(path)); + SetupUI(); + }); + + } + + private void btnloaddefault_Click(object sender, EventArgs e) + { + temp_details.Clear(); + foreach(var type in WidgetManager.GetAllWidgetTypes()) + { + temp_details.Add(type.Key.ToString(), new WidgetDetails + { + IsVisible = false, + Location = new Point(-1, -1) + }); + } + SetupUI(); + } + + private void btnclose_Click(object sender, EventArgs e) + { + AppearanceManager.Close(this); + } + } +} diff --git a/ShiftOS.WinForms/Applications/WidgetManagerFrontend.resx b/ShiftOS.WinForms/Applications/WidgetManagerFrontend.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ShiftOS.WinForms/Applications/WidgetManagerFrontend.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ShiftOS.WinForms/Resources/Shiftorium.txt b/ShiftOS.WinForms/Resources/Shiftorium.txt index dadb022..ca555d4 100644 --- a/ShiftOS.WinForms/Resources/Shiftorium.txt +++ b/ShiftOS.WinForms/Resources/Shiftorium.txt @@ -270,6 +270,13 @@ Category: "Device Drivers", Dependencies: "color_depth_8_bits" }, + { + Name: "AL Widget Manager", + Cost: 125, + Description: "Desktop Widgets are a huge advancement in ShiftOS technology, allowing access to system information, and quick control of your system, without even opening a window. However, we still need to be able to modify each widget. This upgrade adds an App Launcher entry for the Desktop Widget Manager.", + Description: "app_launcher;desktop_widgets", + Category: "GUI" + }, { Name: "FS Delete", Cost: 75, diff --git a/ShiftOS.WinForms/ShiftOS.WinForms.csproj b/ShiftOS.WinForms/ShiftOS.WinForms.csproj index 915543f..f018390 100644 --- a/ShiftOS.WinForms/ShiftOS.WinForms.csproj +++ b/ShiftOS.WinForms/ShiftOS.WinForms.csproj @@ -240,6 +240,12 @@ UpdateManager.cs + + UserControl + + + WidgetManagerFrontend.cs + @@ -416,6 +422,9 @@ UpdateManager.cs + + WidgetManagerFrontend.cs + Clock.cs diff --git a/ShiftOS.WinForms/WidgetManager.cs b/ShiftOS.WinForms/WidgetManager.cs index 15e2076..fec09f9 100644 --- a/ShiftOS.WinForms/WidgetManager.cs +++ b/ShiftOS.WinForms/WidgetManager.cs @@ -48,13 +48,13 @@ namespace ShiftOS.WinForms return types; } - internal static void SaveLocation(Type type, Point location) + internal static void SaveDetails(Type type, WidgetDetails location) { - var dict = new Dictionary(); + var dict = new Dictionary(); var attrib = type.GetCustomAttributes(false).FirstOrDefault(x => x is DesktopWidgetAttribute) as DesktopWidgetAttribute; try { - dict = JsonConvert.DeserializeObject>(Utils.ReadAllText(Paths.GetPath("widgets.dat"))); + dict = JsonConvert.DeserializeObject>(Utils.ReadAllText(Paths.GetPath("widgets.dat"))); dict[attrib.ToString()] = location; } @@ -69,20 +69,30 @@ namespace ShiftOS.WinForms } - internal static Point LoadLocation(Type type) + internal static WidgetDetails LoadDetails(Type type) { - var dict = new Dictionary(); + var dict = new Dictionary(); var attrib = type.GetCustomAttributes(false).FirstOrDefault(x => x is DesktopWidgetAttribute) as DesktopWidgetAttribute; try { - dict = JsonConvert.DeserializeObject>(Utils.ReadAllText(Paths.GetPath("widgets.dat"))); + dict = JsonConvert.DeserializeObject>(Utils.ReadAllText(Paths.GetPath("widgets.dat"))); return dict[attrib.ToString()]; } catch { - return new Point(-1, -1); + var details = new WinForms.WidgetDetails + { + Location = new Point(-1, -1), + IsVisible = false + }; + if (dict.ContainsKey(attrib.ToString())) + dict[attrib.ToString()] = details; + else + dict.Add(attrib.ToString(), details); + Utils.WriteAllText(Paths.GetPath("widgets.dat"), JsonConvert.SerializeObject(dict)); + return details; } finally { @@ -90,4 +100,15 @@ namespace ShiftOS.WinForms } } + + public class WidgetDetails + { + public WidgetDetails() + { + IsVisible = true; + } + + public Point Location { get; set; } + public bool IsVisible { get; set; } + } } diff --git a/ShiftOS.WinForms/WinformsDesktop.cs b/ShiftOS.WinForms/WinformsDesktop.cs index 61c371e..c5e3efe 100644 --- a/ShiftOS.WinForms/WinformsDesktop.cs +++ b/ShiftOS.WinForms/WinformsDesktop.cs @@ -455,21 +455,28 @@ namespace ShiftOS.WinForms { UserControl w = (UserControl)Activator.CreateInstance(widget.Value, null); - w.Location = WidgetManager.LoadLocation(w.GetType()); + w.Location = WidgetManager.LoadDetails(w.GetType()).Location; pnlwidgetlayer.Controls.Add(w); MakeWidgetMovable(w); Widgets.Add(w as IDesktopWidget); } } + int lastHeight = 5; foreach (var widget in Widgets) { - if (Shiftorium.UpgradeInstalled("desktop_widgets")) + if (WidgetManager.LoadDetails(widget.GetType()).IsVisible && Shiftorium.UpgradeInstalled("desktop_widgets")) { widget.OnSkinLoad(); + widget.OnUpgrade(); widget.Setup(); widget.Show(); + if (widget.Location.X == -1 && widget.Location.Y == -1) + { + widget.Location = new Point(5, lastHeight); + lastHeight += (widget.Location.Y + widget.Size.Height) + 5; + } } else { @@ -525,7 +532,9 @@ namespace ShiftOS.WinForms w.MouseUp += (o, a) => { moving = false; - WidgetManager.SaveLocation(startCtrl.GetType(), startCtrl.Location); + var details = WidgetManager.LoadDetails(startCtrl.GetType()); + details.Location = startCtrl.Location; + WidgetManager.SaveDetails(startCtrl.GetType(), details); }; foreach (Control c in w.Controls)