コード例 #1
0
ファイル: CompareForm.cs プロジェクト: clayne/BSA_Browser
 private void txtSearch_TextChanged(object sender, EventArgs e)
 {
     LimitedAction.RunAfter(SearchLimitId, 500, () =>
     {
         this.FilterAndUpdateUI(tvDirectories.SelectedNode?.FullPath);
     });
 }
コード例 #2
0
ファイル: TextViewer.cs プロジェクト: clayne/BSA_Browser
 private void txtFind_TextChanged(object sender, EventArgs e)
 {
     LimitedAction.RunAfter(2, 500, delegate
     {
         if (string.IsNullOrEmpty(txtFind.Text))
         {
             this.ClearHighlighting();
         }
         else
         {
             this.HighlightText(txtFind.Text);
         }
     });
 }
コード例 #3
0
ファイル: CompareForm.cs プロジェクト: clayne/BSA_Browser
        private void Filter(string subFolder = "")
        {
            LimitedAction.Stop(SearchLimitId);

            this.FilteredFiles.Clear();
            txtSearch.ForeColor = SystemColors.WindowText;

            // Get selected types
            var types = GetFilteredTypes();

            Regex           regex   = null;
            WildcardPattern pattern = null;

            try
            {
                if (cbRegex.Checked && !string.IsNullOrEmpty(txtSearch.Text))
                {
                    regex = new Regex(txtSearch.Text, RegexOptions.Compiled | RegexOptions.Singleline);
                }
                else if (!cbRegex.Checked && !string.IsNullOrEmpty(txtSearch.Text))
                {
                    // Escape special characters, then unescape wild card characters again
                    string str = WildcardPattern.Escape(txtSearch.Text).Replace("`*", "*");
                    pattern = new WildcardPattern($"*{str}*", WildcardOptions.Compiled | WildcardOptions.IgnoreCase);
                }
            }
            catch
            {
                // Set text color to red to indicate an error with the search pattern
                txtSearch.ForeColor = Color.Red;
                return;
            }

            foreach (var file in Files)
            {
                // Filter by selected folder, if any
                if (!string.IsNullOrEmpty(subFolder))
                {
                    if (!file.FullPath.StartsWith(subFolder, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                }

                // Filter by type
                if (!types.Contains(file.Type))
                {
                    continue;
                }

                // Filter by search
                if (!string.IsNullOrEmpty(txtSearch.Text))
                {
                    if (cbRegex.Checked
                        ? !regex.IsMatch(file.FullPath)
                        : !pattern.IsMatch(file.FullPath))
                    {
                        continue;
                    }
                }

                this.FilteredFiles.Add(file);
            }
        }