/
ExternalScriptingObject.cs
129 lines (119 loc) · 4.29 KB
/
ExternalScriptingObject.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Web;
using System.Threading;
namespace ChiiTrans
{
[ComVisible(true)]
public class ExternalScriptingObject
{
public bool transparentMode = false;
private static bool welcomed = false;
public void UpdateBrowserSettings()
{
Global.RunScript("ApplySettings",
Global.options.font.FontFamily.Name,
Global.options.font.SizeInPoints,
Global.options.appendBottom,
Global.options.dropShadow,
Global.options.maxBlocks,
Global.options.largeMargins,
Global.options.marginSize
);
List<object> obj = new List<object>();
foreach (KeyValuePair<string, ColorRecord> kvp in Global.options.colors)
{
obj.Add(kvp.Key);
string clr = string.Format("#{0:X6}", kvp.Value.color.ToArgb() & 0xFFFFFF);
obj.Add(clr);
}
Global.RunScript2("ApplyColors", obj.ToArray());
if (transparentMode)
{
Global.RunScript("TransparentModeOn");
FormBottomLayer.instance.BackColor = Global.options.colors["back_tmode"].color;
}
else
{
Global.RunScript("TransparentModeOff");
}
if (!welcomed)
{
welcomed = true;
string appversion = System.Windows.Forms.Application.ProductVersion;
appversion = string.Join(".", appversion.Split('.').Take(2).ToArray());
Global.RunScript("Welcome", "ChiiTrans v." + appversion);
}
}
public void HivemindFastSubmit(string block_id, string block_name, string id, string src, string trans)
{
string url;
url = Global.options.hivemindServer;
url += (url.EndsWith("/") ? "" : "/");
StringBuilder q = new StringBuilder();
if (string.IsNullOrEmpty(id) || id == "0")
{
q.Append("src=" + Translation.UrlEncode(src));
}
else
{
q.Append("src_id=" + Translation.UrlEncode(id));
}
q.Append("&trans=" + Translation.UrlEncode(trans));
HivemindSubmit.RequestData req = new HivemindSubmit.RequestData();
req.query = q.ToString();
req.block_id = block_id;
req.block_name = block_name;
req.translation = trans;
Thread reqThread = new Thread(HivemindSubmit.instance.reqThreadProc);
reqThread.IsBackground = true;
reqThread.Start(req);
}
public void HivemindEdit(string block_id, string block_name, string id, string src)
{
string url;
url = Global.options.hivemindServer;
url += (url.EndsWith("/") ? "" : "/");
if (string.IsNullOrEmpty(id) || id == "0")
{
//url += "index.php?q=" + Translation.UrlEncode(src);
HivemindSubmit.instance.UpdateData(block_id, block_name, src);
HivemindSubmit.instance.Show();
HivemindSubmit.instance.Activate();
}
else
{
url += "index.php?p=view&id=" + id;
Process.Start(url);
}
}
public void LockHotkeys()
{
Global.lockHotkeys = true;
}
public void UnlockHotkeys()
{
Global.lockHotkeys = false;
}
public void ShowTooltip(string key, string reading, string text)
{
FormTooltip.instance.ShowTooltip(key, reading, text);
}
public void TooltipPage(int delta)
{
FormTooltip.instance.TooltipPage(delta);
}
public void HideTooltip()
{
FormTooltip.instance.Hide();
}
public void OnStartClick()
{
Form1.thisForm.buttonRun_Click(null, null);
}
}
}