Exemplo n.º 1
0
        protected override void InitializeLanguageService(IVsTextLines textLines)
        {
            IVsUserData userData = textLines as IVsUserData;

            if (userData != null)
            {
                Guid langSid = typeof(VSGenero4GLLanguageInfo).GUID;
                if (langSid != Guid.Empty)
                {
                    Guid vsCoreSid = new Guid("{8239bec4-ee87-11d0-8c98-00c04fc2ab22}");
                    Guid currentSid;
                    ErrorHandler.ThrowOnFailure(textLines.GetLanguageServiceID(out currentSid));
                    // If the language service is set to the default SID, then
                    // set it to our language
                    if (currentSid == vsCoreSid)
                    {
                        ErrorHandler.ThrowOnFailure(textLines.SetLanguageServiceID(ref langSid));
                    }
                    else if (currentSid != langSid)
                    {
                        // Some other language service has it, so return VS_E_INCOMPATIBLEDOCDATA
                        throw new COMException("Incompatible doc data", VSConstants.VS_E_INCOMPATIBLEDOCDATA);
                    }

                    Guid bufferDetectLang = VSConstants.VsTextBufferUserDataGuid.VsBufferDetectLangSID_guid;
                    ErrorHandler.ThrowOnFailure(userData.SetData(ref bufferDetectLang, false));
                }
            }
        }
Exemplo n.º 2
0
        IWpfTextViewHost GetCurrentViewHost()
        {
            // code to get access to the editor's currently selected text cribbed from
            // http://msdn.microsoft.com/en-us/library/dd884850.aspx
            IVsTextManager txtMgr = (IVsTextManager)this.ServiceProvider.GetService(typeof(SVsTextManager));

            if (txtMgr == null)
            {
                return(null);
            }
            IVsTextView vTextView     = null;
            int         mustHaveFocus = 1;

            txtMgr.GetActiveView(mustHaveFocus, null, out vTextView);
            IVsUserData userData = vTextView as IVsUserData;

            if (userData == null)
            {
                return(null);
            }
            else
            {
                IWpfTextViewHost viewHost;
                object           holder;
                Guid             guidViewHost = DefGuidList.guidIWpfTextViewHost;
                userData.GetData(ref guidViewHost, out holder);
                viewHost = (IWpfTextViewHost)holder;
                return(viewHost);
            }
        }
Exemplo n.º 3
0
        static CaretLocation GetCaretLocation(DTE2 application)
        {
            // dark magic goes here

            IVsUIHierarchy uiHierarchy;
            uint           itemID;
            IVsWindowFrame windowFrame;

            if (!VsShellUtilities.IsDocumentOpen(ServiceCache.ServiceProvider, application.ActiveDocument.FullName, Guid.Empty,
                                                 out uiHierarchy, out itemID, out windowFrame))
            {
                return(null);
            }

            IVsTextView vsTextView = Microsoft.VisualStudio.Shell.VsShellUtilities.GetTextView(windowFrame);
            IVsUserData userData   = vsTextView as IVsUserData;

            if (userData == null)
            {
                return(null);
            }

            object holder;
            Guid   guidViewHost = DefGuidList.guidIWpfTextViewHost;

            userData.GetData(ref guidViewHost, out holder);
            IWpfTextViewHost viewHost = holder as IWpfTextViewHost;

            if (viewHost == null)
            {
                return(null);
            }

            IWpfTextView wpfTextView = viewHost.TextView;

            System.Windows.UIElement uiElement = wpfTextView as System.Windows.UIElement;
            if (uiElement == null)
            {
                return(null);
            }

            var caretPos = wpfTextView.Caret.Position.BufferPosition;
            var bounds   = wpfTextView.GetTextViewLineContainingBufferPosition(caretPos).GetCharacterBounds(caretPos);

            double zoomMultiplier = wpfTextView.ZoomLevel / 100.0;
            double left           = (bounds.Left - wpfTextView.ViewportLeft) * zoomMultiplier;
            double top            = (bounds.Top - wpfTextView.ViewportTop) * zoomMultiplier;
            double bottom         = (bounds.Bottom - wpfTextView.ViewportTop) * zoomMultiplier;

            System.Windows.Point topPoint    = new System.Windows.Point(left, top);
            System.Windows.Point bottomPoint = new System.Windows.Point(left, bottom);
            topPoint    = uiElement.PointToScreen(topPoint);
            bottomPoint = uiElement.PointToScreen(bottomPoint);

            return(new CaretLocation(
                       Convert.ToInt32(topPoint.X),
                       Convert.ToInt32(topPoint.Y),
                       Convert.ToInt32(bottomPoint.Y)
                       ));
        }
Exemplo n.º 4
0
        private IntPtr CreateCodeView(string documentMoniker, IVsTextLines textLines, IVsHierarchy hierarchy, uint itemid, bool createdDocData, ref string editorCaption, ref Guid cmdUI) {
            Type codeWindowType = typeof(IVsCodeWindow);
            Guid riid = codeWindowType.GUID;
            Guid clsid = typeof(VsCodeWindowClass).GUID;
            var compModel = (IComponentModel)_package.GetService(typeof(SComponentModel));
            var adapterService = compModel.GetService<IVsEditorAdaptersFactoryService>();

            var 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));

            IVsUserData userData = textLines as IVsUserData;
            if (userData != null) {
                if (_promptEncodingOnLoad) {
                    var guid = VSConstants.VsTextBufferUserDataGuid.VsBufferEncodingPromptOnLoad_guid;
                    userData.SetData(ref guid, (uint)1);
                }
            }
            var textMgr = (IVsTextManager)_package.GetService(typeof(SVsTextManager));

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

            InitializeLanguageService(textLines);

            cmdUI = VSConstants.GUID_TextEditorFactory;

            return Marshal.GetIUnknownForObject(window);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Here we simply host the visual studio core text editor.
        /// </summary>
        public virtual int 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)
        {
            cancelled     = 0;
            cmdUI         = Guid.Empty;
            docData       = IntPtr.Zero;
            docView       = IntPtr.Zero;
            editorCaption = null;
            string ext = Path.GetExtension(moniker).ToLower();

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

            if (takeover && !IsOurKindOfFile(moniker))
            {
                return((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);

            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;
            return(0);
        }
Exemplo n.º 6
0
        private bool TryGetOpenedDocumentData(RunningDocumentInfo info, out ITextBuffer textBuffer, out string filePath)
        {
            textBuffer = null;
            filePath   = string.Empty;

            if (!info.IsDocumentInitialized)
            {
                return(false);
            }

            IVsUserData vsUserData = info.DocData as IVsUserData;

            if (vsUserData == null)
            {
                return(false);
            }

            // Acquire the text buffer and snapshot from the document
            vsUserData.GetData(Microsoft.VisualStudio.Editor.DefGuidList.guidDocumentTextSnapshot, out object snapshot);
            textBuffer = (snapshot as ITextSnapshot)?.TextBuffer;
            if (textBuffer == null)
            {
                return(false);
            }

            if (!TextDocumentFactoryService.TryGetTextDocument(textBuffer, out ITextDocument textDocument))
            {
                return(false);
            }

            filePath = textDocument.FilePath;

            return(true);
        }
Exemplo n.º 7
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));
        }
Exemplo n.º 8
0
        private static IWpfTextView GetTextViewFromVsTextView(IVsTextView view)
        {
            if (view == null)
            {
                throw new ArgumentNullException("view");
            }

            IVsUserData userData = view as IVsUserData;

            if (userData == null)
            {
                throw new InvalidOperationException();
            }

            object objTextViewHost;

            if (VSConstants.S_OK
                != userData.GetData(Microsoft.VisualStudio
                                    .Editor
                                    .DefGuidList.guidIWpfTextViewHost,
                                    out objTextViewHost))
            {
                throw new InvalidOperationException();
            }

            IWpfTextViewHost textViewHost = objTextViewHost as IWpfTextViewHost;

            if (textViewHost == null)
            {
                throw new InvalidOperationException();
            }

            return(textViewHost.TextView);
        }
Exemplo n.º 9
0
        /// <summary>Implements the OnStartupComplete method of the IDTExtensibility2 interface. Receives notification that the host application has completed loading.</summary>
        /// <param term='custom'>Array of parameters that are host application specific.</param>
        /// <seealso class='IDTExtensibility2' />
        public void OnStartupComplete(ref Array custom)
        {
            IVsOutputWindow outWindow = Package.GetGlobalService(typeof(SVsOutputWindow)) as IVsOutputWindow;

            Guid paneGuid = VSConstants.GUID_OutWindowDebugPane;
            IVsOutputWindowPane debugPane;

            outWindow.GetPane(ref paneGuid, out debugPane);

            debugPane.OutputString("DebugView++ Forwarding initializing...");
            debugPane.Activate(); // Brings this pane into view

            IVsUserData userData = (IVsUserData)debugPane;
            object      o;
            Guid        guidViewHost = DefGuidList.guidIWpfTextViewHost;

            userData.GetData(ref guidViewHost, out o);

            IWpfTextViewHost viewHost = (IWpfTextViewHost)o;

            m_textView = viewHost.TextView;
            m_textView.TextBuffer.Changed += new EventHandler <Microsoft.VisualStudio.Text.TextContentChangedEventArgs>(TextBuffer_Changed);

            debugPane.OutputString("DebugView++ Forwarding installed.");
            Trace.AutoFlush = true;
        }
        protected void InitializeLanguageService(IVsTextLines textLines, Guid langSid)
        {
            IVsUserData userData = textLines as IVsUserData;

            if (userData != null)
            {
                if (langSid != Guid.Empty)
                {
                    Guid vsCoreSid = Guids.DefaultLanguageService;
                    Guid currentSid;
                    ErrorHandler.ThrowOnFailure(textLines.GetLanguageServiceID(out currentSid));
                    // If the language service is set to the default SID, then
                    // set it to our language
                    if (currentSid == vsCoreSid)
                    {
                        ErrorHandler.ThrowOnFailure(textLines.SetLanguageServiceID(ref langSid));
                    }
                    else if (currentSid != langSid)
                    {
                        // Some other language service has it, so return VS_E_INCOMPATIBLEDOCDATA
                        throw new COMException("Incompatible doc data", VSConstants.VS_E_INCOMPATIBLEDOCDATA);
                    }

                    Guid bufferDetectLang = VSConstants.VsTextBufferUserDataGuid.VsBufferDetectLangSID_guid;
                    ErrorHandler.ThrowOnFailure(userData.SetData(ref bufferDetectLang, false));
                }
            }
        }
        /// <summary>
        /// This function is the callback used to execute a command when the a menu item is clicked.
        /// See the Initialize method to see how the menu item is associated to this function using
        /// the OleMenuCommandService service and the MenuCommand class.
        /// </summary>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            //<Snippet37>
            IVsTextManager txtMgr        = (IVsTextManager)GetService(typeof(SVsTextManager));
            IVsTextView    vTextView     = null;
            int            mustHaveFocus = 1;

            txtMgr.GetActiveView(mustHaveFocus, null, out vTextView);
            //</Snippet37>

            //<Snippet38>
            IVsUserData userData = vTextView as IVsUserData;

            if (userData == null)
            {
                Console.WriteLine("No text view is currently open");
                return;
            }
            IWpfTextViewHost viewHost;
            object           holder;
            Guid             guidViewHost = DefGuidList.guidIWpfTextViewHost;

            userData.GetData(ref guidViewHost, out holder);
            viewHost = (IWpfTextViewHost)holder;
            //</Snippet38>

            //<Snippet39>
            Connector.Execute(viewHost);
            //</Snippet39>
        }
Exemplo n.º 12
0
        public static IWpfTextView GetWpfTextView(IServiceProvider provider)
        {
            var         textView = GetIvsTextView(provider);
            IVsUserData userData = textView as IVsUserData;

            if (userData == null)
            {
            }
            object objTextViewHost;

            if (VSConstants.S_OK
                != userData.GetData(Microsoft.VisualStudio.Editor.DefGuidList
                                    .guidIWpfTextViewHost,
                                    out objTextViewHost))
            {
            }

            IWpfTextViewHost textViewHost = objTextViewHost as IWpfTextViewHost;

            if (textViewHost == null)
            {
            }

            IWpfTextView text_View = textViewHost.TextView;

            return(text_View);
        }
Exemplo n.º 13
0
        public void VsTextViewCreated(IVsTextView vsTextView)
        {
            if (vsTextView == null)
            {
                throw new ArgumentNullException(nameof(vsTextView));
            }

            if (ErrorHandler.Failed(vsTextView.GetBuffer(out var textLines)))
            {
                return;
            }

            IVsUserData userData = textLines as IVsUserData;

            if (userData == null)
            {
                return;
            }

            Guid monikerGuid = typeof(IVsUserData).GUID;

            if (ErrorHandler.Failed(userData.GetData(ref monikerGuid, out var monikerObj)))
            {
                return;
            }

            string filePath = monikerObj as string;

            _rdt.Value.FindDocument(filePath, out var hierarchy, out var itemId, out var docCookie);

            AbstractProject project = GetXamlProject(hierarchy);

            if (project == null)
            {
                project = new XamlProject(
                    _vsWorkspace.GetProjectTrackerAndInitializeIfNecessary(_serviceProvider),
                    hierarchy,
                    _serviceProvider,
                    _vsWorkspace);
            }

            IVisualStudioHostDocument vsDocument = project.GetCurrentDocumentFromPath(filePath);

            if (vsDocument == null)
            {
                if (!TryCreateXamlDocument(project, filePath, out vsDocument))
                {
                    return;
                }

                project.AddDocument(vsDocument, isCurrentContext: true, hookupHandlers: true);
            }

            AttachRunningDocTableEvents();

            var wpfTextView = _editorAdaptersFactory.GetWpfTextView(vsTextView);
            var target      = new XamlOleCommandTarget(wpfTextView, CommandHandlerServiceFactory, _editorAdaptersFactory, _serviceProvider);

            target.AttachToVsTextView();
        }
Exemplo n.º 14
0
Arquivo: Utils.cs Projeto: zz110/ILSpy
        public static IWpfTextViewHost GetCurrentViewHost(IServiceProvider serviceProvider)
        {
            IVsTextManager txtMgr = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager));

            if (txtMgr == null)
            {
                return(null);
            }

            IVsTextView vTextView     = null;
            int         mustHaveFocus = 1;

            txtMgr.GetActiveView(mustHaveFocus, null, out vTextView);
            IVsUserData userData = vTextView as IVsUserData;

            if (userData == null)
            {
                return(null);
            }

            object holder;
            Guid   guidViewHost = DefGuidList.guidIWpfTextViewHost;

            userData.GetData(ref guidViewHost, out holder);

            return(holder as IWpfTextViewHost);
        }
Exemplo n.º 15
0
        protected override void Initialize()
        {
            base.Initialize();

            IComponentModel                 compMod         = GetService(typeof(SComponentModel)) as IComponentModel;
            ITextBufferFactoryService       bufferFactory   = compMod.GetService <ITextBufferFactoryService>();
            ITextEditorFactoryService       editorFactory   = compMod.GetService <ITextEditorFactoryService>();
            IVsEditorAdaptersFactoryService adapterFactory  = compMod.GetService <IVsEditorAdaptersFactoryService>();
            IContentTypeRegistryService     registryService = compMod.GetService <IContentTypeRegistryService>();

            //completionBroker = compMod.GetService<ICompletionBroker>();

            textView = adapterFactory.CreateVsTextViewAdapter(GetService(typeof(IOleServiceProvider)) as IOleServiceProvider);
            IVsTextBuffer textBuffer        = adapterFactory.CreateVsTextBufferAdapter(GetService(typeof(IOleServiceProvider)) as IOleServiceProvider);
            uint          textViewInitFlags = (uint)TextViewInitFlags.VIF_DEFAULT |
                                              (uint)TextViewInitFlags.VIF_HSCROLL |
                                              (uint)TextViewInitFlags.VIF_VSCROLL;

            textBuffer.InitializeContent("", 0);
            textView.Initialize(textBuffer as IVsTextLines, IntPtr.Zero, textViewInitFlags, null);

            // Create Dev10 objects
            _textView     = adapterFactory.GetWpfTextView(textView);
            mefTextBuffer = adapterFactory.GetDataBuffer(textBuffer);

            IVsUserData userData = textView as IVsUserData;

            if (userData != null)
            {
                Guid   g = Microsoft.VisualStudio.Editor.DefGuidList.guidIWpfTextViewHost;
                object obj;
                int    hr = userData.GetData(ref g, out obj);
                if (hr == VSConstants.S_OK)
                {
                    _textViewHost = obj as IWpfTextViewHost;
                }
            }

            // disable zoom view
            _textView.Options.SetOptionValue(DefaultTextViewHostOptions.ZoomControlId, false);

            //Initialize the history
            if (null == history)
            {
                history = new HistoryBuffer();
            }

            adapterFactory.GetWpfTextView(textView).Caret.MoveTo(new SnapshotPoint(mefTextBuffer.CurrentSnapshot, mefTextBuffer.CurrentSnapshot.Length));


            IContentType ivsdContentType = registryService.GetContentType(VSDContentTypeDefinition.ContentType);

            mefTextBuffer.ChangeContentType(ivsdContentType, null);

            // init console input
            WriteConsoleInputSymbol();

            return;
        }
Exemplo n.º 16
0
        public void VsTextViewCreated(IVsTextView vsTextView)
        {
            if (vsTextView == null)
            {
                throw new ArgumentNullException(nameof(vsTextView));
            }

            if (ErrorHandler.Failed(vsTextView.GetBuffer(out var textLines)))
            {
                return;
            }

            IVsUserData userData = textLines as IVsUserData;

            if (userData == null)
            {
                return;
            }

            Guid monikerGuid = typeof(IVsUserData).GUID;

            if (ErrorHandler.Failed(userData.GetData(ref monikerGuid, out var monikerObj)))
            {
                return;
            }

            string filePath = monikerObj as string;

            _rdt.Value.FindDocument(filePath, out var hierarchy, out var itemId, out var docCookie);
            if (hierarchy == null)
            {
                return;
            }

            VisualStudioProject project;

            if (!_xamlProjects.TryGetValue(hierarchy, out project))
            {
                string name;
                hierarchy.TryGetName(out name);
                project = _visualStudioProjectFactory.CreateAndAddToWorkspace(name + "-XamlProject", StringConstants.XamlLanguageName);
                _xamlProjects.Add(hierarchy, project);
            }

            if (!project.ContainsSourceFile(filePath))
            {
                project.AddSourceFile(filePath);
            }

            AttachRunningDocTableEvents();

            var wpfTextView = _editorAdaptersFactory.GetWpfTextView(vsTextView);
            var target      = new XamlOleCommandTarget(wpfTextView, CommandHandlerServiceFactory, _editorAdaptersFactory, _serviceProvider);

            target.AttachToVsTextView();
        }
Exemplo n.º 17
0
        private IWpfTextView GetWpfTextView(IVsTextView textView)
        {
            IVsUserData userData = (IVsUserData)textView;
            object      result;

            userData.GetData(s_guidIWpfTextViewHost, out result);
            var textViewHost = (IWpfTextViewHost)result;

            return(textViewHost.TextView);
        }
Exemplo n.º 18
0
        public HighlightInvalidKeyrefTagger(HighlightInvalidKeyrefTaggerProvider owner, ITextView view, ITextBuffer sourceBuffer)
        {
            _owner  = owner;
            _view   = view;
            _buffer = sourceBuffer;
            //View.Caret.PositionChanged += CaretPositionChanged;
            //View.LayoutChanged += ViewLayoutChanged;

            // Get the name of the underlying document buffer
            ITextDocument document;

            if (owner.TextDocumentFactoryService.TryGetTextDocument(view.TextDataModel.DocumentBuffer, out document))
            {
                this.FilePath = document.FilePath;

                document.FileActionOccurred += (sender, ea) => {
                    if (ea.FileActionType == FileActionTypes.DocumentRenamed)
                    {
                        this.FilePath = ea.FilePath;
                    }
                };
                // TODO we should listen for the file changing its name (ITextDocument.FileActionOccurred)
            }

            this.ErrorsSnapshot = new SpellingErrorsSnapshot(this.FilePath, 0, new NormalizedSnapshotSpanCollection(), new ReadOnlyCollection <MyXmlAttribute>(new MyXmlAttribute[0]));

            _owner.AddSpellChecker(this);
            view.Closed += (sender, ea) => {
                _owner.RemoveSpellChecker(this);

                if (_loader != null)
                {
                    _loader.DocumentDataUpdated -= this.OnDocumentDataUpdated;
                }
            };

            var textViewAdapter = view.GetVsTextView();

            if (!ErrorHandler.Failed(textViewAdapter.GetBuffer(out var textLines)))
            {
                IVsUserData userData = textLines as IVsUserData;
                if (userData != null)
                {
                    Guid id = typeof(XmlKeyRefCompletionCommandHandler).GUID;
                    userData.GetData(ref id, out var cmdHandler);

                    _loader = (cmdHandler as XmlKeyRefCompletionCommandHandler)?.DocumentDataLoader;
                    if (_loader != null)
                    {
                        _loader.DocumentDataUpdated += this.OnDocumentDataUpdated;
                    }
                }
            }
        }
Exemplo n.º 19
0
        // TODO move into better place?
        private static string GetFileNameFromTextView(IVsTextView vTextView)
        {
            IVsTextLines buffer;

            vTextView.GetBuffer(out buffer);
            IVsUserData userData    = buffer as IVsUserData;
            Guid        monikerGuid = typeof(IVsUserData).GUID;
            object      pathAsObject;

            userData.GetData(ref monikerGuid, out pathAsObject);
            return((string)pathAsObject);
        }
Exemplo n.º 20
0
        private DaxEditorMargin GetEditorMargin(IVsTextView vsTextView)
        {
            if (vsTextView == null)
            {
                return(null);
            }

            IVsUserData propertyBag = vsTextView as IVsUserData;
            object      textViewHost;
            var         _guidIWpfTextViewHost = new Guid("8C40265E-9FDB-4f54-A0FD-EBB72B7D0476");

            ErrorHandler.ThrowOnFailure(propertyBag.GetData(ref _guidIWpfTextViewHost, out textViewHost));
            return((textViewHost as IWpfTextViewHost).GetTextViewMargin(DaxEditorMargin.MarginName) as DaxEditorMargin);
        }
Exemplo n.º 21
0
        private void ReloadXmlDoCompletionData(uint docCookie)
        {
            var doc = _rdt.GetDocumentInfo(docCookie);
            // var docTextBufferAdapter = doc.DocData as IVsTextBuffer;
            var textLines = doc.DocData as IVsTextLines;

            IVsUserData userData = textLines as IVsUserData;

            if (userData != null)
            {
                Guid id = typeof(XmlKeyRefCompletionCommandHandler).GUID;
                userData.GetData(ref id, out var cmdHandler);
                (cmdHandler as XmlKeyRefCompletionCommandHandler)?.DocumentDataLoader.ScheduleReloading(XmlDocumentLoader.InitTimeout);
            }
        }
        private static IWpfTextView GetWpfTextView(IVsTextView vTextView)
        {
            IWpfTextView view     = null;
            IVsUserData  userData = (IVsUserData)vTextView;

            if (userData != null)
            {
                Guid guidViewHost = Microsoft.VisualStudio.Editor.DefGuidList.guidIWpfTextViewHost;
                userData.GetData(ref guidViewHost, out var holder);
                IWpfTextViewHost viewHost = (IWpfTextViewHost)holder;
                view = viewHost.TextView;
            }

            return(view);
        }
Exemplo n.º 23
0
        private IWpfTextView getWpfView(IVsUserData userData)
        {
            IWpfTextView view = null;

            if (null != userData)
            {
                IWpfTextViewHost viewHost;
                object           holder;
                var guidViewHost = DefGuidList.guidIWpfTextViewHost;
                userData.GetData(ref guidViewHost, out holder);
                viewHost = (IWpfTextViewHost)holder;
                view     = viewHost.TextView;
            }

            return(view);
        }
Exemplo n.º 24
0
        public static IWpfTextView ToIWpfTextView(this IVsTextView vsTextView)
        {
            object      obj2;
            IVsUserData data = vsTextView as IVsUserData;

            if (data == null)
            {
                return(null);
            }
            Guid guidIWpfTextViewHost = GuidIWpfTextViewHost;

            ErrorHelper.ThrowOnFailure(data.GetData(ref guidIWpfTextViewHost, out obj2));
            IWpfTextViewHost host = obj2 as IWpfTextViewHost;

            return(host.TextView);
        }
Exemplo n.º 25
0
        public static ITextView ToITextView(this IVsTextView vsTextView)
        {
            object      obj2;
            IVsUserData data = vsTextView as IVsUserData;

            if (data == null)
            {
                throw new InvalidOperationException("The IVsTextView shims should allow us to cast to IVsUserData");
            }
            Guid guidIWpfTextViewHost = GuidIWpfTextViewHost;

            ErrorHelper.ThrowOnFailure(data.GetData(ref guidIWpfTextViewHost, out obj2));
            IWpfTextViewHost host = obj2 as IWpfTextViewHost;

            return(host.TextView);
        }
Exemplo n.º 26
0
        public static IWpfTextView GetWpfTextView(IVsTextView vTextView)
        {
            IVsUserData userData = vTextView as IVsUserData;

            if (userData == null)
            {
                return(null);
            }

            object holder;
            Guid   guidViewHost = DefGuidList.guidIWpfTextViewHost;

            userData.GetData(ref guidViewHost, out holder);
            IWpfTextViewHost viewHost = (IWpfTextViewHost)holder;

            return(viewHost.TextView);
        }
Exemplo n.º 27
0
        public static IWpfTextView GetWpfTextView(IVsTextView vTextView)
        {
            IWpfTextView view     = null;
            IVsUserData  userData = vTextView as IVsUserData;

            if (null != userData)
            {
                IWpfTextViewHost viewHost;
                object           holder;
                Guid             guidViewHost = DefGuidList.guidIWpfTextViewHost;
                userData.GetData(ref guidViewHost, out holder);
                viewHost = (IWpfTextViewHost)holder;
                view     = viewHost.TextView;
            }

            return(view);
        }
Exemplo n.º 28
0
        private static string GetDocumentPath(IVsTextLines textLines)
        {
            // The path to the document of the IVsTextLines text buffer is used
            // as the moniker of the corresponding IVsUserData interface implementation.
            object fileName = null;

            IVsUserData userData = textLines as IVsUserData;

            if (userData != null)
            {
                // Read the moniker (which is the file name) from userData.
                Guid monikerGuid = typeof(IVsUserData).GUID;
                ErrorHandler.Ignore(userData.GetData(ref monikerGuid, out fileName));
            }

            return((string)fileName);
        }
Exemplo n.º 29
0
        private void CreateCodeEditor()
        {
            Guid clsidTextBuffer = typeof(VsTextBufferClass).GUID;
            Guid iidTextBuffer   = VSConstants.IID_IUnknown;

            TextBuffer = (IVsTextBuffer)MySqlDataProviderPackage.Instance.CreateInstance(
                ref clsidTextBuffer,
                ref iidTextBuffer,
                typeof(object));
            if (TextBuffer == null)
            {
                throw new Exception("Failed to create core editor");
            }

            // first we need to site our buffer
            IObjectWithSite textBufferSite = TextBuffer as IObjectWithSite;

            if (textBufferSite != null)
            {
                textBufferSite.SetSite(psp);
            }

            // then we need to tell our buffer not to attempt to autodetect the
            // language settings
            IVsUserData userData = TextBuffer as IVsUserData;
            Guid        g        = EditorFactory.GuidVSBufferDetectLangSid;
            int         result   = userData.SetData(ref g, false);

            Guid          clsidCodeWindow = typeof(VsCodeWindowClass).GUID;
            Guid          iidCodeWindow   = typeof(IVsCodeWindow).GUID;
            IVsCodeWindow pCodeWindow     = (IVsCodeWindow)MySqlDataProviderPackage.Instance.CreateInstance(
                ref clsidCodeWindow,
                ref iidCodeWindow,
                typeof(IVsCodeWindow));

            if (pCodeWindow == null)
            {
                throw new Exception("Failed to create core editor");
            }

            // Give the text buffer to the code window.
            // We are giving up ownership of the text buffer!
            pCodeWindow.SetBuffer((IVsTextLines)TextBuffer);

            CodeWindow = pCodeWindow;
        }
        /// <summary>
        /// Get <seealso cref="IWpfTextView"/> interface from <seealso cref="IVsTextView"/> interface.
        /// </summary>
        private static IWpfTextView GetWpfTextView(IVsTextView textView)
        {
            IWpfTextView view     = null;
            IVsUserData  userData = textView as IVsUserData;

            if (userData != null)
            {
                IWpfTextViewHost viewHost;
                object           holder;
                Guid             guidViewHost = DefGuidList.guidIWpfTextViewHost;
                if (VSConstants.S_OK == userData.GetData(ref guidViewHost, out holder))
                {
                    viewHost = (IWpfTextViewHost)holder;
                    view     = viewHost.TextView;
                }
            }
            return(view);
        }
Exemplo n.º 31
0
 public int AttemptToCheckOutBufferFromScc(IVsUserData pBufData, out int pfCheckoutSucceeded)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Exemplo n.º 32
0
 public int GetBufferSccStatus(IVsUserData pBufData, out int pbNonEditable)
 {
     throw new Exception("The method or operation is not implemented.");
 }