Exemplo n.º 1
0
        public static void SearchFiles(string term, string fileTypes)
        {
            Find2  find      = (Find2)WebEssentialsPackage.DTE.Find;
            string types     = find.FilesOfType;
            bool   matchCase = find.MatchCase;
            bool   matchWord = find.MatchWholeWord;

            find.WaitForFindToComplete = false;
            find.Action            = EnvDTE.vsFindAction.vsFindActionFindAll;
            find.Backwards         = false;
            find.MatchInHiddenText = true;
            find.MatchWholeWord    = true;
            find.MatchCase         = true;
            find.PatternSyntax     = EnvDTE.vsFindPatternSyntax.vsFindPatternSyntaxLiteral;
            find.ResultsLocation   = EnvDTE.vsFindResultsLocation.vsFindResults1;
            find.SearchSubfolders  = true;
            find.FilesOfType       = fileTypes;
            find.Target            = EnvDTE.vsFindTarget.vsFindTargetSolution;
            find.FindWhat          = term;
            find.Execute();

            find.FilesOfType    = types;
            find.MatchCase      = matchCase;
            find.MatchWholeWord = matchWord;
        }
Exemplo n.º 2
0
        protected override bool Execute(VSConstants.VSStd97CmdID commandId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            SnapshotPoint?point = TextView.Caret.Position.Point.GetPoint(TextView.TextBuffer, PositionAffinity.Predecessor);

            if (point.HasValue)
            {
                TextExtent wordExtent = _navigator.GetExtentOfWord(point.Value - 1);
                string     wordText   = TextView.TextSnapshot.GetText(wordExtent.Span);

                Find2  find      = (Find2)EditorExtensionsPackage.DTE.Find;
                string types     = find.FilesOfType;
                bool   matchCase = find.MatchCase;
                bool   matchWord = find.MatchWholeWord;

                find.WaitForFindToComplete = false;
                find.Action            = EnvDTE.vsFindAction.vsFindActionFindAll;
                find.Backwards         = false;
                find.MatchInHiddenText = true;
                find.MatchWholeWord    = true;
                find.MatchCase         = true;
                find.PatternSyntax     = EnvDTE.vsFindPatternSyntax.vsFindPatternSyntaxLiteral;
                find.ResultsLocation   = EnvDTE.vsFindResultsLocation.vsFindResults1;
                find.SearchSubfolders  = true;
                find.FilesOfType       = "*.js";
                find.Target            = EnvDTE.vsFindTarget.vsFindTargetSolution;
                find.FindWhat          = wordText;
                find.Execute();

                find.FilesOfType    = types;
                find.MatchCase      = matchCase;
                find.MatchWholeWord = matchWord;
            }

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Replaces the text.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="findText">The find text.</param>
        /// <param name="replaceText">The replace text.</param>
        /// <param name="saveFiles">if set to <c>true</c> [save files].</param>
        /// <returns>True or false.</returns>
        public static bool ReplaceText(
            this DTE2 instance,
            string findText,
            string replaceText,
            bool saveFiles)
        {
            TraceService.WriteLine("DTEExtensions::ReplaceText from '" + findText + "' to '" + replaceText + "'");

            bool replaced = true;

            Find2 find2 = (Find2)instance.Find;

            vsFindResult findResults = find2.FindReplace(
                vsFindAction.vsFindActionReplaceAll,
                findText,
                (int)vsFindOptions.vsFindOptionsFromStart,
                replaceText,
                vsFindTarget.vsFindTargetSolution,
                string.Empty,
                string.Empty,
                vsFindResultsLocation.vsFindResultsNone);

            if (findResults == vsFindResult.vsFindResultNotFound)
            {
                replaced = false;
                TraceService.WriteError("Unable to replace text from:-" + findText + " to:- " + replaceText);
            }

            if (saveFiles)
            {
                instance.SaveAll();
            }

            return(replaced);
        }
Exemplo n.º 4
0
        protected override bool Execute(uint commandId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (!EnsureInitialized())
            {
                return(false);
            }

            int       position = TextView.Caret.Position.BufferPosition.Position;
            ParseItem item     = _tree.StyleSheet.ItemBeforePosition(position);

            if (item != null && item.Parent != null)
            {
                Find2  find      = (Find2)EditorExtensionsPackage.DTE.Find;
                string types     = find.FilesOfType;
                bool   matchCase = find.MatchCase;
                bool   matchWord = find.MatchWholeWord;

                find.WaitForFindToComplete = false;
                find.Action            = EnvDTE.vsFindAction.vsFindActionFindAll;
                find.Backwards         = false;
                find.MatchInHiddenText = true;
                find.MatchWholeWord    = true;
                find.MatchCase         = true;
                find.PatternSyntax     = EnvDTE.vsFindPatternSyntax.vsFindPatternSyntaxLiteral;
                find.ResultsLocation   = EnvDTE.vsFindResultsLocation.vsFindResults1;
                find.SearchSubfolders  = true;
                find.FilesOfType       = "*.css;*.less;*.scss;*.sass";
                find.Target            = EnvDTE.vsFindTarget.vsFindTargetSolution;
                find.FindWhat          = SearchText(item);
                find.Execute();

                find.FilesOfType    = types;
                find.MatchCase      = matchCase;
                find.MatchWholeWord = matchWord;
            }

            return(true);
        }
Exemplo n.º 5
0
        private void AddPublicKeyToInternalsVisible(List <Project> projectList, string publicKey)
        {
            EnvDTE.DTE dte  = GetService <EnvDTE.DTE>(true);
            Find2      find = (Find2)dte.Find;

            // Save original settings
            vsFindAction          origAction      = find.Action;
            string                origFilesOfType = find.FilesOfType;
            string                origFindWhat    = find.FindWhat;
            bool                  origKeepModifiedDocumentsOpen = find.KeepModifiedDocumentsOpen;
            bool                  origMatchCase        = find.MatchCase;
            bool                  origMatchHiddenText  = find.MatchInHiddenText;
            bool                  origMatchWholeWord   = find.MatchWholeWord;
            vsFindPatternSyntax   origPatternSyntax    = find.PatternSyntax;
            string                origReplaceWith      = find.ReplaceWith;
            vsFindResultsLocation origResultsLocation  = find.ResultsLocation;
            string                origSearchPath       = find.SearchPath;
            bool                  origSearchSubfolders = find.SearchSubfolders;
            vsFindTarget          origTarget           = find.Target;

            try
            {
                // match InternalsVisibleTo(" followed by anything (non greedy) up until the first comma, if any, as a tag
                // match the remaining non " chars up until the first " (re = "(,[^""]*)*", no "?" operator is supported by VS regex engine)
                // by leaving anything after the coma outside the tag, existing public keys will be ignored
                // by matching InternalsVisibleTo("[content]"), having the attribute together with other attributes is not an issue
                find.FindWhat = @"{InternalsVisibleTo\("".@}(,[^""]*)*""";
                if (publicKey == null)
                {
                    find.ReplaceWith = @"\1""]";
                }
                else
                {
                    find.ReplaceWith = @"\1, PublicKey=" + publicKey + @"""";
                }

                find.Action      = vsFindAction.vsFindActionReplaceAll;
                find.FilesOfType = "AssemblyInfo.*";
                find.KeepModifiedDocumentsOpen = false;
                find.MatchCase             = false;
                find.MatchInHiddenText     = true;
                find.MatchWholeWord        = false;
                find.PatternSyntax         = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr;
                find.ResultsLocation       = vsFindResultsLocation.vsFindResults1;
                find.SearchSubfolders      = true;
                find.Target                = vsFindTarget.vsFindTargetFiles;
                find.WaitForFindToComplete = true;

                foreach (Project project in projectList)
                {
                    string projectPropertiesPath = Path.GetDirectoryName(project.FileName);
                    find.SearchPath = projectPropertiesPath;
                    vsFindResult result = find.Execute();
                    Debug.WriteLine(project.Name + " " + result.ToString());
                }
            }
            finally
            {
                // Restore original settings
                find.Action      = origAction;
                find.FilesOfType = origFilesOfType;
                find.FindWhat    = origFindWhat;
                find.KeepModifiedDocumentsOpen = origKeepModifiedDocumentsOpen;
                find.MatchCase         = origMatchCase;
                find.MatchInHiddenText = origMatchHiddenText;
                find.MatchWholeWord    = origMatchWholeWord;
                find.PatternSyntax     = origPatternSyntax;
                find.ReplaceWith       = origReplaceWith;
                find.ResultsLocation   = origResultsLocation;
                find.SearchPath        = origSearchPath;
                find.SearchSubfolders  = origSearchSubfolders;
                find.Target            = origTarget;
            }
        }