public void SetSelectedReferences(List <EntryAndPagePair> entryAndPagePairs)
        {
            Text = "Edit References...";

            rbSplitAuthor.Visible = false;

            btnChooseDatabase.Visible = false;

            SelectableReference firstReference = null;

            foreach (var entryAndPagePair in entryAndPagePairs)
            {
                var entry = allEntries.Find(reference => reference.ID == entryAndPagePair.EntryName);
                if (entry == null)
                {
                    continue;
                }

                entry.Selected = true;
                entry.Pages    = entryAndPagePair.PageNumberOverride;

                if (firstReference == null)
                {
                    firstReference = entry;

                    switch (entryAndPagePair.AuthorProcessorControl)
                    {
                    case AuthorProcessorControl.AuthorOnly:
                        rbAuthorOnly.Checked = true;
                        break;

                    case AuthorProcessorControl.SuppressAuthor:
                        rbAuthorSuppressAuthor.Checked = true;
                        break;

                    default:
                        rbAuthorStandard.Checked = true;
                        break;
                    }
                }
            }

            if (firstReference != null)
            {
                var firstIndex = bsSelectableReferences.IndexOf(firstReference);

                if (firstIndex != -1)
                {
                    bsSelectableReferences.Position = firstIndex;
                }
            }

            UpdateAddButton();
        }
        public bool IsMatch(SelectableReference reference)
        {
            // Quick return if year does not match
            if (!string.IsNullOrEmpty(yearFilter) && reference.Year != yearFilter)
            {
                return(false);
            }

            if (string.IsNullOrEmpty(textFilter))
            {
                return(true);
            }

            if (FilterType == FilterType.Exact)
            {
                return(IsTextMatch(reference, textFilter));
            }

            var textItems = textFilter.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            if (FilterType == FilterType.And)
            {
                foreach (var textItem in textItems)
                {
                    if (!IsTextMatch(reference, textItem))
                    {
                        return(false);
                    }
                }

                return(true);
            }

            foreach (var textItem in textItems)
            {
                if (IsTextMatch(reference, textItem))
                {
                    return(true);
                }
            }

            return(false);
        }
 static bool IsTextMatch(SelectableReference reference, string text)
 {
     return(reference.Title.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) != -1 ||
            reference.Authors.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) != -1 ||
            reference.ID.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) != -1);
 }
        public void Reset(BibTexDatabase database)
        {
            if (database == null)
            {
                database = new BibTexDatabase();
            }

            this.database = database;

            allEntries = new List <SelectableReference>(database.EntryCount);

            var yearList = new List <string>();

            foreach (var entry in database.Entries)
            {
                var selectableReference = new SelectableReference
                {
                    Selected  = false,
                    ID        = entry.Name,
                    Title     = entry["title", TagEntry.Empty].Display,
                    Authors   = entry["author", TagEntry.Empty].Display,
                    Year      = entry["year", TagEntry.Empty].Display,
                    Timestamp = entry["timestamp", TagEntry.Empty].Display,
                    Pages     = string.Empty
                };

                allEntries.Add(selectableReference);

                if (selectableReference.Year.Length == 4 && !yearList.Contains(selectableReference.Year))
                {
                    yearList.Add(selectableReference.Year);
                }
            }

            source = new BindingListAce <SelectableReference>(allEntries)
            {
                AllowNew    = false,
                AllowRemove = false
            };


            bsSelectableReferences.DataSource = source;

            grid.AutoResizeColumns();

            bsSelectableReferences.ListChanged +=
                (sender, args) =>
            {
                Debug.WriteLine("bsSelectableReferences.ListChanged.ListChanged " + args.ListChangedType);
                UpdateAddButton();
            };

            yearList.Sort();
            yearList.Insert(0, "(any)");
            cmbYear.Items.AddRange(yearList.ToArray());
            cmbYear.SelectedIndex = 0;

            UpdateFilter();

            btnChooseDatabase.Visible = Settings.Instance.AllowPerDocumentDatabases;
        }
		static bool IsTextMatch(SelectableReference reference, string text)
		{
			return reference.Title.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) != -1 ||
			       reference.Authors.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) != -1 ||
			       reference.ID.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) != -1;
		}
		public bool IsMatch(SelectableReference reference)
		{
			// Quick return if year does not match
			if (!string.IsNullOrEmpty(yearFilter) && reference.Year != yearFilter) return false;

			if (string.IsNullOrEmpty(textFilter)) return true;

			if (FilterType == FilterType.Exact)
			{
				return IsTextMatch(reference, textFilter);
			}

			var textItems = textFilter.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
			
			if (FilterType == FilterType.And)
			{
				foreach (var textItem in textItems)
				{
					if (!IsTextMatch(reference, textItem)) return false;
				}

				return true;
			}
			
			foreach (var textItem in textItems)
			{
				if (IsTextMatch(reference, textItem)) return true;
			}

			return false;
		}
		public void Reset(BibTexDatabase database)
		{
			if (database == null)
			{
				database = new BibTexDatabase();
			}

			this.database = database;

			allEntries = new List<SelectableReference>(database.EntryCount);

			var yearList = new List<string>();

			foreach(var entry in database.Entries)
			{
				var selectableReference = new SelectableReference
				                         	{
				                         		Selected = false,
												ID = entry.Name,
				                         		Title = entry["title", TagEntry.Empty].Display,
				                         		Authors = entry["author", TagEntry.Empty].Display,
				                         		Year = entry["year", TagEntry.Empty].Display,
				                         		Timestamp = entry["timestamp", TagEntry.Empty].Display,
												Pages = string.Empty
				                         	};

				allEntries.Add(selectableReference);

				if (selectableReference.Year.Length == 4 && !yearList.Contains(selectableReference.Year))
				{
					yearList.Add(selectableReference.Year);
				}
			}

			source = new BindingListAce<SelectableReference>(allEntries)
			             	{
			             		AllowNew = false,
			             		AllowRemove = false
			             	};


			bsSelectableReferences.DataSource = source;

			grid.AutoResizeColumns();

			bsSelectableReferences.ListChanged +=
				(sender, args) =>
					{
						Debug.WriteLine("bsSelectableReferences.ListChanged.ListChanged " + args.ListChangedType);
						UpdateAddButton();
					};

			yearList.Sort();
			yearList.Insert(0, "(any)");
			cmbYear.Items.AddRange(yearList.ToArray());
			cmbYear.SelectedIndex = 0;

			UpdateFilter();

			btnChooseDatabase.Visible = Settings.Instance.AllowPerDocumentDatabases;
		}