Example #1
0
        private T CreateSearchRequest <T>() where T : SearchRequest, new()
        {
            string[] searchForValues;
            if (MultipleValues)
            {
                searchForValues = SearchFor.Replace(Environment.NewLine, "\r").Split('\r', StringSplitOptions.RemoveEmptyEntries);
            }
            else
            {
                searchForValues = new[] { SearchFor };
            }

            var request = new T()
            {
                SearchFor            = searchForValues,
                Encoding             = SelectedEncoding.EncodingInfo?.GetEncoding(),
                Path                 = path,
                Recursive            = recursive,
                FileTypeFilter       = string.IsNullOrWhiteSpace(searchPattern) ? new string[] { "*" } : searchPattern.Split(','),
                MatchCase            = matchCase,
                UseRegularExpression = UseRegularExpressions
            };

            return(request);
        }
Example #2
0
        // Need to be implemented separately
        #endregion

        #region Public Methods
        public virtual void UpdateState(string name)
        {
            List <string> tempList = null;

            switch (name)
            {
            case "Multiline":
            case "Singleline":
            case "WholeWord":
            case "CaseSensitive":
            case "StopAfterFirstMatch":
                if (Multiline)
                {
                    TextBoxStyle = "{StaticResource ExpandedTextbox}";
                }
                else
                {
                    TextBoxStyle = "";
                }

                CanReplace = false;
                break;

            case "UseFileSizeFilter":
                IsSizeFilterSet = UseFileSizeFilter == FileSizeFilter.Yes;
                break;

            case "UseFileDateFilter":
                IsDateFilterSet = UseFileDateFilter != FileDateFilter.None;
                IsDatesRangeSet = IsDateFilterSet && TypeOfTimeRangeFilter == FileTimeRange.Dates;
                IsHoursRangeSet = IsDateFilterSet && TypeOfTimeRangeFilter == FileTimeRange.Hours;
                if (!IsDateFilterSet)
                {
                    TypeOfTimeRangeFilter = FileTimeRange.None;
                }
                else if (TypeOfTimeRangeFilter == FileTimeRange.None)
                {
                    TypeOfTimeRangeFilter = FileTimeRange.Dates;
                }
                break;

            case "TypeOfTimeRangeFilter":
                IsDatesRangeSet = IsDateFilterSet && TypeOfTimeRangeFilter == FileTimeRange.Dates;
                IsHoursRangeSet = IsDateFilterSet && TypeOfTimeRangeFilter == FileTimeRange.Hours;
                break;
            }

            if (name == "IncludeSubfolder" || name == "IncludeHidden" || name == "IncludeBinary" ||
                name == "UseFileSizeFilter" || name == "UseFileDateFilter")
            {
                tempList = new List <string>();
                if (!IncludeSubfolder)
                {
                    tempList.Add("No subfolders");
                }
                if (!IncludeHidden)
                {
                    tempList.Add("No hidden");
                }
                if (!IncludeBinary)
                {
                    tempList.Add("No binary");
                }
                if (UseFileSizeFilter == FileSizeFilter.Yes)
                {
                    tempList.Add("By Size");
                }
                if (UseFileDateFilter == FileDateFilter.Modified)
                {
                    tempList.Add("By Modified Date");
                }
                if (UseFileDateFilter == FileDateFilter.Created)
                {
                    tempList.Add("By Created Date");
                }

                if (tempList.Count == 0)
                {
                    FileFiltersSummary = "All files";
                }
                else
                {
                    FileFiltersSummary = string.Join(", ", tempList.ToArray());
                }
            }

            //Files found
            if (name == "FileOrFolderPath" || name == "SearchFor" || name == "FilePattern" || name == "FilePatternIgnore")
            {
                FilesFound = false;
            }

            //Change title
            if (name == "FileOrFolderPath" || name == "SearchFor")
            {
                if (string.IsNullOrWhiteSpace(FileOrFolderPath))
                {
                    WindowTitle = "dnGREP";
                }
                else
                {
                    WindowTitle = string.Format("{0} in \"{1}\" - dnGREP", (SearchFor == null ? "Empty" : SearchFor.Replace('\n', ' ').Replace('\r', ' ')), FileOrFolderPath);
                }
            }

            //Change validation
            if (name == "SearchFor" || name == "TypeOfSearch")
            {
                if (string.IsNullOrWhiteSpace(SearchFor))
                {
                    ValidationMessage = "";
                }
                else if (TypeOfSearch == SearchType.Regex)
                {
                    try
                    {
                        Regex regex = new Regex(SearchFor);
                        ValidationMessage = "Regex is OK!";
                    }
                    catch
                    {
                        ValidationMessage = "Regex is not valid!";
                    }
                }
                else if (TypeOfSearch == SearchType.XPath)
                {
                    try
                    {
                        nav = doc.CreateNavigator();
                        XPathExpression expr = nav.Compile(SearchFor);
                        ValidationMessage = "XPath is OK!";
                    }
                    catch
                    {
                        ValidationMessage = "XPath is not valid!";
                    }
                }
                else
                {
                    ValidationMessage = "";
                }
            }

            //Can search
            if (name == "FileOrFolderPath" || name == "CurrentGrepOperation" || name == "SearchFor" || name == "IsSaveInProgress")
            {
                if (Utils.IsPathValid(FileOrFolderPath) && CurrentGrepOperation == GrepOperation.None && !IsSaveInProgress &&
                    (!string.IsNullOrEmpty(SearchFor) || settings.Get <bool>(GrepSettings.Key.AllowSearchingForFileNamePattern)))
                {
                    CanSearch = true;
                }
                else
                {
                    CanSearch = false;
                }
                // Refresh buttons
                CommandManager.InvalidateRequerySuggested();
            }

            if (name == "CurrentGrepOperation" || name == "IsSaveInProgress")
            {
                if (searchResults.Count > 0 && !IsSaveInProgress)
                {
                    CanSearchInResults = true;
                }
                else
                {
                    CanSearchInResults = false;
                }
            }

            //searchResults
            searchResults.FolderPath = FileOrFolderPath;

            // btnReplace
            if (name == "FileOrFolderPath" || name == "FilesFound" || name == "CurrentGrepOperation" || name == "SearchFor" || name == "IsSaveInProgress")
            {
                if (Utils.IsPathValid(FileOrFolderPath) && FilesFound && CurrentGrepOperation == GrepOperation.None &&
                    !IsSaveInProgress && !string.IsNullOrEmpty(SearchFor))
                {
                    CanReplace = true;
                }
                else
                {
                    CanReplace = false;
                }
            }

            //btnCancel
            if (name == "CurrentGrepOperation")
            {
                if (CurrentGrepOperation != GrepOperation.None)
                {
                    CanCancel = true;
                }
                else
                {
                    CanCancel = false;
                }
            }

            //Search type specific options
            if (name == "TypeOfSearch")
            {
                if (TypeOfSearch == SearchType.XPath)
                {
                    IsCaseSensitiveEnabled = false;
                    IsMultilineEnabled     = false;
                    IsSinglelineEnabled    = false;
                    IsWholeWordEnabled     = false;
                    CaseSensitive          = false;
                    Multiline  = false;
                    Singleline = false;
                    WholeWord  = false;
                }
                else if (TypeOfSearch == SearchType.PlainText)
                {
                    IsCaseSensitiveEnabled = true;
                    IsMultilineEnabled     = true;
                    IsSinglelineEnabled    = false;
                    IsWholeWordEnabled     = true;
                    Singleline             = false;
                }
                else if (TypeOfSearch == SearchType.Soundex)
                {
                    IsMultilineEnabled     = true;
                    IsCaseSensitiveEnabled = false;
                    IsSinglelineEnabled    = false;
                    IsWholeWordEnabled     = true;
                    CaseSensitive          = false;
                    Singleline             = false;
                }
                else if (TypeOfSearch == SearchType.Regex)
                {
                    IsCaseSensitiveEnabled = true;
                    IsMultilineEnabled     = true;
                    IsSinglelineEnabled    = true;
                    IsWholeWordEnabled     = true;
                }
            }

            if (IsProperty(() => SearchFor, name) || IsProperty(() => ReplaceWith, name) || IsProperty(() => FilePattern, name))
            {
                if (BookmarkLibrary.Instance.Bookmarks.Contains(new Bookmark(SearchFor, ReplaceWith, FilePattern, "")))
                {
                    IsBookmarked = true;
                }
                else
                {
                    IsBookmarked = false;
                }
            }
        }
Example #3
0
        // Need to be implemented separately
        #endregion

        #region Public Methods
        public virtual void UpdateState(string name)
        {
            List <string> tempList = null;

            switch (name)
            {
            case "Initial":
            case "Multiline":
            case "Singleline":
            case "WholeWord":
            case "CaseSensitive":
            case "StopAfterFirstMatch":
                tempList = new List <string>();
                if (CaseSensitive)
                {
                    tempList.Add("Case sensitive");
                }
                if (Multiline)
                {
                    tempList.Add("Multiline");
                }
                if (WholeWord)
                {
                    tempList.Add("Whole word");
                }
                if (Singleline)
                {
                    tempList.Add("Dot as new line");
                }
                if (StopAfterFirstMatch)
                {
                    tempList.Add("Stop after first match");
                }
                OptionsSummary = "[";
                if (tempList.Count == 0)
                {
                    OptionsSummary += "None";
                }
                else
                {
                    for (int i = 0; i < tempList.Count; i++)
                    {
                        OptionsSummary += tempList[i];
                        if (i < tempList.Count - 1)
                        {
                            OptionsSummary += ", ";
                        }
                    }
                }
                OptionsSummary += "]";

                if (Multiline)
                {
                    TextBoxStyle = "{StaticResource ExpandedTextbox}";
                }
                else
                {
                    TextBoxStyle = "";
                }

                CanReplace = false;

                break;

            case "UseFileSizeFilter":
                if (UseFileSizeFilter == FileSizeFilter.Yes)
                {
                    IsSizeFilterSet = true;
                }
                else
                {
                    IsSizeFilterSet = false;
                }
                break;

            case "FileFilters":
                // Set all properties to correspond to ON value
                if (FileFilters)
                {
                    UseFileSizeFilter = FileSizeFilter.No;
                    IncludeBinary     = true;
                    IncludeHidden     = true;
                    IncludeSubfolder  = true;
                    FilePattern       = "*";
                    FilePatternIgnore = "";
                    TypeOfFileSearch  = FileSearchType.Asterisk;
                    CodePage          = -1;
                }
                break;
            }

            if (name == "FileFilters" || name == "FilePattern" || name == "IncludeSubfolder" ||
                name == "IncludeHidden" || name == "IncludeBinary" || name == "UseFileSizeFilter" ||
                name == "FilePatternIgnore")
            {
                if (FileFilters)
                {
                    FileFiltersSummary = "[All files]";
                }
                else
                {
                    tempList = new List <string>();
                    if (FilePattern != "*")
                    {
                        tempList.Add(FilePattern);
                    }
                    if (!IncludeSubfolder)
                    {
                        tempList.Add("No subfolders");
                    }
                    if (!IncludeHidden)
                    {
                        tempList.Add("No hidden");
                    }
                    if (!IncludeBinary)
                    {
                        tempList.Add("No binary");
                    }
                    if (!string.IsNullOrEmpty(FilePatternIgnore))
                    {
                        tempList.Add("Exclusions");
                    }
                    if (UseFileSizeFilter == FileSizeFilter.Yes)
                    {
                        tempList.Add("Size");
                    }
                    FileFiltersSummary = "[";
                    if (tempList.Count == 0)
                    {
                        FileFiltersSummary += "All files";
                    }
                    else
                    {
                        for (int i = 0; i < tempList.Count; i++)
                        {
                            FileFiltersSummary += tempList[i];
                            if (i < tempList.Count - 1)
                            {
                                FileFiltersSummary += ", ";
                            }
                        }
                    }

                    FileFiltersSummary += "]";
                }
            }

            //Files found
            if (name == "FileOrFolderPath" || name == "SearchFor" || name == "FilePattern" || name == "FilePatternIgnore")
            {
                FilesFound = false;
            }

            //Change title
            if (name == "FileOrFolderPath" || name == "SearchFor")
            {
                if (string.IsNullOrWhiteSpace(FileOrFolderPath))
                {
                    WindowTitle = "dnGREP";
                }
                else
                {
                    WindowTitle = string.Format("{0} in \"{1}\" - dnGREP", (SearchFor == null ? "Empty" : SearchFor.Replace('\n', ' ').Replace('\r', ' ')), FileOrFolderPath);
                }
            }

            //Change validation
            if (name == "SearchFor" || name == "TypeOfSearch")
            {
                if (string.IsNullOrWhiteSpace(SearchFor))
                {
                    ValidationMessage = "";
                }
                else if (TypeOfSearch == SearchType.Regex)
                {
                    try
                    {
                        Regex regex = new Regex(SearchFor);
                        ValidationMessage = "Regex is OK!";
                    }
                    catch
                    {
                        ValidationMessage = "Regex is not valid!";
                    }
                }
                else if (TypeOfSearch == SearchType.XPath)
                {
                    try
                    {
                        nav = doc.CreateNavigator();
                        XPathExpression expr = nav.Compile(SearchFor);
                        ValidationMessage = "XPath is OK!";
                    }
                    catch
                    {
                        ValidationMessage = "XPath is not valid!";
                    }
                }
                else
                {
                    ValidationMessage = "";
                }
            }

            //Can search
            if (name == "FileOrFolderPath" || name == "CurrentGrepOperation" || name == "SearchFor")
            {
                if (Utils.IsPathValid(FileOrFolderPath) && CurrentGrepOperation == GrepOperation.None &&
                    (!string.IsNullOrEmpty(SearchFor) || settings.Get <bool>(GrepSettings.Key.AllowSearchingForFileNamePattern)))
                {
                    CanSearch = true;
                }
                else
                {
                    CanSearch = false;
                }
                // Refersh buttons
                CommandManager.InvalidateRequerySuggested();
            }

            //Set all files if FileOrFolderPath is a file
            if (name == "FileOrFolderPath")
            {
                if (System.IO.File.Exists(FileOrFolderPath))
                {
                    FileFilters = true;
                }
            }

            //btnSearch.ShowAdvance
            if (name == "CurrentGrepOperation" || name == "Initial")
            {
                if (searchResults.Count > 0)
                {
                    //TODO
                    CanSearchInResults = true;
                    SearchButtonMode   = "Split";
                }
                else
                {
                    //TODO
                    CanSearchInResults = false;
                    SearchButtonMode   = "Button";
                }
            }

            //searchResults
            searchResults.FolderPath = FileOrFolderPath;

            // btnReplace
            if (name == "FileOrFolderPath" || name == "FilesFound" || name == "CurrentGrepOperation" || name == "SearchFor")
            {
                if (Utils.IsPathValid(FileOrFolderPath) && FilesFound && CurrentGrepOperation == GrepOperation.None &&
                    !string.IsNullOrEmpty(SearchFor))
                {
                    CanReplace = true;
                }
                else
                {
                    CanReplace = false;
                }
            }

            //btnCancel
            if (name == "CurrentGrepOperation")
            {
                if (CurrentGrepOperation != GrepOperation.None)
                {
                    CanCancel = true;
                }
                else
                {
                    CanCancel = false;
                }
            }

            //Search type specific options
            if (name == "TypeOfSearch")
            {
                if (TypeOfSearch == SearchType.XPath)
                {
                    IsCaseSensitiveEnabled = false;
                    IsMultilineEnabled     = false;
                    IsSinglelineEnabled    = false;
                    IsWholeWordEnabled     = false;
                    CaseSensitive          = false;
                    Multiline  = false;
                    Singleline = false;
                    WholeWord  = false;
                }
                else if (TypeOfSearch == SearchType.PlainText)
                {
                    IsCaseSensitiveEnabled = true;
                    IsMultilineEnabled     = true;
                    IsSinglelineEnabled    = false;
                    IsWholeWordEnabled     = true;
                    Singleline             = false;
                }
                else if (TypeOfSearch == SearchType.Soundex)
                {
                    IsMultilineEnabled     = true;
                    IsCaseSensitiveEnabled = false;
                    IsSinglelineEnabled    = false;
                    IsWholeWordEnabled     = true;
                    CaseSensitive          = false;
                    Singleline             = false;
                }
                else if (TypeOfSearch == SearchType.Regex)
                {
                    IsCaseSensitiveEnabled = true;
                    IsMultilineEnabled     = true;
                    IsSinglelineEnabled    = true;
                    IsWholeWordEnabled     = true;
                }
            }

            if (IsProperty(() => SearchFor, name) || IsProperty(() => ReplaceWith, name) || IsProperty(() => FilePattern, name))
            {
                if (BookmarkLibrary.Instance.Bookmarks.Contains(new Bookmark(SearchFor, ReplaceWith, FilePattern, "")))
                {
                    IsBookmarked = true;
                }
                else
                {
                    IsBookmarked = false;
                }
            }
        }