Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit fc284a5

Browse files
committed
Part of #234: Keyboard shortcuts now working in XmlEditor's tree view.
1 parent 3b9b2ac commit fc284a5

2 files changed

Lines changed: 46 additions & 23 deletions

File tree

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -667,11 +667,20 @@ protected virtual IAddXmlNodeDialog CreateAddAttributeDialog(string[] attributeN
667667
}
668668

669669
/// <summary>
670-
/// Deletes the selected node.
670+
/// Handles a keyboard press event in tree view.
671671
/// </summary>
672-
protected void XmlElementTreeViewDeleteKeyPressed(object source, EventArgs e)
672+
protected void XmlElementTreeViewKeyPressed(object source, XmlTreeViewKeyPressedEventArgs e)
673673
{
674-
Delete();
674+
if (e.KeyData == Keys.Delete)
675+
Delete();
676+
else if (e.KeyData == (Keys.Control | Keys.C))
677+
Copy();
678+
else if (e.KeyData == (Keys.Control | Keys.X))
679+
Cut();
680+
else if (e.KeyData == (Keys.Control | Keys.V))
681+
Paste();
682+
else if (e.KeyData == (Keys.Control | Keys.A))
683+
SelectAll();
675684
}
676685

677686
#region Forms Designer generated code
@@ -738,7 +747,7 @@ void InitializeComponent()
738747
this.xmlElementTreeView.Size = new System.Drawing.Size(185, 326);
739748
this.xmlElementTreeView.TabIndex = 0;
740749
this.xmlElementTreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.XmlElementTreeViewAfterSelect);
741-
this.xmlElementTreeView.DeleteKeyPressed += new System.EventHandler(this.XmlElementTreeViewDeleteKeyPressed);
750+
this.xmlElementTreeView.TreeViewKeyPressed += this.XmlElementTreeViewKeyPressed;
742751
//
743752
// attributesGrid
744753
//

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

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,27 @@
2626

2727
namespace ICSharpCode.XmlEditor
2828
{
29+
public class XmlTreeViewKeyPressedEventArgs : EventArgs
30+
{
31+
public XmlTreeViewKeyPressedEventArgs(Keys keyData)
32+
{
33+
KeyData = keyData;
34+
}
35+
36+
public Keys KeyData
37+
{
38+
get;
39+
private set;
40+
}
41+
}
42+
2943
/// <summary>
3044
/// Displays a tree of XML elements. This is a separate control so it can
3145
/// be unit tested. It has no SharpDevelop specific parts, for example,
3246
/// the context menus are defined in the XmlTreeViewContainerControl.
3347
/// </summary>
3448
public class XmlTreeViewControl : ExtTreeView
35-
{
49+
{
3650
const string ViewStatePropertyName = "XmlTreeViewControl.ViewState";
3751

3852
XmlDocument document;
@@ -43,9 +57,9 @@ enum InsertionMode {
4357
}
4458

4559
/// <summary>
46-
/// Raised when the delete key is pressed.
60+
/// Raised when some key in tree view is pressed.
4761
/// </summary>
48-
public event EventHandler DeleteKeyPressed;
62+
public event EventHandler<XmlTreeViewKeyPressedEventArgs> TreeViewKeyPressed;
4963

5064
public XmlTreeViewControl()
5165
{
@@ -98,20 +112,20 @@ public bool IsElementSelected {
98112
/// Gets the selected text node in the tree.
99113
/// </summary>
100114
public XmlText SelectedTextNode {
101-
get {
115+
get {
102116
XmlTextTreeNode xmlTextTreeNode = SelectedNode as XmlTextTreeNode;
103117
if (xmlTextTreeNode != null) {
104118
return xmlTextTreeNode.XmlText;
105119
}
106120
return null;
107121
}
108122
}
109-
123+
110124
/// <summary>
111125
/// Gets the selected comment node in the tree.
112126
/// </summary>
113127
public XmlComment SelectedComment {
114-
get {
128+
get {
115129
XmlCommentTreeNode commentTreeNode = SelectedNode as XmlCommentTreeNode;
116130
if (commentTreeNode != null) {
117131
return commentTreeNode.XmlComment;
@@ -230,7 +244,7 @@ public void InsertTextNodeAfter(XmlText textNode)
230244
}
231245

232246
/// <summary>
233-
/// Updates the corresponding tree node's text based on
247+
/// Updates the corresponding tree node's text based on
234248
/// the textNode's value.
235249
/// </summary>
236250
public void UpdateTextNode(XmlText textNode)
@@ -240,9 +254,9 @@ public void UpdateTextNode(XmlText textNode)
240254
node.Update();
241255
}
242256
}
243-
257+
244258
/// <summary>
245-
/// Updates the corresponding tree node's text based on
259+
/// Updates the corresponding tree node's text based on
246260
/// the comment's value.
247261
/// </summary>
248262
public void UpdateComment(XmlComment comment)
@@ -314,7 +328,7 @@ public void HideCut(XmlNode node)
314328
}
315329

316330
/// <summary>
317-
/// If no node is selected after a mouse click then we make
331+
/// If no node is selected after a mouse click then we make
318332
/// sure the AfterSelect event is fired. Standard behaviour is
319333
/// for the AfterSelect event not to be fired when the user
320334
/// deselects all tree nodes.
@@ -332,8 +346,8 @@ protected override void OnMouseDown(MouseEventArgs e)
332346
/// </summary>
333347
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
334348
{
335-
if (keyData == Keys.Delete && DeleteKeyPressed != null) {
336-
DeleteKeyPressed(this, new EventArgs());
349+
if (/*keyData == Keys.Delete && */TreeViewKeyPressed != null) {
350+
TreeViewKeyPressed(this, new XmlTreeViewKeyPressedEventArgs(keyData));
337351
}
338352
return base.ProcessCmdKey(ref msg, keyData);
339353
}
@@ -370,7 +384,7 @@ XmlElementTreeNode SelectedElementNode {
370384
}
371385

372386
/// <summary>
373-
/// Inserts a new element node either before or after the
387+
/// Inserts a new element node either before or after the
374388
/// currently selected element node.
375389
/// </summary>
376390
void InsertElement(XmlElement element, InsertionMode insertionMode)
@@ -388,7 +402,7 @@ void InsertElement(XmlElement element, InsertionMode insertionMode)
388402
}
389403

390404
/// <summary>
391-
/// Inserts a new text node either before or after the
405+
/// Inserts a new text node either before or after the
392406
/// currently selected node.
393407
/// </summary>
394408
void InsertTextNode(XmlText textNode, InsertionMode insertionMode)
@@ -406,7 +420,7 @@ void InsertTextNode(XmlText textNode, InsertionMode insertionMode)
406420
}
407421

408422
/// <summary>
409-
/// Inserts a new comment node either before or after the
423+
/// Inserts a new comment node either before or after the
410424
/// currently selected node.
411425
/// </summary>
412426
void InsertComment(XmlComment comment, InsertionMode insertionMode)
@@ -541,7 +555,7 @@ XmlCommentTreeNode FindComment(XmlComment comment)
541555
}
542556

543557
/// <summary>
544-
/// Shows the corresponding tree node with the ghosted image
558+
/// Shows the corresponding tree node with the ghosted image
545559
/// that indicates it is being cut.
546560
/// </summary>
547561
void ShowCutElement(XmlElement element, bool showGhostImage)
@@ -551,17 +565,17 @@ void ShowCutElement(XmlElement element, bool showGhostImage)
551565
}
552566

553567
/// <summary>
554-
/// Shows the corresponding tree node with the ghosted image
568+
/// Shows the corresponding tree node with the ghosted image
555569
/// that indicates it is being cut.
556570
/// </summary>
557571
void ShowCutTextNode(XmlText textNode, bool showGhostImage)
558572
{
559573
XmlTextTreeNode node = FindTextNode(textNode);
560574
node.ShowGhostImage = showGhostImage;
561575
}
562-
576+
563577
/// <summary>
564-
/// Shows the corresponding tree node with the ghosted image
578+
/// Shows the corresponding tree node with the ghosted image
565579
/// that indicates it is being cut.
566580
/// </summary>
567581
void ShowCutComment(XmlComment comment, bool showGhostImage)

0 commit comments

Comments
 (0)