public void Insert(string Keyword) { if (KeywordItems.Count > 0) { bool exist = false; foreach (KeywordItem item in KeywordItems) { if (item.Equals(Keyword)) { item.Usage++; exist = true; } } if (!exist) { if (Count < MAX_COUNT) { KeywordItems.Add(new KeywordItem(Keyword, 0)); Count++; } else { Remove(GetLastItem()); KeywordItems.Add(new KeywordItem(Keyword, 0)); Count++; } } } else { KeywordItems.Add(new KeywordItem(Keyword, 0)); Count++; } }
public void Remove(KeywordItem ki) { if (ki == null) { return; } KeywordItems.Remove(ki); this.mKeywordRecent.Remove(ki.Keyword); Count--; }
public void Compile(string source) { Output.Clear(); ConstantItems.Clear(); StandartItems.Clear(); KeywordItems.Clear(); var bw = new BackgroundWorker(); bw.DoWork += (sender, args) => { var parser = new Parser(); Application.Current.Dispatcher.BeginInvoke(new Action(() => { Output.Add("# ---start to parse code---"); })); parser.Start(source); Application.Current.Dispatcher.BeginInvoke(new Action(() => { KeywordItems = parser.GlobalIndexList.Where(e => e.IsKeyword && !e.IsConstant).ToList(); })); Application.Current.Dispatcher.BeginInvoke(new Action(() => { IdentificatorsItems = parser.GlobalIndexList.Where(e => !e.IsKeyword && !e.IsConstant).ToList(); })); Application.Current.Dispatcher.BeginInvoke(new Action(() => { ConstantItems = parser.GlobalIndexList.Where(e => e.IsConstant).ToList(); })); Application.Current.Dispatcher.BeginInvoke(new Action(() => { StandartItems = parser.GlobalIndexList.Where(e => !e.IsConstant).ToList(); })); }; bw.RunWorkerCompleted += (sender, args) => { Output.Add("# ---finish to parse code---"); if (args.Error != null) { MessageBox.Show(args.Error.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }; bw.RunWorkerAsync(); }