Beispiel #1
0
        /// <summary>
        /// Recursively searches given ProjectItems and returns list of project items satisfying given condition
        /// </summary>
        private static List <ProjectItem> GetFilesOf(ProjectItems items, Predicate <ProjectItem> test, bool includeReadonly)
        {
            List <ProjectItem> list = new List <ProjectItem>();

            if (items != null)
            {
                foreach (ProjectItem item in items)
                {
                    if (test == null || test(item))
                    {
                        if (includeReadonly || !RDTManager.IsFileReadonly(item.GetFullPath()))
                        {
                            list.Add(item);
                        }
                    }
                    else
                    {
                        if (item.ProjectItems != null && item.ProjectItems.Count > 0)
                        {
                            list.AddRange(GetFilesOf(item.ProjectItems, test, includeReadonly));
                        }
                    }
                }
            }

            return(list);
        }
Beispiel #2
0
        /// <summary>
        /// Checks active document whether it can be searched
        /// </summary>
        protected void CheckActiveDocument()
        {
            Document currentDocument = VisualLocalizerPackage.Instance.DTE.ActiveDocument;

            if (currentDocument == null)
            {
                throw new Exception("No selected document");
            }
            if (currentDocument.ProjectItem == null)
            {
                throw new Exception("Selected document has no corresponding Project Item.");
            }
            if (currentDocument.ProjectItem.ContainingProject == null)
            {
                throw new Exception("Selected document is not a part of any Project.");
            }
            if (RDTManager.IsFileReadonly(currentDocument.FullName) || VLDocumentViewsManager.IsFileLocked(currentDocument.FullName))
            {
                throw new Exception("Cannot perform this operation - active document is readonly");
            }
            if (VisualLocalizerPackage.Instance.DTE.Solution.FindProjectItem(currentDocument.FullName) == null)
            {
                throw new Exception("Selected document is not a part of an open Solution.");
            }
        }
Beispiel #3
0
        /// <summary>
        /// Search given ProjectItem, using predicate to determine whether a code element should be explored (used when processing selection)
        /// </summary>
        /// <param name="projectItem">Item to search</param>
        /// <param name="exploreable">Predicate returning true, if given code element should be searched for result items</param>
        /// <param name="verbose"></param>
        protected virtual void Process(ProjectItem projectItem, Predicate <CodeElement> exploreable, bool verbose)
        {
            if (searchedProjectItems.Contains(projectItem))
            {
                return;
            }
            searchedProjectItems.Add(projectItem);

            invisibleWindowsAuthor = GetType();

            if (VLDocumentViewsManager.IsFileLocked(projectItem.GetFullPath()) || RDTManager.IsFileReadonly(projectItem.GetFullPath()))
            {
                if (verbose)
                {
                    VLOutputWindow.VisualLocalizerPane.WriteLine("\tSkipping {0} - document is readonly", projectItem.Name);
                }
            }
            else
            {
                try {
                    switch (projectItem.GetFileType())
                    {
                    case FILETYPE.CSHARP: ProcessCSharp(projectItem, exploreable, verbose); break;

                    case FILETYPE.ASPX: ProcessAspNet(projectItem, verbose); break;

                    case FILETYPE.VB: ProcessVB(projectItem, exploreable, verbose); break;

                    default: break;     // do nothing if file type is not known
                    }
                } catch (Exception ex) {
                    if (verbose)
                    {
                        VLOutputWindow.VisualLocalizerPane.WriteLine("\tException occured while processing " + projectItem.Name);
                        VLOutputWindow.VisualLocalizerPane.WriteException(ex);
                    }
                }
            }
        }
        /// <summary>
        /// If the given item is ResX file, adds it to the list of ResX files
        /// </summary>
        private void SearchForResxFiles(ProjectItem item, List <GlobalTranslateProjectItem> resxFiles)
        {
            if (searchedProjectItems.Contains(item))
            {
                return;
            }
            SearchForResxFiles(item.ProjectItems, resxFiles);

            if (item.IsItemResX())
            {
                GlobalTranslateProjectItem r = new GlobalTranslateProjectItem(item);
                r.Checked  = false;
                r.Readonly = VLDocumentViewsManager.IsFileLocked(item.GetFullPath()) || RDTManager.IsFileReadonly(item.GetFullPath());

                resxFiles.Add(r);
            }
        }