Пример #1
0
        /// <summary>
        /// Here we simply host the visual studio core text editor.
        /// </summary>
        public virtual void CreateEditorInstance(uint createDocFlags, string moniker,
                                                 string physicalView, IVsHierarchy pHier, uint itemid, IntPtr existingDocData,
                                                 out IntPtr docView, out IntPtr docData, out string editorCaption,
                                                 out Guid cmdUI, out int cancelled)
        {
            string ext = Path.GetExtension(moniker).ToLower();

            if (ext.StartsWith("."))
            {
                ext = ext.Substring(1);
            }
            bool takeover = CheckAllFileTypes() && !this.IsRegisteredExtension(ext);

            if (takeover && !IsOurKindOfFile(moniker))
            {
                throw new System.Runtime.InteropServices.COMException("", (int)VsConstants.VS_E_UNSUPPORTEDFORMAT);
            }

            IVsTextLines buffer = null;

            if (existingDocData != IntPtr.Zero)
            {
                buffer = (IVsTextLines)Marshal.GetTypedObjectForIUnknown(existingDocData, typeof(IVsTextLines));
            }
            else
            {
                buffer = (IVsTextLines)VsShell.CreateInstance(this.site, ref VsConstants.CLSID_VsTextBuffer, ref VsConstants.IID_IVsTextLines, typeof(IVsTextLines));
            }

            IObjectWithSite objWithSite = (IObjectWithSite)buffer;

            objWithSite.SetSite(this.site.Unwrap());

            object window = CreateEditorView(moniker, buffer, physicalView, out editorCaption, out cmdUI);

            if (takeover)
            {
                Guid langSid = GetLanguageSID();
                if (langSid != Guid.Empty)
                {
                    buffer.SetLanguageServiceID(ref langSid);
                    IVsUserData vud = (IVsUserData)buffer;
                    vud.SetData(ref VsConstants.GUID_VsBufferDetectLangSID, false);
                }
                // todo: for some reason my commands are disabled when we go through this
                // code path...
            }

            docView = Marshal.GetIUnknownForObject(window);
            docData = Marshal.GetIUnknownForObject(buffer);

            // VS core editor is the primary command handler
            cancelled = 0;
        }
Пример #2
0
        public virtual object CreateEditorView(string moniker, IVsTextLines buffer, string physicalView, out string editorCaption, out Guid cmdUI)
        {
            IVsCodeWindow window = (IVsCodeWindow)VsShell.CreateInstance(this.site, ref VsConstants.CLSID_VsCodeWindow, ref VsConstants.IID_IVsCodeWindow, typeof(IVsCodeWindow));

            window.SetBuffer(buffer);
            window.SetBaseEditorCaption(null);
            window.GetEditorCaption(READONLYSTATUS.ROSTATUS_Unknown, out editorCaption);

            Guid CMDUIGUID_TextEditor = new Guid(0x8B382828, 0x6202, 0x11d1, 0x88, 0x70, 0x00, 0x00, 0xF8, 0x75, 0x79, 0xD2);

            cmdUI = CMDUIGUID_TextEditor;
            return(window);
        }