diff --git a/src/AddIns/DisplayBindings/XmlEditor/Doc/notes.txt b/src/AddIns/DisplayBindings/XmlEditor/Doc/notes.txt new file mode 100644 index 0000000000..6ccdec4605 --- /dev/null +++ b/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. + diff --git a/src/AddIns/DisplayBindings/XmlEditor/Doc/readme.txt b/src/AddIns/DisplayBindings/XmlEditor/Doc/readme.txt new file mode 100644 index 0000000000..e6c704a28b --- /dev/null +++ b/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. diff --git a/src/AddIns/DisplayBindings/XmlEditor/Project/Configuration/AssemblyInfo.cs b/src/AddIns/DisplayBindings/XmlEditor/Project/Configuration/AssemblyInfo.cs index d5ead91fce..7175d9f5a1 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Project/Configuration/AssemblyInfo.cs +++ b/src/AddIns/DisplayBindings/XmlEditor/Project/Configuration/AssemblyInfo.cs @@ -1,33 +1,22 @@ -#region Using directives +// +// +// +// +// $Revision$ +// -using System; 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: AssemblyDescription("")] +[assembly: AssemblyDescription("SharpDevelop Xml Editor AddIn")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("XmlEditor")] -[assembly: AssemblyCopyright("Copyright 2009")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] -// This sets the default COM visibility of types in the assembly to invisible. -// 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.*")] +[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("XmlEditor.Tests")] \ No newline at end of file diff --git a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/AssignStylesheetCommand.cs b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/AssignStylesheetCommand.cs index de2a3c73c4..6b11701adb 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/AssignStylesheetCommand.cs +++ b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/AssignStylesheetCommand.cs @@ -21,15 +21,15 @@ namespace ICSharpCode.XmlEditor public override void Run() { // 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. string stylesheetFileName = BrowseForStylesheetFile(); // Assign stylesheet. if (stylesheetFileName != null) - properties.StylesheetFileName = stylesheetFileName; + xmlView.StylesheetFileName = stylesheetFileName; } } diff --git a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/CodeCompletionPopupCommand.cs b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/CodeCompletionPopupCommand.cs deleted file mode 100644 index 22a9184d26..0000000000 --- a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/CodeCompletionPopupCommand.cs +++ /dev/null @@ -1,28 +0,0 @@ -// -// -// -// -// $Revision$ -// - -using System; -//using ICSharpCode.TextEditor; -//using ICSharpCode.TextEditor.Actions; - -namespace ICSharpCode.XmlEditor -{ -// /// -// /// Command executed when the user hits Ctrl+Space -// /// -// public class CodeCompletionPopupCommand : AbstractEditAction -// { -// public override void Execute(TextArea services) -// { -// throw new NotImplementedException(); -//// XmlEditorControl editor = services.MotherTextEditorControl as XmlEditorControl; -//// if (editor != null) { -//// editor.ShowCompletionWindow(); -//// } -// } -// } -} diff --git a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/CreateSchemaCommand.cs b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/CreateSchemaCommand.cs index 8d36918605..9bae7d419b 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/CreateSchemaCommand.cs +++ b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/CreateSchemaCommand.cs @@ -23,14 +23,14 @@ namespace ICSharpCode.XmlEditor public override void Run() { // Find active XmlView. - XmlView properties = XmlView.ForViewContent(WorkbenchSingleton.Workbench.ActiveViewContent); - if (properties != null) { + XmlView xmlView = XmlView.ActiveXmlView; + if (xmlView != null) { // Create a schema based on the xml. - string[] schemas = properties.InferSchema(); + string[] schemas = xmlView.InferSchema(); if (schemas != null) { // Create a new file for each generated schema. 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]); } } diff --git a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/FormatXmlCommand.cs b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/FormatXmlCommand.cs index a5581089cd..a210866c68 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/FormatXmlCommand.cs +++ b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/FormatXmlCommand.cs @@ -19,10 +19,10 @@ namespace ICSharpCode.XmlEditor public override void Run() { // Find active XmlView. - XmlView properties = XmlView.ForViewContent(WorkbenchSingleton.Workbench.ActiveViewContent); + XmlView xmlView = XmlView.ActiveXmlView; - if (properties != null) { - properties.FormatXml(); + if (xmlView != null) { + xmlView.FormatXml(); } } } diff --git a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/GoToSchemaDefinitionCommand.cs b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/GoToSchemaDefinitionCommand.cs index 0b0b6d3b3b..0df774bf15 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/GoToSchemaDefinitionCommand.cs +++ b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/GoToSchemaDefinitionCommand.cs @@ -20,10 +20,10 @@ namespace ICSharpCode.XmlEditor { public override void Run() { - XmlView properties = XmlView.ForViewContent(WorkbenchSingleton.Workbench.ActiveViewContent); + XmlView xmlView = XmlView.ActiveXmlView; - if (properties != null) { - properties.GoToSchemaDefinition(); + if (xmlView != null) { + xmlView.GoToSchemaDefinition(); } } } diff --git a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/OpenStylesheetCommand.cs b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/OpenStylesheetCommand.cs index 56698bed8d..1a14ded045 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/OpenStylesheetCommand.cs +++ b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/OpenStylesheetCommand.cs @@ -19,10 +19,10 @@ namespace ICSharpCode.XmlEditor { public override void Run() { - XmlView properties = XmlView.ForViewContent(WorkbenchSingleton.Workbench.ActiveViewContent); - if (properties != null && properties.StylesheetFileName != null) { + XmlView xmlView = XmlView.ActiveXmlView; + if (xmlView != null && xmlView.StylesheetFileName != null) { try { - FileService.OpenFile(properties.StylesheetFileName); + FileService.OpenFile(xmlView.StylesheetFileName); } catch (Exception ex) { MessageService.ShowError(ex); } diff --git a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/RunXslTransformCommand.cs b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/RunXslTransformCommand.cs index 40cdc729e1..b626bf2184 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/RunXslTransformCommand.cs +++ b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/RunXslTransformCommand.cs @@ -27,27 +27,27 @@ namespace ICSharpCode.XmlEditor /// 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. - 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) { LoggingService.Debug("Using associated xml file."); - properties = assocFile; + xmlView = assocFile; } } // Assign a stylesheet. - if (properties.StylesheetFileName == null) { - properties.StylesheetFileName = AssignStylesheetCommand.BrowseForStylesheetFile(); + if (xmlView.StylesheetFileName == null) { + xmlView.StylesheetFileName = AssignStylesheetCommand.BrowseForStylesheetFile(); } - if (properties.StylesheetFileName != null) { + if (xmlView.StylesheetFileName != null) { try { - properties.RunXslTransform(GetStylesheetContent(properties.StylesheetFileName)); + xmlView.RunXslTransform(GetStylesheetContent(xmlView.StylesheetFileName)); } catch (Exception ex) { MessageService.ShowError(ex); } @@ -62,10 +62,10 @@ namespace ICSharpCode.XmlEditor static XmlView GetAssociatedXmlView(string stylesheetFileName) { foreach (IViewContent content in WorkbenchSingleton.Workbench.ViewContentCollection) { - XmlView prop = XmlView.ForViewContent(content); - if (prop != null && !string.IsNullOrEmpty(prop.StylesheetFileName)) { - if (FileUtility.IsEqualFileName(prop.StylesheetFileName, stylesheetFileName)) { - return prop; + XmlView view = XmlView.ForViewContent(content); + if (view != null && !string.IsNullOrEmpty(view.StylesheetFileName)) { + if (FileUtility.IsEqualFileName(view.StylesheetFileName, stylesheetFileName)) { + return view; } } } diff --git a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/StylesheetAssignedCondition.cs b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/StylesheetAssignedCondition.cs index d0250c6735..7c48c8b0cb 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/StylesheetAssignedCondition.cs +++ b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/StylesheetAssignedCondition.cs @@ -19,9 +19,9 @@ namespace ICSharpCode.XmlEditor { public bool IsValid(object owner, Condition condition) { - XmlView properties = XmlView.ForViewContent(WorkbenchSingleton.Workbench.ActiveViewContent); - if (properties != null) - return properties.StylesheetFileName != null; + XmlView xmlView = XmlView.ActiveXmlView; + if (xmlView != null) + return xmlView.StylesheetFileName != null; return false; } } diff --git a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/ValidateXmlCommand.cs b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/ValidateXmlCommand.cs index 581cab1eb9..3a96094454 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/ValidateXmlCommand.cs +++ b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/ValidateXmlCommand.cs @@ -22,10 +22,10 @@ namespace ICSharpCode.XmlEditor public override void Run() { // Find active XmlView. - XmlView properties = XmlView.ForViewContent(WorkbenchSingleton.Workbench.ActiveViewContent); - if (properties != null) { + XmlView xmlView = XmlView.ActiveXmlView; + if (xmlView != null) { // Validate the xml. - properties.ValidateXml(); + xmlView.ValidateXml(); } } } diff --git a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XPathNodeTextMarker.cs b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XPathNodeTextMarker.cs index c74c7dddba..d33866928f 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XPathNodeTextMarker.cs +++ b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XPathNodeTextMarker.cs @@ -8,7 +8,7 @@ using System; using System.Linq; using System.Collections.Generic; -using System.Drawing; +using System.Windows.Media; using ICSharpCode.SharpDevelop.Editor; @@ -19,7 +19,7 @@ namespace ICSharpCode.XmlEditor /// 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 markers = new List(); ITextMarker marker; @@ -28,6 +28,7 @@ namespace ICSharpCode.XmlEditor ITextMarkerService markerService = document.GetService(typeof(ITextMarkerService)) as ITextMarkerService; marker = markerService.Create(offset, node.Value.Length); marker.Tag = this; + marker.BackgroundColor = MarkerBackColor; } /// diff --git a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XPathQueryControl.cs b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XPathQueryControl.cs index 4fc9f87987..8ff5c2dba2 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XPathQueryControl.cs +++ b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XPathQueryControl.cs @@ -177,9 +177,7 @@ namespace ICSharpCode.XmlEditor foreach (IViewContent view in WorkbenchSingleton.Workbench.ViewContentCollection) { ITextEditorProvider textEditorProvider = view as ITextEditorProvider; if (textEditorProvider != null) { - // TODO : markers are currently not supported in AvalonEdit. -// XPathNodeTextMarker.RemoveMarkers(textEditorProvider.TextEditorControl.Document.MarkerStrategy); -// textEditorProvider.TextEditorControl.Refresh(); + XPathNodeTextMarker.RemoveMarkers(textEditorProvider.TextEditor.Document); } } } @@ -419,25 +417,24 @@ namespace ICSharpCode.XmlEditor void RunXPathQuery() { - XmlView properties = XmlView.ForViewContent(WorkbenchSingleton.Workbench.ActiveViewContent); - if (properties == null) { + XmlView xmlView = XmlView.ActiveXmlView; + if (xmlView == null) { return; } try { // TODO : markers are currently not supported in AvalonEdit. - //MarkerStrategy markerStrategy = view.GetTextEditor().Document.MarkerStrategy; - fileName = properties.File.FileName; + fileName = xmlView.File.FileName; // Clear previous XPath results. ClearResults(); - //XPathNodeTextMarker.RemoveMarkers(markerStrategy); + XPathNodeTextMarker.RemoveMarkers(xmlView.TextEditor.Document); // Run XPath query. - XPathNodeMatch[] nodes = properties.SelectNodes(xPathComboBox.Text, GetNamespaces()); + XPathNodeMatch[] nodes = xmlView.SelectNodes(xPathComboBox.Text, GetNamespaces()); if (nodes.Length > 0) { AddXPathResults(nodes); - //XPathNodeTextMarker.AddMarkers(markerStrategy, nodes); + XPathNodeTextMarker.AddMarkers(xmlView.TextEditor.Document, nodes); } else { AddNoXPathResult(); } @@ -448,7 +445,6 @@ namespace ICSharpCode.XmlEditor AddErrorResult(xmlEx); } finally { BringResultsTabToFront(); - //view.TextEditorControl.Refresh(); } } @@ -595,11 +591,11 @@ namespace ICSharpCode.XmlEditor if (view != null) { ITextEditor editor = view.TextEditor; if (editor == null) return; - int corLine = Math.Min(line, editor.Document.TotalNumberOfLines - 1); - editor.JumpTo(corLine, column); + int corLine = Math.Min(line + 1, editor.Document.TotalNumberOfLines - 1); + editor.JumpTo(corLine, column + 1); if (length > 0 && line < editor.Document.TotalNumberOfLines) { - int offset = editor.Document.PositionToOffset(line, column); - editor.Select(offset, offset + length); + int offset = editor.Document.PositionToOffset(line + 1, column + 1); + editor.Select(offset, length); } } } diff --git a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlTreeView.cs b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlTreeView.cs index f0aebae99b..1f08c572b7 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlTreeView.cs +++ b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlTreeView.cs @@ -30,7 +30,7 @@ namespace ICSharpCode.XmlEditor public XmlTreeView(IViewContent parent) : base(parent) { - this.TabPageText = "XML Tree"; + this.TabPageText = "${res:ICSharpCode.XmlEditor.XmlTreeView.Title}"; this.treeViewContainer = new XmlTreeViewContainerControl(); this.treeViewContainer.DirtyChanged += TreeViewContainerDirtyChanged; treeViewContainer.AttributesGrid.ContextMenuStrip = MenuService.CreateContextMenu(treeViewContainer, "/AddIns/XmlEditor/XmlTree/AttributesGrid/ContextMenu"); @@ -182,5 +182,18 @@ namespace ICSharpCode.XmlEditor this.PrimaryFile.IsDirty = treeViewContainer.IsDirty; } } + + bool disposed; + + public override void Dispose() + { + LoggingService.Debug("XmlTreeView.Dispose"); + + if (!disposed) { + disposed = true; + treeViewContainer.Dispose(); + } + base.Dispose(); + } } } diff --git a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlView.cs b/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlView.cs index 85ef27b047..dc05bcac1f 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlView.cs +++ b/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); + } + } + /// /// Finds the xml nodes that match the specified xpath. /// @@ -175,7 +181,7 @@ namespace ICSharpCode.XmlEditor /// and line position information aswell as the node found. public XPathNodeMatch[] SelectNodes(string xpath, ReadOnlyCollection namespaces) { - return SelectNodes(View.XmlContent, xpath, namespaces); + return SelectNodes(TextEditor.Document.Text, xpath, namespaces); } public void GoToSchemaDefinition() diff --git a/src/AddIns/DisplayBindings/XmlEditor/Project/XmlEditor.addin b/src/AddIns/DisplayBindings/XmlEditor/Project/XmlEditor.addin index 86479c032c..563ae0c813 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Project/XmlEditor.addin +++ b/src/AddIns/DisplayBindings/XmlEditor/Project/XmlEditor.addin @@ -65,12 +65,8 @@ - - - - + - Always + + Configuration\GlobalAssemblyInfo.cs + @@ -77,7 +80,6 @@ Form - diff --git a/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockTextMarker.cs b/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockTextMarker.cs index 997fcc6c07..dedb9ecad5 100644 --- a/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockTextMarker.cs +++ b/src/AddIns/DisplayBindings/XmlEditor/Test/Utils/MockTextMarker.cs @@ -51,23 +51,9 @@ namespace XmlEditor.Tests.Utils } } - public Nullable BackgroundColor { - get { - throw new NotImplementedException(); - } - set { - throw new NotImplementedException(); - } - } + public Nullable BackgroundColor { get; set; } - public Nullable ForegroundColor { - get { - throw new NotImplementedException(); - } - set { - throw new NotImplementedException(); - } - } + public Nullable ForegroundColor { get; set; } public object Tag { get; set; } diff --git a/src/Main/Base/Project/Src/TextEditor/Conditions/TextContentCondition.cs b/src/Main/Base/Project/Src/TextEditor/Conditions/TextContentCondition.cs index bbb7731b9a..a4ae8dd483 100644 --- a/src/Main/Base/Project/Src/TextEditor/Conditions/TextContentCondition.cs +++ b/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) { string textcontent = condition.Properties["textcontent"]; - if (caller is WpfWorkbench) { - IViewContent content = (caller as WpfWorkbench).ActiveViewContent; - if (content is ITextEditorProvider) { - var ctrl = (content as ITextEditorProvider).TextEditor.GetService(typeof(AvalonEdit.TextEditor)) as AvalonEdit.TextEditor; - if (ctrl != null && ctrl.SyntaxHighlighting.Name != null) { - return string.Equals(textcontent, ctrl.SyntaxHighlighting.Name, StringComparison.OrdinalIgnoreCase); - } + IViewContent content = WorkbenchSingleton.Workbench.ActiveViewContent; + if (content is ITextEditorProvider) { + var ctrl = (content as ITextEditorProvider).TextEditor.GetService(typeof(AvalonEdit.TextEditor)) as AvalonEdit.TextEditor; + if (ctrl != null && ctrl.SyntaxHighlighting.Name != null) { + return string.Equals(textcontent, ctrl.SyntaxHighlighting.Name, StringComparison.OrdinalIgnoreCase); } } return false;