Browse Source

Currently selected xpath query result list item is highlighted in the XML editor. Fixed FileNotFound exception when running xpath queries on XMLSchema.xsd. Fixed exception that could occur when scrolling to the selected node when the XML had been removed.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1690 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Matt Ward 19 years ago
parent
commit
019487d8c2
  1. 31
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XPathQueryControl.cs
  2. 4
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlView.cs

31
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XPathQueryControl.cs

@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.TextEditor;
using ICSharpCode.TextEditor.Document;
using System;
using System.Drawing;
@ -303,6 +304,7 @@ namespace ICSharpCode.XmlEditor @@ -303,6 +304,7 @@ namespace ICSharpCode.XmlEditor
this.xPathResultsListView.View = System.Windows.Forms.View.Details;
this.xPathResultsListView.ItemActivate += new System.EventHandler(this.XPathResultsListViewItemActivate);
this.xPathResultsListView.SelectedIndexChanged += new System.EventHandler(this.XPathResultsListViewSelectedIndexChanged);
this.xPathResultsListView.Click += new System.EventHandler(this.XPathResultsListViewClick);
//
// matchColumnHeader
//
@ -544,7 +546,7 @@ namespace ICSharpCode.XmlEditor @@ -544,7 +546,7 @@ namespace ICSharpCode.XmlEditor
if (moveCaret == MoveCaret.ByJumping) {
JumpTo(fileName, node.LineNumber, node.LinePosition);
} else {
ScrollTo(fileName, node.LineNumber, node.LinePosition);
ScrollTo(fileName, node.LineNumber, node.LinePosition, node.Value.Length);
}
}
@ -564,14 +566,32 @@ namespace ICSharpCode.XmlEditor @@ -564,14 +566,32 @@ namespace ICSharpCode.XmlEditor
FileService.JumpToFilePosition(fileName, line, column);
}
void ScrollTo(string fileName, int line, int column)
/// <summary>
/// Scrolls to the specified line and column and also selects the given
/// length of text at this location.
/// </summary>
void ScrollTo(string fileName, int line, int column, int length)
{
XmlView view = XmlView.ActiveXmlView;
if (view != null && IsFileNameMatch(view)) {
view.TextEditorControl.ActiveTextAreaControl.ScrollTo(line, column);
TextAreaControl textAreaControl = view.TextEditorControl.ActiveTextAreaControl;
if (length > 0 && line < textAreaControl.Document.TotalNumberOfLines) {
SelectionManager selectionManager = textAreaControl.SelectionManager;
selectionManager.ClearSelection();
Point startPos = new Point(column, line);
Point endPos = new Point(column + length, line);
selectionManager.SetSelection(startPos, endPos);
}
line = Math.Min(line, textAreaControl.Document.TotalNumberOfLines - 1);
textAreaControl.ScrollTo(line, column);
}
}
void ScrollTo(string fileName, int line, int column)
{
ScrollTo(fileName, line, column, 0);
}
/// <summary>
/// Tests whether the specified view matches the filename the XPath
/// results were found in.
@ -655,5 +675,10 @@ namespace ICSharpCode.XmlEditor @@ -655,5 +675,10 @@ namespace ICSharpCode.XmlEditor
{
ScrollToResultLocation();
}
void XPathResultsListViewClick(object sender, EventArgs e)
{
ScrollToResultLocation();
}
}
}

4
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlView.cs

@ -150,7 +150,9 @@ namespace ICSharpCode.XmlEditor @@ -150,7 +150,9 @@ namespace ICSharpCode.XmlEditor
/// and line position information aswell as the node found.</returns>
public static XPathNodeMatch[] SelectNodes(string xml, string xpath, ReadOnlyCollection<XmlNamespace> namespaces)
{
XPathDocument doc = new XPathDocument(new StringReader(xml));
XmlTextReader xmlReader = new XmlTextReader(new StringReader(xml));
xmlReader.XmlResolver = null;
XPathDocument doc = new XPathDocument(xmlReader);
XPathNavigator navigator = doc.CreateNavigator();
// Add namespaces.

Loading…
Cancel
Save