Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear text visualizer on right double-click #1487

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Bonsai.Design/ObjectTextVisualizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ public override void Load(IServiceProvider provider)
textBox.Multiline = true;
textBox.WordWrap = false;
textBox.ScrollBars = RichTextBoxScrollBars.Horizontal;
textBox.MouseDoubleClick += (sender, e) =>
{
if (e.Button == MouseButtons.Right)
{
buffer.Clear();
textBox.Text = string.Empty;
textPanel.Invalidate();
}
};

textPanel = new UserControl();
textPanel.SuspendLayout();
Expand Down
34 changes: 34 additions & 0 deletions Bonsai.Design/RichTextLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,46 @@ namespace Bonsai.Design
{
internal class RichTextLabel : RichTextBox
{
const int WM_RBUTTONDOWN = 0x204;
const int WM_RBUTTONUP = 0x205;
const int WM_RBUTTONDBLCLK = 0x206;

public RichTextLabel()
{
ReadOnly = true;
TabStop = false;
SetStyle(ControlStyles.Selectable, false);
SetStyle(ControlStyles.UserMouse, true);
}

static MouseEventArgs CreateMouseEventArgs(MouseButtons button, int clicks = 1)
{
var mousePosition = MousePosition;
return new MouseEventArgs(
button,
clicks,
mousePosition.X,
mousePosition.Y,
delta: 0);
}

protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_RBUTTONDOWN:
OnMouseDown(CreateMouseEventArgs(MouseButtons.Right));
break;
case WM_RBUTTONUP:
OnMouseUp(CreateMouseEventArgs(MouseButtons.Right));
break;
case WM_RBUTTONDBLCLK:
OnMouseDoubleClick(CreateMouseEventArgs(MouseButtons.Right, clicks: 2));
break;
default:
base.WndProc(ref m);
break;
}
}
}
}