Exemplo n.º 1
0
        public static List <IFilter> GetPositiveFilters(this IFiltersList filters)
        {
            var positiveFilters = filters.Items.Where(f => f.Enabled && f.Action != FilterAction.Exclude).ToList();

            if (filters.GetDefaultAction() != FilterAction.Exclude)
            {
                positiveFilters.Add(null);
            }
            return(positiveFilters);
        }
Exemplo n.º 2
0
        void IPresenter.UpdateView()
        {
            updateLock++;
            view.BeginUpdate();
            try
            {
                IFiltersList filters       = filtersList;
                IViewItem    defActionItem = null;
                for (int i = view.Count - 1; i >= 0; --i)
                {
                    IFilter ls = view.GetItem(i).Filter;
                    if (ls == null)
                    {
                        defActionItem = view.GetItem(i);
                    }
                    else if (ls.Owner == null)
                    {
                        view.RemoveAt(i);
                    }
                }
                int filterIdx = 0;
                foreach (var f in filters.Items)
                {
                    IViewItem lvi;
                    int       existingItemIdx = view.GetItemIndexByKey(f.GetHashCode().ToString());
                    if (existingItemIdx < 0)
                    {
                        lvi = view.CreateItem(f, f.GetHashCode().ToString());
                        view.Insert(filterIdx, lvi);
                    }
                    else
                    {
                        lvi = view.GetItem(existingItemIdx);
                        if (existingItemIdx != filterIdx)
                        {
                            view.RemoveAt(existingItemIdx);
                            view.Insert(filterIdx, lvi);
                        }
                    }
                    ++filterIdx;

                    if (!f.IsDisposed)
                    {
                        lvi.Text    = f.Name;
                        lvi.Color   = f.Action.ToColor(highlightColorsTable.Items);
                        lvi.Checked = f.Enabled;
                        if (f.Enabled)
                        {
                            lvi.CheckboxTooltip = "Uncheck to disable rule without deleting it";
                        }
                        else
                        {
                            lvi.CheckboxTooltip = "Check to enable rule";
                        }
                        lvi.SetImageType(f.Action == FilterAction.Exclude ? ViewItemImageType.Exclude : ViewItemImageType.Include);
                        if (filtersList.Purpose == FiltersListPurpose.Highlighting)
                        {
                            if (f.Action == FilterAction.Exclude)
                            {
                                lvi.ActionTooltip = "Rule excludes matched messages from highlighting";
                            }
                            else
                            {
                                lvi.ActionTooltip = string.Format(
                                    "Rule highlights matched messages with color #{0}",
                                    f.Action - FilterAction.IncludeAndColorizeFirst + 1);
                            }
                        }
                        else if (filtersList.Purpose == FiltersListPurpose.Search)
                        {
                            if (f.Action == FilterAction.Exclude)
                            {
                                lvi.ActionTooltip = "Rule excludes matched messages from search results";
                            }
                            else
                            {
                                lvi.ActionTooltip = string.Format(
                                    "Rule includes matched messages to search results" +
                                    (f.Action == FilterAction.Include
                                                                         ? "" : " and highlights them with color #{0}"),
                                    f.Action - FilterAction.IncludeAndColorizeFirst + 1);
                            }
                        }
                    }
                    else
                    {
                        lvi.Text            = "-";
                        lvi.Checked         = null;
                        lvi.CheckboxTooltip = "";
                        lvi.Color           = null;
                        lvi.SetImageType(ViewItemImageType.None);
                    }
                }

                if (filters.Items.Count == 0)
                {
                    if (defActionItem != null)
                    {
                        view.Remove(defActionItem);
                    }
                }
                else
                {
                    if (defActionItem == null)
                    {
                        defActionItem = view.CreateItem(null, "");
                        view.Insert(filterIdx, defActionItem);
                        defActionItem.Checked = null;
                    }
                    if (filters.GetDefaultAction() == FilterAction.Exclude)
                    {
                        if (filtersList.Purpose == FiltersListPurpose.Highlighting)
                        {
                            defActionItem.Text = "Don't hightlight by-default";
                        }
                        else if (filtersList.Purpose == FiltersListPurpose.Search)
                        {
                            defActionItem.Text = "Exclude from search results by-default";
                        }
                        else
                        {
                            defActionItem.Text = "Exclude all by-default";
                        }
                        defActionItem.SetImageType(ViewItemImageType.Exclude);
                    }
                    else
                    {
                        if (filtersList.Purpose == FiltersListPurpose.Highlighting)
                        {
                            defActionItem.Text = "Highlight all by-default";
                        }
                        else if (filtersList.Purpose == FiltersListPurpose.Search)
                        {
                            defActionItem.Text = "Include all to search results by-default";
                        }
                        else
                        {
                            defActionItem.Text = "Include all by-default";
                        }
                        defActionItem.SetImageType(ViewItemImageType.Include);
                    }
                }

                view.SetEnabled(filters.FilteringEnabled);
            }
            finally
            {
                updateLock--;
                view.EndUpdate();
            }
        }