This repository has been archived by the owner. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathFilterItem.cs
89 lines (75 loc) · 2.51 KB
/
FilterItem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using System.Collections.Generic;
using System.Text;
namespace GongSolutions.Shell
{
internal class FilterItem
{
public FilterItem(string caption, string filter)
{
Caption = caption;
Filter = filter;
}
public bool Contains(string filter)
{
string[] filters = Filter.Split(',');
foreach (string s in filters)
{
if (filter == s.Trim()) return true;
}
return false;
}
public override string ToString()
{
string filterString = string.Format(" ({0})", Filter);
if (Caption.EndsWith(filterString))
{
return Caption;
}
else
{
return Caption + filterString;
}
}
public static FilterItem[] ParseFilterString(string filterString)
{
int dummy;
return ParseFilterString(filterString, string.Empty, out dummy);
}
public static FilterItem[] ParseFilterString(string filterString,
string existing,
out int existingIndex)
{
List<FilterItem> result = new List<FilterItem>();
string[] items;
existingIndex = -1;
if (filterString != string.Empty)
{
items = filterString.Split('|');
}
else
{
items = new string[0];
}
if ((items.Length % 2) != 0)
{
throw new ArgumentException(
"Filter string you provided is not valid. The filter " +
"string must contain a description of the filter, " +
"followed by the vertical bar (|) and the filter pattern." +
"The strings for different filtering options must also be " +
"separated by the vertical bar. Example: " +
"\"Text files|*.txt|All files|*.*\"");
}
for (int n = 0; n < items.Length; n += 2)
{
FilterItem item = new FilterItem(items[n], items[n + 1]);
result.Add(item);
if (item.Filter == existing) existingIndex = result.Count - 1;
}
return result.ToArray();
}
public string Caption;
public string Filter;
}
}