Browse Source

Part of #234: Keyboard shortcuts now working in XmlEditor's tree view.

pull/516/head
Andreas Weizel 11 years ago
parent
commit
fc284a5d16
  1. 17
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlTreeViewContainerControl.cs
  2. 52
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlTreeViewControl.cs

17
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlTreeViewContainerControl.cs

@ -667,11 +667,20 @@ namespace ICSharpCode.XmlEditor @@ -667,11 +667,20 @@ namespace ICSharpCode.XmlEditor
}
/// <summary>
/// Deletes the selected node.
/// Handles a keyboard press event in tree view.
/// </summary>
protected void XmlElementTreeViewDeleteKeyPressed(object source, EventArgs e)
protected void XmlElementTreeViewKeyPressed(object source, XmlTreeViewKeyPressedEventArgs e)
{
Delete();
if (e.KeyData == Keys.Delete)
Delete();
else if (e.KeyData == (Keys.Control | Keys.C))
Copy();
else if (e.KeyData == (Keys.Control | Keys.X))
Cut();
else if (e.KeyData == (Keys.Control | Keys.V))
Paste();
else if (e.KeyData == (Keys.Control | Keys.A))
SelectAll();
}
#region Forms Designer generated code
@ -738,7 +747,7 @@ namespace ICSharpCode.XmlEditor @@ -738,7 +747,7 @@ namespace ICSharpCode.XmlEditor
this.xmlElementTreeView.Size = new System.Drawing.Size(185, 326);
this.xmlElementTreeView.TabIndex = 0;
this.xmlElementTreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.XmlElementTreeViewAfterSelect);
this.xmlElementTreeView.DeleteKeyPressed += new System.EventHandler(this.XmlElementTreeViewDeleteKeyPressed);
this.xmlElementTreeView.TreeViewKeyPressed += this.XmlElementTreeViewKeyPressed;
//
// attributesGrid
//

52
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlTreeViewControl.cs

@ -26,13 +26,27 @@ using ICSharpCode.SharpDevelop.Gui; @@ -26,13 +26,27 @@ using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.XmlEditor
{
public class XmlTreeViewKeyPressedEventArgs : EventArgs
{
public XmlTreeViewKeyPressedEventArgs(Keys keyData)
{
KeyData = keyData;
}
public Keys KeyData
{
get;
private set;
}
}
/// <summary>
/// Displays a tree of XML elements. This is a separate control so it can
/// be unit tested. It has no SharpDevelop specific parts, for example,
/// the context menus are defined in the XmlTreeViewContainerControl.
/// </summary>
public class XmlTreeViewControl : ExtTreeView
{
{
const string ViewStatePropertyName = "XmlTreeViewControl.ViewState";
XmlDocument document;
@ -43,9 +57,9 @@ namespace ICSharpCode.XmlEditor @@ -43,9 +57,9 @@ namespace ICSharpCode.XmlEditor
}
/// <summary>
/// Raised when the delete key is pressed.
/// Raised when some key in tree view is pressed.
/// </summary>
public event EventHandler DeleteKeyPressed;
public event EventHandler<XmlTreeViewKeyPressedEventArgs> TreeViewKeyPressed;
public XmlTreeViewControl()
{
@ -98,7 +112,7 @@ namespace ICSharpCode.XmlEditor @@ -98,7 +112,7 @@ namespace ICSharpCode.XmlEditor
/// Gets the selected text node in the tree.
/// </summary>
public XmlText SelectedTextNode {
get {
get {
XmlTextTreeNode xmlTextTreeNode = SelectedNode as XmlTextTreeNode;
if (xmlTextTreeNode != null) {
return xmlTextTreeNode.XmlText;
@ -106,12 +120,12 @@ namespace ICSharpCode.XmlEditor @@ -106,12 +120,12 @@ namespace ICSharpCode.XmlEditor
return null;
}
}
/// <summary>
/// Gets the selected comment node in the tree.
/// </summary>
public XmlComment SelectedComment {
get {
get {
XmlCommentTreeNode commentTreeNode = SelectedNode as XmlCommentTreeNode;
if (commentTreeNode != null) {
return commentTreeNode.XmlComment;
@ -230,7 +244,7 @@ namespace ICSharpCode.XmlEditor @@ -230,7 +244,7 @@ namespace ICSharpCode.XmlEditor
}
/// <summary>
/// Updates the corresponding tree node's text based on
/// Updates the corresponding tree node's text based on
/// the textNode's value.
/// </summary>
public void UpdateTextNode(XmlText textNode)
@ -240,9 +254,9 @@ namespace ICSharpCode.XmlEditor @@ -240,9 +254,9 @@ namespace ICSharpCode.XmlEditor
node.Update();
}
}
/// <summary>
/// Updates the corresponding tree node's text based on
/// Updates the corresponding tree node's text based on
/// the comment's value.
/// </summary>
public void UpdateComment(XmlComment comment)
@ -314,7 +328,7 @@ namespace ICSharpCode.XmlEditor @@ -314,7 +328,7 @@ namespace ICSharpCode.XmlEditor
}
/// <summary>
/// If no node is selected after a mouse click then we make
/// If no node is selected after a mouse click then we make
/// sure the AfterSelect event is fired. Standard behaviour is
/// for the AfterSelect event not to be fired when the user
/// deselects all tree nodes.
@ -332,8 +346,8 @@ namespace ICSharpCode.XmlEditor @@ -332,8 +346,8 @@ namespace ICSharpCode.XmlEditor
/// </summary>
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Delete && DeleteKeyPressed != null) {
DeleteKeyPressed(this, new EventArgs());
if (/*keyData == Keys.Delete && */TreeViewKeyPressed != null) {
TreeViewKeyPressed(this, new XmlTreeViewKeyPressedEventArgs(keyData));
}
return base.ProcessCmdKey(ref msg, keyData);
}
@ -370,7 +384,7 @@ namespace ICSharpCode.XmlEditor @@ -370,7 +384,7 @@ namespace ICSharpCode.XmlEditor
}
/// <summary>
/// Inserts a new element node either before or after the
/// Inserts a new element node either before or after the
/// currently selected element node.
/// </summary>
void InsertElement(XmlElement element, InsertionMode insertionMode)
@ -388,7 +402,7 @@ namespace ICSharpCode.XmlEditor @@ -388,7 +402,7 @@ namespace ICSharpCode.XmlEditor
}
/// <summary>
/// Inserts a new text node either before or after the
/// Inserts a new text node either before or after the
/// currently selected node.
/// </summary>
void InsertTextNode(XmlText textNode, InsertionMode insertionMode)
@ -406,7 +420,7 @@ namespace ICSharpCode.XmlEditor @@ -406,7 +420,7 @@ namespace ICSharpCode.XmlEditor
}
/// <summary>
/// Inserts a new comment node either before or after the
/// Inserts a new comment node either before or after the
/// currently selected node.
/// </summary>
void InsertComment(XmlComment comment, InsertionMode insertionMode)
@ -541,7 +555,7 @@ namespace ICSharpCode.XmlEditor @@ -541,7 +555,7 @@ namespace ICSharpCode.XmlEditor
}
/// <summary>
/// Shows the corresponding tree node with the ghosted image
/// Shows the corresponding tree node with the ghosted image
/// that indicates it is being cut.
/// </summary>
void ShowCutElement(XmlElement element, bool showGhostImage)
@ -551,7 +565,7 @@ namespace ICSharpCode.XmlEditor @@ -551,7 +565,7 @@ namespace ICSharpCode.XmlEditor
}
/// <summary>
/// Shows the corresponding tree node with the ghosted image
/// Shows the corresponding tree node with the ghosted image
/// that indicates it is being cut.
/// </summary>
void ShowCutTextNode(XmlText textNode, bool showGhostImage)
@ -559,9 +573,9 @@ namespace ICSharpCode.XmlEditor @@ -559,9 +573,9 @@ namespace ICSharpCode.XmlEditor
XmlTextTreeNode node = FindTextNode(textNode);
node.ShowGhostImage = showGhostImage;
}
/// <summary>
/// Shows the corresponding tree node with the ghosted image
/// Shows the corresponding tree node with the ghosted image
/// that indicates it is being cut.
/// </summary>
void ShowCutComment(XmlComment comment, bool showGhostImage)

Loading…
Cancel
Save