Ejemplo n.º 1
0
        public override bool DisplayCommand(EnvDTE.UIHierarchyItem item)
        {
            try
            {
                UIHierarchy solExplorer = this.ApplicationObject.ToolWindows.SolutionExplorer;
                if (((System.Array)solExplorer.SelectedItems).Length != 1)
                {
                    return(false);
                }

                UIHierarchyItem hierItem = ((UIHierarchyItem)((System.Array)solExplorer.SelectedItems).GetValue(0));
                SolutionClass   solution = hierItem.Object as SolutionClass;
                if (hierItem.Object is Project)
                {
                    Project p = (Project)hierItem.Object;
                    if (!(p.Object is Database))
                    {
                        return(false);
                    }
                    Microsoft.DataWarehouse.VsIntegration.Shell.Project.Extensibility.ProjectExt projExt = (Microsoft.DataWarehouse.VsIntegration.Shell.Project.Extensibility.ProjectExt)p;
                    return(projExt.Kind == BIDSProjectKinds.SSAS);
                }
            }
            catch { }
            return(false);
        }
Ejemplo n.º 2
0
        private string determinePath(EnvDTE.UIHierarchyItem selectedItem)
        {
            List <UIHierarchyItem> filterList = new List <UIHierarchyItem>();
            // The filter element does not have a path.
            // Try to determine the path from nested project files.
            bool oldExpandedVal = selectedItem.UIHierarchyItems.Expanded;

            selectedItem.UIHierarchyItems.Expanded = true;
            foreach (UIHierarchyItem item in selectedItem.UIHierarchyItems)
            {
                if (item.Object is EnvDTE.ProjectItem)
                {
                    if (item.UIHierarchyItems != null && item.UIHierarchyItems.Count > 0)
                    {
                        //filter element
                        filterList.Add(item);
                        continue;
                    }

                    ProjectItem prjItem = item.Object as ProjectItem;
                    Property    prop    = GetProperty(prjItem.Properties, "FullPath");
                    if (prop != null)
                    {
                        string res = Path.GetDirectoryName(prop.Value.ToString());
                        if (Directory.Exists(res))
                        {
                            selectedItem.UIHierarchyItems.Expanded = oldExpandedVal;
                            return(Path.GetDirectoryName(prop.Value.ToString()));
                        }
                    }
                }
            }
            // if not found, try to determine path from sub folders/filters
            foreach (UIHierarchyItem item in filterList)
            {
                string path = determinePath(item);
                if (path.Length > 0)
                {
                    try
                    {
                        string res = path.Substring(0, path.Length - item.Name.Length - 1);
                        if (res.EndsWith(selectedItem.Name) && Directory.Exists(res))
                        {
                            selectedItem.UIHierarchyItems.Expanded = oldExpandedVal;
                            return(res);
                        }
                    }
                    catch (Exception) { }
                }
            }
            selectedItem.UIHierarchyItems.Expanded = oldExpandedVal;
            // not able to determine path
            return("");
        }
Ejemplo n.º 3
0
        private void printHierarchy(string prefix, EnvDTE.UIHierarchyItem item)
        {
            Debug.Write(prefix + item.Name + "\n");
            bool oldval = item.UIHierarchyItems.Expanded;

            item.UIHierarchyItems.Expanded = true;
            foreach (EnvDTE.UIHierarchyItem child in item.UIHierarchyItems)
            {
                printHierarchy(prefix + "  ", child);
            }
            item.UIHierarchyItems.Expanded = oldval;
        }
 /// <summary>
 /// Selects project item in Solution Explorer
 /// </summary>
 /// <remarks></remarks>
 public static void SelectSolutionExplorerNode(this EnvDTE80.DTE2 dte2, string nodePath)
 {
     EnvDTE.UIHierarchyItem item = null;
     try
     {
         item = dte2.ToolWindows.SolutionExplorer.GetItem(nodePath);
         item.Select(vsUISelectionType.vsUISelectionTypeSelect);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Ejemplo n.º 5
0
        private string guessPath(EnvDTE.UIHierarchyItem selectedItem)
        {
            // try "..\..\..\filterName"
            DTE dte = (DTE)GetService(typeof(DTE));

            dte = selectedItem.DTE;
            string solutionDir = System.IO.Path.GetDirectoryName(dte.Solution.FullName);

            Debug.Write(solutionDir + "\n");
            solutionDir += "..\\..\\..\\" + selectedItem.Name;
            string guessedPath = Path.GetFullPath(solutionDir + "..\\..\\..\\" + selectedItem.Name);

            Debug.Write(guessedPath + "\n");

            if (Directory.Exists(guessedPath))
            {
                Debug.Write("Guessed path found!\n");
                return(guessedPath);
            }
            return("");
        }
Ejemplo n.º 6
0
        private void RefreshSelectedFolder(EnvDTE.UIHierarchyItem selectedItem, string dir)
        {
            List <string>          pathList   = new List <string>();
            List <UIHierarchyItem> filterList = new List <UIHierarchyItem>();
            string path = "";

            //printHierarchy("", selectedItem);

            bool oldval = selectedItem.UIHierarchyItems.Expanded;

            selectedItem.UIHierarchyItems.Expanded = true;
            // Remove references which aren't exist
            foreach (UIHierarchyItem item in selectedItem.UIHierarchyItems)
            {
                if (!(item.Object is EnvDTE.ProjectItem))
                {
                    continue;
                }

                bool oldval2 = selectedItem.UIHierarchyItems.Expanded;
                selectedItem.UIHierarchyItems.Expanded = true;
                if (item.UIHierarchyItems != null && item.UIHierarchyItems.Count > 0)
                {
                    filterList.Add(item);
                    selectedItem.UIHierarchyItems.Expanded = oldval2;
                    //filter element
                    continue;
                }
                selectedItem.UIHierarchyItems.Expanded = oldval2;

                ProjectItem prjItem = item.Object as ProjectItem;
                Property    prop    = GetProperty(prjItem.Properties, "FullPath");
                if (prop != null)
                {
                    path = prop.Value.ToString();
                    if (!File.Exists(path))
                    {
                        // remove prjItem if path does not exist
                        try
                        {
                            prjItem.Remove();
                        }
                        catch (Exception) { }
                    }
                    else
                    {
                        // else store in pathList
                        pathList.Add(path);
                    }
                }
                else
                {
                    //empty filter
                    filterList.Add(item);
                }
            }
            selectedItem.UIHierarchyItems.Expanded = oldval;

            // Add existing files which are not in pathList
            if (dir.Length > 0)
            {
                string[] fileEntries = Directory.GetFiles(dir);
                foreach (string fileName in fileEntries)
                {
                    if (!pathList.Contains(fileName))
                    {
                        ProjectItem filter = selectedItem.Object as EnvDTE.ProjectItem;
                        if (filter != null && filter.ProjectItems != null)
                        {
                            try
                            {
                                filter.ProjectItems.AddFromFile(fileName);
                            }
                            catch (Exception) { }
                        }
                    }
                }
            }

            // Add existing directories which are not listed as filters
            if (dir.Length > 0)
            {
                string[]      dirEntries = Directory.GetDirectories(dir);
                List <string> fl         = new List <string>();
                foreach (UIHierarchyItem item in filterList)
                {
                    fl.Add(dir + "\\" + item.Name);
                }
                foreach (string dirName in dirEntries)
                {
                    if (!fl.Contains(dirName))
                    {
                        ProjectItem filter   = selectedItem.Object as EnvDTE.ProjectItem;
                        VCFilter    vcFilter = (VCFilter)filter.Object;
                        if (vcFilter != null)
                        {
                            addNewFilterRecursive(vcFilter, dirName, dir);
                        }
                        // add
                        Debug.WriteLine(dirName);
                    }
                }
            }

            // recursively update sub dirs/filters
            foreach (UIHierarchyItem item in filterList)
            {
                string newPath = dir + "\\" + item.Name;
                if (Directory.Exists(newPath))
                {
                    RefreshSelectedFolder(item, newPath);
                }
            }
        }