forked from ArduPilot/MissionPlanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapInfoDockPanel.cs
80 lines (72 loc) · 2.51 KB
/
MapInfoDockPanel.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
using System.Text;
using System.Windows.Forms;
using AltitudeAngelWings.ApiClient.Client;
using AltitudeAngelWings.Plugin.Properties;
using AltitudeAngelWings.Service;
namespace AltitudeAngelWings.Plugin
{
public class MapInfoDockPanel : IMapInfoDockPanel
{
private const string MapInfoDockPanelName = "###MapInfoDockPanel###";
private readonly Control _parent;
private readonly IUiThreadInvoke _uiThreadInvoke;
public MapInfoDockPanel(Control parent, IUiThreadInvoke uiThreadInvoke)
{
_parent = parent;
_uiThreadInvoke = uiThreadInvoke;
}
public void Show(FeatureProperties[] featureProperties)
{
if (featureProperties.Length == 0)
{
Hide();
return;
}
var builder = new StringBuilder();
foreach (var featureProperty in featureProperties)
{
builder.Append(featureProperty.FormatAsHtml());
}
_uiThreadInvoke.FireAndForget(() =>
{
_parent.SuspendLayout();
var browser = GetOrAddWebBrowser();
browser.BringToFront();
browser.DocumentText = Resources.MapInfoDockPanel.Replace(
MapInfoDockPanelName,
builder.ToString());
browser.Visible = true;
_parent.ResumeLayout();
});
}
public void Hide()
{
_uiThreadInvoke.FireAndForget(() =>
{
_parent.SuspendLayout();
GetOrAddWebBrowser().Visible = false;
_parent.ResumeLayout();
});
}
private WebBrowser GetOrAddWebBrowser()
{
if (_parent.Controls.ContainsKey(MapInfoDockPanelName))
{
return (WebBrowser)_parent.Controls[MapInfoDockPanelName];
}
var browser = new WebBrowser
{
Name = MapInfoDockPanelName,
Dock = DockStyle.Right,
WebBrowserShortcutsEnabled = false,
AllowWebBrowserDrop = false,
IsWebBrowserContextMenuEnabled = false,
ScriptErrorsSuppressed = true,
Width = 350,
Visible = false
};
_parent.Controls.Add(browser);
return browser;
}
}
}