Add Widget Manager UI

You can now toggle visibility of widgets.
This commit is contained in:
Michael 2017-04-22 17:10:15 -04:00
parent c718fbb565
commit 40fc14a237
7 changed files with 471 additions and 10 deletions

View file

@ -0,0 +1,164 @@
namespace ShiftOS.WinForms.Applications
{
partial class WidgetManagerFrontend
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

View file

@ -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<string, WidgetDetails> temp_details = null;
public void SetupUI()
{
flbody.Controls.Clear();
if(temp_details == null)
temp_details = new Dictionary<string, WinForms.WidgetDetails>();
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<Dictionary<string, WidgetDetails>>(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);
}
}
}

View file

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View file

@ -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,

View file

@ -240,6 +240,12 @@
<Compile Include="Applications\UpdateManager.Designer.cs">
<DependentUpon>UpdateManager.cs</DependentUpon>
</Compile>
<Compile Include="Applications\WidgetManagerFrontend.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Applications\WidgetManagerFrontend.Designer.cs">
<DependentUpon>WidgetManagerFrontend.cs</DependentUpon>
</Compile>
<Compile Include="AudioManager.cs" />
<Compile Include="Commands.cs" />
<Compile Include="Controls\ColorControl.cs">
@ -416,6 +422,9 @@
<EmbeddedResource Include="Applications\UpdateManager.resx">
<DependentUpon>UpdateManager.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Applications\WidgetManagerFrontend.resx">
<DependentUpon>WidgetManagerFrontend.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="DesktopWidgets\Clock.resx">
<DependentUpon>Clock.cs</DependentUpon>
</EmbeddedResource>

View file

@ -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<string, Point>();
var dict = new Dictionary<string, WidgetDetails>();
var attrib = type.GetCustomAttributes(false).FirstOrDefault(x => x is DesktopWidgetAttribute) as DesktopWidgetAttribute;
try
{
dict = JsonConvert.DeserializeObject<Dictionary<string, Point>>(Utils.ReadAllText(Paths.GetPath("widgets.dat")));
dict = JsonConvert.DeserializeObject<Dictionary<string, WidgetDetails>>(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<string, Point>();
var dict = new Dictionary<string, WidgetDetails>();
var attrib = type.GetCustomAttributes(false).FirstOrDefault(x => x is DesktopWidgetAttribute) as DesktopWidgetAttribute;
try
{
dict = JsonConvert.DeserializeObject<Dictionary<string, Point>>(Utils.ReadAllText(Paths.GetPath("widgets.dat")));
dict = JsonConvert.DeserializeObject<Dictionary<string, WidgetDetails>>(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; }
}
}

View file

@ -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)