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