diff options
Diffstat (limited to 'ShiftOS.WinForms/Applications')
| -rw-r--r-- | ShiftOS.WinForms/Applications/Shiftnet.Designer.cs | 139 | ||||
| -rw-r--r-- | ShiftOS.WinForms/Applications/Shiftnet.cs | 167 | ||||
| -rw-r--r-- | ShiftOS.WinForms/Applications/Shiftnet.resx | 120 |
3 files changed, 426 insertions, 0 deletions
diff --git a/ShiftOS.WinForms/Applications/Shiftnet.Designer.cs b/ShiftOS.WinForms/Applications/Shiftnet.Designer.cs new file mode 100644 index 0000000..8ac9ea5 --- /dev/null +++ b/ShiftOS.WinForms/Applications/Shiftnet.Designer.cs @@ -0,0 +1,139 @@ +namespace ShiftOS.WinForms.Applications +{ + partial class Shiftnet + { + /// <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.flcontrols = new System.Windows.Forms.FlowLayoutPanel(); + this.btnback = new System.Windows.Forms.Button(); + this.btnforward = new System.Windows.Forms.Button(); + this.txturl = new System.Windows.Forms.TextBox(); + this.btngo = new System.Windows.Forms.Button(); + this.wbcanvas = new System.Windows.Forms.WebBrowser(); + this.flcontrols.SuspendLayout(); + this.SuspendLayout(); + // + // flcontrols + // + this.flcontrols.AutoSize = true; + this.flcontrols.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.flcontrols.Controls.Add(this.btnback); + this.flcontrols.Controls.Add(this.btnforward); + this.flcontrols.Controls.Add(this.txturl); + this.flcontrols.Controls.Add(this.btngo); + this.flcontrols.Dock = System.Windows.Forms.DockStyle.Top; + this.flcontrols.Location = new System.Drawing.Point(0, 0); + this.flcontrols.Name = "flcontrols"; + this.flcontrols.Size = new System.Drawing.Size(805, 29); + this.flcontrols.TabIndex = 0; + // + // btnback + // + this.btnback.AutoSize = true; + this.btnback.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.btnback.Location = new System.Drawing.Point(3, 3); + this.btnback.Name = "btnback"; + this.btnback.Size = new System.Drawing.Size(23, 23); + this.btnback.TabIndex = 0; + this.btnback.Text = "<"; + this.btnback.UseVisualStyleBackColor = true; + this.btnback.Click += new System.EventHandler(this.btnback_Click); + // + // btnforward + // + this.btnforward.AutoSize = true; + this.btnforward.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.btnforward.Location = new System.Drawing.Point(32, 3); + this.btnforward.Name = "btnforward"; + this.btnforward.Size = new System.Drawing.Size(23, 23); + this.btnforward.TabIndex = 1; + this.btnforward.Text = ">"; + this.btnforward.UseVisualStyleBackColor = true; + this.btnforward.Click += new System.EventHandler(this.btnforward_Click); + // + // txturl + // + this.txturl.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.txturl.Location = new System.Drawing.Point(61, 3); + this.txturl.Name = "txturl"; + this.txturl.Size = new System.Drawing.Size(702, 20); + this.txturl.TabIndex = 2; + this.txturl.WordWrap = false; + this.txturl.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txturl_KeyDown); + // + // btngo + // + this.btngo.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btngo.AutoSize = true; + this.btngo.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.btngo.Location = new System.Drawing.Point(769, 3); + this.btngo.Name = "btngo"; + this.btngo.Size = new System.Drawing.Size(31, 23); + this.btngo.TabIndex = 3; + this.btngo.Text = "Go"; + this.btngo.UseVisualStyleBackColor = true; + this.btngo.Click += new System.EventHandler(this.btngo_Click); + // + // wbcanvas + // + this.wbcanvas.Dock = System.Windows.Forms.DockStyle.Fill; + this.wbcanvas.IsWebBrowserContextMenuEnabled = false; + this.wbcanvas.Location = new System.Drawing.Point(0, 29); + this.wbcanvas.MinimumSize = new System.Drawing.Size(20, 20); + this.wbcanvas.Name = "wbcanvas"; + this.wbcanvas.ScriptErrorsSuppressed = true; + this.wbcanvas.Size = new System.Drawing.Size(805, 510); + this.wbcanvas.TabIndex = 1; + this.wbcanvas.WebBrowserShortcutsEnabled = false; + this.wbcanvas.Navigating += new System.Windows.Forms.WebBrowserNavigatingEventHandler(this.wbcanvas_Navigating); + // + // Shiftnet + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.wbcanvas); + this.Controls.Add(this.flcontrols); + this.Name = "Shiftnet"; + this.Size = new System.Drawing.Size(805, 539); + this.flcontrols.ResumeLayout(false); + this.flcontrols.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.FlowLayoutPanel flcontrols; + private System.Windows.Forms.Button btnback; + private System.Windows.Forms.Button btnforward; + private System.Windows.Forms.TextBox txturl; + private System.Windows.Forms.Button btngo; + private System.Windows.Forms.WebBrowser wbcanvas; + } +} diff --git a/ShiftOS.WinForms/Applications/Shiftnet.cs b/ShiftOS.WinForms/Applications/Shiftnet.cs new file mode 100644 index 0000000..d4183a4 --- /dev/null +++ b/ShiftOS.WinForms/Applications/Shiftnet.cs @@ -0,0 +1,167 @@ +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 Newtonsoft.Json; +using static ShiftOS.Engine.SkinEngine; + +namespace ShiftOS.WinForms.Applications +{ + [Launcher("Shiftnet", false)] + public partial class Shiftnet : UserControl, IShiftOSWindow + { + public Shiftnet() + { + InitializeComponent(); + ServerManager.MessageReceived += (msg) => + { + try + { + if (msg.Name == "shiftnet_file") + { + this.Invoke(new Action(() => + { + wbcanvas.DocumentText = ConstructHtml(msg.Contents); + })); + } + } + catch + { + + } + }; + } + + public string ConstructHtml(string markdown) + { + string html = $@"<html> + <head> + <style> + <!-- Skin the web page --> + body {{ + background-color: rgb({LoadedSkin.ControlColor.R}, {LoadedSkin.ControlColor.G}, {LoadedSkin.ControlColor.B}); + color: rgb({LoadedSkin.ControlTextColor.R}, {LoadedSkin.ControlTextColor.G}, {LoadedSkin.ControlTextColor.B}); + font-family: ""{LoadedSkin.MainFont.Name}""; + font-size: {LoadedSkin.MainFont.Size}em; + }} + + h1 {{ + font-family: ""{LoadedSkin.HeaderFont.Name}""; + font-size: {LoadedSkin.HeaderFont.Size}em; + }} + + h2 {{ + font-family: ""{LoadedSkin.Header2Font.Name}""; + font-size: {LoadedSkin.Header2Font.Size}em; + }} + + h3 {{ + font-family: ""{LoadedSkin.Header3Font.Name}""; + font-size: {LoadedSkin.Header3Font.Size}em; + }} + + </style> + </head> + <body> + <markdown/> + </body> +</html>"; + + string body = CommonMark.CommonMarkConverter.Convert(markdown); + + html = html.Replace("<markdown/>", body); + return html; + } + + public string CurrentUrl { get; set; } + + + private void wbcanvas_Navigating(object sender, WebBrowserNavigatingEventArgs e) + { + if (CurrentUrl != e.Url.ToString()) + { + e.Cancel = true; + Future.Clear(); + ShiftnetNavigate(e.Url.ToString()); + } + } + + public Stack<string> History = new Stack<string>(); + public Stack<string> Future = new Stack<string>(); + + public void ShiftnetNavigate(string Url, bool pushHistory = true) + { + if (!string.IsNullOrEmpty(CurrentUrl) && pushHistory) + History.Push(CurrentUrl); + CurrentUrl = Url; + + ServerManager.SendMessage("shiftnet_get", JsonConvert.SerializeObject(new + { + url = Url + })); + } + + public void OnLoad() + { + ShiftnetNavigate("shiftnet/main"); + } + + public void OnSkinLoad() + { + ShiftnetNavigate(CurrentUrl); + } + + public bool OnUnload() + { + return true; + } + + public void OnUpgrade() + { + } + + private void btnback_Click(object sender, EventArgs e) + { + string hist = History.Pop(); + if (!string.IsNullOrEmpty(hist)) + { + Future.Push(hist); + ShiftnetNavigate(hist, false); + } + } + + private void btnforward_Click(object sender, EventArgs e) + { + string fut = Future.Pop(); + if (!string.IsNullOrEmpty(fut)) + { + ShiftnetNavigate(fut); + } + } + + private void btngo_Click(object sender, EventArgs e) + { + if (!string.IsNullOrWhiteSpace(txturl.Text)) + { + Future.Clear(); + + ShiftnetNavigate(txturl.Text); + } + } + + private void txturl_KeyDown(object sender, KeyEventArgs e) + { + if(e.KeyCode == Keys.Enter) + { + btngo_Click(sender, EventArgs.Empty); + e.SuppressKeyPress = true; + } + } + } +} diff --git a/ShiftOS.WinForms/Applications/Shiftnet.resx b/ShiftOS.WinForms/Applications/Shiftnet.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ShiftOS.WinForms/Applications/Shiftnet.resx @@ -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>
\ No newline at end of file |
