Browse Source

Add AllowLabelEdit to DynamicListItem. Improve drawing of '+' sign.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@684 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
e8c8159477
  1. 49
      src/Main/Base/Project/Src/Gui/TreeGrid/DynamicListItem.cs
  2. 36
      src/Main/Base/Project/Src/Gui/TreeGrid/DynamicTreeRow.cs
  3. 1
      src/Main/Base/Project/Src/Gui/TreeGrid/ScrollButton.cs

49
src/Main/Base/Project/Src/Gui/TreeGrid/DynamicListItem.cs

@ -199,6 +199,7 @@ namespace ICSharpCode.SharpDevelop.Gui.TreeGrid @@ -199,6 +199,7 @@ namespace ICSharpCode.SharpDevelop.Gui.TreeGrid
{
if (Click != null)
Click(this, new DynamicListEventArgs(list));
HandleLabelEditClick(list);
}
public event EventHandler<DynamicListEventArgs> DoubleClick;
@ -266,6 +267,53 @@ namespace ICSharpCode.SharpDevelop.Gui.TreeGrid @@ -266,6 +267,53 @@ namespace ICSharpCode.SharpDevelop.Gui.TreeGrid
}
#endregion
#region Label editing
bool allowLabelEdit;
public bool AllowLabelEdit {
get {
return allowLabelEdit;
}
set {
allowLabelEdit = value;
}
}
public event EventHandler<DynamicListEventArgs> BeginLabelEdit;
public event EventHandler<DynamicListEventArgs> FinishLabelEdit;
public event EventHandler<DynamicListEventArgs> CancelledLabelEdit;
void HandleLabelEditClick(DynamicList list)
{
if (!allowLabelEdit)
return;
if (BeginLabelEdit != null)
BeginLabelEdit(this, new DynamicListEventArgs(list));
TextBox txt = new TextBox();
txt.Text = this.Text;
AssignControlUntilFocusChange(txt);
bool escape = false;
txt.KeyDown += delegate(object sender2, KeyEventArgs e2) {
if (e2.KeyData == Keys.Enter || e2.KeyData == Keys.Escape) {
e2.Handled = true;
if (e2.KeyData == Keys.Escape) {
if (CancelledLabelEdit != null)
CancelledLabelEdit(this, new DynamicListEventArgs(list));
escape = true;
}
this.Control = null;
txt.Dispose();
}
};
txt.LostFocus += delegate {
if (!escape) {
this.Text = txt.Text;
if (FinishLabelEdit != null)
FinishLabelEdit(this, new DynamicListEventArgs(list));
}
};
}
/// <summary>
/// Display the control for this item. Automatically assign focus to the control
/// and removes+disposes the control when it looses focus.
@ -287,6 +335,7 @@ namespace ICSharpCode.SharpDevelop.Gui.TreeGrid @@ -287,6 +335,7 @@ namespace ICSharpCode.SharpDevelop.Gui.TreeGrid
};
this.Control = control;
}
#endregion
}
public class DynamicListEventArgs : EventArgs

36
src/Main/Base/Project/Src/Gui/TreeGrid/DynamicTreeRow.cs

@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace ICSharpCode.SharpDevelop.Gui.TreeGrid
@ -21,9 +22,6 @@ namespace ICSharpCode.SharpDevelop.Gui.TreeGrid @@ -21,9 +22,6 @@ namespace ICSharpCode.SharpDevelop.Gui.TreeGrid
public DynamicTreeRow()
{
plus = this[0];
plus.TextFormat = new StringFormat(plus.TextFormat);
plus.TextFormat.Alignment = StringAlignment.Center;
plus.TextFormat.LineAlignment = StringAlignment.Center;
ShowPlus = true;
}
@ -34,26 +32,52 @@ namespace ICSharpCode.SharpDevelop.Gui.TreeGrid @@ -34,26 +32,52 @@ namespace ICSharpCode.SharpDevelop.Gui.TreeGrid
return showPlus;
}
set {
if (showPlus == value)
return;
showPlus = value;
plus.HighlightBrush = showPlus ? Brushes.AliceBlue : null;
plus.Cursor = showPlus ? Cursors.Hand : null;
if (showPlus) {
plus.Click += OnPlusClick;
plus.Paint += OnPlusPaint;
plus.Text = "+";
} else {
plus.Click -= OnPlusClick;
plus.Paint -= OnPlusPaint;
plus.Text = "";
}
OnShowPlusChanged(EventArgs.Empty);
}
}
public event EventHandler ShowPlusChanged;
public virtual void OnShowPlusChanged(EventArgs e)
{
if (ShowPlusChanged != null) {
ShowPlusChanged(this, e);
}
}
static readonly Color PlusBorder = Color.FromArgb(120, 152, 181);
static readonly Color LightPlusBorder = Color.FromArgb(176, 194, 221);
protected virtual void OnPlusPaint(object sender, PaintEventArgs e)
{
Rectangle r = e.ClipRectangle;
r.Inflate(-4, -4);
e.Graphics.DrawRectangle(SystemPens.ControlDarkDark, r);
using (Brush b = new LinearGradientBrush(r, Color.White, Color.FromArgb(221, 218, 203), 66f)) {
e.Graphics.FillRectangle(b, r);
}
using (Pen p = new Pen(PlusBorder)) {
e.Graphics.DrawRectangle(p, r);
}
using (Brush b = new SolidBrush(LightPlusBorder)) {
e.Graphics.FillRectangle(b, new Rectangle(r.X, r.Y, 1, 1));
e.Graphics.FillRectangle(b, new Rectangle(r.Right, r.Y, 1, 1));
e.Graphics.FillRectangle(b, new Rectangle(r.X, r.Bottom, 1, 1));
e.Graphics.FillRectangle(b, new Rectangle(r.Right, r.Bottom, 1, 1));
}
e.Graphics.DrawLine(Pens.Black, r.Left + 2, r.Top + r.Height / 2, r.Right - 2, r.Top + r.Height / 2);
e.Graphics.DrawLine(Pens.Black, r.Left + r.Width / 2, r.Top + 2, r.Left + r.Width / 2, r.Bottom - 2);
}
public class ChildForm : Form

1
src/Main/Base/Project/Src/Gui/TreeGrid/ScrollButton.cs

@ -19,6 +19,7 @@ namespace ICSharpCode.SharpDevelop.Gui.TreeGrid @@ -19,6 +19,7 @@ namespace ICSharpCode.SharpDevelop.Gui.TreeGrid
this.BackColor = DynamicListColumn.DefaultBackColor;
this.TabStop = false;
this.SetStyle(ControlStyles.Selectable, false);
this.SetStyle(ControlStyles.ResizeRedraw, true);
}
protected override Size DefaultSize {

Loading…
Cancel
Save