public void AddFilterItem(string name, string tag, int pid, string text, string package,
                                  LogcatItem.Level level, bool isNew)
        {
            string       xaml_item    = XamlWriter.Save(FilterTemplateItem);
            StringReader stringReader = new StringReader(xaml_item);
            XmlReader    xmlReader    = XmlReader.Create(stringReader);
            CheckBox     newCheckbox  = (CheckBox)XamlReader.Load(xmlReader);
            TextBlock    tb           = new TextBlock();

            tb.Text             = name;
            tb.Foreground       = Brushes.MediumSeaGreen;
            newCheckbox.Name    = name;
            newCheckbox.Content = tb; //name;

            newCheckbox.Visibility = Visibility.Visible;
            (newCheckbox.ContextMenu.Items[0] as MenuItem).Command = DeleteFilter;
            (newCheckbox.ContextMenu.Items[1] as MenuItem).Command = EditFilter;
            newCheckbox.Click      += new RoutedEventHandler(FilterTemplate_Clicked);
            newCheckbox.DataContext = new LogFilterData()
            {
                FilterName     = name,
                TokenByLevel   = level,
                TokenByPid     = pid,
                TokenByTag     = tag,
                TokenByText    = text,
                TokenByPackage = package
            };
            FilterListBox.Items.Add(newCheckbox);

            if (isNew)
            {
                CreateFilterStoreData(name, tag, pid, text, package, level);
            }
        }
        public void ChangeFilterItem(CheckBox chk_box, string tag, int pid, string text, string package,
                                     LogcatItem.Level level)
        {
            LogFilterData filter_data = chk_box.DataContext as LogFilterData;

            filter_data.TokenByTag     = tag;
            filter_data.TokenByPid     = pid;
            filter_data.TokenByText    = text;
            filter_data.TokenByPackage = package;
            filter_data.TokenByLevel   = level;

            CreateFilterStoreData(chk_box.Name, tag, pid, text, package, level);
        }
        public void CreateFilterStoreData(string name, string tag, int pid, string text, string package,
                                          LogcatItem.Level level)
        {
            SettingsManager       settingsManager            = new ShellSettingsManager(LogcatOutputToolWindowCommand.Instance.ServiceProvider);
            WritableSettingsStore configurationSettingsStore = settingsManager.GetWritableSettingsStore(SettingsScope.UserSettings);

            configurationSettingsStore.CreateCollection(LogcatOutputToolWindowControl.StoreFilterCollectionName);
            string filter_sub_collection = LogcatOutputToolWindowControl.StoreFilterCollectionName
                                           + "\\" + name;

            configurationSettingsStore.CreateCollection(filter_sub_collection);
            configurationSettingsStore.SetString(filter_sub_collection,
                                                 LogcatOutputToolWindowControl.StorePropertyFilterTagName, tag);
            configurationSettingsStore.SetInt32(filter_sub_collection,
                                                LogcatOutputToolWindowControl.StorePropertyFilterPidName, pid);
            configurationSettingsStore.SetString(filter_sub_collection,
                                                 LogcatOutputToolWindowControl.StorePropertyFilterMsgName, text);
            configurationSettingsStore.SetString(filter_sub_collection,
                                                 LogcatOutputToolWindowControl.StorePropertyFilterPackageName, package);
            configurationSettingsStore.SetInt32(filter_sub_collection,
                                                LogcatOutputToolWindowControl.StorePropertyFilterLevelName, (int)level);
        }
        void OnLogcatOutput(LogcatItem.Level level_token, string time_token, int pid_token,
                            string tag_token, string msg_token, string raw_msg)
        {
            LogcatItem logcat_item = new LogcatItem()
            {
                LevelToken = level_token,
                TimeToken  = time_token,
                PidToken   = pid_token,
                TagToken   = tag_token,
                TextToken  = msg_token,
                RawContent = raw_msg
            };

            Dispatcher.InvokeAsync(() =>
            {
                LogsToView.Add(logcat_item);
                if (LogsToView.Count > LogLimitCount)
                {
                    LogsToView.RemoveAt(0);
                }
            });

            /*lock (DeferredLogs)
             * {
             *  DeferredLogs.Add(new LogcatItem()
             *  {
             *      LevelToken = level_token,
             *      TimeToken = time_token,
             *      PidToken = pid_token,
             *      TagToken = tag_token,
             *      TextToken = msg_token
             *  });
             * }
             * if (DeferredLogs.Count < 1) return;
             * List<LogcatItem> collectLogs;
             * lock (DeferredLogs)
             * {
             *  collectLogs = new List<LogcatItem>(DeferredLogs);
             *  DeferredLogs.Clear();
             * }
             * Dispatcher.InvokeAsync(() =>
             * {
             *  foreach (var log_item in collectLogs)
             *  {
             *      LogsToView.Add(log_item);
             *  }
             * });
             *  /*bool needRefresh = false;
             *  foreach (LogcatItem log_item in collectLogs)
             *  {
             *      if (LogcatList.Items.Count > LogLimitCount)
             *      {
             *          LogcatList.Items.RemoveAt(0);
             *      }
             *      LogcatList.Items.Add(log_item);
             *      if (LogcatList.Items.Filter != null)
             *      {
             *          if (!LogcatList.Items.Filter(log_item))
             *          {
             *              needRefresh = true;
             *          }
             *      }
             *  }
             *  if (needRefresh) LogcatList.Items.Refresh();*/
            /*if ((IsAutoScroll) && (LogcatList.Items.Count > 0))
             * {
             *  LogcatList.SelectedIndex = LogcatList.Items.Count - 1;
             *  LogcatList.ScrollIntoView(LogcatList.SelectedItem);
             * }
             * /*if (LogcatList.Items.Count > LogLimitCount)
             * {
             *  LogcatList.Items.RemoveAt(0);
             * }
             * LogcatItem log_item = new LogcatItem()
             * {
             *  LevelToken = level_token,
             *  TimeToken = time_token,
             *  PidToken = pid_token,
             *  TagToken = tag_token,
             *  TextToken = msg_token
             * };
             * LogcatList.Items.Add(log_item);
             * if (LogcatList.Items.Filter != null)
             * {
             *  if (!LogcatList.Items.Filter(log_item))
             *  {
             *      LogcatList.Items.Refresh();
             *  }
             * }*/
            //LogcatList.Items.Refresh();
            //});
        }