Ejemplo n.º 1
0
        public int CreateEditorInstance(uint grfCreateDoc, string pszMkDocument, string pszPhysicalView, IVsHierarchy pvHier, uint itemid, IntPtr punkDocDataExisting, out IntPtr ppunkDocView, out IntPtr ppunkDocData, out string pbstrEditorCaption, out Guid pguidCmdUI, out int pgrfCDW)
        {
            ppunkDocView       = IntPtr.Zero;
            ppunkDocData       = IntPtr.Zero;
            pbstrEditorCaption = String.Empty;

            //pguidCmdUI is the highest priority Guid that Visual Studio Shell looks at when translating key strokes into editor commands.
            //Here we intentionally set it to Guid.Empty so it will not play a part in translating keystrokes at all. The next highest priority
            //will be commands tied to this FSharpEditorFactory (such as Alt-Enter).
            //However, because we are setting pguidCmdUI, we are not going to get typical text editor commands bound to this editor unless we inherit
            //those keybindings on the IVsWindowFrame in which our editor lives.
            pguidCmdUI = Guid.Empty;
            pgrfCDW    = 0;

            IVsTextBuffer textBuffer = null;

            // Is this document already open? If so, let's see if it's a IVsTextBuffer we should re-use. This allows us
            // to properly handle multiple windows open for the same document.
            if (punkDocDataExisting != IntPtr.Zero)
            {
                object docDataExisting = Marshal.GetObjectForIUnknown(punkDocDataExisting);

                textBuffer = docDataExisting as IVsTextBuffer;

                if (textBuffer == null)
                {
                    // We are incompatible with the existing doc data
                    return(VSConstants.VS_E_INCOMPATIBLEDOCDATA);
                }
            }

            // Do we need to create a text buffer?
            if (textBuffer == null)
            {
                var contentType = _contentTypeRegistryService.GetContentType(Constants.FSharpContentType);
                textBuffer = _editorAdaptersFactoryService.CreateVsTextBufferAdapter(_oleServiceProvider, contentType);
            }

            // If the text buffer is marked as read-only, ensure that the padlock icon is displayed
            // next the new window's title and that [Read Only] is appended to title.
            READONLYSTATUS readOnlyStatus = READONLYSTATUS.ROSTATUS_NotReadOnly;
            uint           textBufferFlags;

            if (ErrorHandler.Succeeded(textBuffer.GetStateFlags(out textBufferFlags)) &&
                0 != (textBufferFlags & ((uint)BUFFERSTATEFLAGS.BSF_FILESYS_READONLY | (uint)BUFFERSTATEFLAGS.BSF_USER_READONLY)))
            {
                readOnlyStatus = READONLYSTATUS.ROSTATUS_ReadOnly;
            }

            var codeWindow = _editorAdaptersFactoryService.CreateVsCodeWindowAdapter(_oleServiceProvider);

            codeWindow.SetBuffer((IVsTextLines)textBuffer);
            codeWindow.GetEditorCaption(readOnlyStatus, out pbstrEditorCaption);

            ppunkDocView = Marshal.GetIUnknownForObject(codeWindow);
            ppunkDocData = Marshal.GetIUnknownForObject(textBuffer);

            return(VSConstants.S_OK);
        }
        public static string GetEditorCaption(this IVsCodeWindow codeWindow, READONLYSTATUS status)
        {
            Contract.Requires<ArgumentNullException>(codeWindow != null, "codeWindow");

            string caption;
            if (ErrorHandler.Failed(codeWindow.GetEditorCaption(status, out caption)))
                return null;

            return caption;
        }
Ejemplo n.º 3
0
        public int GetEditorCaption(READONLYSTATUS dwReadOnly, out string pbstrEditorCaption)
        {
            IVsCodeWindow vsCodeWindow = SourceCodeWindow;

            if (vsCodeWindow != null)
            {
                return(vsCodeWindow.GetEditorCaption(dwReadOnly, out pbstrEditorCaption));
            }
            pbstrEditorCaption = null;
            return(VSConstants.E_NOTIMPL);
        }
        public static string GetEditorCaption(this IVsCodeWindow codeWindow, READONLYSTATUS status)
        {
            Contract.Requires <ArgumentNullException>(codeWindow != null, "codeWindow");

            string caption;

            if (ErrorHandler.Failed(codeWindow.GetEditorCaption(status, out caption)))
            {
                return(null);
            }

            return(caption);
        }
Ejemplo n.º 5
0
        public int CreateEditorInstance(
            uint grfCreateDoc,
            string pszMkDocument,
            string pszPhysicalView,
            IVsHierarchy vsHierarchy,
            uint itemid,
            IntPtr punkDocDataExisting,
            out IntPtr ppunkDocView,
            out IntPtr ppunkDocData,
            out string pbstrEditorCaption,
            out Guid pguidCmdUI,
            out int pgrfCDW)
        {
            ppunkDocView       = IntPtr.Zero;
            ppunkDocData       = IntPtr.Zero;
            pbstrEditorCaption = string.Empty;
            pguidCmdUI         = Guid.Empty;
            pgrfCDW            = 0;

            var physicalView = pszPhysicalView == null
                ? "Code"
                : pszPhysicalView;

            IVsTextBuffer textBuffer = null;

            // Is this document already open? If so, let's see if it's a IVsTextBuffer we should re-use. This allows us
            // to properly handle multiple windows open for the same document.
            if (punkDocDataExisting != IntPtr.Zero)
            {
                object docDataExisting = Marshal.GetObjectForIUnknown(punkDocDataExisting);

                textBuffer = docDataExisting as IVsTextBuffer;

                if (textBuffer == null)
                {
                    // We are incompatible with the existing doc data
                    return(VSConstants.VS_E_INCOMPATIBLEDOCDATA);
                }
            }

            // Do we need to create a text buffer?
            if (textBuffer == null)
            {
                var contentType = _contentTypeRegistryService.GetContentType(ContentTypeName);
                textBuffer = _editorAdaptersFactoryService.CreateVsTextBufferAdapter(_oleServiceProvider, contentType);

                if (_encoding)
                {
                    var userData = textBuffer as IVsUserData;
                    if (userData != null)
                    {
                        // The editor shims require that the boxed value when setting the PromptOnLoad flag is a uint
                        int hresult = userData.SetData(
                            VSConstants.VsTextBufferUserDataGuid.VsBufferEncodingPromptOnLoad_guid,
                            (uint)__PROMPTONLOADFLAGS.codepagePrompt);

                        if (ErrorHandler.Failed(hresult))
                        {
                            return(hresult);
                        }
                    }
                }
            }

            // If the text buffer is marked as read-only, ensure that the padlock icon is displayed
            // next the new window's title and that [Read Only] is appended to title.
            READONLYSTATUS readOnlyStatus = READONLYSTATUS.ROSTATUS_NotReadOnly;
            uint           textBufferFlags;

            if (ErrorHandler.Succeeded(textBuffer.GetStateFlags(out textBufferFlags)) &&
                0 != (textBufferFlags & ((uint)BUFFERSTATEFLAGS.BSF_FILESYS_READONLY | (uint)BUFFERSTATEFLAGS.BSF_USER_READONLY)))
            {
                readOnlyStatus = READONLYSTATUS.ROSTATUS_ReadOnly;
            }

            switch (physicalView)
            {
            case "Form":

                // We must create the WinForms designer here
                const string LoaderName      = "Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader";
                var          designerService = (IVSMDDesignerService)ServiceProvider.GetService(typeof(SVSMDDesignerService));
                var          designerLoader  = (IVSMDDesignerLoader)designerService.CreateDesignerLoader(LoaderName);

                try
                {
                    designerLoader.Initialize(_oleServiceProvider, vsHierarchy, (int)itemid, (IVsTextLines)textBuffer);
                    pbstrEditorCaption = designerLoader.GetEditorCaption((int)readOnlyStatus);

                    var designer = designerService.CreateDesigner(_oleServiceProvider, designerLoader);
                    ppunkDocView = Marshal.GetIUnknownForObject(designer.View);
                    pguidCmdUI   = designer.CommandGuid;
                }
                catch
                {
                    designerLoader.Dispose();
                    throw;
                }

                break;

            case "Code":

                var codeWindow = _editorAdaptersFactoryService.CreateVsCodeWindowAdapter(_oleServiceProvider);
                codeWindow.SetBuffer((IVsTextLines)textBuffer);

                codeWindow.GetEditorCaption(readOnlyStatus, out pbstrEditorCaption);

                ppunkDocView = Marshal.GetIUnknownForObject(codeWindow);
                pguidCmdUI   = VSConstants.GUID_TextEditorFactory;

                break;

            default:

                return(VSConstants.E_INVALIDARG);
            }

            ppunkDocData = Marshal.GetIUnknownForObject(textBuffer);

            return(VSConstants.S_OK);
        }
Ejemplo n.º 6
0
 public int GetEditorCaption(READONLYSTATUS dwReadOnly, out string pbstrEditorCaption)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 7
0
 public int GetEditorCaption(READONLYSTATUS dwReadOnly, out string pbstrEditorCaption)
 {
     pbstrEditorCaption = null;
     return VSConstants.S_OK;
 }
Ejemplo n.º 8
0
 int IVsCodeWindow.GetEditorCaption(READONLYSTATUS dwReadOnly, out string pbstrEditorCaption)
 {
     pbstrEditorCaption = null;
     return VSConstants.E_NOTIMPL;
 }
 public int GetEditorCaption(READONLYSTATUS dwReadOnly, out string pbstrEditorCaption) {
     throw new NotImplementedException();
 }
Ejemplo n.º 10
0
 public int GetEditorCaption(READONLYSTATUS dwReadOnly, out string pbstrEditorCaption)
 {
     return(codeWindow.GetEditorCaption(dwReadOnly, out pbstrEditorCaption));
 }
Ejemplo n.º 11
0
 int IVsCodeWindow.GetEditorCaption(READONLYSTATUS dwReadOnly, out string pbstrEditorCaption) => _editorWindow.GetEditorCaption(dwReadOnly, out pbstrEditorCaption);
 public int GetEditorCaption(READONLYSTATUS dwReadOnly, out string pbstrEditorCaption)
 {
     return _vsCodeWindow.GetEditorCaption(dwReadOnly, out pbstrEditorCaption);
 }
Ejemplo n.º 13
0
        public static string GetEditorCaption([NotNull] this IVsCodeWindow codeWindow, READONLYSTATUS status)
        {
            Requires.NotNull(codeWindow, nameof(codeWindow));

            string caption;

            if (ErrorHandler.Failed(codeWindow.GetEditorCaption(status, out caption)))
            {
                return(null);
            }

            return(caption);
        }
Ejemplo n.º 14
0
 public int GetEditorCaption(READONLYSTATUS dwReadOnly, out string pbstrEditorCaption) => editor.codeWindow.GetEditorCaption(dwReadOnly, out pbstrEditorCaption);
Ejemplo n.º 15
0
 int IVsCodeWindow.GetEditorCaption(READONLYSTATUS dwReadOnly, out string pbstrEditorCaption)
 {
     return(((IVsCodeWindow)_subCodeWindow).GetEditorCaption(dwReadOnly, out pbstrEditorCaption));
 }
Ejemplo n.º 16
0
 public int GetEditorCaption(READONLYSTATUS dwReadOnly, out string pbstrEditorCaption)
 {
     pbstrEditorCaption = null;
     return(VSConstants.S_OK);
 }