Example #1
0
        private void on_apply(snoop_around_form self, List <string> selection, bool used)
        {
            var  new_sel    = new HashSet <string>(selection);
            var  info       = this.info(self);
            bool same_snoop = info.snoop_selection.SetEquals(new_sel);

            if (same_snoop && info.selection_used == used)
            {
                return; // nothing changed
            }
            if (same_snoop && selection.Count == 0)
            {
                // nothing is selected, it doesn't matter
                return;
            }

            lock (this) {
                info.selection_used  = used;
                info.snoop_selection = new_sel;

                if (!same_snoop)
                {
                    bool has_sel = new_sel.Count > 0;
                    if (info.apply_index >= 0)
                    {
                        // all snoops with a higher index, are cleared (the selection changed, thus, they need to be re-done)
                        foreach (var snoop in snoops_.Values)
                        {
                            if (snoop.apply_index > info.apply_index)
                            {
                                snoop.clear();
                            }
                        }
                    }

                    if (!has_sel)
                    {
                        // user cleared this snoop
                        info.clear();
                    }

                    if (has_sel && info.apply_index < 0)
                    {
                        // need to find out the apply_index
                        int max_apply = snoops_.Values.Max(x => x.apply_index);
                        info.apply_index = max_apply + 1;
                    }

                    // all snoops that did not have a selection yet, they need re-doing
                    foreach (var snoop in snoops_.Values)
                    {
                        if (snoop.apply_index < 0)
                        {
                            snoop.clear();
                        }
                    }
                }
            }
            view_.reapply_quick_filter();
        }