有没有一种方法可以在Visual Studio 2008中指定概述默认值,以便打开文件时默认情况下折叠的成员? [英] Is there a way to specify outlining defaults in Visual Studio 2008 so that a file opens up with members collapsed by default?

查看:86
本文介绍了有没有一种方法可以在Visual Studio 2008中指定概述默认值,以便打开文件时默认情况下折叠的成员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的是使用VS2008,当我打开代码文件时,默认情况下折叠文件中所有类/接口的成员(至关重要的是,包括所有XML文档和注释).

What I would like to do is have VS2008, when I open a code file, collapse all members of the classes/interfaces in the file by default (including, crucially, any XML documentation and comments).

我根本不想要使用区域.

I do not want to use regions, at all.

我还希望能够使用ctrl + m和ctrl + l和弦切换所有 member 概述(例如,如果所有内容都折叠了,我希望它扩展所有成员,但不包括注释或XML文档.

I would also like to be able to use the ctrl+m, ctrl+l chord to toggle all member outlining (for example, if everything is collapsed, I would like it to expand all of the members, but not the comments or XML documentation).

可能吗?怎么样?

推荐答案

对第1部分是.

不确定第2部分.

要使VS2008自动以折叠状态打开文件,您需要创建一个加载项以在每个文档打开时运行"Edit.CollapsetoDefinition".

To have VS2008 automatically open files in a Collapsed state you'll need to create an addin to run the "Edit.CollapsetoDefinition" when each document opens.

这并不是太棘手-困难的部分似乎是您必须在实际打开文档后几毫秒内运行代码,因此您需要使用三元组池来做到这一点.

This isn't overly tricky - The difficult parts seems to be the that you have to run the code a few milliseconds after the document is actually opened so you need to use the threed pool to do that.

  1. 为VS2008创建一个Addin项目.
  2. 将此代码(请参阅下文)添加到Connect类的OnConnection方法的末尾.


    switch (connectMode)
    {
        case ext_ConnectMode.ext_cm_UISetup:
        case ext_ConnectMode.ext_cm_Startup:
            //Do nothing OnStartup will be called once IDE is initialised.
            break;
        case ext_ConnectMode.ext_cm_AfterStartup:
            //The addin was started post startup so we need to call its initialisation manually
            InitialiseHandlers();
            break;
    }

  1. 将此方法添加到Connect类


    private void InitialiseHandlers()
    {
        this._openHandler = new OnOpenHandler(_applicationObject);
    }

  1. 将对InitialiseHandlers()的调用添加到Connect类的OnStartupComplete方法.


    public void OnStartupComplete(ref Array custom)
    {
        InitialiseHandlers();
    }

  1. 将此类添加到项目中.


    using System;
    using System.Collections.Generic;
    using System.Text;
    using EnvDTE80;
    using EnvDTE;
    using System.Threading;

    namespace Collapser
    {
        internal class OnOpenHandler
        {
            DTE2 _application = null;
            EnvDTE.Events events = null;
            EnvDTE.DocumentEvents docEvents = null;

            internal OnOpenHandler(DTE2 application)
            {
                _application = application;
                events = _application.Events;
                docEvents = events.get_DocumentEvents(null);
                docEvents.DocumentOpened +=new _dispDocumentEvents_DocumentOpenedEventHandler(OnOpenHandler_DocumentOpened);
            }

            void OnOpenHandler_DocumentOpened(EnvDTE.Document document)
            {
                if (_application.Debugger.CurrentMode != dbgDebugMode.dbgBreakMode)
                {
                    ThreadPool.QueueUserWorkItem(new WaitCallback(Collapse));
                }
            }

            private void Collapse(object o)
            {
                System.Threading.Thread.Sleep(150);
                _application.ExecuteCommand("Edit.CollapsetoDefinitions", "");
            }
        }
    }

现在所有打开的文件都应该完全折叠.

And now all opened files should be fully collapsed.

这篇关于有没有一种方法可以在Visual Studio 2008中指定概述默认值,以便打开文件时默认情况下折叠的成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆