Пример #1
0
        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();
                }
            }
        }
Пример #2
0
        private void LoadFilters()
        {
            loading = true;
            FilterHost.SuspendLayout();
            filterViews.Clear();
            FilterHost.Controls.Clear();

            if(fileFilter == null) {
                FilterHost.ResumeLayout();
                return;
            }

            int count = fileFilter.FilterCount;
            for(int i = 0; i < count; i++) {
                FilterBase filter = fileFilter.GetFilter(i);

                if(filter is SizeFilter) {
                    AddSizeFilter(filter as SizeFilter, false);
                }
                else if(filter is DateFilter) {
                    AddDateFilter(filter as DateFilter, false);
                }
                else if(filter is AttributeFilter) {
                    AddAttributeFilter(filter as AttributeFilter, false);
                }
                else if(filter is ImageFilter) {
                    AddImageFilter(filter as ImageFilter, false);
                }
                else {
                    Debug.ReportWarning("Unsupported file Filter. Type: {0}", filter.GetType().FullName);
                }
            }

            LayoutFilterViews();
            FilterHost.ResumeLayout();

            if(fileFilter.ExpressionTree != null) {
                ExpressionEvaluator evaluator = new ExpressionEvaluator();
                ExpressionText.Text = evaluator.GetExpressionTreeString(fileFilter.ExpressionTree);
                AdvancedButton.Checked = true;
                splitContainer1.Panel2Collapsed = false;
                ExpressionText.Height = splitContainer1.Panel2.Height;
                UpdateTextColor(GetFilerNames());
            }

            loading = false;
        }