Esempio n. 1
0
 /// <summary>
 /// Retrieves the currently selected target in the solution explorer.
 /// </summary>
 /// <remarks>
 /// If there's only one item selected, then the corresponding Solution, Project
 /// or ProjectItem element is returned. Otherwise, the <see cref="EnvDTE.SelectedItems"/>
 /// property is returned.
 /// </remarks>
 /// <exception cref="InvalidOperationException">There's no current selection in the solution explorer.</exception>
 /// <returns>The current selection.</returns>
 public static object GetTarget(_DTE vs)
 {
     if (vs.SelectedItems != null && vs.SelectedItems.Count > 0)
     {
         if (vs.SelectedItems.Count == 1)
         {
             IEnumerator enumerator = vs.SelectedItems.GetEnumerator();
             enumerator.MoveNext();
             EnvDTE.SelectedItem item = (EnvDTE.SelectedItem)enumerator.Current;
             // Determine target to load.
             if (item.Project != null)
             {
                 return(item.Project);
             }
             else if (item.ProjectItem != null)
             {
                 return(item.ProjectItem);
             }
             else if (vs.Solution.Properties.Item("Name").Value.Equals(item.Name))
             {
                 return(vs.Solution);
             }
             return(item);
         }
         else
         {
             //If more than one element is selected, then assert should deal with the DTE.SelectedItems object
             return(vs.SelectedItems);
         }
     }
     throw new InvalidOperationException(Properties.Resources.DteHelper_NoSelection);
 }
Esempio n. 2
0
        /// <summary>
        /// Retrieves the currently selected target in the solution explorer.
        /// </summary>
        /// <remarks>
        /// If there's only one item selected, then the corresponding EnvDTE.Solution, Project
        /// or ProjectItem element is returned. Otherwise, the <see cref="EnvDTE.SelectedItems"/>
        /// property is returned.
        /// </remarks>
        /// <exception cref="InvalidOperationException">There's no current selection in the solution explorer.</exception>
        /// <returns>The current selection.</returns>
        public static object GetTarget(_DTE vs)
        {
            Guard.ArgumentNotNull(vs, "vs");

            if (vs.SelectedItems != null && vs.SelectedItems.Count > 0)
            {
                if (vs.SelectedItems.Count == 1)
                {
                    EnvDTE.SelectedItem item = vs.SelectedItems.Item(1);
                    // Determine target to load.
                    if (item.Project != null)
                    {
                        return(item.Project);
                    }
                    else if (item.ProjectItem != null)
                    {
                        return(item.ProjectItem);
                    }
                    else if (vs.Solution.Properties.Item("Name").Value.Equals(item.Name))
                    {
                        return(vs.Solution);
                    }
                    return(item);
                }
                else
                {
                    //If more than one element is selected, then assert should deal with the DTE.SelectedItems object
                    return(vs.SelectedItems);
                }
            }
            throw new InvalidOperationException(Properties.Resources.DteHelper_NoSelection);
        }
Esempio n. 3
0
        public static bool IsSolution(this EnvDTE.SelectedItem me)
        {
            if (me.ProjectItem == null && me.Project == null)
            {
                return(true);
            }

            return(false);
        }
Esempio n. 4
0
        //获取选中文件全路径
        private string GetSelecteditempath()
        {
            //从被选中对象中获取工程对象
            EnvDTE.SelectedItem item = _applicationObject.SelectedItems.Item(1);

            string selectpath = item.ProjectItem.Properties.Item("FullPath").Value.ToString();

            return(selectpath);
        }
Esempio n. 5
0
        //获取选中文件全路径
        private SelectedItem GetProjectItemSel()
        {
            //从被选中对象中获取工程对象
            EnvDTE.SelectedItem item = _applicationObject.SelectedItems.Item(1);

            //string selectpath = item.ProjectItem.Properties.Item("FullPath").Value.ToString();

            return(item);
        }
        /// <summary>
        /// Gets whether the specified item is supported by this command.
        /// </summary>
        protected bool IsSupported(EnvDTE.SelectedItem item)
        {
            switch (item.GetKind())
            {
            case SelectedItemKind.Project:
                return(SupportProject);

            case SelectedItemKind.Solution:
                return(SupportSolution);
            }

            return(false);
        }
Esempio n. 7
0
        public static SelectedItemKind GetKind(this EnvDTE.SelectedItem me)
        {
            if (me.IsProject())
            {
                return(SelectedItemKind.Project);
            }

            if (me.IsSolution())
            {
                return(SelectedItemKind.Solution);
            }

            return(SelectedItemKind.Unknown);
        }
Esempio n. 8
0
        //获取选中所属项目
        private Project GetSelectedProject()
        {
            Project project = null;

            //从被选中对象中获取工程对象
            EnvDTE.SelectedItem item = _applicationObject.SelectedItems.Item(1);

            if (item.Project != null)
            {            //被选中的就是项目本生
                project = item.Project;
            }
            else
            {            //被选中的是项目下的子项
                project = item.ProjectItem.ProjectItems.ContainingProject;
            }
            return(project);
        }
Esempio n. 9
0
        private string GetPathFromSelectedProjectItem()
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var selItems = package.DTE.SelectedItems;

            if (selItems.Count > 0)
            {
                EnvDTE.SelectedItem item = selItems.Item(1);   // 1-based index
                if (item != null)
                {
                    var projItem = item.ProjectItem;
                    if (projItem != null)
                    {
                        // Selected item is a part of the project.
                        if (projItem.FileCount > 0)
                        {
                            return(projItem.FileNames[0]);
                        }
                    }
                }
            }
            return("");
        }