Skip to content

Commit

Permalink
Filter automatically created groups by entrytype (JabRef#4539)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shubham Atlani committed Dec 27, 2018
1 parent 75b147e commit 2fa906b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We updated updated the Related Articles tab to accept JSON from the new version of the Mr. DLib service
- We added an option in the preference dialog box that allows user to choose behavior after dragging and dropping files in Entry Editor. [#4356](https://github.com/JabRef/jabref/issues/4356)
- We added the ability to have an export preference where previously "File"-->"Export"/"Export selected entries" would not save the user's preference[#4495](https://github.com/JabRef/jabref/issues/4495)

- For automatically created groups, added ability to filter groups by entry type. [#4539](https://github.com/JabRef/jabref/issues/4539)



Expand Down
11 changes: 10 additions & 1 deletion src/main/java/org/jabref/model/entry/BibEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ private void invalidateFieldCache(String fieldName) {
}

public Optional<String> getLatexFreeField(String name) {
if (!hasField(name)) {
if (!hasField(name) && !TYPE_HEADER.equals(name)) {
return Optional.empty();
} else if (latexFreeFields.containsKey(name)) {
return Optional.ofNullable(latexFreeFields.get(toLowerCase(name)));
Expand All @@ -812,6 +812,15 @@ public Optional<String> getLatexFreeField(String name) {
Optional<String> citeKey = getCiteKeyOptional();
latexFreeFields.put(name, citeKey.get());
return citeKey;
} else if (TYPE_HEADER.equals(name)) {
Optional<EntryType> entryType = EntryTypes.getType(getType(), BibDatabaseMode.BIBLATEX);
if (entryType.isPresent()) {
String entryName = entryType.get().getName();
latexFreeFields.put(name, entryName);
return Optional.of(entryName);
} else {
return Optional.empty();
}
} else {
String latexFreeField = LatexToUnicodeAdapter.format(getField(name).get()).intern();
latexFreeFields.put(name, latexFreeField);
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/org/jabref/model/groups/WordKeywordGroup.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package org.jabref.model.groups;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;

import org.jabref.model.EntryTypes;
import org.jabref.model.FieldChange;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.EntryType;
import org.jabref.model.entry.KeywordList;
import org.jabref.model.strings.StringUtil;

Expand Down Expand Up @@ -113,6 +118,14 @@ public boolean contains(BibEntry entry) {

private Set<String> getFieldContentAsWords(BibEntry entry) {
if (onlySplitWordsAtSeparator) {
if (BibEntry.TYPE_HEADER.equals(searchField)) {
for (String searchWord : searchWords) {
Optional<EntryType> entryType = EntryTypes.getType(entry.getType(), BibDatabaseMode.BIBLATEX);
if (entryType.isPresent() && entryType.get().getName().equals(searchWord)) {
return new HashSet<>(Arrays.asList(searchWord));
}
}
}
return entry.getField(searchField)
.map(content -> KeywordList.parse(content, keywordSeparator).toStringList())
.orElse(Collections.emptySet());
Expand Down

0 comments on commit 2fa906b

Please sign in to comment.