拖动文件警告扩展VS 2010?

时间:2012-02-29 21:03:15

标签: visual-studio visual-studio-2010

我想知道如果您通过VS 2010解决方案资源管理器将文件拖到另一个文件夹,是否有人知道会弹出警告的扩展程序。很多时候我会在一个文件上,而我的计算机可能会滞后一秒钟,而且文件现在突然出现在其他文件夹中,我甚至可能都没有注意到它。

2 个答案:

答案 0 :(得分:7)

有一个名为VSCommands 2010的可用Visual Studio扩展,其功能防止意外拖动&放入解决方案资源管理器

enter image description here

修改 该功能是Pro包的一部分,不是免费的。

答案 1 :(得分:0)

我不知道会有一个免费的Visual Studio扩展程序,但这里是一个Addin的C#示例,演示了如何挂钩到Visual Studio全局删除&重命名文件管理。它基于IVsTrackProjectDocumentsEvents2界面。

您必须扩展两个OnQueryxxx方法以满足您的需求。

using System;
using System.Diagnostics;
using EnvDTE;
using EnvDTE80;
using Extensibility;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;

namespace MyAddin1
{
    public class Connect : IDTExtensibility2, IVsTrackProjectDocumentsEvents2
    {
        private uint _trackerCookie;

        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            _applicationObject = (DTE2)application;
            _addInInstance = (AddIn)addInInst;

            // the Addin project needs assembly references to Microsoft.VisualStudio.Shell, Microsoft.VisualStudio.Shell.Interop && Microsoft.VisualStudio.OLE.Interop
            // any version should do
            ServiceProvider sp = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)_applicationObject);
            IVsTrackProjectDocuments2 tracker = (IVsTrackProjectDocuments2)sp.GetService(typeof(SVsTrackProjectDocuments));

            // ask VS to notify us of files & directories changes
            tracker.AdviseTrackProjectDocumentsEvents(this, out _trackerCookie);
        }

        public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom)
        {
            if (_trackerCookie != 0)
            {
                // we quit, tell VS not to notify us anymore
                ServiceProvider sp = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)_applicationObject);
                IVsTrackProjectDocuments2 tracker = (IVsTrackProjectDocuments2)sp.GetService(typeof(SVsTrackProjectDocuments));
                tracker.UnadviseTrackProjectDocumentsEvents(_trackerCookie);
                _trackerCookie = 0;
            }
        }

        public int OnQueryRenameFiles(IVsProject pProject, int cFiles, string[] rgszMkOldNames, string[] rgszMkNewNames, VSQUERYRENAMEFILEFLAGS[] rgFlags, VSQUERYRENAMEFILERESULTS[] pSummaryResult, VSQUERYRENAMEFILERESULTS[] rgResults)
        {
            Trace.WriteLine("OnQueryRenameFiles pProject:" + pProject + " old[0]:" + rgszMkOldNames[0] + " new[0]:" + rgszMkNewNames[0]);

            // TODO: implement this (I have assumed cFiles is 1 here)
            if (!NotRenameOk(old[0], new[0])
            {
                rgResults[0] = VSQUERYRENAMEFILERESULTS.VSQUERYRENAMEFILERESULTS_RenameNotOK; // nope, it's not ok
            }
            return 0;
        }

        public int OnQueryRemoveFiles(IVsProject pProject, int cFiles, string[] rgpszMkDocuments, VSQUERYREMOVEFILEFLAGS[] rgFlags, VSQUERYREMOVEFILERESULTS[] pSummaryResult, VSQUERYREMOVEFILERESULTS[] rgResults)
        {
            Trace.WriteLine("OnQueryRemoveFiles pProject:" + pProject + " file[0]:" + rgpszMkDocuments[0]);

            // TODO: needs to be implemented, use rgResults to tell VS if it's ok or not
            return 0;
        }

        // other IVsTrackProjectDocumentsEvents2 methods implementation omitted for brevity...