Skip to content

Commit

Permalink
Automatically created groups with Field to group by as entrytype (#4539
Browse files Browse the repository at this point in the history
…) (#4555)

* Filter automatically created groups by entrytype (#4539)

* Address review comments - replace for loop with stream (#4539)

* return value in case of unknown entry type (#4539)
  • Loading branch information
shubhamatlani authored and tobiasdiez committed Feb 9, 2019
1 parent 71e0237 commit 8e7b1f9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +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)
- We added the ability to add field names from the Preferences Dialog [#4546](https://github.com/JabRef/jabref/issues/4546)
- We added the ability change the column widths directly in the main table. [#4546](https://github.com/JabRef/jabref/issues/4546)
- We added the ability to execute default action in dialog by using with <kbd>Ctrl</kbd> + <kbd>Enter</kbd> combination [#4496](https://github.com/JabRef/jabref/issues/4496)
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 @@ -792,7 +792,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 @@ -801,6 +801,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.of(StringUtil.capitalizeFirst(getType()));
}
} else {
String latexFreeField = LatexToUnicodeAdapter.format(getField(name).get()).intern();
latexFreeFields.put(name, latexFreeField);
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/jabref/model/groups/WordKeywordGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

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,12 @@ public boolean contains(BibEntry entry) {

private Set<String> getFieldContentAsWords(BibEntry entry) {
if (onlySplitWordsAtSeparator) {
if (BibEntry.TYPE_HEADER.equals(searchField)) {
Optional<EntryType> entryType = EntryTypes.getType(entry.getType(), BibDatabaseMode.BIBLATEX);
if (entryType.isPresent()) {
return searchWords.stream().filter(sw -> entryType.get().getName().equals(sw)).collect(Collectors.toSet());
}
}
return entry.getField(searchField)
.map(content -> KeywordList.parse(content, keywordSeparator).toStringList())
.orElse(Collections.emptySet());
Expand Down

0 comments on commit 8e7b1f9

Please sign in to comment.