Yes để phần 1.
Không chắc chắn về phần 2.
Để có VS2008 file tự động mở trong một trạng thái Đã thu gọn bạn sẽ cần phải tạo ra một addin để chạy "Edit.CollapsetoDefinition" khi mỗi tài liệu mở ra.
Đây không phải là quá phức tạp - Các phần khó có vẻ là bạn phải chạy mã một vài phần nghìn giây sau khi tài liệu được mở thực sự, do đó bạn cần phải sử dụng hồ bơi để làm điều đó.
- Tạo dự án Addin cho VS2008.
- Thêm mã này (xem phần sau) vào cuối Phương thức OnConnection của lớp Connect.
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;
}
- Thêm phương pháp này để lớp Connect
private void InitialiseHandlers()
{
this._openHandler = new OnOpenHandler(_applicationObject);
}
- Thêm một cuộc gọi đến InitialiseHandlers() vào phương thức OnStartupComplete của lớp Connect.
public void OnStartupComplete(ref Array custom)
{
InitialiseHandlers();
}
- Thêm lớp này đến dự án.
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", "");
}
}
}
Và bây giờ tất cả các tệp đã mở sẽ được thu gọn hoàn toàn.
Bạn có thể làm rõ làm thế nào bạn sẽ làm điều này? Tôi đã thêm câu trả lời (http://stackoverflow.com/questions/293806/is-there-a-way-to-specify-outlining-defaults-in-visual-studio-so-that-a-file-open/1050267 # 1050267) cho câu hỏi này nhưng không thể lấy mã macro của tôi để hoạt động. –