/
MainWindow.xaml.cs
154 lines (131 loc) · 4.9 KB
/
MainWindow.xaml.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
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
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Threading;
using CefSharp.Example;
namespace CefSharp.Wpf.Example
{
public partial class MainWindow : Window, IExampleView
{
// file
public event EventHandler ShowDevToolsActivated;
public event EventHandler CloseDevToolsActivated;
public event EventHandler ExitActivated;
// edit
public event EventHandler UndoActivated;
public event EventHandler RedoActivated;
public event EventHandler CutActivated;
public event EventHandler CopyActivated;
public event EventHandler PasteActivated;
public event EventHandler DeleteActivated;
public event EventHandler SelectAllActivated;
// test
public event EventHandler TestResourceLoadActivated;
public event EventHandler TestSchemeLoadActivated;
public event EventHandler TestExecuteScriptActivated;
public event EventHandler TestEvaluateScriptActivated;
public event EventHandler TestBindActivated;
public event EventHandler TestConsoleMessageActivated;
public event EventHandler TestTooltipActivated;
public event EventHandler TestPopupActivated;
public event EventHandler TestLoadStringActivated;
public event EventHandler TestCookieVisitorActivated;
// navigation
public event Action<object, string> UrlActivated;
public event EventHandler BackActivated;
public event EventHandler ForwardActivated;
private IDictionary<object, EventHandler> handlers;
public MainWindow()
{
InitializeComponent();
var presenter = new ExamplePresenter(web_view, this,
invoke => Dispatcher.BeginInvoke(invoke));
handlers = new Dictionary<object, EventHandler>
{
// file
{ showDevToolsMenuItem, ShowDevToolsActivated},
{ closeDevToolsMenuItem, CloseDevToolsActivated},
{ exitMenuItem, ExitActivated },
// edit
{ undoMenuItem, UndoActivated },
{ redoMenuItem, RedoActivated },
{ cutMenuItem, CutActivated },
{ copyMenuItem, CopyActivated },
{ pasteMenuItem, PasteActivated },
{ deleteMenuItem, DeleteActivated },
{ selectAllMenuItem, SelectAllActivated },
// test
{ testResourceLoadMenuItem, TestResourceLoadActivated },
{ testSchemeLoadMenuItem, TestSchemeLoadActivated },
{ testExecuteScriptMenuItem, TestExecuteScriptActivated },
{ testEvaluateScriptMenuItem, TestEvaluateScriptActivated },
{ testBindMenuItem, TestBindActivated },
{ testConsoleMessageMenuItem, TestConsoleMessageActivated },
{ testTooltipMenuItem, TestTooltipActivated },
{ testPopupMenuItem, TestPopupActivated },
{ testLoadStringMenuItem, TestLoadStringActivated },
{ testCookieVisitorMenuItem, TestCookieVisitorActivated },
// navigation
{ backButton, BackActivated },
{ forwardButton, ForwardActivated },
};
}
public void SetTitle(string title)
{
Title = title;
}
public void SetAddress(string address)
{
urlTextBox.Text = address;
}
public void SetCanGoBack(bool can_go_back)
{
backButton.IsEnabled = can_go_back;
}
public void SetCanGoForward(bool can_go_forward)
{
forwardButton.IsEnabled = can_go_forward;
}
public void SetIsLoading(bool is_loading)
{
}
public void ExecuteScript(string script)
{
web_view.ExecuteScript(script);
}
public object EvaluateScript(string script)
{
return web_view.EvaluateScript(script);
}
public void DisplayOutput(string output)
{
outputLabel.Content = output;
}
private void control_Activated(object sender, RoutedEventArgs e)
{
EventHandler handler;
if (handlers.TryGetValue(sender, out handler) &&
handler != null)
{
handler(this, EventArgs.Empty);
}
}
private void urlTextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key != Key.Enter)
{
return;
}
var handler = UrlActivated;
if (handler != null)
{
handler(this, urlTextBox.Text);
}
}
}
}