forked from thedeemon/gep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SearchFilterForm.cs
138 lines (122 loc) · 4.78 KB
/
SearchFilterForm.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace gep
{
public partial class SearchFilterForm : Form
{
private SearchFilterForm(IEnumerable<string> cats, bool allcats, string namepart, string current_cat)
{
all_categories = allcats;
categories = cats;
name_part = namepart;
current_category = current_cat;
InitializeComponent();
filtertree.Sorted = true;
}
private static SearchFilterForm form;
public static void ShowSearchFilterForm(IEnumerable<string> cats, bool allcats, string namepart, string current_cat, Form mdiparent)
{
if (form == null)
{
form = new SearchFilterForm(cats, allcats, namepart, current_cat);
form.MdiParent = mdiparent;
form.Show();
}
else
form.BringToFront();
}
bool all_categories;
IEnumerable<string> categories;
string name_part;
string current_category;
private void OnLoad(object sender, EventArgs e)
{
ToolTip toolTip = new ToolTip();
toolTip.AutoPopDelay = 5000;
toolTip.InitialDelay = 500;
toolTip.ReshowDelay = 500;
toolTip.ShowAlways = true;
toolTip.SetToolTip(catcombo, "Filter category to search in");
toolTip.SetToolTip(textBoxName, "Substring to be found in filter's friendly name");
toolTip.SetToolTip(textBoxDispName, "Substring to be found in filter's display name");
toolTip.SetToolTip(textBoxCLSID, "Part of filter's CLSID");
toolTip.SetToolTip(textBoxPathName, "Part of filter's file name or path");
toolTip.SetToolTip(filtertree, "Double click or drag a filter to add it to current graph");
catcombo.Items.Add("All categories");
foreach(string catname in categories)
catcombo.Items.Add(catname);
if (all_categories)
catcombo.SelectedIndex = 0;
else
foreach(object item in catcombo.Items)
if (item.ToString() == current_category)
{
catcombo.SelectedItem = item;
break;
}
textBoxName.Text = name_part;
textBoxName.Focus();
}
List<FilterProps> filters;
private void OnCategoryChanged(object sender, EventArgs e)
{
if (catcombo.SelectedIndex == 0)
filters = Filterz.GetAllFilters();
else
filters = Filterz.GetFiltersOfCategory(catcombo.SelectedItem.ToString());
ShowFoundFilters();
}
static bool match(string str, string substr)
{
if (str == null) return false;
return str.ToLowerInvariant().Contains(substr);
}
IEnumerable<FilterProps> SearchFilters(IEnumerable<FilterProps> flist)
{
string namepart = textBoxName.Text.ToLowerInvariant();
string dispname = textBoxDispName.Text.ToLowerInvariant();
string clsdpart = textBoxCLSID.Text.ToLowerInvariant();
string pathpart = textBoxPathName.Text.ToLowerInvariant();
foreach (FilterProps fp in flist)
if (match(fp.Name, namepart) && match(fp.DisplayName, dispname) &&
match(fp.CLSID, clsdpart) && match(fp.GetFileName(), pathpart))
yield return fp;
}
void ShowFoundFilters()
{
Filterz.FillFilterTree(filtertree, SearchFilters(filters));
}
private void OnTextChanged(object sender, EventArgs e)
{
ShowFoundFilters();
}
private void OnDblClick(object sender, MouseEventArgs e)
{
TreeNode nd = filtertree.SelectedNode;
if (nd == null)
return;
while (nd.Parent != null && nd.Tag == null)
nd = nd.Parent;
FilterProps fp = (FilterProps)nd.Tag;
if (fp != null)
{
GraphForm gf = Program.mainform.ActiveGraphForm;
if (gf != null)
gf.AddFilter(fp);
}
}
private void OnClose(object sender, FormClosedEventArgs e)
{
form = null;
}
private void OnItemDrag(object sender, ItemDragEventArgs e)
{
DoDragDrop(e.Item, DragDropEffects.Copy);
}
}
}