Exemplo n.º 1
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.º 2
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;
        }
Exemplo n.º 3
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.º 4
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);
        }
        /// <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.º 6
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.º 7
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.º 8
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.º 9
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.º 10
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.º 11
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.º 12
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.º 13
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.º 14
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.º 15
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.º 16
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.º 17
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.º 18
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);
        }
        /// <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.º 20
0
        /// <summary>
        /// Helper method for getting a IWpfTextView from a IVsTextView object
        /// </summary>
        /// <param name="textView"></param>
        /// <returns></returns>
        private IWpfTextView GetWpfTextView(IVsTextView textView)
        {
            IWpfTextViewHost textViewHost = null;
            IVsUserData userData = textView as IVsUserData;
            if (userData != null)
            {
                Guid guid = Microsoft.VisualStudio.Editor.DefGuidList.guidIWpfTextViewHost;
                object wpfTextViewHost = null;
                userData.GetData(ref guid, out wpfTextViewHost);
                textViewHost = wpfTextViewHost as IWpfTextViewHost;
            }

            if (textViewHost == null)
            {
                return null;
            }
            return textViewHost.TextView;
        }
Exemplo n.º 21
0
        /// <summary>
        /// gets the current text view for dte purposes
        /// </summary>
        /// <param name="vTextView"></param>
        /// <returns></returns>
        IWpfTextViewHost GetCurrentViewHost(IVsTextView 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.º 22
0
        public static IWpfTextView GetWpfTextView(IVsTextView vTextView)
        {
            IWpfTextView view     = null;
            IVsUserData  userData = vTextView as IVsUserData;

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

            return(view);
        }
Exemplo n.º 23
0
        public static ITextBuffer ToITextBuffer(this IVsTextBuffer vsTextBuffer)
        {
            object      obj2;
            IVsUserData data = vsTextBuffer as IVsUserData;

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

            ErrorHelper.ThrowOnFailure(data.GetData(ref guidIVxTextBuffer, out obj2));
            ITextBuffer buffer = obj2 as ITextBuffer;

            if (buffer == null)
            {
                throw new InvalidOperationException("user data doesnt implement the interface");
            }
            return(buffer);
        }
Exemplo n.º 24
0
        public static IWpfTextViewHost GetCurrentViewHost()
        {
            var         txtMgr = SpoiledCat.Utils.Services.TextManager;
            IVsTextView tv     = null;

            txtMgr.GetActiveView(1, null, out tv);
            IVsUserData userData = tv as IVsUserData;

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

            IWpfTextViewHost viewHost;
            object           holder;
            Guid             guidViewHost = Microsoft.VisualStudio.Editor.DefGuidList.guidIWpfTextViewHost;

            userData.GetData(ref guidViewHost, out holder);
            viewHost = (IWpfTextViewHost)holder;
            return(viewHost);
        }
Exemplo n.º 25
0
        internal static string GetFilePathInternal(object obj)
        {
            string      fname = null;
            int         hr    = 0;
            IVsUserData ud    = obj as IVsUserData;

            if (ud != null)
            {
                object oname;
                Guid   GUID_VsBufferMoniker = typeof(IVsUserData).GUID;
                hr = ud.GetData(ref GUID_VsBufferMoniker, out oname);
                if (Microsoft.VisualStudio.ErrorHandler.Succeeded(hr) && oname != null)
                {
                    fname = oname.ToString();
                }
            }
            if (string.IsNullOrEmpty(fname))
            {
                IPersistFileFormat fileFormat = obj as IPersistFileFormat;
                if (fileFormat != null)
                {
                    uint format;
                    hr = fileFormat.GetCurFile(out fname, out format);
                }
            }
            if (!string.IsNullOrEmpty(fname))
            {
                Microsoft.VisualStudio.Shell.Url url = new Microsoft.VisualStudio.Shell.Url(fname);
                if (!url.Uri.IsAbsoluteUri)
                {
                    // make the file name absolute using app startup path...
                    Microsoft.VisualStudio.Shell.Url baseUrl = new Microsoft.VisualStudio.Shell.Url(Application.StartupPath + Path.DirectorySeparatorChar);
                    url   = new Microsoft.VisualStudio.Shell.Url(baseUrl, fname);
                    fname = url.AbsoluteUrl;
                }
            }
            return(fname);
        }
Exemplo n.º 26
0
        private void InstallForwarder(Package package)
        {
            IVsOutputWindow     outWindow = Package.GetGlobalService(typeof(SVsOutputWindow)) as IVsOutputWindow;
            Guid                paneGuid  = VSConstants.GUID_OutWindowDebugPane; // codenotes: GUID_BuildOutputWindowPane / GUID_OutWindowDebugPane
            IVsOutputWindowPane debugPane;

            outWindow.GetPane(ref paneGuid, out debugPane);
            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("Cobalt Fusion Output Window forwarding initialized.\n");
            Trace.AutoFlush = true;
        }
Exemplo n.º 27
0
        /// <summary>
        /// Gets the active IWpfTextView, if one exists. <see href="https://github.com/CodeConnect/gistify/blob/master/CodeConnect.Gistify.Extension/TextManagerExtensions.cs"/>
        /// </summary>
        /// <returns>The active IWpfTextView, or null if no such IWpfTextView exists.</returns>
        public static IWpfTextView GetActiveTextView(IVsTextManager textManager)
        {
            IWpfTextView view      = null;
            IVsTextView  vTextView = null;

            textManager.GetActiveView(
                fMustHaveFocus: 1
                , pBuffer: null
                , ppView: out vTextView);

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


            //Initialize the history
            history = new HistoryBuffer();

            // Create the stream on top of the text buffer.
            textStream = new TextBufferStream(mefTextBuffer);

            // Initialize the engine.
            InitializeEngine();

            IContentType ipContentType = registryService.GetContentType(PyContentTypeDefinition.ConsoleContentType);

            mefTextBuffer.ChangeContentType(ipContentType, null);

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

            // Set the title of the window.
            this.Caption = Resources.ToolWindowTitle;

            // Set the icon of the toolwindow.
            this.BitmapResourceID = 301;
            this.BitmapIndex      = 0;

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

            IVsTextLines textLines;

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

            IVsUserData userData = textLines as IVsUserData;

            if (userData == null)
            {
                return;
            }

            object monikerObj;
            Guid   monikerGuid = typeof(IVsUserData).GUID;

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

            string       filePath = monikerObj as string;
            uint         itemId;
            uint         docCookie;
            IVsHierarchy hierarchy;

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

            AbstractProject project = GetXamlProject(hierarchy);

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

            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.º 30
0
        private void ProcessFile(string filePath)
        {
            IVsTextBuffer      textBuffer        = null;
            IPersistFileFormat textBufferPersist = null;
            IVsTextStream      textStream        = null;
            IVsUserData        userData          = null;
            IServiceProvider   serviceProvider   = (IServiceProvider)GetService(typeof(IServiceProvider));

            using (DocData docData = new DocData(serviceProvider, filePath))
                try
                {
                    textBuffer = docData.Buffer;
                    userData   = (IVsUserData)textBuffer;
                    Guid VsBufferDetectLangSID = new Guid("{17F375AC-C814-11d1-88AD-0000F87579D2}");
                    Marshal.ThrowExceptionForHR(userData.SetData(ref VsBufferDetectLangSID, false));
                    textBufferPersist = (IPersistFileFormat)textBuffer;
                    textStream        = (IVsTextStream)textBuffer;
                    int fileLenBeforeReplacement = 0;
                    Marshal.ThrowExceptionForHR(textStream.GetSize(out fileLenBeforeReplacement));
                    IntPtr buffer = IntPtr.Zero;
                    try
                    {
                        buffer = Marshal.StringToCoTaskMemUni(this.Content);
                        Marshal.ThrowExceptionForHR(textStream.ReloadStream(0, fileLenBeforeReplacement, buffer, Content.Length));
                    }
                    finally
                    {
                        Marshal.FreeCoTaskMem(buffer);
                        buffer = IntPtr.Zero;
                    }

                    // Get the original encoding as Texteditor detected it.
                    // The Unicode lib packs codePage in the low word and flags (as emmit BOM) in high word.
                    object encObj = null;
                    Guid   VsBufferEncodingVSTFF = new Guid("{16417F39-A6B7-4c90-89FA-770D2C60440B}");
                    Marshal.ThrowExceptionForHR(userData.GetData(ref VsBufferEncodingVSTFF, out encObj));
                    uint encValue = (uint)encObj;
                    // set the desired encoding
                    encValue = 65001 | 0x10000;
                    Marshal.ThrowExceptionForHR(userData.SetData(ref VsBufferEncodingVSTFF, encValue));
                    Marshal.ThrowExceptionForHR(textBufferPersist.Save(filePath, 1, 0));
                    Marshal.ThrowExceptionForHR(textBufferPersist.SaveCompleted(filePath));
                }
                finally
                {
                    //if (userData != null)
                    //{
                    //    Marshal.ReleaseComObject(userData);
                    //}
                    //if (textStream != null)
                    //{
                    //    Marshal.ReleaseComObject(textStream);
                    //}
                    //if (textBufferPersist != null)
                    //{
                    //    Marshal.ReleaseComObject(textBufferPersist);
                    //}
                    //if (textBuffer != null)
                    //{
                    //    Marshal.ReleaseComObject(textBuffer);
                    //}
                }
        }