locked
VSPackage Tool Window: Find Results and Find Symbol Results Events (Search Complete Events) RRS feed

  • Question

  • I would like to subscribe to the "Find Results Completed" and "Find Symbol Results Completed" events (if they exist) to display the results in a different format (sortable, filterable, tabs of previous searches, etc).  Are there any events I can subscribe to that would notify me when a "Find" command has completed?  (any kind of Find/Search.  Find in Files, Find All References, etc)

     

    Extension Details:

    VSPackage that will add a new Tool Window to the IDE.

    VS2010

    Windows 7

    C#

    Tuesday, October 19, 2010 2:08 AM

Answers

  • Hi Aaron,

    Feel free to ignore the documentation. A better link would have been http://msdn.microsoft.com/en-us/library/envdte.findeventsclass.finddone.aspx. We still have some issues with the generated docsets apparently.

    The following is simple example of how to add an event handler to recieve a notification when the FindDone event is fired.

    using System;
    using Extensibility;
    using EnvDTE;
    using EnvDTE80;

    namespace FindEventsAddin
    {
        public class Connect : IDTExtensibility2
        {
            public Connect(){ }

            public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
            {
                _applicationObject = (DTE2)application;
                _addInInstance = (AddIn)addInInst;
                _findEvents = _applicationObject.Events.FindEvents;
                _findEvents.FindDone += new _dispFindEvents_FindDoneEventHandler(OnFindDone);
            }

            public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom)
            {
                if (_findEvents != null)
                {
                    _findEvents.FindDone -= new _dispFindEvents_FindDoneEventHandler(OnFindDone);
                    _findEvents = null;
                }
            }

            public void OnAddInsUpdate(ref Array custom) {}
            public void OnStartupComplete(ref Array custom) {}
            public void OnBeginShutdown(ref Array custom) {}

            private void OnFindDone(vsFindResult result, bool cancelled)
            {
                System.Diagnostics.Debug.Write("FindDone event fired with vsFindResult = ");
                System.Diagnostics.Debug.WriteLine(result.ToString());
            }

            private DTE2 _applicationObject;
            private AddIn _addInInstance;
            private FindEvents _findEvents;
        }
    }

    The tougher question is how to retrieve the results. And we don't have a good answer for that. There isn't any way to intercept the results, so if you want to process them, you have to pick them out of the results toolwindow, as described in an earlier post. It's macro based, but it does show how to grab the text via a TextSelection object.

    Sincerely,


    Ed Dore
    Wednesday, October 27, 2010 10:59 PM

All replies

  • You can check DTE.Events.FindEvents, which supports FindDone event. http://msdn.microsoft.com/en-us/library/d0h0aaf1.aspx

    Hope it helps.


    Looking for TFS Hot Issues? Follow us at Twitter.

    Hongye Sun [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, October 20, 2010 3:24 AM
  • Thanks Hongye,

     

    Should I be concerned about either of these comments within the MSDN documentation:

    "Infrastructure. Microsoft Internal Use Only."  -or-  " This API supports the .NET Framework infrastructure and is not intended to be used directly from your code." :-)

     

    I guess I was looking for a Prism-like Event Aggregation method of subscribing to these events.  Is there anything like that?

     

    Wednesday, October 20, 2010 1:55 PM
  • Hi Aaron,

    Feel free to ignore the documentation. A better link would have been http://msdn.microsoft.com/en-us/library/envdte.findeventsclass.finddone.aspx. We still have some issues with the generated docsets apparently.

    The following is simple example of how to add an event handler to recieve a notification when the FindDone event is fired.

    using System;
    using Extensibility;
    using EnvDTE;
    using EnvDTE80;

    namespace FindEventsAddin
    {
        public class Connect : IDTExtensibility2
        {
            public Connect(){ }

            public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
            {
                _applicationObject = (DTE2)application;
                _addInInstance = (AddIn)addInInst;
                _findEvents = _applicationObject.Events.FindEvents;
                _findEvents.FindDone += new _dispFindEvents_FindDoneEventHandler(OnFindDone);
            }

            public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom)
            {
                if (_findEvents != null)
                {
                    _findEvents.FindDone -= new _dispFindEvents_FindDoneEventHandler(OnFindDone);
                    _findEvents = null;
                }
            }

            public void OnAddInsUpdate(ref Array custom) {}
            public void OnStartupComplete(ref Array custom) {}
            public void OnBeginShutdown(ref Array custom) {}

            private void OnFindDone(vsFindResult result, bool cancelled)
            {
                System.Diagnostics.Debug.Write("FindDone event fired with vsFindResult = ");
                System.Diagnostics.Debug.WriteLine(result.ToString());
            }

            private DTE2 _applicationObject;
            private AddIn _addInInstance;
            private FindEvents _findEvents;
        }
    }

    The tougher question is how to retrieve the results. And we don't have a good answer for that. There isn't any way to intercept the results, so if you want to process them, you have to pick them out of the results toolwindow, as described in an earlier post. It's macro based, but it does show how to grab the text via a TextSelection object.

    Sincerely,


    Ed Dore
    Wednesday, October 27, 2010 10:59 PM