public void Init()
		{
			testSchemaXml = "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='http://test' />";
			XmlSchemaCompletion testSchema = new XmlSchemaCompletion(new StringReader(testSchemaXml));
			testSchema.IsReadOnly = false;

			string xml = "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='http://xml' />";
			XmlSchemaCompletion xmlSchema = new XmlSchemaCompletion(new StringReader(xml));
			xmlSchema.IsReadOnly = false;
			
			schemas = new XmlSchemaCompletionCollection();
			schemas.Add(testSchema);
			schemas.Add(xmlSchema);
			
			string userDirectory = @"c:\users\user\schemas";
			factory = new MockXmlSchemaCompletionDataFactory();
			MockFileSystem fileSystem = new MockFileSystem();
			registeredXmlSchemas = new RegisteredXmlSchemas(new string[0], userDirectory, fileSystem, factory);
			registeredXmlSchemas.Schemas.AddRange(schemas);
			
			properties = new Properties();
			associations = new XmlSchemaFileAssociations(properties, new DefaultXmlSchemaFileAssociations(new AddInTreeNode()), schemas);
			
			panel = new MockXmlSchemasPanel();
			schemasEditor = new RegisteredXmlSchemasEditor(registeredXmlSchemas, new string[0], associations, panel, factory);
			schemasEditor.LoadOptions();
			
			panel.SelectedXmlSchemaListItemIndex = 0;
			schemasEditor.RemoveSelectedSchema();
		}
		void CreateFooSchema()
		{
			string xml =
				"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"foo\" xmlns=\"foo\" elementFormDefault=\"qualified\">\r\n" +
				"    <xs:element name=\"foo-note\">\r\n" +
				"        <xs:complexType> \r\n" +
				"            <xs:sequence>\r\n" +
				"                <xs:element name=\"foo-text\" type=\"text-type\"/>\r\n" +
				"            </xs:sequence>\r\n" +
				"        </xs:complexType>\r\n" +
				"    </xs:element>\r\n" +
				"    <xs:complexType name=\"text-type\">\r\n" +
				"        <xs:attribute name=\"foo-text-attribute\">\r\n" +
				"            <xs:simpleType>\r\n" +
				"                <xs:restriction base=\"xs:string\">\r\n" +
				"                    <xs:enumeration value=\"first\"/>\r\n" +
				"                    <xs:enumeration value=\"second\"/>\r\n" +
				"                    <xs:enumeration value=\"third\"/>\r\n" +
				"                    <xs:enumeration value=\"fourth\"/>\r\n" +
				"                </xs:restriction>\r\n" +
				"            </xs:simpleType>\r\n" +
				"        </xs:attribute>\r\n" +
				"    </xs:complexType>\r\n" +
				"</xs:schema>";

			fooSchema = new XmlSchemaCompletion(new StringReader(xml));
			fooSchema.FileName = FileName.Create("foo.xsd");
		}
		public void AddingNewUserSchemaDoesNotCreateUserDefinedSchemaDirectory()
		{
			XmlSchemaCompletion schema = new XmlSchemaCompletion();
			registeredXmlSchemas.AddUserSchema(schema);
			
			Assert.AreEqual(0, fileSystem.CreatedFolders.Count);
		}
		public void SetUpFixture()
		{
			schemas = new XmlSchemaCompletionCollection();
			XmlSchemaCompletion completionData = new XmlSchemaCompletion(ResourceManager.ReadXsdSchema());
			expectedNamespace = completionData.NamespaceUri;
			completionData.FileName = FileName.Create(@"C:\Schemas\MySchema.xsd");
			schemas.Add(completionData);
		}
		XmlSchemaCompletion LoadTestSchema()
		{
			string xml = "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='http://test'>\r\n" +
				"</xs:schema>";
			
			XmlSchemaCompletion schema = new XmlSchemaCompletion(new StringReader(xml));
			schema.FileName = @"c:\projects\schemas\test.xsd";
			return schema;
		}
		public void OneSchemaWithFileName()
		{
			XmlSchemaCompletion schema = new XmlSchemaCompletion();
			schema.FileName = FileName.Create("a.xsd");
			schemas.Add(schema);
			
			string[] expectedFileNames = new string[] {"a.xsd"};
			Assert.AreEqual(expectedFileNames, XmlSchemaCompletionCollectionFileNames.GetFileNames(schemas));
		}
Example #7
0
		public XmlTreeView(IViewContent parent, XmlSchemaCompletionCollection schemas, XmlSchemaCompletion defaultSchema)
			: base(parent)
		{
			this.schemas = schemas;
			this.defaultSchema = defaultSchema;
			
			this.TabPageText = "${res:ICSharpCode.XmlEditor.XmlTreeView.Title}";
			this.treeViewContainer = new XmlTreeViewContainerControl(schemas, defaultSchema);
			this.treeViewContainer.DirtyChanged += TreeViewContainerDirtyChanged;
			treeViewContainer.AttributesGrid.ContextMenuStrip = MenuService.CreateContextMenu(treeViewContainer, "/AddIns/XmlEditor/XmlTree/AttributesGrid/ContextMenu");
			treeViewContainer.TreeView.ContextMenuStrip = MenuService.CreateContextMenu(treeViewContainer, "/AddIns/XmlEditor/XmlTree/ContextMenu");
		}
		public void AddUserSchema(XmlSchemaCompletion schema)
		{
			fileSystem.CreateDirectory(userDefinedSchemaFolder);
			
			FileName newSchemaDestinationFileName = GetUserDefinedSchemaDestination(schema);
			fileSystem.CopyFile(schema.FileName, newSchemaDestinationFileName);			
			
			schema.FileName = newSchemaDestinationFileName;
			schemas.Add(schema);
			
			OnUserDefinedSchemaAdded();
		}		
		public void TwoSchemasWithFileName()
		{
			XmlSchemaCompletion schema = new XmlSchemaCompletion();
			schema.FileName = "a.xsd";
			schemas.Add(schema);
			
			schema = new XmlSchemaCompletion();
			schema.FileName = "b.xsd";
			schemas.Add(schema);
			
			string[] expectedFileNames = new string[] {"a.xsd", "b.xsd"};
			Assert.AreEqual(expectedFileNames, XmlSchemaCompletionCollectionFileNames.GetFileNames(schemas));
		}
		public override void FixtureInit()
		{
			XmlSchemaCompletionCollection schemas = new XmlSchemaCompletionCollection();
			schemas.Add(SchemaCompletion);
			XmlSchemaCompletion xsdSchemaCompletionData = new XmlSchemaCompletion(ResourceManager.ReadXsdSchema());
			schemas.Add(xsdSchemaCompletionData);
			
			string xml = GetSchema();			
			int index = xml.IndexOf("ref=\"dir\"");
			index = xml.IndexOf("dir", index);
			XmlSchemaDefinition schemaDefinition = new XmlSchemaDefinition(schemas, SchemaCompletion);
			schemaAttribute = (XmlSchemaAttribute)schemaDefinition.GetSelectedSchemaObject(xml, index);
		}
        public override void FixtureInit()
        {
            XmlSchemaCompletionCollection schemas = new XmlSchemaCompletionCollection();
            schemas.Add(SchemaCompletion);
            XmlSchemaCompletion xsdSchemaCompletion = new XmlSchemaCompletion(ResourceManager.ReadXsdSchema());
            schemas.Add(xsdSchemaCompletion);

            string xml = GetSchema();
            int index = xml.IndexOf("type=\"text-type\"");
            index = xml.IndexOf("text-type", index);
            XmlSchemaDefinition schemaDefinition = new XmlSchemaDefinition(schemas, SchemaCompletion);
            schemaComplexType = (XmlSchemaComplexType)schemaDefinition.GetSelectedSchemaObject(xml, index);
        }
		public void FixtureInit()
		{
			schemaCompletion = new XmlSchemaCompletion(ResourceManager.ReadXhtmlStrictSchema());
			
			// Set up h1 element's path.
			h1Path = new XmlElementPath();
			h1Path.AddElement(new QualifiedName("html", namespaceURI));
			h1Path.AddElement(new QualifiedName("body", namespaceURI));
			h1Path.AddElement(new QualifiedName("h1", namespaceURI));
			
			// Get h1 element info.
			h1Attributes = schemaCompletion.GetAttributeCompletion(h1Path);
		}
		public void Init()
		{
			userDefinedSchemaFolder = @"c:\users\user\sharpdevelop\schemas";
			
			schema = LoadTestSchema();

			userSchemaAddedEventFiredCount = 0;
			fileSystem = new MockFileSystem();
			factory = new MockXmlSchemaCompletionDataFactory();
			registeredSchemas = new RegisteredXmlSchemas(new string[0], userDefinedSchemaFolder, fileSystem, factory);
			registeredSchemas.UserDefinedSchemaAdded += UserSchemaAdded;
			registeredSchemas.AddUserSchema(schema);
		}
		public void FixtureInit()
		{
			XmlSchemaCompletionCollection items = new XmlSchemaCompletionCollection();
			
			StringReader reader = new StringReader(GetSchema(firstNamespace));
			XmlSchemaCompletion schema = new XmlSchemaCompletion(reader);
			items.Add(schema);
			
			reader = new StringReader(GetSchema(secondNamespace));
			schema = new XmlSchemaCompletion(reader);
			items.Add(schema);
			namespaceCompletionItems = items.GetNamespaceCompletion();
		}
		public override void FixtureInit()
		{
			XmlSchemaCompletionCollection schemas = new XmlSchemaCompletionCollection();
			schemas.Add(SchemaCompletion);
			XmlSchemaCompletion xsdSchemaCompletionData = new XmlSchemaCompletion(ResourceManager.ReadXsdSchema());
			schemas.Add(xsdSchemaCompletionData);
			
			string xml = GetSchema();
			
			int index = xml.IndexOf("ref=\"xs:list");
			index = xml.IndexOf("xs", index);
			XmlSchemaDefinition schemaDefinition = new XmlSchemaDefinition(schemas, SchemaCompletion);
			referencedSchemaElement = (XmlSchemaElement)schemaDefinition.GetSelectedSchemaObject(xml, index);
		}
		public void Init()
		{
			treeViewContainer = new DerivedXmlTreeViewContainerControl();
							
			XmlSchemaCompletion xhtmlSchema = new XmlSchemaCompletion(ResourceManager.ReadXhtmlStrictSchema());
			XmlSchemaCompletionCollection schemas = new XmlSchemaCompletionCollection();
			
			treeViewContainer.LoadXml("<html><body></body></html>", schemas, null);
			doc = treeViewContainer.Document;
			treeView = treeViewContainer.TreeView;
			
			htmlTreeNode = (XmlElementTreeNode)treeView.Nodes[0];
			htmlTreeNode.Expanding();
			bodyTreeNode = (XmlElementTreeNode)htmlTreeNode.Nodes[0];
			
			bodyElement = (XmlElement)doc.SelectSingleNode("/html/body");
		}
		XmlCompletionItemCollection GetCompletionItems(ITextEditor editor, XmlSchemaCompletion defaultSchema)
		{
			int offset = editor.Caret.Offset;
			string textUpToCursor = editor.Document.GetText(0, offset);
			
			XmlCompletionItemCollection items = new XmlCompletionItemCollection();
			if (XmlParser.IsInsideAttributeValue(textUpToCursor, offset)) {
				items = schemas.GetNamespaceCompletion(textUpToCursor);
				if (items.Count == 0)
					items = schemas.GetAttributeValueCompletion(textUpToCursor, editor.Caret.Offset, defaultSchema);
			} else {
				items = schemas.GetAttributeCompletion(textUpToCursor, defaultSchema);
				if (items.Count == 0)
					items = schemas.GetElementCompletion(textUpToCursor, defaultSchema);
			}
			return items;
		}
		public void Init()
		{
			XmlSchemaCompletionCollection schemas = new XmlSchemaCompletionCollection();
			xsdSchema = new XmlSchemaCompletion(ResourceManager.ReadXsdSchema());
			schemas.Add(xsdSchema);

			associations = new XmlSchemaFileAssociations(new Properties(), new DefaultXmlSchemaFileAssociations(new AddInTreeNode()), schemas);
			associations.SetSchemaFileAssociation(new XmlSchemaFileAssociation(".xsd", "http://www.w3.org/2001/XMLSchema", "xs"));
			
			textEditor = new MockTextEditor();
			textEditor.FileName = new FileName(@"c:\projects\test.xsd");
			textEditor.Document.Text = "<xs:schema elementFormDefault=\"\"></xs:schema>";
			
			// Put cursor inside the double quotes following the elementFormDefault attribute
			textEditor.Caret.Offset = 31;	
			
			completionBinding = new XmlCodeCompletionBinding(associations);
			result = completionBinding.CtrlSpace(textEditor);
		}
		public void Init()
		{
			treeViewContainer = new DerivedXmlTreeViewContainerControl();
			treeViewContainer.DirtyChanged += TreeViewContainerDirtyChanged;
							
			XmlSchemaCompletion xhtmlSchema = new XmlSchemaCompletion(ResourceManager.ReadXhtmlStrictSchema());
			schemas = new XmlSchemaCompletionCollection();
			
			treeViewContainer.LoadXml("<html id='a'>text<body></body></html>", schemas, null);
			doc = treeViewContainer.Document;
			treeView = treeViewContainer.TreeView;
			
			htmlTreeNode = (XmlElementTreeNode)treeView.Nodes[0];
			htmlTreeNode.Expanding();
			textTreeNode = (XmlTextTreeNode)htmlTreeNode.Nodes[0];

			splitContainer = (SplitContainer)treeViewContainer.Controls["splitContainer"];
			
			textBox = (RichTextBox)splitContainer.Panel2.Controls["textBox"];
			errorMessageTextBox = (RichTextBox)splitContainer.Panel2.Controls["errorMessageTextBox"];
			attributesGrid = (PropertyGrid)splitContainer.Panel2.Controls["attributesGrid"];
		}
		public void Init()
		{
			treeViewContainer = new XmlTreeViewContainerControl();
							
			XmlSchemaCompletion xhtmlSchema = new XmlSchemaCompletion(ResourceManager.ReadXhtmlStrictSchema());
			XmlSchemaCompletionCollection schemas = new XmlSchemaCompletionCollection();
			
			treeViewContainer.LoadXml("<!-- comment --><html><body class='a'><p>Text</p></body></html>", schemas, null);
			doc = treeViewContainer.Document;
			treeView = treeViewContainer.TreeView;
			
			commentTreeNode = (XmlCommentTreeNode)treeView.Nodes[0];
			htmlTreeNode = (XmlElementTreeNode)treeView.Nodes[1];
			htmlTreeNode.Expanding();
			
			bodyTreeNode = (XmlElementTreeNode)htmlTreeNode.Nodes[0];
			bodyTreeNode.Expanding();
			
			paraTreeNode = (XmlElementTreeNode)bodyTreeNode.Nodes[0];
			paraTreeNode.Expanding();
			
			textTreeNode = (XmlTextTreeNode)paraTreeNode.Nodes[0];
		}
        public void Init()
        {
            fileSystem = new MockFileSystem();
            factory = new MockXmlSchemaCompletionDataFactory();
            registeredXmlSchemas = new RegisteredXmlSchemas(new string[0], @"c:\users\user\sharpdevelop\schemas", fileSystem, factory);

            string testSchemaXml = "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='http://test' />";
            XmlSchemaCompletion schema = new XmlSchemaCompletion(new StringReader(testSchemaXml));
            schema.IsReadOnly = false;
            registeredXmlSchemas.Schemas.Add(schema);

            XmlSchemaFileAssociations associations = new XmlSchemaFileAssociations(new Properties(), new DefaultXmlSchemaFileAssociations(null), registeredXmlSchemas.Schemas);
            associations.SetSchemaFileAssociation(new XmlSchemaFileAssociation(".test", "http://test"));
            panel = new MockXmlSchemasPanel();

            schemasEditor = new RegisteredXmlSchemasEditor(registeredXmlSchemas, new string[] { ".test" }, associations, panel, factory);
            schemasEditor.LoadOptions();

            string newXmlSchemaFileName = @"c:\projects\new.xsd";
            string newSchemaXml = "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='http://new' />";
            factory.AddSchemaXml(newXmlSchemaFileName, newSchemaXml);

            panel.OpenFileDialogFileNameToReturn = newXmlSchemaFileName;
            panel.OpenFileDialogResultToReturn = true;

            // Add schema from file system to ensure that the list of schemas shown to the
            // user is from the list of schemas in the list box when changing the association
            // to a file extension
            schemasEditor.AddSchemaFromFileSystem();

            panel.SelectedXmlSchemaFileAssociationListItemIndex = 0;
            schemasEditor.XmlSchemaFileAssociationFileExtensionSelectionChanged();

            panel.SelectXmlSchemaWindowDialogResultToReturn = true;
            panel.SelectXmlSchemaWindowNamespaceToReturn = "http://new";
            schemasEditor.ChangeSchemaAssociation();
        }
		public XmlTreeViewContainerControl(XmlSchemaCompletionCollection schemas, XmlSchemaCompletion defaultSchema)
		{
			InitializeComponent();
			InitImages();
			editor = new XmlTreeEditor(this, schemas, defaultSchema);
		}
 void CreateBarSchema()
 {
     string xml = "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='bar' />";
     barSchema = new XmlSchemaCompletion(new StringReader(xml));
     barSchema.FileName = FileName.Create("bar.xsd");
 }
Example #24
0
 public XmlTreeEditor(IXmlTreeView view, XmlSchemaCompletionCollection schemas, XmlSchemaCompletion defaultSchema)
 {
     this.view = view;
     this.schemas = schemas;
     this.defaultSchema = defaultSchema;
 }
		public void SchemaReturnedForKnownSchemaFileExtension()
		{
			string xml = "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='http://example.com' />";
			XmlSchemaCompletion schema = new XmlSchemaCompletion(new StringReader(xml));
			schemas.Add(schema);
			
			Assert.AreSame(schema, associations.GetSchemaCompletion(".xml"));
		}
		XmlSchemaAttribute FindSchemaObjectForSelectedAttribute(XmlSchemaCompletion schemaForSelectedElement, XmlSchemaElement selectedSchemaElement)
		{
			return schemaForSelectedElement.FindAttribute(selectedSchemaElement, selectedElement.SelectedAttribute);
		}
		XmlSchemaElement FindSchemaObjectForSelectedElement(XmlSchemaCompletion schemaForSelectedElement)
		{
			return schemaForSelectedElement.FindElement(selectedElement.Path);
		}
		XmlSchemaObject FindSchemaObjectType(QualifiedName qualifiedName, string elementName, XmlSchemaCompletion schema)
		{
			switch (elementName) {
				case "element":
					return schema.FindComplexType(qualifiedName);
				case "attribute":
					return schema.FindSimpleType(qualifiedName.Name);
			}
			return null;
		}
		public XmlSchemaDefinition(XmlSchemaCompletionCollection schemas, XmlSchemaCompletion currentSchema)
		{
			this.schemas = schemas;
			this.currentSchema = currentSchema;
		}
		XmlSchemaObject FindSchemaObjectReference(QualifiedName qualifiedName, string elementName, XmlSchemaCompletion schema)
		{
			switch (elementName) {
				case "element":
					return schema.FindRootElement(qualifiedName);
				case "attribute":
					return schema.FindAttribute(qualifiedName.Name);
				case "group":
					return schema.FindGroup(qualifiedName.Name);
				case "attributeGroup":
					return schema.FindAttributeGroup(qualifiedName.Name);
			}
			return null;
		}