-
Notifications
You must be signed in to change notification settings - Fork 0
/
Preview.cs
118 lines (101 loc) · 3.89 KB
/
Preview.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using Awesomium.Core;
using Awesomium.Windows.Forms;
namespace Luminate
{
public partial class Preview : DockContent
{
private WebControl mControl;
public Preview()
{
InitializeComponent();
mControl = new WebControl();
Controls.Add(mControl);
mControl.Dock = DockStyle.Fill;
mControl.JSConsoleMessageAdded += new JSConsoleMessageAddedEventHandler(OnJSError);
mControl.BeginNavigation += new BeginNavigationEventHandler(OnNavigating);
mControl.BeginLoading += new BeginLoadingEventHandler(OnBeginLoading);
mControl.DomReady += new EventHandler(OnDomReady);
this.Resize += new EventHandler(OnWindowResized);
TabPageContextMenuStrip = contextMenuStrip;
}
/// <summary>
/// When the window resizes move the logo around
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void OnWindowResized(object sender, EventArgs e)
{
luminateLogo.Location = new Point(Width / 2 - luminateLogo.Width / 2, Height / 2 - luminateLogo.Height / 2);
luminateLogo.BackColor = Color.FromArgb(255, 255, 255);
}
void OnDomReady(object sender, EventArgs e) { TabText = "Preview - Dom Ready"; }
void OnBeginLoading(object sender, BeginLoadingEventArgs e)
{
if (mControl.TargetURL == "" || mControl.TargetURL == null )
TabText = "Preview";
else
TabText = "Preview - Loading...";
}
/// <summary>
/// Closes the form
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnCloseClick(object sender, EventArgs e)
{
this.Hide();
}
/// <summary>
/// Removes all the files from the panel
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnCloseAllClick(object sender, EventArgs e)
{
Luminate.Singleton.RemoveAll("");
this.Hide();
}
void OnNavigating(object sender, BeginNavigationEventArgs e) { TabText = "Preview - Navigating to URL..."; }
/// <summary>
/// When we receive a javascript error we print it
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void OnJSError(object sender, JSConsoleMessageEventArgs e)
{
Logger.Singleton.Log("Javascript Error: " + e.Message + " on line " + e.LineNumber + ". " + e.Source, Logger.MessageType.ERROR, new string[]{ e.Source, e.LineNumber.ToString() } );
}
/// <summary>
/// This is a small fix to make sure the doc is saved before it closes
/// </summary>
/// <param name="e"></param>
protected override void OnFormClosing(FormClosingEventArgs e)
{
e.Cancel = true; e.Cancel = true;
Hide();
base.OnFormClosing(e);
}
/// <summary>
/// Try to load a given URL for a project
/// </summary>
/// <param name="url"></param>
public void LoadURL(string url)
{
if (luminateLogo.Parent != null)
luminateLogo.Parent.Controls.Remove(luminateLogo);
if (Visible && mControl.IsLive)
mControl.Source = new Uri(url);
else
TabText = "Preview - Not Live.";
}
}
}