Example #1
0
        private void on_snoop(snoop_around_form self, ref bool keep_running)
        {
            var info = this.info(self);

            if (info.snoop_selection.Count > 0)
            {
                // in this case, user selected at least something,
                // and then applied the selection - thus, no re-snooping
                self.reuse_last_values();
                return;
            }

            // we cannot be visible if users doesn't have any rows
            int sel = view_.sel_row_idx;

            if (sel <= 0)
            {
                sel = 0;
            }
            if (info.snoop_sel >= 0)
            {
                if (Math.Abs(info.snoop_sel - sel) <= app.inst.reuse_snoop_surrounding)
                {
                    // we already snooped near by, reuse that
                    self.reuse_last_values();
                    return;
                }
            }

            // here, I know for sure I need to (re)snoop
            int  all = view_.item_count;
            bool snoop_all = all <= app.inst.snoop_all_if_entries_less_than;
            int  min = 0, max = all;

            if (!snoop_all)
            {
                var surrounding = util.surrounding(sel, app.inst.snoop_surrounding_entries, 0, all);
                min = surrounding.Item1;
                max = surrounding.Item2;
            }

            var type      = info_key(self);
            int snoop_idx = 0;
            Dictionary <string, int> values = new Dictionary <string, int>();
            // update
            int snoop_update_ui_step = (max - min) / app.inst.snoop_update_ui_times;

            for (int idx = min; idx < max; ++idx)
            {
                var i         = view_.item_at(idx) as filter.match;
                var cur_value = i.line.part(type);
                if (!values.ContainsKey(cur_value))
                {
                    values.Add(cur_value, 0);
                }
                ++values[cur_value];

                if (++snoop_idx % snoop_update_ui_step == 0)
                {
                    if (keep_running)
                    {
                        // ... set to a copy, since we're modifying this one
                        self.set_values(values.ToDictionary(x => x.Key, x => x.Value), false, false);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if (keep_running)
            {
                self.set_values(values, true, snoop_all);
                info.snoop_sel = sel;
            }
        }