Skip to content

Commit 93850bf

Browse files
committed
Added ShowOnHotSpot method.
1 parent 08a5996 commit 93850bf

File tree

3 files changed

+97
-91
lines changed

3 files changed

+97
-91
lines changed

ReClass.NET/UI/HotSpotTextBox.cs

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,13 @@
11
using System;
22
using System.ComponentModel;
3+
using System.Drawing;
34
using System.Windows.Forms;
45

56
namespace ReClassNET.UI
67
{
78
public class HotSpotTextBox : TextBox
89
{
9-
private HotSpot hotSpot;
10-
11-
[Browsable(false)]
12-
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
13-
public HotSpot HotSpot
14-
{
15-
get => hotSpot;
16-
set
17-
{
18-
if (hotSpot != value)
19-
{
20-
hotSpot = value;
21-
22-
var rect = hotSpot.Rect;
23-
24-
SetBounds(rect.Left + 2, rect.Top, rect.Width, rect.Height);
25-
26-
minimumWidth = rect.Width;
27-
28-
Text = hotSpot.Text.Trim();
29-
}
30-
}
31-
}
10+
private HotSpot currentHotSpot;
3211

3312
private FontEx font;
3413
private int minimumWidth;
@@ -49,20 +28,24 @@ public HotSpot HotSpot
4928
}
5029
}
5130

52-
public event EventHandler Committed;
31+
public event HotSpotTextBoxCommitEventHandler Committed;
5332

5433
public HotSpotTextBox()
5534
{
5635
BorderStyle = BorderStyle.None;
5736
}
5837

38+
#region Events
39+
5940
protected override void OnVisibleChanged(EventArgs e)
6041
{
6142
base.OnVisibleChanged(e);
6243

6344
if (Visible)
6445
{
65-
if (HotSpot != null)
46+
BackColor = Program.Settings.BackgroundColor;
47+
48+
if (currentHotSpot != null)
6649
{
6750
Focus();
6851
Select(0, TextLength);
@@ -83,13 +66,6 @@ protected override void OnKeyDown(KeyEventArgs e)
8366
base.OnKeyDown(e);
8467
}
8568

86-
/*protected override void OnLeave(EventArgs e)
87-
{
88-
base.OnLeave(e);
89-
90-
OnCommit();
91-
}*/
92-
9369
protected override void OnTextChanged(EventArgs e)
9470
{
9571
base.OnTextChanged(e);
@@ -105,9 +81,49 @@ private void OnCommit()
10581
{
10682
Visible = false;
10783

108-
hotSpot.Text = Text.Trim();
84+
currentHotSpot.Text = Text.Trim();
85+
86+
Committed?.Invoke(this, new HotSpotTextBoxCommitEventArgs(currentHotSpot));
87+
}
10988

110-
Committed?.Invoke(this, EventArgs.Empty);
89+
#endregion
90+
91+
public void ShowOnHotSpot(HotSpot hotSpot)
92+
{
93+
currentHotSpot = hotSpot;
94+
95+
if (hotSpot == null)
96+
{
97+
Visible = false;
98+
99+
return;
100+
}
101+
102+
AlignToRect(hotSpot.Rect);
103+
104+
Text = hotSpot.Text.Trim();
105+
ReadOnly = hotSpot.Id == HotSpot.ReadOnlyId;
106+
107+
Visible = true;
108+
}
109+
110+
private void AlignToRect(Rectangle rect)
111+
{
112+
SetBounds(rect.Left + 2, rect.Top, rect.Width, rect.Height);
113+
114+
minimumWidth = rect.Width;
115+
}
116+
}
117+
118+
public delegate void HotSpotTextBoxCommitEventHandler(object sender, HotSpotTextBoxCommitEventArgs e);
119+
120+
public class HotSpotTextBoxCommitEventArgs : EventArgs
121+
{
122+
public HotSpot HotSpot { get; set; }
123+
124+
public HotSpotTextBoxCommitEventArgs(HotSpot hotSpot)
125+
{
126+
HotSpot = hotSpot;
111127
}
112128
}
113129
}

ReClass.NET/UI/MemoryViewControl.Designer.cs

Lines changed: 36 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ReClass.NET/UI/MemoryViewControl.cs

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public MemoryViewControl()
8282

8383
font = Program.MonoSpaceFont;
8484

85-
editBox.Font = font;
85+
hotSpotEditBox.Font = font;
8686

8787
memoryPreviewPopUp = new MemoryPreviewPopUp(font);
8888
}
@@ -166,6 +166,8 @@ protected override void OnMouseClick(MouseEventArgs e)
166166
{
167167
Contract.Requires(e != null);
168168

169+
hotSpotEditBox.Hide();
170+
169171
var invalidate = false;
170172

171173
foreach (var hotSpot in hotSpots)
@@ -316,8 +318,6 @@ protected override void OnMouseClick(MouseEventArgs e)
316318
}
317319
}
318320

319-
editBox.Visible = false;
320-
321321
if (invalidate)
322322
{
323323
Invalidate();
@@ -330,7 +330,7 @@ protected override void OnMouseDoubleClick(MouseEventArgs e)
330330
{
331331
Contract.Requires(e != null);
332332

333-
editBox.Visible = false;
333+
hotSpotEditBox.Hide();
334334

335335
var invalidate = false;
336336

@@ -354,7 +354,7 @@ protected override void OnMouseDoubleClick(MouseEventArgs e)
354354
}
355355
if (hotSpot.Type == HotSpotType.Edit)
356356
{
357-
ShowNodeNameEditBox(hotSpot);
357+
hotSpotEditBox.ShowOnHotSpot(hotSpot);
358358

359359
break;
360360
}
@@ -441,7 +441,7 @@ protected override void OnMouseMove(MouseEventArgs e)
441441

442442
protected override void OnMouseWheel(MouseEventArgs e)
443443
{
444-
editBox.Visible = false;
444+
hotSpotEditBox.Hide();
445445

446446
if (memoryPreviewPopUp.Visible)
447447
{
@@ -455,7 +455,7 @@ protected override void OnMouseWheel(MouseEventArgs e)
455455

456456
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
457457
{
458-
if (editBox.Visible == false) // Only process keys if the edit field is not visible.
458+
if (hotSpotEditBox.Visible == false) // Only process keys if the edit field is not visible.
459459
{
460460
var key = keyData & Keys.KeyCode;
461461
var modifier = keyData & Keys.Modifiers;
@@ -602,11 +602,9 @@ private void repaintTimer_Tick(object sender, EventArgs e)
602602
Invalidate(false);
603603
}
604604

605-
private void editBox_Committed(object sender, EventArgs e)
605+
private void editBox_Committed(object sender, HotSpotTextBoxCommitEventArgs e)
606606
{
607-
var hotspotTextBox = sender as HotSpotTextBox;
608-
609-
var hotSpot = hotspotTextBox?.HotSpot;
607+
var hotSpot = e.HotSpot;
610608
if (hotSpot != null)
611609
{
612610
try
@@ -673,18 +671,10 @@ public void ShowNodeNameEditBox(BaseNode node)
673671
.FirstOrDefault(s => s.Node == node && s.Type == HotSpotType.Edit && s.Id == HotSpot.NameId);
674672
if (hotSpot != null)
675673
{
676-
ShowNodeNameEditBox(hotSpot);
674+
hotSpotEditBox.ShowOnHotSpot(hotSpot);
677675
}
678676
}
679677

680-
private void ShowNodeNameEditBox(HotSpot hotSpot)
681-
{
682-
editBox.BackColor = Program.Settings.SelectedColor;
683-
editBox.HotSpot = hotSpot;
684-
editBox.Visible = true;
685-
editBox.ReadOnly = hotSpot.Id == HotSpot.ReadOnlyId;
686-
}
687-
688678
/// <summary>
689679
/// Resets the selection state of all selected nodes.
690680
/// </summary>
@@ -708,7 +698,7 @@ public void Reset()
708698
{
709699
ClearSelection();
710700

711-
editBox.Visible = false;
701+
hotSpotEditBox.Hide();
712702

713703
VerticalScroll.Value = VerticalScroll.Minimum;
714704
}

0 commit comments

Comments
 (0)