Browse Source

- fixed Unit Tests

- fixed XPath Query Pad
- added documentation and AssemblyInfo.cs from old XmlEditor

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/XmlEditor@4198 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Siegfried Pammer 17 years ago
parent
commit
436413a26e
  1. 175
      src/AddIns/DisplayBindings/XmlEditor/Doc/notes.txt
  2. 50
      src/AddIns/DisplayBindings/XmlEditor/Doc/readme.txt
  3. 37
      src/AddIns/DisplayBindings/XmlEditor/Project/Configuration/AssemblyInfo.cs
  4. 6
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/AssignStylesheetCommand.cs
  5. 28
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/CodeCompletionPopupCommand.cs
  6. 8
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/CreateSchemaCommand.cs
  7. 6
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/FormatXmlCommand.cs
  8. 6
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/GoToSchemaDefinitionCommand.cs
  9. 6
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/OpenStylesheetCommand.cs
  10. 26
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/RunXslTransformCommand.cs
  11. 6
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/StylesheetAssignedCondition.cs
  12. 6
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/ValidateXmlCommand.cs
  13. 5
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XPathNodeTextMarker.cs
  14. 26
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XPathQueryControl.cs
  15. 15
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlTreeView.cs
  16. 8
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlView.cs
  17. 6
      src/AddIns/DisplayBindings/XmlEditor/Project/XmlEditor.addin
  18. 4
      src/AddIns/DisplayBindings/XmlEditor/Project/XmlEditor.csproj
  19. 18
      src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockTextMarker.cs
  20. 12
      src/Main/Base/Project/Src/TextEditor/Conditions/TextContentCondition.cs

175
src/AddIns/DisplayBindings/XmlEditor/Doc/notes.txt

@ -0,0 +1,175 @@
Xml Intellisense
----------------
In order to be able to provide intellisense for an xml document we need a schema. From the schema we can determine an element's attributes and its child elements. Without resorting to writing our own xml schema parser, can we retrieve this information from the schema?
XmlSchema class
---------------
The .Net framework provides us with the XmlSchema class. It provides us with two methods that of interest to us when reading rather than creating an xml schema.
1) Read - Reads an XML Schema definition language (XSD) schema.
2) Compile - Compiles the XML Schema definition language (XSD) Schema Object Model (SOM) into schema information for validation. Used to check the syntactic and semantic structure of the programmatically-built SOM. Semantic validation checking is performed during compilation.
Let us first look at the Read method and see what we can get from it.
The read method seems to do a first parse of the schema, the XmlSchema.Elements property is not populated, about the only thing that is populated is the Items property, which seems to be pretty much a mirror image of what is in the xsd file.
Quickstart sample from Microsoft
--------------------------------
XmlSchemaObjectModel sample
http://go.microsoft.com/fwlink/?linkid=3268&url=/quickstart/howto/doc/XML/XmlSchemaObjectModel.aspx
A sample provided by Microsoft adds two schemas to an XmlSchemaCollection, outputs the schema xsd based on what was read in, then generates an xml documentrepresentative of the read in schema.
XmlNameTable myXmlNameTable = new NameTable();
XmlSchemaCollection myXmlSchemaCollection = new XmlSchemaCollection(myXmlNameTable);
myXmlSchemaCollection.Add(null, "books.xsd");
myXmlSchemaCollection.Add(null, "poschema.xsd");
foreach(XmlSchema myTempXmlSchema in myXmlSchemaCollection)
{
myXmlSchema = myTempXmlSchema;
// Write out the various schema parts
WriteXSDSchema();
// Write out an example of the XML for the schema
WriteExample();
}
void WriteXSDSchema()
{
myXmlTextWriter.WriteStartElement("schema", XmlSchema.Namespace);
myXmlTextWriter.WriteAttributeString("targetNamespace", myXmlSchema.TargetNamespace);
foreach(XmlSchemaInclude include in myXmlSchema.Includes)
{
myXmlTextWriter.WriteStartElement("include", XmlSchema.Namespace);
myXmlTextWriter.WriteAttributeString("schemaLocation", include.SchemaLocation);
myXmlTextWriter.WriteEndElement();
}
foreach(object item in myXmlSchema.Items)
{
if (item is XmlSchemaAttribute)
WriteXmlSchemaAttribute((XmlSchemaAttribute)item); //attribute
else if (item is XmlSchemaComplexType)
WriteXmlSchemaComplexType((XmlSchemaComplexType)item); //complexType
else if (item is XmlSchemaSimpleType)
WriteXmlSchemaSimpleType((XmlSchemaSimpleType)item); //simpleType
else if (item is XmlSchemaElement)
WriteXmlSchemaElement((XmlSchemaElement)item); //element
else if (item is XmlSchemaAnnotation)
WriteXmlSchemaAnnotation((XmlSchemaAnnotation)item); //annotation
else if (item is XmlSchemaAttributeGroup)
WriteXmlSchemaAttributeGroup((XmlSchemaAttributeGroup)item); //attributeGroup
else if (item is XmlSchemaNotation)
WriteXmlSchemaNotation((XmlSchemaNotation)item); //notation
else if (item is XmlSchemaGroup)
WriteXmlSchemaGroup((XmlSchemaGroup)item); //group
else
Console.WriteLine("Not Implemented.");
}
myXmlTextWriter.WriteEndElement();
}
// Write out the example of the XSD usage
void WriteExample()
{
foreach(XmlSchemaElement element in myXmlSchema.Elements.Values)
WriteExampleElement(element);
}
// Write some example elements
void WriteExampleElement(XmlSchemaElement element)
{
myXmlTextWriter.WriteStartElement(element.QualifiedName.Name, element.QualifiedName.Namespace);
if (element.ElementType is XmlSchemaComplexType)
{
XmlSchemaComplexType type = (XmlSchemaComplexType)element.ElementType;
if (type.ContentModel != null)
Console.WriteLine("Not Implemented for this ContentModel");
WriteExampleAttributes(type.Attributes);
WriteExampleParticle(type.Particle);
}
else
WriteExampleValue(element.ElementType);
myXmlTextWriter.WriteEndElement();
}
Now how does this work? The WriteExample code iterates through the XmlSchema.Elements.Values collection and outputs some data for each XmlSchemaElement. The Elements property is not generated when you only do an XmlSchema.Read. What is actually happening is that the schema is being compiled aswell. I stumbled across this not using Reflector, but when changing the sample code to read in NAnt's 0.84 schema. Reading in NAnt-0.84.xsd the code threw an exception since one of the types (formatter) was defined twice, even though the schema is valid as far as I can tell. The exception was thrown at the line
myXmlSchemaCollection.Add(null, "nant-0.84.xsd");
The exception call stack showed that XmlSchemaCollection.Add method calls XmlSchema.Compile.
So it looks like we need to compile the XmlSchema object to get it to do a second parse.
Xhtml1-Strict
-------------
Fun and games getting this to load in the XmlSchema object.
First, set the XmlResolver to null on the XmlTextReader. If this is not done the reader tries to look for referenced DTDs in the assembly folder. When the resolver is set to null it looks for the DTDs in the same folder as the .xsd itself which seems more reasonable.
XmlSchema throws an exception because the xhtml1-strict.xsd redefines the xml namespace via the string xmlns:xml="http://www.w3.org/XML/1998/namespace" at the top of the file. According to the w3 spec this is valid, but the XmlSchema class does not like it.
Xml Editor handling property changes
------------------------------------
The properties are changed from inside SharpDevelop. Options are:
1) Directly access the SharpDevelop properties each time the control is about to do something.
2) Control exposes properties which need to be changed via another object, not the editor,
when they have changed.
3) Control exposes a property object with a defined interface which the user of the control
can set. This object is checked whenever the control attempts to do something. This
object can access the SharpDevelop properties.
I want to keep the Xml Editor control only dependent on the SharpDevelop Text Editor. This rules out option 1.
Schemas
-------
System schemas
--------------
System schemas will live in the C:\Program Files\SharpDevelop\data\schemas folder.
The PropertyService gives us a DataDirectory property which usually points to C:\Program Files\SharpDevelop\data so we can use this.
If the folder does not exist it is not created since access to C:\Program Files can be restricted.
User schemas
------------
User schemas will live in C:\Documents and Settings\web\Application Data\.ICSharpCode\SharpDevelop\schemas folder.
The PropertyService gives us a ConfigDirectory which points to the parent of the above folder (i.e. SharpDevelop above the schemas folder).
XmlEditor addin
---------------
The binary and its addin file will exist in AddIns/AddIns/DisplayBindings/XmlEditor
Folding
-------
The standard way in SharpDevelop that folds are added is via the parser. The SharpDevelop has a parser thread which checks if the current view's text has changed, then looks for a parser that can handle that particular filename. This parser then parses the contents and the IParseInformation is sent to the view's IParseInformationListener.ParseInformationUpdated method. This method then usually uses the parse info to update the foldings.
Now, the SharpDevelop parsers are programming language orientated, so a lot of the properties and objects are not relevant to parsed xml, so do we create a parser just to update the folds? The fold updating still needs to be done on a background thread, because folds aren't massively important, so creating our own extra thread is out of the question. We could trigger a fold update on every key press, but again this is overkill and will be probably be slow.
Enabling searching in the xml editor
------------------------------------
The view class needs to implement the ITextEditorControlProvider otherwise the search menu options are disabled.

50
src/AddIns/DisplayBindings/XmlEditor/Doc/readme.txt

@ -0,0 +1,50 @@
INSTALLATION:
-------------
Using Binaries
--------------
Assuming SharpDevelop is installed in the folder "C:/Program Files/SharpDevelop"
Copy the contents of the "bin" folder to "C:/Program Files/SharpDevelop/AddIns/AddIns/DisplayBindings/XmlEditor".
The binaries should work with SharpDevelop v1.0.3.1768.
Building source
---------------
Copy the contents of the XmlEditor folder to "src/AddIns/DisplayBindings/XmlEditor".
Load the "XmlEditor.cmbx" combine and build the project OR run the "XmlEditor.build" file with NAnt 0.84.
Configuring Schema Auto-completion
----------------------------------
Go to Tools->Options->Text Editor->Xml Schemas. Use the Add button to add your .xsds to SharpDevelop.
Done:
-----
Properties taken from SharpDevelop.
Handle property changes whilst editor is open.
Validate xml menu only available for the xml editor.
Validation against schema. Right click and menu option.
User added xsds.
System xsds.
Check that we can still "jump to" NAnt errors in .build files.
Test getting element completion data for the root element of a document.
Code completion window size. Long namespace URIs do not fit in the window. Duplicated
the CodeCompletionWindow class. The item width calculation should really be in
the CodeCompletionListView.
Custom code completion window. Only autocomplete when the tab or return key
is pressed.
Validation of the xml against the schema - send output to build window and add
task list entry.
Comment folding.
Recognise special file extensions (e.g. build). Allow user to specify schema
for a file extension. This would act as a default, but could be overriden
by specifying an xmlns in the xml.

37
src/AddIns/DisplayBindings/XmlEditor/Project/Configuration/AssemblyInfo.cs

@ -1,33 +1,22 @@
#region Using directives // <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices;
#endregion // Information about this assembly is defined by the following
// attributes.
//
// change them to the information which is associated with the assembly
// you compile.
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("XmlEditor")] [assembly: AssemblyTitle("XmlEditor")]
[assembly: AssemblyDescription("")] [assembly: AssemblyDescription("SharpDevelop Xml Editor AddIn")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("XmlEditor")]
[assembly: AssemblyCopyright("Copyright 2009")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
// This sets the default COM visibility of types in the assembly to invisible. [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("XmlEditor.Tests")]
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
[assembly: ComVisible(false)]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("XmlEditor.Tests")]
// The assembly version has following format :
//
// Major.Minor.Build.Revision
//
// You can specify all the values or you can use the default the Revision and
// Build Numbers by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.*")]

6
src/AddIns/DisplayBindings/XmlEditor/Project/Src/AssignStylesheetCommand.cs

@ -21,15 +21,15 @@ namespace ICSharpCode.XmlEditor
public override void Run() public override void Run()
{ {
// Get active xml document. // Get active xml document.
XmlView properties = XmlView.ForViewContent(WorkbenchSingleton.Workbench.ActiveViewContent); XmlView xmlView = XmlView.ActiveXmlView;
if (properties != null) { if (xmlView != null) {
// Prompt user for filename. // Prompt user for filename.
string stylesheetFileName = BrowseForStylesheetFile(); string stylesheetFileName = BrowseForStylesheetFile();
// Assign stylesheet. // Assign stylesheet.
if (stylesheetFileName != null) if (stylesheetFileName != null)
properties.StylesheetFileName = stylesheetFileName; xmlView.StylesheetFileName = stylesheetFileName;
} }
} }

28
src/AddIns/DisplayBindings/XmlEditor/Project/Src/CodeCompletionPopupCommand.cs

@ -1,28 +0,0 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
// <version>$Revision$</version>
// </file>
using System;
//using ICSharpCode.TextEditor;
//using ICSharpCode.TextEditor.Actions;
namespace ICSharpCode.XmlEditor
{
// /// <summary>
// /// Command executed when the user hits Ctrl+Space
// /// </summary>
// public class CodeCompletionPopupCommand : AbstractEditAction
// {
// public override void Execute(TextArea services)
// {
// throw new NotImplementedException();
//// XmlEditorControl editor = services.MotherTextEditorControl as XmlEditorControl;
//// if (editor != null) {
//// editor.ShowCompletionWindow();
//// }
// }
// }
}

8
src/AddIns/DisplayBindings/XmlEditor/Project/Src/CreateSchemaCommand.cs

@ -23,14 +23,14 @@ namespace ICSharpCode.XmlEditor
public override void Run() public override void Run()
{ {
// Find active XmlView. // Find active XmlView.
XmlView properties = XmlView.ForViewContent(WorkbenchSingleton.Workbench.ActiveViewContent); XmlView xmlView = XmlView.ActiveXmlView;
if (properties != null) { if (xmlView != null) {
// Create a schema based on the xml. // Create a schema based on the xml.
string[] schemas = properties.InferSchema(); string[] schemas = xmlView.InferSchema();
if (schemas != null) { if (schemas != null) {
// Create a new file for each generated schema. // Create a new file for each generated schema.
for (int i = 0; i < schemas.Length; ++i) { for (int i = 0; i < schemas.Length; ++i) {
string fileName = GenerateSchemaFileName(properties.File.FileName, i + 1); string fileName = GenerateSchemaFileName(xmlView.File.FileName, i + 1);
OpenNewXmlFile(fileName, schemas[i]); OpenNewXmlFile(fileName, schemas[i]);
} }
} }

6
src/AddIns/DisplayBindings/XmlEditor/Project/Src/FormatXmlCommand.cs

@ -19,10 +19,10 @@ namespace ICSharpCode.XmlEditor
public override void Run() public override void Run()
{ {
// Find active XmlView. // Find active XmlView.
XmlView properties = XmlView.ForViewContent(WorkbenchSingleton.Workbench.ActiveViewContent); XmlView xmlView = XmlView.ActiveXmlView;
if (properties != null) { if (xmlView != null) {
properties.FormatXml(); xmlView.FormatXml();
} }
} }
} }

6
src/AddIns/DisplayBindings/XmlEditor/Project/Src/GoToSchemaDefinitionCommand.cs

@ -20,10 +20,10 @@ namespace ICSharpCode.XmlEditor
{ {
public override void Run() public override void Run()
{ {
XmlView properties = XmlView.ForViewContent(WorkbenchSingleton.Workbench.ActiveViewContent); XmlView xmlView = XmlView.ActiveXmlView;
if (properties != null) { if (xmlView != null) {
properties.GoToSchemaDefinition(); xmlView.GoToSchemaDefinition();
} }
} }
} }

6
src/AddIns/DisplayBindings/XmlEditor/Project/Src/OpenStylesheetCommand.cs

@ -19,10 +19,10 @@ namespace ICSharpCode.XmlEditor
{ {
public override void Run() public override void Run()
{ {
XmlView properties = XmlView.ForViewContent(WorkbenchSingleton.Workbench.ActiveViewContent); XmlView xmlView = XmlView.ActiveXmlView;
if (properties != null && properties.StylesheetFileName != null) { if (xmlView != null && xmlView.StylesheetFileName != null) {
try { try {
FileService.OpenFile(properties.StylesheetFileName); FileService.OpenFile(xmlView.StylesheetFileName);
} catch (Exception ex) { } catch (Exception ex) {
MessageService.ShowError(ex); MessageService.ShowError(ex);
} }

26
src/AddIns/DisplayBindings/XmlEditor/Project/Src/RunXslTransformCommand.cs

@ -27,27 +27,27 @@ namespace ICSharpCode.XmlEditor
/// </summary> /// </summary>
public override void Run() public override void Run()
{ {
XmlView properties = XmlView.ForViewContent(WorkbenchSingleton.Workbench.ActiveViewContent); XmlView xmlView = XmlView.ActiveXmlView;
if (properties != null) { if (xmlView != null) {
// Check to see if this view is actually a referenced stylesheet. // Check to see if this view is actually a referenced stylesheet.
if (!string.IsNullOrEmpty(properties.File.FileName)) { if (!string.IsNullOrEmpty(xmlView.File.FileName)) {
XmlView assocFile = GetAssociatedXmlView(properties.File.FileName); XmlView assocFile = GetAssociatedXmlView(xmlView.File.FileName);
if (assocFile != null) { if (assocFile != null) {
LoggingService.Debug("Using associated xml file."); LoggingService.Debug("Using associated xml file.");
properties = assocFile; xmlView = assocFile;
} }
} }
// Assign a stylesheet. // Assign a stylesheet.
if (properties.StylesheetFileName == null) { if (xmlView.StylesheetFileName == null) {
properties.StylesheetFileName = AssignStylesheetCommand.BrowseForStylesheetFile(); xmlView.StylesheetFileName = AssignStylesheetCommand.BrowseForStylesheetFile();
} }
if (properties.StylesheetFileName != null) { if (xmlView.StylesheetFileName != null) {
try { try {
properties.RunXslTransform(GetStylesheetContent(properties.StylesheetFileName)); xmlView.RunXslTransform(GetStylesheetContent(xmlView.StylesheetFileName));
} catch (Exception ex) { } catch (Exception ex) {
MessageService.ShowError(ex); MessageService.ShowError(ex);
} }
@ -62,10 +62,10 @@ namespace ICSharpCode.XmlEditor
static XmlView GetAssociatedXmlView(string stylesheetFileName) static XmlView GetAssociatedXmlView(string stylesheetFileName)
{ {
foreach (IViewContent content in WorkbenchSingleton.Workbench.ViewContentCollection) { foreach (IViewContent content in WorkbenchSingleton.Workbench.ViewContentCollection) {
XmlView prop = XmlView.ForViewContent(content); XmlView view = XmlView.ForViewContent(content);
if (prop != null && !string.IsNullOrEmpty(prop.StylesheetFileName)) { if (view != null && !string.IsNullOrEmpty(view.StylesheetFileName)) {
if (FileUtility.IsEqualFileName(prop.StylesheetFileName, stylesheetFileName)) { if (FileUtility.IsEqualFileName(view.StylesheetFileName, stylesheetFileName)) {
return prop; return view;
} }
} }
} }

6
src/AddIns/DisplayBindings/XmlEditor/Project/Src/StylesheetAssignedCondition.cs

@ -19,9 +19,9 @@ namespace ICSharpCode.XmlEditor
{ {
public bool IsValid(object owner, Condition condition) public bool IsValid(object owner, Condition condition)
{ {
XmlView properties = XmlView.ForViewContent(WorkbenchSingleton.Workbench.ActiveViewContent); XmlView xmlView = XmlView.ActiveXmlView;
if (properties != null) if (xmlView != null)
return properties.StylesheetFileName != null; return xmlView.StylesheetFileName != null;
return false; return false;
} }
} }

6
src/AddIns/DisplayBindings/XmlEditor/Project/Src/ValidateXmlCommand.cs

@ -22,10 +22,10 @@ namespace ICSharpCode.XmlEditor
public override void Run() public override void Run()
{ {
// Find active XmlView. // Find active XmlView.
XmlView properties = XmlView.ForViewContent(WorkbenchSingleton.Workbench.ActiveViewContent); XmlView xmlView = XmlView.ActiveXmlView;
if (properties != null) { if (xmlView != null) {
// Validate the xml. // Validate the xml.
properties.ValidateXml(); xmlView.ValidateXml();
} }
} }
} }

5
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XPathNodeTextMarker.cs

@ -8,7 +8,7 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Windows.Media;
using ICSharpCode.SharpDevelop.Editor; using ICSharpCode.SharpDevelop.Editor;
@ -19,7 +19,7 @@ namespace ICSharpCode.XmlEditor
/// </summary> /// </summary>
public class XPathNodeTextMarker public class XPathNodeTextMarker
{ {
public static readonly Color MarkerBackColor = Color.FromArgb(159, 255, 162); public static readonly Color MarkerBackColor = Color.FromArgb(255, 159, 255, 162);
static List<XPathNodeTextMarker> markers = new List<XPathNodeTextMarker>(); static List<XPathNodeTextMarker> markers = new List<XPathNodeTextMarker>();
ITextMarker marker; ITextMarker marker;
@ -28,6 +28,7 @@ namespace ICSharpCode.XmlEditor
ITextMarkerService markerService = document.GetService(typeof(ITextMarkerService)) as ITextMarkerService; ITextMarkerService markerService = document.GetService(typeof(ITextMarkerService)) as ITextMarkerService;
marker = markerService.Create(offset, node.Value.Length); marker = markerService.Create(offset, node.Value.Length);
marker.Tag = this; marker.Tag = this;
marker.BackgroundColor = MarkerBackColor;
} }
/// <summary> /// <summary>

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

@ -177,9 +177,7 @@ namespace ICSharpCode.XmlEditor
foreach (IViewContent view in WorkbenchSingleton.Workbench.ViewContentCollection) { foreach (IViewContent view in WorkbenchSingleton.Workbench.ViewContentCollection) {
ITextEditorProvider textEditorProvider = view as ITextEditorProvider; ITextEditorProvider textEditorProvider = view as ITextEditorProvider;
if (textEditorProvider != null) { if (textEditorProvider != null) {
// TODO : markers are currently not supported in AvalonEdit. XPathNodeTextMarker.RemoveMarkers(textEditorProvider.TextEditor.Document);
// XPathNodeTextMarker.RemoveMarkers(textEditorProvider.TextEditorControl.Document.MarkerStrategy);
// textEditorProvider.TextEditorControl.Refresh();
} }
} }
} }
@ -419,25 +417,24 @@ namespace ICSharpCode.XmlEditor
void RunXPathQuery() void RunXPathQuery()
{ {
XmlView properties = XmlView.ForViewContent(WorkbenchSingleton.Workbench.ActiveViewContent); XmlView xmlView = XmlView.ActiveXmlView;
if (properties == null) { if (xmlView == null) {
return; return;
} }
try { try {
// TODO : markers are currently not supported in AvalonEdit. // TODO : markers are currently not supported in AvalonEdit.
//MarkerStrategy markerStrategy = view.GetTextEditor().Document.MarkerStrategy; fileName = xmlView.File.FileName;
fileName = properties.File.FileName;
// Clear previous XPath results. // Clear previous XPath results.
ClearResults(); ClearResults();
//XPathNodeTextMarker.RemoveMarkers(markerStrategy); XPathNodeTextMarker.RemoveMarkers(xmlView.TextEditor.Document);
// Run XPath query. // Run XPath query.
XPathNodeMatch[] nodes = properties.SelectNodes(xPathComboBox.Text, GetNamespaces()); XPathNodeMatch[] nodes = xmlView.SelectNodes(xPathComboBox.Text, GetNamespaces());
if (nodes.Length > 0) { if (nodes.Length > 0) {
AddXPathResults(nodes); AddXPathResults(nodes);
//XPathNodeTextMarker.AddMarkers(markerStrategy, nodes); XPathNodeTextMarker.AddMarkers(xmlView.TextEditor.Document, nodes);
} else { } else {
AddNoXPathResult(); AddNoXPathResult();
} }
@ -448,7 +445,6 @@ namespace ICSharpCode.XmlEditor
AddErrorResult(xmlEx); AddErrorResult(xmlEx);
} finally { } finally {
BringResultsTabToFront(); BringResultsTabToFront();
//view.TextEditorControl.Refresh();
} }
} }
@ -595,11 +591,11 @@ namespace ICSharpCode.XmlEditor
if (view != null) { if (view != null) {
ITextEditor editor = view.TextEditor; ITextEditor editor = view.TextEditor;
if (editor == null) return; if (editor == null) return;
int corLine = Math.Min(line, editor.Document.TotalNumberOfLines - 1); int corLine = Math.Min(line + 1, editor.Document.TotalNumberOfLines - 1);
editor.JumpTo(corLine, column); editor.JumpTo(corLine, column + 1);
if (length > 0 && line < editor.Document.TotalNumberOfLines) { if (length > 0 && line < editor.Document.TotalNumberOfLines) {
int offset = editor.Document.PositionToOffset(line, column); int offset = editor.Document.PositionToOffset(line + 1, column + 1);
editor.Select(offset, offset + length); editor.Select(offset, length);
} }
} }
} }

15
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlTreeView.cs

@ -30,7 +30,7 @@ namespace ICSharpCode.XmlEditor
public XmlTreeView(IViewContent parent) public XmlTreeView(IViewContent parent)
: base(parent) : base(parent)
{ {
this.TabPageText = "XML Tree"; this.TabPageText = "${res:ICSharpCode.XmlEditor.XmlTreeView.Title}";
this.treeViewContainer = new XmlTreeViewContainerControl(); this.treeViewContainer = new XmlTreeViewContainerControl();
this.treeViewContainer.DirtyChanged += TreeViewContainerDirtyChanged; this.treeViewContainer.DirtyChanged += TreeViewContainerDirtyChanged;
treeViewContainer.AttributesGrid.ContextMenuStrip = MenuService.CreateContextMenu(treeViewContainer, "/AddIns/XmlEditor/XmlTree/AttributesGrid/ContextMenu"); treeViewContainer.AttributesGrid.ContextMenuStrip = MenuService.CreateContextMenu(treeViewContainer, "/AddIns/XmlEditor/XmlTree/AttributesGrid/ContextMenu");
@ -182,5 +182,18 @@ namespace ICSharpCode.XmlEditor
this.PrimaryFile.IsDirty = treeViewContainer.IsDirty; this.PrimaryFile.IsDirty = treeViewContainer.IsDirty;
} }
} }
bool disposed;
public override void Dispose()
{
LoggingService.Debug("XmlTreeView.Dispose");
if (!disposed) {
disposed = true;
treeViewContainer.Dispose();
}
base.Dispose();
}
} }
} }

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

@ -129,6 +129,12 @@ namespace ICSharpCode.XmlEditor
} }
} }
public static XmlView ActiveXmlView {
get {
return XmlView.ForViewContent(WorkbenchSingleton.Workbench.ActiveViewContent);
}
}
/// <summary> /// <summary>
/// Finds the xml nodes that match the specified xpath. /// Finds the xml nodes that match the specified xpath.
/// </summary> /// </summary>
@ -175,7 +181,7 @@ namespace ICSharpCode.XmlEditor
/// and line position information aswell as the node found.</returns> /// and line position information aswell as the node found.</returns>
public XPathNodeMatch[] SelectNodes(string xpath, ReadOnlyCollection<XmlNamespace> namespaces) public XPathNodeMatch[] SelectNodes(string xpath, ReadOnlyCollection<XmlNamespace> namespaces)
{ {
return SelectNodes(View.XmlContent, xpath, namespaces); return SelectNodes(TextEditor.Document.Text, xpath, namespaces);
} }
public void GoToSchemaDefinition() public void GoToSchemaDefinition()

6
src/AddIns/DisplayBindings/XmlEditor/Project/XmlEditor.addin

@ -65,12 +65,8 @@
<ComplexCondition> <ComplexCondition>
<Or> <Or>
<Condition name = "WindowActive" activewindow="ICSharpCode.XmlEditor.XmlTreeView" /> <Condition name = "WindowActive" activewindow="ICSharpCode.XmlEditor.XmlTreeView" />
<And> <Condition name = "TextContent" textcontent="XML" />
<Condition name = "WindowActive" activewindow="ICSharpCode.SharpDevelop.Editor.ITextEditorProvider" />
<Condition name = "TextContent" textcontent="XML" />
</And>
</Or> </Or>
<MenuItem id = "Xml" insertafter="View" insertbefore="Tools" label="&amp;XML" type = "Menu"> <MenuItem id = "Xml" insertafter="View" insertbefore="Tools" label="&amp;XML" type = "Menu">
<MenuItem id = "CreateSchema" <MenuItem id = "CreateSchema"
label = "${res:ICSharpCode.XmlEditor.CreateSchemaMenuLabel}" label = "${res:ICSharpCode.XmlEditor.CreateSchemaMenuLabel}"

4
src/AddIns/DisplayBindings/XmlEditor/Project/XmlEditor.csproj

@ -68,6 +68,9 @@
<None Include="XmlEditor.addin"> <None Include="XmlEditor.addin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>
<Compile Include="..\..\..\..\Main\GlobalAssemblyInfo.cs">
<Link>Configuration\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Configuration\AssemblyInfo.cs" /> <Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="Src\AddAttributeCommand.cs" /> <Compile Include="Src\AddAttributeCommand.cs" />
<Compile Include="Src\AddChildCommentCommand.cs" /> <Compile Include="Src\AddChildCommentCommand.cs" />
@ -77,7 +80,6 @@
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="Src\AssignStylesheetCommand.cs" /> <Compile Include="Src\AssignStylesheetCommand.cs" />
<Compile Include="Src\CodeCompletionPopupCommand.cs" />
<Compile Include="Src\CreateSchemaCommand.cs" /> <Compile Include="Src\CreateSchemaCommand.cs" />
<Compile Include="Src\EncodedStringWriter.cs" /> <Compile Include="Src\EncodedStringWriter.cs" />
<Compile Include="Src\FormatXmlCommand.cs" /> <Compile Include="Src\FormatXmlCommand.cs" />

18
src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockTextMarker.cs

@ -51,23 +51,9 @@ namespace XmlEditor.Tests.Utils
} }
} }
public Nullable<Color> BackgroundColor { public Nullable<Color> BackgroundColor { get; set; }
get {
throw new NotImplementedException();
}
set {
throw new NotImplementedException();
}
}
public Nullable<Color> ForegroundColor { public Nullable<Color> ForegroundColor { get; set; }
get {
throw new NotImplementedException();
}
set {
throw new NotImplementedException();
}
}
public object Tag { get; set; } public object Tag { get; set; }

12
src/Main/Base/Project/Src/TextEditor/Conditions/TextContentCondition.cs

@ -26,13 +26,11 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Conditions
public bool IsValid(object caller, Condition condition) public bool IsValid(object caller, Condition condition)
{ {
string textcontent = condition.Properties["textcontent"]; string textcontent = condition.Properties["textcontent"];
if (caller is WpfWorkbench) { IViewContent content = WorkbenchSingleton.Workbench.ActiveViewContent;
IViewContent content = (caller as WpfWorkbench).ActiveViewContent; if (content is ITextEditorProvider) {
if (content is ITextEditorProvider) { var ctrl = (content as ITextEditorProvider).TextEditor.GetService(typeof(AvalonEdit.TextEditor)) as AvalonEdit.TextEditor;
var ctrl = (content as ITextEditorProvider).TextEditor.GetService(typeof(AvalonEdit.TextEditor)) as AvalonEdit.TextEditor; if (ctrl != null && ctrl.SyntaxHighlighting.Name != null) {
if (ctrl != null && ctrl.SyntaxHighlighting.Name != null) { return string.Equals(textcontent, ctrl.SyntaxHighlighting.Name, StringComparison.OrdinalIgnoreCase);
return string.Equals(textcontent, ctrl.SyntaxHighlighting.Name, StringComparison.OrdinalIgnoreCase);
}
} }
} }
return false; return false;

Loading…
Cancel
Save