コード例 #1
0
        /// <summary>
        /// Search given ProjectItem and its dependant items
        /// </summary>
        protected virtual void Process(ProjectItem projectItem, bool verbose)
        {
            if (projectItem.CanShowCodeContextMenu())
            {
                Process(projectItem, (e) => { return(true); }, verbose);
            }

            if (projectItem.ProjectItems != null)
            {
                foreach (ProjectItem item in projectItem.ProjectItems)
                {
                    Process(item, verbose);
                }
            }

            // in ASP .NET projects, ProjectItems returns null even though there are child items
            if (projectItem.GetFileType() == FILETYPE.ASPX)
            {
                foreach (string ext in StringConstants.CodeExtensions)   // try adding .vb and .cs extensions and search for the file
                {
                    string      path = projectItem.GetFullPath() + ext;
                    ProjectItem item = VisualLocalizerPackage.Instance.DTE.Solution.FindProjectItem(path);
                    if (item != null && item != projectItem)
                    {
                        Process(item, verbose);
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Determines whether "Visual Localizer" menu should be visible in Solution Explorer's context menu.
        /// This happens only when all selected items are of known type.
        /// </summary>
        private void SolExpMenuQueryStatus(object sender, EventArgs args)
        {
            try {
                if (VisualLocalizerPackage.Instance.UIHierarchy == null)
                {
                    VisualLocalizerPackage.Instance.UIHierarchy = (EnvDTE.UIHierarchy)VisualLocalizerPackage.Instance.DTE.Windows.Item(EnvDTE.Constants.vsWindowKindSolutionExplorer).Object;
                }

                Array selectedItems = (Array)VisualLocalizerPackage.Instance.UIHierarchy.SelectedItems;
                bool  menuOk        = selectedItems.Length > 0;
                batchOperationsEnabled = menuOk;
                globalTranslateEnabled = menuOk;

                foreach (UIHierarchyItem o in selectedItems)
                {
                    if (o.Object is ProjectItem)
                    {
                        ProjectItem item = (ProjectItem)o.Object;

                        bool isFolder = item.IsContainer();
                        bool isresx   = item.IsItemResX();
                        bool canShow  = item.CanShowCodeContextMenu();

                        menuOk = menuOk && (canShow || isresx || isFolder);
                        globalTranslateEnabled = globalTranslateEnabled && (isresx || isFolder);
                        batchOperationsEnabled = batchOperationsEnabled && (canShow || isFolder);
                    }
                    else if (o.Object is Project)
                    {
                        Project proj = (Project)o.Object;
                        menuOk = menuOk && proj.IsKnownProjectType();
                    }
                    else if (o.Object is Solution)
                    {
                        menuOk = true;
                    }
                    else
                    {
                        throw new Exception("Unexpected project item type: " + o.Object.GetVisualBasicType());
                    }
                }

                (sender as OleMenuCommand).Visible = menuOk;
            } catch (Exception ex) {
                VLOutputWindow.VisualLocalizerPane.WriteException(ex);
            }
        }