private void LoadTags() { var allTags = _notebook.AllTags.ToList(); var liTags = NotebookTagControls.ToList(); foreach (var tag in allTags) { var liTag = liTags.FirstOrDefault(c => ((string)c.Tag) == tag); if (liTag == null) { liTag = new ListBoxItem() { Tag = tag, Style = (Style)Application.Current.FindResource("NbTagStyle"), Content = tag }; ConfigureTabCheckbox(liTag); lbTags.Items.Add(liTag); } } foreach (var liTag in liTags) { if (!allTags.Any(t => t == ((string)liTag.Tag))) { lbTags.Items.Remove(liTag); } } }
private Func <INote, bool> CreateNoteFilter() { var filterPattern = txtFilterNotes.Text ?? txtFilterNotes.Text.Trim(); var tags = NotebookTagControls.Where(c => c.IsSelected).Select(c => (string)c.Tag).ToList(); List <Func <INote, bool> > filterChain = new List <Func <INote, bool> >(); if (!liAll.IsSelected) { if (tags.Count > 0) { filterChain.Add(note => tags.All(t => note.Tags.Contains(t))); } if (liTodo.IsSelected) { filterChain.Add(note => note.Content.Contains("[]")); } } if (filterPattern != null) { filterChain.Add(note => Regex.IsMatch(note.Title, filterPattern, RegexOptions.IgnoreCase) || Regex.IsMatch(note.Content, filterPattern, RegexOptions.IgnoreCase)); } return(new Func <INote, bool>(note => { return filterChain.All(f => f(note)); })); }
private void OnNotebookSet() { _loading = true; try { foreach (var liTag in NotebookTagControls.ToList()) { lbTags.Items.Remove(liTag); } liAll.IsSelected = true; pnlNotes.Children.Clear(); if (_notebook == null) { return; } _notebook.TagAdded += notebook_TagAdded; _notebook.TagRemoved += notebook_TagRemoved; _notebook.NoteAdded += notebook_NoteAdded; _notebook.NoteRemoved += notebook_NoteRemoved; LoadTags(); LoadLastTags(); LoadNotes(); } finally { _loading = false; } }