/// <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); } } } }
/// <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); }
public override void Run() { ITextEditor textEditor = SD.GetActiveViewContentService <ITextEditor>(); if (textEditor != null) { XmlView.FormatXml(textEditor); } }
public override void Run() { ITextEditorProvider provider = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorProvider; if (provider != null) { XmlView.FormatXml(provider.TextEditor); } }
public override void Run() { XmlView xmlView = XmlView.ActiveXmlView; if (xmlView != null) { xmlView.GoToSchemaDefinition(); } }
/// <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 override void Run() { // Find active XmlView. XmlView xmlView = XmlView.ActiveXmlView; if (xmlView != null) { xmlView.FormatXml(); } }
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); } }
/// <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); }
/// <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); } } }
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); }
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); }
/// <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); }
/// <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; } } }
/// <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; }
/// <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); } }
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]); } } } }
/// <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; }
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(); } }
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(); } }
/// <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)); }
public bool CanParse(string fileName) { return(XmlView.IsFileNameHandled(fileName)); }
/// <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); }
/// <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)); }
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"); }
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"); }