Ejemplo n.º 1
0
        protected virtual IntPtr CreateCodeView(string documentMoniker, IVsTextLines textLines, ref string editorCaption, ref Guid cmdUI)
        {
            Type          codeWindowType = typeof(IVsCodeWindow);
            Guid          riid           = codeWindowType.GUID;
            Guid          clsid          = typeof(VsCodeWindowClass).GUID;
            IVsCodeWindow window         = (IVsCodeWindow)_package.CreateInstance(ref clsid, ref riid, codeWindowType);

            ErrorHandler.ThrowOnFailure(window.SetBuffer(textLines));
            ErrorHandler.ThrowOnFailure(window.SetBaseEditorCaption(null));
            ErrorHandler.ThrowOnFailure(window.GetEditorCaption(READONLYSTATUS.ROSTATUS_Unknown, out editorCaption));

            IVsUserData userData = textLines as IVsUserData;

            if (userData != null)
            {
                if (_promptEncodingOnLoad)
                {
                    var guid = VSConstants.VsTextBufferUserDataGuid.VsBufferEncodingPromptOnLoad_guid;
                    userData.SetData(ref guid, (uint)1);
                }
            }

            InitializeLanguageService(textLines);

            cmdUI = VSConstants.GUID_TextEditorFactory;
            return(Marshal.GetIUnknownForObject(window));
        }
Ejemplo n.º 2
0
        public CodeEditor(IDocument document)
        {
            Package       package        = MySqlDataProviderPackage.Instance;
            Type          codeWindowType = typeof(IVsCodeWindow);
            Guid          riid           = codeWindowType.GUID;
            Guid          clsid          = typeof(VsCodeWindowClass).GUID;
            IVsCodeWindow window         = (IVsCodeWindow)package.CreateInstance(ref clsid, ref riid, codeWindowType);

            codeWindow = (IVsWindowPane)window;

            IVsTextLines textLines;
            // Create a new IVsTextLines buffer.
            Type textLinesType = typeof(IVsTextLines);

            riid      = textLinesType.GUID;
            clsid     = typeof(VsTextBufferClass).GUID;
            textLines = package.CreateInstance(ref clsid, ref riid, textLinesType) as IVsTextLines;

            String test = "            Package package = MySqlDataProviderPackage.Instance;";

            textLines.InitializeContent(test, test.Length);

            String editorCaption;

            ErrorHandler.ThrowOnFailure(window.SetBuffer(textLines));
            ErrorHandler.ThrowOnFailure(window.SetBaseEditorCaption(null));
            ErrorHandler.ThrowOnFailure(window.GetEditorCaption(READONLYSTATUS.ROSTATUS_Unknown, out editorCaption));
        }
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);
        }
        private IntPtr CreateCodeView(IVsTextLines textLines, ref string editorCaption, ref Guid cmdUI)
        {
            IVsCodeWindow window = this.CreateInstance <IVsCodeWindow, VsCodeWindowClass>();

            ErrorHandler.ThrowOnFailure(window.SetBuffer(textLines));
            ErrorHandler.ThrowOnFailure(window.SetBaseEditorCaption(null));
            ErrorHandler.ThrowOnFailure(window.GetEditorCaption(READONLYSTATUS.ROSTATUS_Unknown, out editorCaption));

            cmdUI = VSConstants.GUID_TextEditorFactory;

            return(Marshal.GetIUnknownForObject(window));
        }
Ejemplo n.º 5
0
        private IntPtr CreateCodeView(IVsTextLines textLines, ref string editorCaption, ref Guid cmdUI)
        {
            Type          codeWindowType = typeof(IVsCodeWindow);
            Guid          riid           = codeWindowType.GUID;
            Guid          clsid          = typeof(VsCodeWindowClass).GUID;
            IVsCodeWindow window         = (IVsCodeWindow)package.CreateInstance(ref clsid, ref riid, codeWindowType);

            ErrorHandler.ThrowOnFailure(window.SetBuffer(textLines));
            ErrorHandler.ThrowOnFailure(window.SetBaseEditorCaption(null));
            ErrorHandler.ThrowOnFailure(window.GetEditorCaption(READONLYSTATUS.ROSTATUS_Unknown, out editorCaption));
            cmdUI = VSConstants.GUID_TextEditorFactory;
            return(Marshal.GetIUnknownForObject(window));
        }
        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.º 7
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);
        }
Ejemplo n.º 8
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.º 9
0
        private IntPtr CreateTextView(
            IVsTextLines textLines,
            IntPtr docDataExisting,
            Guid languageServiceId,
            out string editorCaption)
        {
            IVsCodeWindow window = _adaptersFactory.CreateVsCodeWindowAdapter(VsServiceProvider);

            ErrorHandler.ThrowOnFailure(window.SetBuffer(textLines));
            ErrorHandler.ThrowOnFailure(window.SetBaseEditorCaption(null));
            ErrorHandler.ThrowOnFailure(window.GetEditorCaption(READONLYSTATUS.ROSTATUS_Unknown, out editorCaption));

            CreateTextBufferInitializationTracker(textLines, docDataExisting, languageServiceId);
            return(Marshal.GetIUnknownForObject(window));
        }
Ejemplo n.º 10
0
        /// <include file='doc\EditorFactory.uex' path='docs/doc[@for="EditorFactory.CreateEditorView"]/*' />
        /// <summary>Return docView IUnknown COM object.</summary>
        public virtual IntPtr CreateEditorView(string moniker, IVsTextLines buffer, string physicalView, out string editorCaption, out Guid cmdUI)
        {
            Type          tcw     = typeof(IVsCodeWindow);
            Guid          riid    = tcw.GUID;
            Guid          clsid   = typeof(VsCodeWindowClass).GUID;
            IntPtr        docView = IntPtr.Zero;
            IVsCodeWindow window  = (IVsCodeWindow)package.CreateInstance(ref clsid, ref riid, tcw);

            NativeMethods.ThrowOnFailure(window.SetBuffer(buffer));
            NativeMethods.ThrowOnFailure(window.SetBaseEditorCaption(null));
            NativeMethods.ThrowOnFailure(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;
            docView = Marshal.GetIUnknownForObject(window);

            return(docView);
        }
Ejemplo n.º 11
0
        /// <include file='doc\EditorFactory.uex' path='docs/doc[@for="EditorFactory.CreateEditorView"]/*' />
        /// <summary>Return docView IUnknown COM object.</summary>
        public virtual IntPtr CreateEditorView(string moniker, IVsTextLines buffer, string physicalView, out string editorCaption, out Guid cmdUI)
        {
            Type tcw  = typeof(IVsCodeWindow);
            Guid riid = tcw.GUID;
            // Once this is done the project's assembly reference to "$(EnvRefPath)\Microsoft.VisualStudio.Editor.dll" may be removed
            Guid          clsid   = typeof(VsCodeWindowClass).GUID;
            IntPtr        docView = IntPtr.Zero;
            IVsCodeWindow window  = (IVsCodeWindow)package.CreateInstance(ref clsid, ref riid, tcw);

            Marshal.ThrowExceptionForHR(window.SetBuffer(buffer));
            Marshal.ThrowExceptionForHR(window.SetBaseEditorCaption(null));
            Marshal.ThrowExceptionForHR(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;
            docView = Marshal.GetIUnknownForObject(window);

            return(docView);
        }
Ejemplo n.º 12
0
        private IntPtr CreateTextView(
            IVsTextLines textLines,
            string documentName,
            IVsHierarchy hierarchy,
            VSConstants.VSITEMID itemid,
            IntPtr docDataExisting,
            Guid languageServiceId,
            ref string editorCaption,
            ref Guid cmdUI)
        {
            IVsCodeWindow window = _adaptersFactory.CreateVsCodeWindowAdapter(VsServiceProvider);

            ErrorHandler.ThrowOnFailure(window.SetBuffer(textLines));
            ErrorHandler.ThrowOnFailure(window.SetBaseEditorCaption(null));
            ErrorHandler.ThrowOnFailure(window.GetEditorCaption(READONLYSTATUS.ROSTATUS_Unknown, out editorCaption));

            cmdUI = VSConstants.GUID_TextEditorFactory;

            CreateTextBufferInitializationTracker(textLines, documentName, hierarchy, itemid, docDataExisting, languageServiceId);

            return(Marshal.GetIUnknownForObject(window));
        }
        /// <summary>
        /// Creates the code view.
        /// </summary>
        protected virtual IVsCodeWindow CreateCodeView(string documentMoniker, IVsTextLines?textLines, bool createdDocData, ref string editorCaption, ref Guid cmdUI)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (_serviceProvider == null)
            {
                throw new Exception("ServiceProvider can't be null");
            }

            IVsEditorAdaptersFactoryService adapterService = VS.GetMefService <IVsEditorAdaptersFactoryService>();

            IVsCodeWindow window = adapterService.CreateVsCodeWindowAdapter((IOleServiceProvider)_serviceProvider.GetService(typeof(IOleServiceProvider)));

            ErrorHandler.ThrowOnFailure(window.SetBuffer(textLines));
            ErrorHandler.ThrowOnFailure(window.SetBaseEditorCaption(null));
            ErrorHandler.ThrowOnFailure(window.GetEditorCaption(READONLYSTATUS.ROSTATUS_Unknown, out editorCaption));

            if (textLines is IVsUserData userData)
            {
                if (PromptEncodingOnLoad)
                {
                    Guid guid = VSConstants.VsTextBufferUserDataGuid.VsBufferEncodingPromptOnLoad_guid;
                    userData.SetData(ref guid, (uint)1);
                }
            }

            cmdUI = VSConstants.GUID_TextEditorFactory;

            if (!createdDocData && textLines != null)
            {
                // we have a pre-created buffer, go ahead and initialize now as the buffer already
                // exists and is initialized
                TextBufferEventListener?bufferEventListener = new(textLines, _languageServiceId);
                bufferEventListener.OnLoadCompleted(0);
            }

            return(window);
        }
Ejemplo n.º 14
0
 public int GetEditorCaption(READONLYSTATUS dwReadOnly, out string pbstrEditorCaption)
 {
     return(codeWindow.GetEditorCaption(dwReadOnly, out pbstrEditorCaption));
 }
Ejemplo n.º 15
0
 int IVsCodeWindow.GetEditorCaption(READONLYSTATUS dwReadOnly, out string pbstrEditorCaption) => _editorWindow.GetEditorCaption(dwReadOnly, out pbstrEditorCaption);