Ejemplo n.º 1
0
 /// <summary>
 /// Default ctor
 /// </summary>
 internal XmlEditorPane(Dot42Package package, IXmlEditorPaneContext context, string fileName, IVsTextLines textBuffer)
     : base(null)
 {
     thisPackage     = package;
     this.context    = context;
     _fileName       = fileName;
     this.textBuffer = textBuffer;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Default ctor
 /// </summary>
 internal XmlEditorPane(Dot42Package package, IXmlEditorPaneContext context, string fileName, IVsTextLines textBuffer)
     : base(null)
 {
     thisPackage = package;
     this.context = context;
     _fileName = fileName;
     this.textBuffer = textBuffer;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates the document view.
        /// </summary>
        /// <param name="physicalView">The physical view.</param>
        /// <param name="itemid">The itemid.</param>
        /// <param name="textLines">The text lines.</param>
        /// <param name="editorCaption">The editor caption.</param>
        /// <param name="cmdUI">The CMD UI.</param>
        /// <param name="documentPath">The document path.</param>
        /// <returns></returns>
        private IntPtr CreateDocumentView(string physicalView, uint itemid, IVsTextLines textLines, out string editorCaption, out Guid cmdUI, string documentPath, IXmlEditorPaneContext context)
        {
            // Initialize out parameters
            editorCaption = String.Empty;
            cmdUI         = Guid.Empty;

            if (String.IsNullOrEmpty(physicalView))
            {
                // Create Code view as default physical view
                return(this.CreateCodeView(textLines, ref editorCaption, ref cmdUI));
            }

            if (physicalView == "Design")
            {
                try
                {
                    // Create Designer View
                    return(this.CreateDesignerView(itemid, textLines, ref editorCaption, ref cmdUI, documentPath, context));
                }
                catch (InvalidOperationException ex)
                {
                    var openCodeEditor = MessageBox.Show(ex.Message, null, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes;
                    if (openCodeEditor)
                    {
                        // Create Code view instead
                        return(this.CreateCodeView(textLines, ref editorCaption, ref cmdUI));
                    }

                    // Could not handle exception, rethrow
                    throw;
                }
            }

            // We couldn't create the view
            // Return special error code so VS can try another editor factory.
            ErrorHandler.ThrowOnFailure(VSConstants.VS_E_UNSUPPORTEDFORMAT);

            return(IntPtr.Zero);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates the designer view.
        /// </summary>
        /// <param name="itemid">The itemid.</param>
        /// <param name="textLines">The text lines.</param>
        /// <param name="editorCaption">The editor caption.</param>
        /// <param name="cmdUI">The CMD UI.</param>
        /// <param name="documentMoniker">The document moniker.</param>
        /// <returns></returns>
        private IntPtr CreateDesignerView(uint itemid, IVsTextLines textLines, ref string editorCaption, ref Guid cmdUI, string documentMoniker, IXmlEditorPaneContext context)
        {
            // Create the editor pane
            var editorPane = new XmlEditorPane(package, context, documentMoniker, textLines);

            // Set the Command guid and the editor caption
            cmdUI         = GuidList.Guids.guidXmlEditorFactory;
            editorCaption = " [Design]";

            return(Marshal.GetIUnknownForObject(editorPane));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates an instance of the FrameXML editor.
        /// </summary>
        public int CreateEditorInstance(
            uint createEditorFlags,
            string documentMoniker,
            string physicalView,
            IVsHierarchy hierarchy,
            uint itemid,
            IntPtr docDataExisting,
            out IntPtr docView,
            out IntPtr docData,
            out string editorCaption,
            out Guid commandUIGuid,
            out int createDocumentWindowFlags)
        {
            // Initialize out parameters
            docView                   = IntPtr.Zero;
            docData                   = IntPtr.Zero;
            commandUIGuid             = new Guid(GuidList.Strings.guidXmlEditorFactory);
            createDocumentWindowFlags = 0;
            editorCaption             = null;

            // Validate inputs
            if ((createEditorFlags & (VSConstants.CEF_OPENFILE | VSConstants.CEF_SILENT)) == 0)
            {
                return(VSConstants.E_INVALIDARG);
            }

            // Get item type
            var projectItem = hierarchy.GetProjectItemFromHierarchy(itemid);
            var itemType    = projectItem.GetProjectItemType(serviceProvider);
            IXmlEditorPaneContext context = null;

            foreach (var ctx in editorContexts)
            {
                if (ctx.SupportsItemType(itemType))
                {
                    context = ctx;
                    break;
                }
            }
            if (context == null)
            {
                return(VSConstants.VS_E_UNSUPPORTEDFORMAT);
            }

            // Get the text buffer
            IVsTextLines textLines = GetTextBuffer(docDataExisting, documentMoniker);

            // Assign docData IntPtr to either existing docData or the new text buffer
            docData = docDataExisting != IntPtr.Zero ? docDataExisting : Marshal.GetIUnknownForObject(textLines);

            try
            {
                docView = CreateDocumentView(physicalView, itemid, textLines, out editorCaption, out commandUIGuid, documentMoniker, context);
            }
            finally
            {
                // If we were not able to create a view
                if (docView == IntPtr.Zero)
                {
                    // And we've created a new docData that is not the same as the docDataExisting
                    if (docDataExisting != docData && docData != IntPtr.Zero)
                    {
                        // Release the docData we have created and null it out
                        Marshal.Release(docData);
                        docData = IntPtr.Zero;
                    }
                }
            }

            return(VSConstants.S_OK);
        }