public static IVsTextView GetActiveView(this IVsTextManager vsTextManager)
        {
            vsTextManager = vsTextManager ?? throw new ArgumentNullException(
                                      $"Argument {nameof(VsTextBuffer)} in method {nameof(GetActiveView)} is empty");
            int res;

            if ((res = vsTextManager.GetActiveView(MustHaveFocusFlag, null, out IVsTextView view)) != VSConstants.S_OK)
            {
                throw new Exception($"GetActiveView returned {res}, S_OK(0) status was expected");
            }
            return(view ?? throw new Exception($"{nameof(GetActiveView)} is trying to return empty value"));
        }
Example #2
0
        public static Tuple <bool, IWpfTextView> TryGetActiveTextView(this IVsTextManager vsTextManager, IVsEditorAdaptersFactoryService factoryService)
        {
            IVsTextView  vsTextView;
            IWpfTextView textView = null;

            if (ErrorHandler.Succeeded(vsTextManager.GetActiveView(0, null, out vsTextView)) && vsTextView != null)
            {
                textView = factoryService.GetWpfTextViewNoThrow(vsTextView);
            }

            return(Tuple.Create(textView != null, textView));
        }
Example #3
0
        public void Init()
        {
            DTE dte = Package.GetGlobalService(typeof(DTE)) as DTE;

            IVsTextView view;

            manager.GetActiveView(1, null, out view);

            docEvent = dte.Events.get_DocumentEvents(null);

            winEvent = dte.Events.get_WindowEvents(null);
        }
Example #4
0
        /// <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)
        {
            // Show a Message Box to prove we were here
            //IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
            IVsTextManager txtMgr = (IVsTextManager)Package.GetGlobalService(typeof(SVsTextManager));

            if (txtMgr == null)
            {
                return;
            }

            IVsTextView view       = null;
            int         errorValue = txtMgr.GetActiveView(0, null, out view);

            if (view == null)
            {
                return;
            }

            IComponentModel componentModel = Package.GetGlobalService(typeof(SComponentModel)) as IComponentModel;
            IVsEditorAdaptersFactoryService editorFactory = componentModel.GetService <IVsEditorAdaptersFactoryService>();
            IWpfTextView wpfTextView = editorFactory.GetWpfTextView(view);

            if (wpfTextView == null)
            {
                return;
            }

            ITextSnapshot snapshot = wpfTextView.TextSnapshot;

            if (snapshot != snapshot.TextBuffer.CurrentSnapshot)
            {
                return;
            }

            if (sender == menuItemSwapLinesDown)
            {
                SwapLines(wpfTextView, true);
            }
            else if (sender == menuItemSwapLinesUp)
            {
                SwapLines(wpfTextView, false);
            }
            else if (sender == menuItemCopyLinesDown)
            {
                CopyLines(wpfTextView, true);
            }
            else if (sender == menuItemCopyLinesUp)
            {
                CopyLines(wpfTextView, false);
            }
        }
        public static string main()
        {
            IVsTextManager txtMgr        = (IVsTextManager)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SVsTextManager));
            IVsTextView    vTextView     = null;
            int            mustHaveFocus = 1;

            txtMgr.GetActiveView(mustHaveFocus, null, out vTextView);
            return(GetFullPath(vTextView));


            // IVsTextManager.GetUserPreferences(VIEWPREFERENCES[]pViewPrefs, FRAMEPREFERENCES[], LANGPREFERENCES[], FONTCOLORPREFERENCES[]);
            //return GetFullPath(GetActiveView());
        }
    void commandEvents_BeforeExecute(string Guid, int ID, object CustomIn, object CustomOut, ref bool CancelDefault)
    {
        var doc = dte.ActiveDocument

                  IVsTextView textViewCurrent;

        txtMngr.GetActiveView(1, null, out textViewCurrent);
        int a, b, c, verticalScrollPosition;

        var scrollInfo = textViewCurrent.GetScrollInfo(1, out a, out b, out c, out verticalScrollPosition);

        textViewCurrent.SetScrollPosition(1, verticalScrollPosition);
    }
Example #7
0
        public IVsTextView GetActiveView()
        {
            IVsTextView view;

            myTextManager.GetActiveView(1, null, out view);

            if (view == null)
            {
                Debug.WriteLine("AceJumpCommand.cs | MenuItemCallback | could not retrieve current view");
                return(null);
            }

            return(view);
        }
        public static IVsTextView GetActiveIVsTextView()
        {
            //see also: http://stackoverflow.com/questions/2413530/find-an-ivstextview-or-iwpftextview-for-a-given-projectitem-in-vs-2010-rc-exten

            IVsTextManager textManager = (IVsTextManager)Package.GetGlobalService(typeof(SVsTextManager));
            IVsTextView    view;
            var            result = textManager.GetActiveView(VSConstants.S_FALSE, null, out view);

            if (result != VSConstants.S_OK)
            {
                return(null);
            }
            return(view);
        }
        /// <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)
        {
            IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
            Guid       clsid   = Guid.Empty;

            IVsTextManager txtMgr        = VisualStudioServices.GetService <SVsTextManager, IVsTextManager>();
            int            mustHaveFocus = 1;
            IVsTextView    vTextView     = null;

            txtMgr.GetActiveView(mustHaveFocus, null, out vTextView);

            string textUnderCursor = CodeUnderCursor.GetExpression(vTextView);

            ShowToolWindow(textUnderCursor);
        }
Example #10
0
        public string GetSelectedText()
        {
            IVsTextManager textManager = serviceProvider.GetService <SVsTextManager, IVsTextManager>();
            string         selectedText;
            IVsTextView    activeView;

            if (textManager != null &&
                ErrorHandler.Succeeded(textManager.GetActiveView(1, null, out activeView)) &&
                ErrorHandler.Succeeded(activeView.GetSelectedText(out selectedText)))
            {
                return(selectedText);
            }

            return(string.Empty);
        }
Example #11
0
        IVsUserData GetUserData()
        {
            int         mustHaveFocus = 1;//means true
            IVsTextView currentTextView;

            txtMgr.GetActiveView(mustHaveFocus, null, out currentTextView);

            if (currentTextView is IVsUserData)
            {
                return(currentTextView as IVsUserData);
            }
            else
            {
                throw new ApplicationException("No text view is currently open");
            }
        }
Example #12
0
        protected void Execute(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            IVsTextView              textView    = _vsTextManager.GetActiveView();
            IWpfTextView             wpfTextView = _editorAdaptersFactoryService.GetWpfTextView(textView);
            CocoJumperCommandPackage cocoJumperCommandPackage = (CocoJumperCommandPackage)_package;

            CleanupLogicAndInputListener();
            WpfViewProvider renderer = new WpfViewProvider(wpfTextView);

            Logic          = new CocoJumperLogic(renderer, cocoJumperCommandPackage);
            _inputListener = new InputListener(textView);
            _inputListener.KeyPressEvent += OnKeyboardAction;

            ExecutePostAction();
        }
Example #13
0
        internal static async Task <IWpfTextView> GetWpfTextViewAsync(this Shell.IAsyncServiceProvider serviceProvider)
        {
            if (serviceProvider == null)
            {
                return(null);
            }

            IVsTextManager textManager = await serviceProvider.GetServiceAsync <SVsTextManager, IVsTextManager>();

            if (textManager == null || textManager.GetActiveView(1, null, out IVsTextView textView) != VSConstants.S_OK)
            {
                return(null);
            }

            return(await serviceProvider.GetWpfTextViewFromTextViewAsync(textView));
        }
Example #14
0
        public TextView GetActiveTextView()
        {
            lock (_watcherSyncRoot)
            {
                IVsTextView activeVsView;
                _textManager.GetActiveView(Convert.ToInt32(true), null, out activeVsView);

                if (activeVsView != null && _textViews.ContainsKey(activeVsView))
                {
                    return(_textViews[activeVsView]);
                }
                else
                {
                    return(null);
                }
            }
        }
Example #15
0
        public static IVsUserData GetUserData(this IVsTextManager txtMgr)
        {
            int         mustHaveFocus = 1;//means true
            IVsTextView currentTextView;

            txtMgr.GetActiveView(mustHaveFocus, null, out currentTextView);

            if (currentTextView is IVsUserData)
            {
                return(currentTextView as IVsUserData);
            }
            else
            {
                throw new ApplicationException("No text view is currently open");
            }
            // Console.WriteLine("No text view is currently open"); return;
        }
Example #16
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void Execute(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            // 向当前文件窗口发送一个格式化命令
            if (m_text_manager == null)
            {
                return;
            }
            m_text_manager.GetActiveView(1, null, out IVsTextView view);
            if (view == null)
            {
                return;
            }
            if (m_adapters_factory == null)
            {
                return;
            }
            var text_view = m_adapters_factory.GetWpfTextView(view);

            if (text_view == null)
            {
                return;
            }

            if (!text_view.Properties.TryGetProperty(nameof(UIViewItem), out UIViewItem info))
            {
                return;
            }

            string ext = "lua";

            if (GeneralOptions.Instance.TargetLanguage == TargetLanguages.JavaScript)
            {
                ext = "js";
            }

            string full_path = ALittleScriptUtility.CalcTargetFullPath(info.GetProjectPath(), info.GetFullPath(), ext, out _);

            if (full_path == null)
            {
                return;
            }
            ALanguageUtility.OpenFile(null, ALittleScriptVsTextViewCreationListener.s_adapters_factory, full_path, 0, 0);
        }
Example #17
0
        public string GetCurrentlyHighlightedWord()
        {
            IVsTextManager vsTextManager = (IVsTextManager)base.GetService(typeof(SVsTextManager));
            IVsTextView    vsTextView    = null;
            int            num           = 1;

            vsTextManager.GetActiveView(num, null, out vsTextView);
            IComponentModel componentModel = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel));
            IVsEditorAdaptersFactoryService vsEditorAdaptersFactoryService =
                (IVsEditorAdaptersFactoryService)base.GetService(typeof(IVsEditorAdaptersFactoryService));
            IVsEditorAdaptersFactoryService service = componentModel.GetService <IVsEditorAdaptersFactoryService>();
            ITextView     wpfTextView = service.GetWpfTextView(vsTextView);
            ITextBuffer   textBuffer  = wpfTextView.TextBuffer;
            SnapshotPoint?point       = wpfTextView.Caret.Position.Point.GetPoint(textBuffer, wpfTextView.Caret.Position.Affinity);

            if (point == null)
            {
                return(null);
            }
            ITextStructureNavigatorSelectorService service2 = componentModel.GetService <ITextStructureNavigatorSelectorService>();
            ITextStructureNavigator textStructureNavigator  = service2.GetTextStructureNavigator(textBuffer);
            TextExtent extentOfWord = textStructureNavigator.GetExtentOfWord(point.Value);
            bool       flag         = true;

            if (!PersistHighlighterPackage.WordExtentIsValid(point.Value, extentOfWord))
            {
                if (extentOfWord.Span.Start != point.Value || point.Value == point.Value.GetContainingLine().Start || char.IsWhiteSpace((point.Value - 1).GetChar()))
                {
                    flag = false;
                }
                else
                {
                    extentOfWord = textStructureNavigator.GetExtentOfWord(point.Value - 1);
                    if (!PersistHighlighterPackage.WordExtentIsValid(point.Value, extentOfWord))
                    {
                        flag = false;
                    }
                }
            }
            if (!flag)
            {
                return(null);
            }
            return(extentOfWord.Span.GetText());
        }
Example #18
0
        private void MenuItemCallback(object sender, EventArgs e)
        {
            try
            {
                ////////////////////////
                /// Replace multiple rules that priorize operators with one rule and multiple ordered alts.
                ////////////////////////

                IVsTextManager manager = ((IServiceProvider)ServiceProvider).GetService(typeof(VsTextManagerClass)) as IVsTextManager;
                if (manager == null)
                {
                    return;
                }
                manager.GetActiveView(1, null, out IVsTextView view);
                if (view == null)
                {
                    return;
                }
                view.GetCaretPos(out int l, out int c);
                view.GetSelection(out int ls, out int cs, out int le, out int ce);
                view.GetBuffer(out IVsTextLines buf);
                if (buf == null)
                {
                    return;
                }
                ITextBuffer buffer = AntlrLanguageClient.AdaptersFactory.GetWpfTextView(view)?.TextBuffer;
                string      ffn    = buffer.GetFFN();
                if (ffn == null)
                {
                    return;
                }
                Workspaces.Document document = Workspaces.Workspace.Instance.FindDocument(ffn);
                if (document == null)
                {
                    return;
                }
                int start = new LanguageServer.Module().GetIndex(ls, cs, document);
                int end   = new LanguageServer.Module().GetIndex(le, ce, document);
                AntlrLanguageClient.CMReplacePriorization(ffn, start, end);
            }
            catch (Exception exception)
            {
                Logger.Log.Notify(exception.StackTrace);
            }
        }
Example #19
0
        private void MenuItemCallback(object sender, EventArgs e)
        {
            try
            {
                ////////////////////////
                /// Remove useless parser productions.
                ////////////////////////

                IVsTextManager manager = ((IServiceProvider)ServiceProvider).GetService(typeof(VsTextManagerClass)) as IVsTextManager;
                if (manager == null)
                {
                    return;
                }
                manager.GetActiveView(1, null, out IVsTextView view);
                if (view == null)
                {
                    return;
                }
                view.GetCaretPos(out int l, out int c);
                view.GetBuffer(out IVsTextLines buf);
                if (buf == null)
                {
                    return;
                }
                ITextBuffer buffer = AntlrLanguageClient.AdaptersFactory.GetWpfTextView(view)?.TextBuffer;
                string      ffn    = buffer.GetFFN();
                if (ffn == null)
                {
                    return;
                }
                Workspaces.Document document = Workspaces.Workspace.Instance.FindDocument(ffn);
                if (document == null)
                {
                    return;
                }
                int pos = new LanguageServer.Module().GetIndex(l, c, document);
                AntlrLanguageClient.CMMoveStartRuleToTop(ffn);
            }
            catch (Exception exception)
            {
                Logger.Log.Notify(exception.StackTrace);
            }
        }
Example #20
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void Execute(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var solution = AProtobufFactoryClass.inst.GetSolution();

            if (solution == null)
            {
                return;
            }
            var server = solution.GetServer();

            // 向当前文件窗口发送一个格式化命令
            if (m_text_manager == null)
            {
                return;
            }
            m_text_manager.GetActiveView(1, null, out IVsTextView view);
            if (view == null)
            {
                return;
            }
            if (m_adapters_factory == null)
            {
                return;
            }
            var text_view = m_adapters_factory.GetWpfTextView(view);

            if (text_view == null)
            {
                return;
            }

            text_view.Properties.TryGetProperty(nameof(UIViewItem), out UIViewItem view_item);
            // 如果是proto,那么就
            if (view_item != null)
            {
                ProtoToEMsgTypes(server, text_view, view_item);
                return;
            }

            OtherToProto(server, text_view);
        }
Example #21
0
        /// <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 OnPasteToTargetClicked(object sender, EventArgs e)
        {
            try
            {
                DTE dte = GetService(typeof(SDTE)) as DTE;
                var doc = dte.ActiveDocument;
                var win = doc.ActiveWindow;

                IVsTextManager vsEditors    = (IVsTextManager)GetService(typeof(VsTextManagerClass)) as IVsTextManager;
                IVsTextView    activeEditor = null;
                Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(vsEditors.GetActiveView(-1, null, out activeEditor));

                m_activity.StartOperation(dte, activeEditor, win);
            }
            catch (Exception ex) // TODO: Remove generic catch stmt
            {
                VSHelpers.ShowException(ex);
            }
        }
Example #22
0
        public CursorPos GetCurrentCursorPosition()
        {
            int lineNumber = 0, columnNumber = 0;

            try
            {
                IVsTextView currentTextView = null;
                var         doc             = dte.ActiveDocument;
                textManager.GetActiveView(1, null, out currentTextView);
                var status = currentTextView.GetCaretPos(out lineNumber, out columnNumber);
                lineNumber++;
            }
            catch (Exception e) //We have to catch the exception here, or the IDE can crash
            {
                Trace.TraceInformation("caught exception of type " + e.GetType() + " message: " + e.Message);
                return(new CursorPos(true));
            }
            return(new CursorPos(lineNumber, columnNumber));
        }
        public static ParamBlockAst GetScriptParameters(IVsEditorAdaptersFactoryService adaptersFactory, IVsTextManager textManager)
        {
            IVsTextView   vsTextView;
            ParamBlockAst paramBlock = null;

            //Returns the active or previously active view.
            //
            // Parameters:
            //   fMustHaveFocus:
            //     [in] If true, then the current UI active view is returned. If false, then
            //     the last active view is returned, regardless of whether this view is currently
            //     UI active.
            //
            //   pBuffer:
            //     [in] Pass null for pBuffer to get the previously active code view, regardless
            //     of the text buffer that it was associated with. If you pass in a valid pointer
            //     to a buffer, then you are returned the last active view for that particular
            //     buffer.
            //
            //   ppView:
            //     [out] Pointer to the Microsoft.VisualStudio.TextManager.Interop.IVsTextView
            //     interface.
            textManager.GetActiveView(1, null, out vsTextView);
            if (vsTextView == null)
            {
                return(null);
            }

            IVsTextLines textLines;

            vsTextView.GetBuffer(out textLines);
            ITextBuffer textBuffer = adaptersFactory.GetDataBuffer(textLines as IVsTextBuffer);
            Ast         scriptAst;

            if (!textBuffer.Properties.TryGetProperty <Ast>(BufferProperties.Ast, out scriptAst))
            {
                return(null);
            }

            PowerShellParseUtilities.HasParamBlock(scriptAst, out paramBlock);
            return(paramBlock);
        }
Example #24
0
        public int NavigateTo()
        {
            int hr = VSConstants.S_OK;
            IVsUIShellOpenDocument openDoc = _serviceProvider.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument;

            Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp = null;
            IVsUIHierarchy hierarchy = null;
            uint           itemID    = 0;
            IVsWindowFrame frame     = null;
            Guid           viewGuid  = VSConstants.LOGVIEWID_TextView;

            hr = openDoc.OpenDocumentViaProject(_file, ref viewGuid, out sp, out hierarchy, out itemID, out frame);
            Debug.Assert(hr == VSConstants.S_OK, "OpenDocumentViaProject did not return S_OK.");

            hr = frame.Show();
            Debug.Assert(hr == VSConstants.S_OK, "Show did not return S_OK.");

            IntPtr viewPtr       = IntPtr.Zero;
            Guid   textLinesGuid = typeof(IVsTextLines).GUID;

            hr = frame.QueryViewInterface(ref textLinesGuid, out viewPtr);
            Debug.Assert(hr == VSConstants.S_OK, "QueryViewInterface did not return S_OK.");

            IVsTextLines textLines = Marshal.GetUniqueObjectForIUnknown(viewPtr) as IVsTextLines;

            IVsTextManager textMgr  = _serviceProvider.GetService(typeof(SVsTextManager)) as IVsTextManager;
            IVsTextView    textView = null;

            hr = textMgr.GetActiveView(0, textLines, out textView);
            Debug.Assert(hr == VSConstants.S_OK, "QueryViewInterface did not return S_OK.");

            if (textView != null)
            {
                if (_line >= 0)
                {
                    textView.SetCaretPos(_line, Math.Max(_column, 0));
                }
            }

            return(VSConstants.S_OK);
        }
Example #25
0
        public static IWpfTextViewHost GetCurrentViewHost(IServiceProvider serviceProvider)
        {
            IVsTextManager txtMgr        = (IVsTextManager)serviceProvider.GetService(typeof(SVsTextManager));
            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);
        }
        internal void Activate()
        {
            try {
                IVsTextView  view    = null;
                IWpfTextView wpfView = null;
                TextManagerService.GetActiveView(0, null, out view);
                if (view == null)
                {
                    CurrentContentType = null;
                }
                else
                {
                    wpfView            = EditorAdapters.GetWpfTextView(view);
                    CurrentContentType = wpfView.TextDataModel.ContentType.DisplayName;
                }
            } catch {
                CurrentContentType = null;
            }

            Child.Activate();

            if (ActiveTheme == null)
            {
                IndentTheme activeTheme;
                if (CurrentContentType == null ||
                    !Service.Themes.TryGetValue(CurrentContentType, out activeTheme) ||
                    activeTheme == null)
                {
                    activeTheme = Service.DefaultTheme;
                }
                if (activeTheme == null)
                {
                    activeTheme = Service.DefaultTheme = new IndentTheme();
                }
                ActiveTheme = activeTheme;
            }

            UpdateThemeList();
            UpdateDisplay();
        }
Example #27
0
 private void MenuItemCallback(object sender, EventArgs e)
 {
     try
     {
         IVsTextManager manager = ((IServiceProvider)ServiceProvider).GetService(typeof(VsTextManagerClass)) as IVsTextManager;
         if (manager == null)
         {
             return;
         }
         manager.GetActiveView(1, null, out IVsTextView view);
         if (view == null)
         {
             return;
         }
         view.GetCaretPos(out int l, out int c);
         view.GetBuffer(out IVsTextLines buf);
         if (buf == null)
         {
             return;
         }
         ITextBuffer buffer = AntlrLanguageClient.AdaptersFactory.GetWpfTextView(view)?.TextBuffer;
         string      ffn    = buffer.GetFFN();
         if (ffn == null)
         {
             return;
         }
         Workspaces.Document document = Workspaces.Workspace.Instance.FindDocument(ffn);
         if (document == null)
         {
             return;
         }
         AntlrLanguageClient.CMPerformAnalysis(ffn);
     }
     catch (Exception exception)
     {
         Logger.Log.Notify(exception.StackTrace);
     }
 }
Example #28
0
        public static ITextView GetActiveTextView()
        {
            if (DTE.ActiveDocument.ActiveWindow != DTE.ActiveWindow)
            {
                return(null);
            }

            IServiceProvider sp   = ServiceProvider.GlobalProvider;
            IVsTextManager   mngr = sp.GetService(typeof(VsTextManagerClass)) as IVsTextManager;
            IVsTextView      textViewActive;

            int res = mngr.GetActiveView(0, null, out textViewActive);

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

            IComponentModel container = sp.GetService(typeof(SComponentModel)) as IComponentModel;
            IVsEditorAdaptersFactoryService adapter = container.DefaultExportProvider.GetExport <IVsEditorAdaptersFactoryService>().Value;

            return(adapter.GetWpfTextView(textViewActive));
        }
Example #29
0
        /// <summary>
        /// Gets the active IWpfTextView, if one exists.
        /// </summary>
        /// <returns>The active IWpfTextView, or null if no such IWpfTextView exists.</returns>
        private 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;
        }
        // get the active WpfTextView, if there is one.
        private IWpfTextView GetActiveTextView()
        {
            IVsTextView vTextView = null;

            IVsTextManager txtMgr = (IVsTextManager)GetService(typeof(SVsTextManager));

            txtMgr.GetActiveView(1, null, out vTextView);

            var userData = vTextView as IVsUserData;

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

            object holder;
            var    guidViewHost = DefGuidList.guidIWpfTextViewHost;

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

            return(viewHost.TextView);
        }
Example #31
0
        ///rootsuffix Exp
        private void MenuItemCallbackCommentOrNo(object sender, EventArgs e)
        {
            IVsTextManager txtMgr = (IVsTextManager)Package.GetGlobalService(typeof(SVsTextManager));

            if (txtMgr == null)
            {
                return;
            }

            IVsTextView view       = null;
            int         errorValue = txtMgr.GetActiveView(0, null, out view);

            if (view == null)
            {
                return;
            }

            IComponentModel componentModel = Package.GetGlobalService(typeof(SComponentModel)) as IComponentModel;
            IVsEditorAdaptersFactoryService editorFactory = componentModel.GetService <IVsEditorAdaptersFactoryService>();
            IWpfTextView wpfTextView = editorFactory.GetWpfTextView(view);

            if (wpfTextView == null)
            {
                return;
            }

            ITextSnapshot snapshot = wpfTextView.TextSnapshot;

            if (snapshot != snapshot.TextBuffer.CurrentSnapshot)
            {
                return;
            }

            bool bAllHaveComment = IsAllSelectedLinesHaveComment(wpfTextView);

            ProcessComments(!bAllHaveComment);
        }