/// <summary>
        /// Runs the transform on the xml file using the assigned stylesheet.
        /// If no stylesheet is assigned the user is prompted to choose one.
        /// If the view represents a stylesheet that is currently assigned to an
        /// opened document then run the transform on that document.
        /// </summary>
        public override void Run()
        {
            XmlView xmlView = XmlView.ActiveXmlView;

            if (xmlView != null)
            {
                // Check to see if this view is actually a referenced stylesheet.
                if (!string.IsNullOrEmpty(xmlView.File.FileName))
                {
                    XmlView assocFile = GetAssociatedXmlView(xmlView.File.FileName);
                    if (assocFile != null)
                    {
                        LoggingService.Debug("Using associated xml file.");
                        xmlView = assocFile;
                    }
                }

                // Assign a stylesheet.
                if (xmlView.StylesheetFileName == null)
                {
                    xmlView.StylesheetFileName = AssignStylesheetCommand.BrowseForStylesheetFile();
                }

                if (xmlView.StylesheetFileName != null)
                {
                    try {
                        xmlView.RunXslTransform(GetStylesheetContent(xmlView.StylesheetFileName));
                    } catch (Exception ex) {
                        MessageService.ShowException(ex);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Retrieves additional data for a XML file.
        /// </summary>
        /// <param name="file">The file to retrieve the data for.</param>
        /// <returns>null if the file is not a valid XML file, otherwise a XmlView instance with additional data used by the XML editor.</returns>
        public static XmlView ForFile(OpenedFile file)
        {
            if (file == null)
            {
                return(null);
            }
            if (!XmlDisplayBinding.IsFileNameHandled(file.FileName))
            {
                return(null);
            }

            XmlView instance;

            if (!mapping.TryGetValue(file, out instance))
            {
                file.FileClosed += new EventHandler(FileClosedHandler);
                instance         = new XmlView()
                {
                    File = file
                };
                mapping.Add(file, instance);
            }

            return(instance);
        }
Exemplo n.º 3
0
        public override void Run()
        {
            ITextEditor textEditor = SD.GetActiveViewContentService <ITextEditor>();

            if (textEditor != null)
            {
                XmlView.FormatXml(textEditor);
            }
        }
Exemplo n.º 4
0
        public override void Run()
        {
            ITextEditorProvider provider = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorProvider;

            if (provider != null)
            {
                XmlView.FormatXml(provider.TextEditor);
            }
        }
Exemplo n.º 5
0
        public override void Run()
        {
            XmlView xmlView = XmlView.ActiveXmlView;

            if (xmlView != null)
            {
                xmlView.GoToSchemaDefinition();
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates an XmlTreeView with the specified context menu strips.
        /// This constructor is only used to test the XmlTreeView class.
        /// </summary>
        public XmlTreeView(XmlView xmlView, ContextMenuStrip attributesGridContextMenuStrip, ContextMenuStrip treeViewContextMenuStrip)
            : base(xmlView)
        {
            this.TabPageText = "${res:ICSharpCode.XmlEditor.XmlTreeView.Title}";

            this.xmlView = xmlView;
            treeViewContainer.DirtyChanged += TreeViewContainerDirtyChanged;
            treeViewContainer.AttributesGrid.ContextMenuStrip = attributesGridContextMenuStrip;
            treeViewContainer.TreeView.ContextMenuStrip = treeViewContextMenuStrip;
        }
Exemplo n.º 7
0
        public override void Run()
        {
            // Find active XmlView.
            XmlView xmlView = XmlView.ActiveXmlView;

            if (xmlView != null)
            {
                xmlView.FormatXml();
            }
        }
Exemplo n.º 8
0
		protected override void LoadFromPrimary()
		{
			IFileDocumentProvider provider = this.PrimaryViewContent as IFileDocumentProvider;
			IDocument document = provider.GetDocumentForFile(this.PrimaryFile);
			treeViewContainer.LoadXml(document.Text);
			XmlView view = XmlView.ForFile(this.PrimaryFile);
			if (view != null) {
				XmlView.CheckIsWellFormed(view.TextEditor);
			}
		}
Exemplo n.º 9
0
        /// <summary>
        /// Creates an XmlTreeView with the specified context menu strips.
        /// This constructor is only used to test the XmlTreeView class.
        /// </summary>
        public XmlTreeView(XmlView xmlView, ContextMenuStrip attributesGridContextMenuStrip, ContextMenuStrip treeViewContextMenuStrip)
            : base(xmlView)
        {
            this.TabPageText = "${res:ICSharpCode.XmlEditor.XmlTreeView.Title}";

            this.xmlView = xmlView;
            treeViewContainer.DirtyChanged += TreeViewContainerDirtyChanged;
            treeViewContainer.AttributesGrid.ContextMenuStrip = attributesGridContextMenuStrip;
            treeViewContainer.TreeView.ContextMenuStrip       = treeViewContextMenuStrip;
        }
        public bool IsValid(object owner, Condition condition)
        {
            XmlView xmlView = XmlView.ActiveXmlView;

            if (xmlView != null)
            {
                return(xmlView.StylesheetFileName != null);
            }
            return(false);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Validate the xml.
        /// </summary>
        public override void Run()
        {
            // Find active XmlView.
            XmlView xmlView = XmlView.ActiveXmlView;

            if (xmlView != null)
            {
                // Validate the xml.
                xmlView.ValidateXml();
            }
        }
        public override void Run()
        {
            XmlView xmlView = XmlView.ActiveXmlView;

            if (xmlView != null && xmlView.StylesheetFileName != null)
            {
                try {
                    FileService.OpenFile(xmlView.StylesheetFileName);
                } catch (Exception ex) {
                    MessageService.ShowException(ex);
                }
            }
        }
Exemplo n.º 13
0
		protected override void SaveToPrimary()
		{
			// Do not modify text in the primary view if the data is not well-formed XML
			if (!treeViewContainer.IsErrorMessageTextBoxVisible && treeViewContainer.IsDirty) {
				XmlView view = XmlView.ForFile(this.PrimaryFile);
				if (view != null) {
					XmlView.ReplaceAll(treeViewContainer.Document.OuterXml, view.TextEditor);
					ignoreDirtyChange = true;
					treeViewContainer.IsDirty = false;
					ignoreDirtyChange = false;
				}
			}
		}
        public bool IsValid(object caller, Condition condition)
        {
            IWorkbenchWindow window = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow;

            if (window != null)
            {
                XmlView view = window.ActiveViewContent as XmlView;
                if (view != null)
                {
                    return(view.StylesheetFileName != null);
                }
            }
            return(false);
        }
Exemplo n.º 15
0
        string GetStylesheetContent(string fileName)
        {
            // File already open?
            XmlView view = FileService.GetOpenFile(fileName) as XmlView;

            if (view != null)
            {
                return(view.Text);
            }

            // Read in file contents.
            StreamReader reader = new StreamReader(fileName, true);

            return(reader.ReadToEnd());
        }
 /// <summary>
 /// Gets the xml view that is currently referencing the
 /// specified stylesheet view.
 /// </summary>
 static XmlView GetAssociatedXmlView(string stylesheetFileName)
 {
     foreach (IViewContent content in SD.Workbench.ViewContentCollection)
     {
         XmlView view = XmlView.ForViewContent(content);
         if (view != null && !string.IsNullOrEmpty(view.StylesheetFileName))
         {
             if (FileUtility.IsEqualFileName(view.StylesheetFileName, stylesheetFileName))
             {
                 return(view);
             }
         }
     }
     return(null);
 }
Exemplo n.º 17
0
 /// <summary>
 /// Gets the xml view that is currently referencing the
 /// specified stylesheet view.
 /// </summary>
 XmlView GetAssociatedXmlView(string stylesheetFileName)
 {
     foreach (IViewContent content in WorkbenchSingleton.Workbench.ViewContentCollection)
     {
         XmlView view = content as XmlView;
         if (view != null && view.StylesheetFileName != null)
         {
             if (FileUtility.IsEqualFileName(view.StylesheetFileName, stylesheetFileName))
             {
                 return(view);
             }
         }
     }
     return(null);
 }
Exemplo n.º 18
0
        /// <summary>
        /// Reads the configured xml file extensions and their associated namespaces.
        /// </summary>
        void PopulateFileExtensionComboBox()
        {
            string [] extensions = XmlView.GetXmlFileExtensions();

            foreach (string extension in extensions)
            {
                XmlSchemaAssociation            association = XmlEditorAddInOptions.GetSchemaAssociation(extension);
                XmlSchemaAssociationListBoxItem item        = new XmlSchemaAssociationListBoxItem(association.Extension, association.NamespaceUri, association.NamespacePrefix);
                fileExtensionComboBox.Items.Add(item);
            }

            if (fileExtensionComboBox.Items.Count > 0)
            {
                fileExtensionComboBox.SelectedIndex = 0;
                FileExtensionComboBoxSelectedIndexChanged(this, new EventArgs());
            }
        }
        public override void Run()
        {
            // Get active xml document.
            XmlView xmlView = XmlView.ActiveXmlView;

            if (xmlView != null)
            {
                // Prompt user for filename.
                string stylesheetFileName = BrowseForStylesheetFile();

                // Assign stylesheet.
                if (stylesheetFileName != null)
                {
                    xmlView.StylesheetFileName = stylesheetFileName;
                }
            }
        }
Exemplo n.º 20
0
		/// <summary>
		/// Retrieves additional data for a XML file.
		/// </summary>
		/// <param name="file">The file to retrieve the data for.</param>
		/// <returns>null if the file is not a valid XML file, otherwise a XmlView instance with additional data used by the XML editor.</returns>
		public static XmlView ForFile(OpenedFile file)
		{
			if (file == null) {
				return null;
			}
			if (!XmlDisplayBinding.IsFileNameHandled(file.FileName)) {
				return null;
			}
			
			XmlView instance;
			if (!mapping.TryGetValue(file, out instance)) {
				file.FileClosed += new EventHandler(FileClosedHandler);
				instance = new XmlView() { File = file };
				mapping.Add(file, instance);
			}
			
			return instance;
		}
Exemplo n.º 21
0
        /// <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))
            {
                TextAreaControl textAreaControl = view.TextEditorControl.ActiveTextAreaControl;
                if (length > 0 && line < textAreaControl.Document.TotalNumberOfLines)
                {
                    SelectionManager selectionManager = textAreaControl.SelectionManager;
                    selectionManager.ClearSelection();
                    TextLocation startPos = new TextLocation(column, line);
                    TextLocation endPos   = new TextLocation(column + length, line);
                    selectionManager.SetSelection(startPos, endPos);
                }
                line = Math.Min(line, textAreaControl.Document.TotalNumberOfLines - 1);
                textAreaControl.ScrollTo(line, column);
            }
        }
Exemplo n.º 22
0
        public override void Run()
        {
            // Find active XmlView.
            XmlView xmlView = XmlView.ActiveXmlView;

            if (xmlView != null)
            {
                // Create a schema based on the xml.
                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(xmlView.File.FileName, i + 1);
                        OpenNewXmlFile(fileName, schemas[i]);
                    }
                }
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// Scrolls to the specified line and column and also selects the given
        /// length of text at this location.
        /// </summary>
        static void ScrollTo(string filename, int line, int column, int length)
        {
            XmlView view = XmlView.ForFileName(filename);

            if (view != null)
            {
                ITextEditor editor = view.TextEditor;
                if (editor == null)
                {
                    return;
                }
                int corLine = Math.Min(line + 1, editor.Document.LineCount - 1);
                editor.JumpTo(corLine, column + 1);
                if (length > 0 && line < editor.Document.LineCount)
                {
                    int offset = editor.Document.PositionToOffset(line + 1, column + 1);
                    editor.Select(offset, length);
                }
            }
        }
		public void SetUp()
		{
			MockOpenedFile openedFile = new MockOpenedFile("test.xml");
			XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection();
			xmlView = new XmlView(new DefaultTextEditorProperties(), schemas);
			xmlView.SetPrimaryFileUnitTestMode(openedFile);
			view = new XmlTreeView(xmlView, null, null);
			treeViewContainer = (XmlTreeViewContainerControl)view.Control;
			treeView = treeViewContainer.TreeView;
			clipboardHandler = view as IClipboardHandler;
			
			xmlView.XmlEditor.Text = "<html><body><p></p></body></html>";
			openedFile.SwitchToView(view);
			
			htmlTreeNode = treeView.Nodes[0] as XmlElementTreeNode;
			htmlTreeNode.PerformInitialization();
			bodyTreeNode = htmlTreeNode.Nodes[0] as XmlElementTreeNode;
			bodyTreeNode.PerformInitialization();
			paragraphTreeNode = bodyTreeNode.Nodes[0] as XmlElementTreeNode;

			treeView.SelectedNode = null;
		}
Exemplo n.º 25
0
        void RunXPathQuery()
        {
            XmlView xmlView = XmlView.ActiveXmlView;

            if (xmlView == null)
            {
                return;
            }

            try {
                fileName = xmlView.File.FileName;

                // Clear previous XPath results.
                ClearResults();
                XPathNodeTextMarker.RemoveMarkers(xmlView.TextEditor.Document);

                // Run XPath query.
                XPathQuery       query = new XPathQuery(xmlView.TextEditor, GetNamespaces());
                XPathNodeMatch[] nodes = query.FindNodes(xpathComboBox.Text);
                if (nodes.Length > 0)
                {
                    AddXPathResults(nodes);
                    XPathNodeTextMarker marker = new XPathNodeTextMarker(xmlView.TextEditor.Document);
                    marker.AddMarkers(nodes);
                }
                else
                {
                    AddNoXPathResult();
                }
                AddXPathToHistory();
            } catch (XPathException xpathEx) {
                AddErrorResult(xpathEx);
            } catch (XmlException xmlEx) {
                AddErrorResult(xmlEx);
            } finally {
                BringResultsTabToFront();
            }
        }
Exemplo n.º 26
0
        void RunXPathQuery()
        {
            XmlView view = XmlView.ActiveXmlView;

            if (view == null)
            {
                return;
            }

            try {
                MarkerStrategy markerStrategy = view.TextEditorControl.Document.MarkerStrategy;
                fileName = view.PrimaryFileName;

                // Clear previous XPath results.
                ClearResults();
                XPathNodeTextMarker.RemoveMarkers(markerStrategy);

                // Run XPath query.
                XPathNodeMatch[] nodes = view.SelectNodes(xPathComboBox.Text, GetNamespaces());
                if (nodes.Length > 0)
                {
                    AddXPathResults(nodes);
                    XPathNodeTextMarker.AddMarkers(markerStrategy, nodes);
                }
                else
                {
                    AddNoXPathResult();
                }
                AddXPathToHistory();
            } catch (XPathException xpathEx) {
                AddErrorResult(xpathEx);
            } catch (XmlException xmlEx) {
                AddErrorResult(xmlEx);
            } finally {
                BringResultsTabToFront();
                view.TextEditorControl.Refresh();
            }
        }
Exemplo n.º 27
0
 /// <summary>
 /// Can only create content for file with extensions that are
 /// known to be xml files as specified in the SyntaxModes.xml file.
 /// </summary>
 public bool CanCreateContentForFile(string fileName)
 {
     return(XmlView.IsFileNameHandled(fileName));
 }
Exemplo n.º 28
0
 public bool CanParse(string fileName)
 {
     return(XmlView.IsFileNameHandled(fileName));
 }
Exemplo n.º 29
0
		/// <summary>
		/// Tests whether the specified view matches the filename the XPath
		/// results were found in.
		/// </summary>
		bool IsFileNameMatch(XmlView view)
		{
			return FileUtility.IsEqualFileName(fileName, view.PrimaryFileName);
		}
Exemplo n.º 30
0
 /// <summary>
 /// Tests whether the specified view matches the filename the XPath
 /// results were found in.
 /// </summary>
 bool IsFileNameMatch(XmlView view)
 {
     return(FileUtility.IsEqualFileName(fileName, view.PrimaryFileName));
 }
Exemplo n.º 31
0
 public XmlTreeView(XmlView xmlView)
     : this(xmlView, null, null)
 {
     treeViewContainer.AttributesGrid.ContextMenuStrip = MenuService.CreateContextMenu(treeViewContainer, "/AddIns/XmlEditor/XmlTree/AttributesGrid/ContextMenu");
     treeViewContainer.TreeView.ContextMenuStrip = MenuService.CreateContextMenu(treeViewContainer, "/AddIns/XmlEditor/XmlTree/ContextMenu");
 }
Exemplo n.º 32
0
 public XmlTreeView(XmlView xmlView) : this(xmlView, null, null)
 {
     treeViewContainer.AttributesGrid.ContextMenuStrip = MenuService.CreateContextMenu(treeViewContainer, "/AddIns/XmlEditor/XmlTree/AttributesGrid/ContextMenu");
     treeViewContainer.TreeView.ContextMenuStrip       = MenuService.CreateContextMenu(treeViewContainer, "/AddIns/XmlEditor/XmlTree/ContextMenu");
 }