-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAddLabel.cs
More file actions
208 lines (174 loc) · 6.75 KB
/
AddLabel.cs
File metadata and controls
208 lines (174 loc) · 6.75 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
using deskdecorator.DekstopEngine;
using deskdecorator.DekstopEngine.DesktopElements;
using System.Diagnostics;
using System.Windows.Forms;
using LabelAlias = deskdecorator.DekstopEngine.DesktopElements.Label;
namespace deskdecorator
{
public partial class AddLabel : Form
{
string _labelname = "";
string _labeltext = "";
bool _dynamic = false;
bool fromContext = false;
bool edit = false;
Font tmpFont = null!;
Form1 origin;
private LabelAlias? gEditLabel;
private LabelAlias? gLabel;
public AddLabel(Form1 origin_)
{
InitializeComponent();
origin = origin_;
checkTextInput(null!, null!);
}
public AddLabel(Form1 origin_, bool fromcont = false)
{
InitializeComponent();
origin = origin_;
fromContext = fromcont;
btn_SetPosition.Text = Language.Get("Create_here");
checkTextInput(null!, null!);
}
public AddLabel(string name, string txt, bool dynamic, LabelAlias lbl)
{
InitializeComponent();
_labelname = name;
_labeltext = txt;
_dynamic = dynamic;
gLabel = lbl;
textBox1.Text = _labelname;
richTextBox1.Text = _labeltext;
checkBox1.Checked = _dynamic;
this.Text = Language.Get("crlabel_editlabelversion") + $"'{_labelname}'";
tmpFont = lbl._label?.Font ?? new Font("Segoe UI", 12);
edit = true;
checkTextInput(null!, null!);
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(Language.Get("helptext"), Language.Get("Help"));
}
private void OnBtn_SetPosition(object sender, EventArgs e)
{
if (edit && gLabel != null)
{
gLabel.Description = textBox1.Text;
gLabel._text = richTextBox1.Text;
gLabel.Save();
gLabel._label!.Text = richTextBox1.Text;
StartMouseTracking(gLabel);
return;
}
if (fromContext)
{
tmpFont ??= new Font("Segoe UI", 12);
var newLabelx = new LabelAlias(textBox1.Text, richTextBox1.Text, checkBox1.Checked, tmpFont);
Invoke(() =>
{
newLabelx.CreateControl(Point.Empty);
Manager.Label_Add(newLabelx);
});
WindowState = FormWindowState.Minimized;
Hide();
StartMouseTracking(newLabelx);
return;
}
if (string.IsNullOrWhiteSpace(textBox1.Text) || string.IsNullOrWhiteSpace(richTextBox1.Text))
return;
if (Engine.ElementNameTable.Contains(textBox1.Text))
{
MessageBox.Show($"'{textBox1.Text}' " + Language.Get("crlabel_001"), Language.Get("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (textBox1.Text.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
{
MessageBox.Show(Language.Get("crlabel_002"), Language.Get("crlabel_invalidname"), MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
tmpFont ??= new Font("Segoe UI", 12);
var newLabel = new LabelAlias(textBox1.Text, richTextBox1.Text, checkBox1.Checked, tmpFont);
gEditLabel = newLabel;
Invoke(() =>
{
newLabel.CreateControl(Point.Empty);
Manager.Label_Add(newLabel);
});
tools.Utils.RefreshComboBox();
StartMouseTracking(newLabel);
}
private void StartMouseTracking(LabelAlias label)
{
Thread thread = new(() =>
{
Debug.WriteLine("[INFO] Mouse pointer thread started");
while (Engine.m_Running)
{
Point mousePos = Cursor.Position;
Invoke(() =>
{
if (label._label != null)
{
Point clientPos = Engine._form.PointToClient(mousePos);
label._label.Location = clientPos;
}
});
if (Control.MouseButtons == MouseButtons.Left)
{
Invoke(() =>
{
if (label._label != null)
{
label._text = richTextBox1.Text;
label.Description = textBox1.Text;
label._label.Text = richTextBox1.Text;
label.Position = label._label.Location;
label.Save();
if (!Engine.combox_EditItemSelector.Items.Contains(label.Description))
Engine.combox_EditItemSelector.Items.Add(label.Description);
Engine.combox_EditItemSelector.SelectedItem = label.Description;
Debug.WriteLine("[INFO] Mouse pointer thread finished.");
Dispose();
}
});
break;
}
Thread.Sleep(80);
}
});
thread.IsBackground = true;
thread.Start();
}
private void checkTextInput(object sender, EventArgs e)
{
bool hasText = !string.IsNullOrWhiteSpace(richTextBox1.Text) && !string.IsNullOrWhiteSpace(textBox1.Text);
btn_SetPosition.Enabled = hasText;
btn_SetPosition.BackColor = hasText ? Color.DarkGreen : Color.DarkRed;
}
private void fontDialog1_Apply(object sender, EventArgs e)
{
tmpFont = fontDialog1.Font;
}
private void AddLabel_KeyPress(object sender, KeyPressEventArgs e)
{
if (edit && e.KeyChar == (char)Keys.Escape && gEditLabel?._label != null)
{
gEditLabel._label.Hide();
Dispose(true);
Close();
}
}
private void btn_FontSettings_Click(object sender, EventArgs e)
{
if (fontDialog1.ShowDialog() == DialogResult.OK)
{
tmpFont = fontDialog1.Font;
if (gLabel != null)
{
gLabel.SetFont(tmpFont);
gLabel.Save();
}
}
}
}
}