Exemple #1
0
        private bool OpenSolutionResource(SolutionFile sr, string editor)
        {
            if (sr == null) return false;
            if (string.IsNullOrEmpty(sr.FilePath)) return false;
            IVsCommandWindow cmw = (IVsCommandWindow)GetService(typeof(SVsCommandWindow));
            if (cmw == null) return false;

            if (editor == null)
                cmw.ExecuteCommand("of \"" + sr.FilePath + "\"");
            else if (editor.Length == 0)
                cmw.ExecuteCommand("of \"" + sr.FilePath + "\" /editor");
            else
                cmw.ExecuteCommand("of \"" + sr.FilePath + "\" /e:\"" + editor + "\"");

            return true;
        }
Exemple #2
0
        /// <summary>
        /// This function diplays the name of the Hierarchy node. This function is passed to the 
        /// Hierarchy enumeration routines to process the current node.
        /// </summary>
        /// <param name="hierarchy">Hierarchy of the current node</param>
        /// <param name="itemid">Itemid of the current node</param>
        /// <param name="recursionLevel">Depth of recursion in hierarchy enumeration. We add one tab
        /// for each level in the recursion.</param>
        private void ProcessSolutionNode(IVsHierarchy hierarchy, uint itemid, int recursionLevel)
        {
            int hr;

            // get name
            object objName;
            hr = hierarchy.GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_Name, out objName);

            if (recursionLevel == 0) traversalState.CurrentSolutionName = (string)objName;
            if (recursionLevel == 1) traversalState.CurrentProjectName = (string)objName;

            // skip non-member items (dependencies, files not referenced by the solution)
            object objIsNonMember;
            hr = hierarchy.GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_IsNonMemberItem, out objIsNonMember);
            if (objIsNonMember != null)
                if ((bool)objIsNonMember)
                    return;

            SolutionFile sr = new SolutionFile();
            sr.Name = (string)objName;
            sr.Project = traversalState.CurrentProjectName;
            sr.ItemId = itemid;

            // get canonical filename and last write time
            if (recursionLevel > 0 && itemid != VSConstants.VSITEMID_NIL && itemid != VSConstants.VSITEMID_ROOT)
            {
                try
                {
                    string filePath = "";
                    if (hierarchy.GetCanonicalName(itemid, out filePath) == VSConstants.S_OK)
                    {
                        if (!string.IsNullOrEmpty(filePath) && System.IO.Path.IsPathRooted(filePath))
                        {
                            if (File.Exists(filePath))
                            {
                                sr.FilePath = filePath;
                                sr.LastWriteTime = File.GetLastWriteTime(filePath);
                            }
                        }
                    }
                }
                catch (ArgumentException) { }
                catch (System.Reflection.TargetInvocationException) { }
                catch (Exception) { }
            }

            // Exclude empty names and paths (also non-existent files).
            if (string.IsNullOrEmpty(sr.Name) || string.IsNullOrEmpty(sr.FilePath))
                return;

            // Exclude canonical names that appear to be directories
            if (sr.FilePath.EndsWith("\\") || sr.FilePath.EndsWith("/"))
                return;

            // get icon
            object objIconIndex;
            hr = hierarchy.GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_IconIndex, out objIconIndex);
            if (objIconIndex != null) sr.IconIndex = (int)objIconIndex;
            // TODO: look how to obtain item's icons for display in the list view
            //    -> http://connect.microsoft.com/VisualStudio/feedback/details/520256/cannot-find-icon-for-vs2010-database-project

            solutionFiles.Add(sr);
        }
Exemple #3
0
        /// <summary>
        /// This function diplays the name of the Hierarchy node. This function is passed to the
        /// Hierarchy enumeration routines to process the current node.
        /// </summary>
        /// <param name="hierarchy">Hierarchy of the current node</param>
        /// <param name="itemid">Itemid of the current node</param>
        /// <param name="recursionLevel">Depth of recursion in hierarchy enumeration. We add one tab
        /// for each level in the recursion.</param>
        private void ProcessSolutionNode(IVsHierarchy hierarchy, uint itemid, int recursionLevel)
        {
            int hr;

            // get name
            object objName;

            hr = hierarchy.GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_Name, out objName);

            if (recursionLevel == 0)
            {
                traversalState.CurrentSolutionName = (string)objName;
            }

            if (recursionLevel == 1)
            {
                traversalState.CurrentProjectName = (string)objName;
            }

            // skip non-member items (dependencies, files not referenced by the solution)
            object objIsNonMember;

            hr = hierarchy.GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_IsNonMemberItem, out objIsNonMember);
            if (objIsNonMember != null)
            {
                if ((bool)objIsNonMember)
                {
                    return;
                }
            }

            SolutionFile sr = new SolutionFile();

            sr.Name    = (string)objName;
            sr.Project = traversalState.CurrentProjectName;
            sr.ItemId  = itemid;

            // get canonical filename and last write time
            if (recursionLevel > 0 && itemid != VSConstants.VSITEMID_NIL && itemid != VSConstants.VSITEMID_ROOT)
            {
                try
                {
                    string filePath = "";
                    if (hierarchy.GetCanonicalName(itemid, out filePath) == VSConstants.S_OK)
                    {
                        if (!string.IsNullOrEmpty(filePath) && System.IO.Path.IsPathRooted(filePath))
                        {
                            if (File.Exists(filePath))
                            {
                                sr.FilePath             = filePath;
                                sr.SolutionRelativePath = traversalState.SolutionRelativePath(filePath);
                                sr.LastWriteTime        = File.GetLastWriteTime(filePath);
                            }
                        }
                    }
                }
                catch (ArgumentException) { }
                catch (System.Reflection.TargetInvocationException) { }
                catch (Exception) { }
            }

            // Exclude empty names and paths (also non-existent files).
            if (string.IsNullOrEmpty(sr.Name) || string.IsNullOrEmpty(sr.FilePath))
            {
                return;
            }

            // Exclude canonical names that appear to be directories
            if (sr.FilePath.EndsWith("\\") || sr.FilePath.EndsWith("/"))
            {
                return;
            }

            // get icon
            object objIconIndex;

            hr = hierarchy.GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_IconIndex, out objIconIndex);
            if (objIconIndex != null)
            {
                sr.IconIndex = (int)objIconIndex;
            }
            // TODO: look how to obtain item's icons for display in the list view
            //    -> http://connect.microsoft.com/VisualStudio/feedback/details/520256/cannot-find-icon-for-vs2010-database-project

            solutionFiles.Add(sr);
        }