有没有办法在Visual Studio 2008中指定默认值,以便在默认情况下折叠成员时打开文件?
-
08-07-2019 - |
题
我想要做的是拥有VS2008,当我打开一个代码文件时,默认情况下会折叠文件中所有类/接口的成员(包括,至关重要的是,任何XML文档和注释)。
我不想要使用区域。
我还希望能够使用ctrl + m,ctrl + l和弦来切换所有成员大纲(例如,如果所有内容都已折叠,我希望它能够展开全部成员,但不是评论或XML文档。)
可能?怎么样?
解决方案
是第1部分。
不确定第2部分。
要让VS2008自动打开处于折叠状态的文件,您需要创建一个插件来运行<!> quot; Edit.CollapsetoDefinition <!> quot;当每个文件打开时。
这并不是太棘手 - 困难的部分似乎是你必须在文件实际打开几毫秒后运行代码,所以你需要使用threed池来做到这一点。
- 为VS2008创建一个Addin项目。
- 将此代码(请参阅下文)添加到Connect类的OnConnection方法的末尾。 醇>
- 将此方法添加到Connect类 醇>
- 将对InitialiseHandlers()的调用添加到Connect类的OnStartupComplete方法。 醇>
- 将此课程添加到项目中。 醇>
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;
}
private void InitialiseHandlers()
{
this._openHandler = new OnOpenHandler(_applicationObject);
}
public void OnStartupComplete(ref Array custom)
{
InitialiseHandlers();
}
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", "");
}
}
}
现在所有打开的文件都应该完全折叠。
其他提示
使用Visual Studio宏来做同样的事情要容易得多。编辑<!>“; EnvironmentEvents <!>”; MyMacros中的宏文件,并为DocumentEvents.DocumentOpened添加处理程序:
DTE.ExecuteCommand(QUOT <!>; Edit.CollapsetoDefinitions QUOT <!>)
将所有概述折叠为函数定义的快速方法是按: 上下文菜单按钮* (右侧窗口按钮旁边) *,L,O
我一直都在使用它。如果有真正的热键请告诉我:)
我曾经尝试过为一个宏编写一些Visual Basic代码,从不同的地方借用,并且无法获得任何工作。那我该怎么办?为什么,我当然要求关于StackOverflow的问题!它得到了答案,我将建议的代码添加到我的EnvironmentEvents
宏,现在当我打开CS文件时,大约一秒后,我的所有定义都被折叠了。 :)