Edited how Cef loads
This commit is contained in:
parent
4c831a7b2c
commit
de196cfcb3
2 changed files with 70 additions and 23 deletions
22
Form1.Designer.cs
generated
22
Form1.Designer.cs
generated
|
@ -43,7 +43,6 @@
|
||||||
Saver = new SaveFileDialog();
|
Saver = new SaveFileDialog();
|
||||||
groupBox4 = new GroupBox();
|
groupBox4 = new GroupBox();
|
||||||
progressBar1 = new ProgressBar();
|
progressBar1 = new ProgressBar();
|
||||||
chromiumWebBrowser1 = new CefSharp.WinForms.ChromiumWebBrowser();
|
|
||||||
button4 = new Button();
|
button4 = new Button();
|
||||||
button3 = new Button();
|
button3 = new Button();
|
||||||
groupBox3 = new GroupBox();
|
groupBox3 = new GroupBox();
|
||||||
|
@ -110,13 +109,13 @@
|
||||||
//
|
//
|
||||||
fontFamilyToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { serifToolStripMenuItem, sansSerifToolStripMenuItem, forceMonospaceToolStripMenuItem });
|
fontFamilyToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { serifToolStripMenuItem, sansSerifToolStripMenuItem, forceMonospaceToolStripMenuItem });
|
||||||
fontFamilyToolStripMenuItem.Name = "fontFamilyToolStripMenuItem";
|
fontFamilyToolStripMenuItem.Name = "fontFamilyToolStripMenuItem";
|
||||||
fontFamilyToolStripMenuItem.Size = new Size(180, 22);
|
fontFamilyToolStripMenuItem.Size = new Size(136, 22);
|
||||||
fontFamilyToolStripMenuItem.Text = "Font Family";
|
fontFamilyToolStripMenuItem.Text = "Font Family";
|
||||||
//
|
//
|
||||||
// serifToolStripMenuItem
|
// serifToolStripMenuItem
|
||||||
//
|
//
|
||||||
serifToolStripMenuItem.Name = "serifToolStripMenuItem";
|
serifToolStripMenuItem.Name = "serifToolStripMenuItem";
|
||||||
serifToolStripMenuItem.Size = new Size(180, 22);
|
serifToolStripMenuItem.Size = new Size(176, 22);
|
||||||
serifToolStripMenuItem.Text = "Serif";
|
serifToolStripMenuItem.Text = "Serif";
|
||||||
serifToolStripMenuItem.Click += serifToolStripMenuItem_Click;
|
serifToolStripMenuItem.Click += serifToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
|
@ -125,14 +124,14 @@
|
||||||
sansSerifToolStripMenuItem.Checked = true;
|
sansSerifToolStripMenuItem.Checked = true;
|
||||||
sansSerifToolStripMenuItem.CheckState = CheckState.Checked;
|
sansSerifToolStripMenuItem.CheckState = CheckState.Checked;
|
||||||
sansSerifToolStripMenuItem.Name = "sansSerifToolStripMenuItem";
|
sansSerifToolStripMenuItem.Name = "sansSerifToolStripMenuItem";
|
||||||
sansSerifToolStripMenuItem.Size = new Size(180, 22);
|
sansSerifToolStripMenuItem.Size = new Size(176, 22);
|
||||||
sansSerifToolStripMenuItem.Text = "(Default) Sans serif";
|
sansSerifToolStripMenuItem.Text = "(Default) Sans serif";
|
||||||
sansSerifToolStripMenuItem.Click += sansSerifToolStripMenuItem_Click;
|
sansSerifToolStripMenuItem.Click += sansSerifToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// forceMonospaceToolStripMenuItem
|
// forceMonospaceToolStripMenuItem
|
||||||
//
|
//
|
||||||
forceMonospaceToolStripMenuItem.Name = "forceMonospaceToolStripMenuItem";
|
forceMonospaceToolStripMenuItem.Name = "forceMonospaceToolStripMenuItem";
|
||||||
forceMonospaceToolStripMenuItem.Size = new Size(180, 22);
|
forceMonospaceToolStripMenuItem.Size = new Size(176, 22);
|
||||||
forceMonospaceToolStripMenuItem.Text = "(Force) Monospace";
|
forceMonospaceToolStripMenuItem.Text = "(Force) Monospace";
|
||||||
forceMonospaceToolStripMenuItem.Click += forceMonospaceToolStripMenuItem_Click;
|
forceMonospaceToolStripMenuItem.Click += forceMonospaceToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
|
@ -151,7 +150,6 @@
|
||||||
// groupBox4
|
// groupBox4
|
||||||
//
|
//
|
||||||
groupBox4.Controls.Add(progressBar1);
|
groupBox4.Controls.Add(progressBar1);
|
||||||
groupBox4.Controls.Add(chromiumWebBrowser1);
|
|
||||||
groupBox4.Controls.Add(button4);
|
groupBox4.Controls.Add(button4);
|
||||||
groupBox4.Dock = DockStyle.Fill;
|
groupBox4.Dock = DockStyle.Fill;
|
||||||
groupBox4.Location = new Point(0, 91);
|
groupBox4.Location = new Point(0, 91);
|
||||||
|
@ -168,19 +166,8 @@
|
||||||
progressBar1.Location = new Point(3, 42);
|
progressBar1.Location = new Point(3, 42);
|
||||||
progressBar1.Name = "progressBar1";
|
progressBar1.Name = "progressBar1";
|
||||||
progressBar1.Size = new Size(794, 5);
|
progressBar1.Size = new Size(794, 5);
|
||||||
progressBar1.Style = ProgressBarStyle.Marquee;
|
|
||||||
progressBar1.TabIndex = 2;
|
progressBar1.TabIndex = 2;
|
||||||
//
|
//
|
||||||
// chromiumWebBrowser1
|
|
||||||
//
|
|
||||||
chromiumWebBrowser1.ActivateBrowserOnCreation = false;
|
|
||||||
chromiumWebBrowser1.Dock = DockStyle.Fill;
|
|
||||||
chromiumWebBrowser1.Location = new Point(3, 42);
|
|
||||||
chromiumWebBrowser1.Name = "chromiumWebBrowser1";
|
|
||||||
chromiumWebBrowser1.Size = new Size(794, 333);
|
|
||||||
chromiumWebBrowser1.TabIndex = 0;
|
|
||||||
chromiumWebBrowser1.LoadingStateChanged += chromiumWebBrowser1_LoadingStateChanged;
|
|
||||||
//
|
|
||||||
// button4
|
// button4
|
||||||
//
|
//
|
||||||
button4.Dock = DockStyle.Top;
|
button4.Dock = DockStyle.Top;
|
||||||
|
@ -275,7 +262,6 @@
|
||||||
private SaveFileDialog Saver;
|
private SaveFileDialog Saver;
|
||||||
private GroupBox groupBox4;
|
private GroupBox groupBox4;
|
||||||
private Button button3;
|
private Button button3;
|
||||||
private CefSharp.WinForms.ChromiumWebBrowser chromiumWebBrowser1;
|
|
||||||
private Button button4;
|
private Button button4;
|
||||||
private ToolStripMenuItem renderToolStripMenuItem;
|
private ToolStripMenuItem renderToolStripMenuItem;
|
||||||
private ToolStripMenuItem fontFamilyToolStripMenuItem;
|
private ToolStripMenuItem fontFamilyToolStripMenuItem;
|
||||||
|
|
71
Form1.cs
71
Form1.cs
|
@ -5,6 +5,8 @@ namespace MintHTML
|
||||||
{
|
{
|
||||||
public partial class Form1 : Form
|
public partial class Form1 : Form
|
||||||
{
|
{
|
||||||
|
ChromiumWebBrowser chromiumWebBrowser1;
|
||||||
|
string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
||||||
string markfile;
|
string markfile;
|
||||||
string htmlfile = "<h1>Welcome to MintHTML</h1><p>Open a markdown file and press \"Render preview\" to see the output here.</p>";
|
string htmlfile = "<h1>Welcome to MintHTML</h1><p>Open a markdown file and press \"Render preview\" to see the output here.</p>";
|
||||||
string csssuffix = @"
|
string csssuffix = @"
|
||||||
|
@ -25,15 +27,48 @@ border-width: 1px
|
||||||
string line;
|
string line;
|
||||||
while ((line = reader.ReadLine()) != null)
|
while ((line = reader.ReadLine()) != null)
|
||||||
{
|
{
|
||||||
|
// Header 1
|
||||||
if (line.Contains("# "))
|
if (line.Contains("# "))
|
||||||
{
|
{
|
||||||
line = "<h1>" + line[1..] + "</h1>";
|
line = "<h1>" + line[1..] + "</h1>";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// Header 2
|
||||||
|
else if (line.Contains("## "))
|
||||||
|
{
|
||||||
|
line = "<h2>" + line[1..] + "</h2>";
|
||||||
|
|
||||||
|
}
|
||||||
|
// Header 3
|
||||||
|
else if (line.Contains("### "))
|
||||||
|
{
|
||||||
|
line = "<h3>" + line[1..] + "</h3>";
|
||||||
|
|
||||||
|
}
|
||||||
|
// Header 4
|
||||||
|
else if (line.Contains("#### "))
|
||||||
|
{
|
||||||
|
line = "<h4>" + line[1..] + "</h4>";
|
||||||
|
|
||||||
|
}
|
||||||
|
// Header 5
|
||||||
|
else if (line.Contains("##### "))
|
||||||
|
{
|
||||||
|
line = "<h5>" + line[1..] + "</h5>";
|
||||||
|
|
||||||
|
}
|
||||||
|
// Header 6
|
||||||
|
else if (line.Contains("###### "))
|
||||||
|
{
|
||||||
|
line = "<h6>" + line[1..] + "</h6>";
|
||||||
|
|
||||||
|
}
|
||||||
|
// Code block
|
||||||
else if (line.Contains("`"))
|
else if (line.Contains("`"))
|
||||||
{
|
{
|
||||||
line = "<div>" + line[1..^1] + "</div>";
|
line = "<div>" + line[1..^1] + "</div>";
|
||||||
}
|
}
|
||||||
|
// Everything else (Possibly paragraph or HTML code)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
line = line + "<br>";
|
line = line + "<br>";
|
||||||
|
@ -43,9 +78,39 @@ border-width: 1px
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Custom functions end
|
// Custom functions end
|
||||||
|
|
||||||
public Form1()
|
public Form1()
|
||||||
{
|
{
|
||||||
|
if (File.Exists(appdata + "/SweeZero/MintHTML/RootCache/lockfile"))
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("There is another instance of MintHTML running. If there isn't, press Yes to try opening anyways.","Cef Warning",MessageBoxButtons.YesNo,MessageBoxIcon.Warning) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File.Delete(appdata + "/SweeZero/MintHTML/RootCache/lockfile");
|
||||||
|
} catch (Exception ex) {
|
||||||
|
MessageBox.Show(ex.Message, "Cef Error (fatal)", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var settings = new CefSettings()
|
||||||
|
{
|
||||||
|
RootCachePath = appdata + "/SweeZero/MintHTML/RootCache",
|
||||||
|
LogFile = appdata + "/SweeZero/MintHTML/CefSharp.log",
|
||||||
|
LogSeverity = LogSeverity.Default
|
||||||
|
};
|
||||||
|
Cef.Initialize(settings);
|
||||||
|
chromiumWebBrowser1 = new ChromiumWebBrowser();
|
||||||
|
chromiumWebBrowser1.LoadingStateChanged += chromiumWebBrowser1_LoadingStateChanged;
|
||||||
|
chromiumWebBrowser1.Dock = DockStyle.Fill;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
groupBox4.Controls.Add(chromiumWebBrowser1);
|
||||||
|
chromiumWebBrowser1.BringToFront();
|
||||||
|
css = @"<style>
|
||||||
|
html{
|
||||||
|
font-family: sans-serif
|
||||||
|
}" + csssuffix;
|
||||||
|
chromiumWebBrowser1.LoadHtml(css + htmlfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
|
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
@ -67,11 +132,6 @@ border-width: 1px
|
||||||
|
|
||||||
private void Form1_Load(object sender, EventArgs e)
|
private void Form1_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
css = @"<style>
|
|
||||||
html{
|
|
||||||
font-family: sans-serif
|
|
||||||
}" + csssuffix;
|
|
||||||
chromiumWebBrowser1.LoadHtml(css + htmlfile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void button3_Click(object sender, EventArgs e)
|
private void button3_Click(object sender, EventArgs e)
|
||||||
|
@ -101,6 +161,7 @@ font-family: sans-serif
|
||||||
private void chromiumWebBrowser1_LoadingStateChanged(object sender, LoadingStateChangedEventArgs e)
|
private void chromiumWebBrowser1_LoadingStateChanged(object sender, LoadingStateChangedEventArgs e)
|
||||||
{
|
{
|
||||||
this.Invoke(new Action(() => progressBar1.Visible = chromiumWebBrowser1.IsLoading));
|
this.Invoke(new Action(() => progressBar1.Visible = chromiumWebBrowser1.IsLoading));
|
||||||
|
this.Invoke(new Action(() => progressBar1.Style = ProgressBarStyle.Marquee));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openDevToolsToolStripMenuItem_Click_1(object sender, EventArgs e)
|
private void openDevToolsToolStripMenuItem_Click_1(object sender, EventArgs e)
|
||||||
|
|
Loading…
Reference in a new issue