private void ParseExpression()
{
ExpressionEvaluator evaluator = new ExpressionEvaluator();
evaluator.Filters = fileFilter;
fileFilter.ExpressionTree = evaluator.EvaluateExpression(ExpressionText.Text);
InvalidLabel.Visible = fileFilter.ExpressionTree == null && ExpressionText.Text.Trim() != string.Empty;
// get the _filter names and update the color
FilterName[] filterNames = GetFilerNames();
UpdateTextColor(filterNames);
// get current word
string word;
int start;
int end;
List<FilterName> suggestions = new List<FilterName>();
if(GetCurrentWord(out word, out start, out end)) {
// match the word with the _filter names
int length = filterNames.Length;
for(int i = 0; i < length; i++) {
if(filterNames[i].Name == word) {
suggestions.Clear();
break;
}
if(filterNames[i].Name.ToLower().Contains(word.ToLower())) {
// add the _filter name
suggestions.Add(filterNames[i]);
}
}
// match it with the logical operators
if(ExpressionEvaluator.AndImplication.ToLower().StartsWith(word.ToLower())) {
suggestions.Add(new FilterName(ExpressionEvaluator.AndImplication, true, ExpressionType.Implication));
}
if(ExpressionEvaluator.OrImplication.ToLower().StartsWith(word.ToLower())) {
suggestions.Add(new FilterName(ExpressionEvaluator.OrImplication, true, ExpressionType.Implication));
}
}
if(suggestions.Count > 0) {
// show dialog if not already visible
if(completitionDialog == null) {
completitionDialog = new CompletitionDialog();
}
// place the dialog
Point p;
Rectangle r;
if(completitionDialog.Visible) {
p = ExpressionText.GetPositionFromCharIndex(start);
r = ExpressionText.RectangleToScreen(new Rectangle(p.X, p.Y - 2, 10, 10));
}
else {
p = ExpressionText.GetPositionFromCharIndex(start);
r = ExpressionText.RectangleToScreen(new Rectangle(p.X, p.Y - 2, 10, 10));
}
// set suggestions and show
completitionDialog.ParentControl = ExpressionText;
completitionDialog.ParentBox = this;
completitionDialog.Suggestions = suggestions;
completitionDialog.Show();
completitionDialog.Left = r.X;
completitionDialog.Top = r.Y - completitionDialog.Height;
// move focus back on edit box
ExpressionText.Focus();
}
else {
if(completitionDialog != null) {
completitionDialog.Hide();
}
}
}