Esempio n. 1
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            var selectedItems = ((UIHierarchy)((DTE2)this.ServiceProvider.GetService(typeof(DTE))).Windows.Item("{3AE79031-E1BC-11D0-8F78-00A0C9110057}").Object).SelectedItems as object[];

            if (selectedItems != null)
            {
                LocateFile.FilesOrFolders((IEnumerable <string>)(from t in selectedItems
                                                                 where (t as UIHierarchyItem)?.Object is ProjectItem
                                                                 select((ProjectItem)((UIHierarchyItem)t).Object).FileNames[1]));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private async void ExecuteAsync(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var dte = (DTE2)await this.ServiceProvider.GetServiceAsync(typeof(DTE));

            var uiHierachy = (UIHierarchy)dte.Windows.Item("{3AE79031-E1BC-11D0-8F78-00A0C9110057}").Object;

            if (uiHierachy.SelectedItems is object[] selectedItems)
            {
                LocateFile.FilesOrFolders(from t in selectedItems
                                          where (t as UIHierarchyItem)?.Object is ProjectItem
                                          select((ProjectItem)((UIHierarchyItem)t).Object).FileNames[1]);
            }
        }