1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
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;
}
}
}
}
|