-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
single line text fields #4138
Merged
Merged
single line text fields #4138
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4c44087
force author, title and year text areas to be single line text field …
Naitoreivun 24e2183
consider 'institution' as a field, that should contain only one line
Naitoreivun d426291
create EditorTextField and use that control for author, institution, …
Naitoreivun 9223dfe
Merge branch 'master' into fix-for-issue-4126
Naitoreivun 1bb4754
Merge branch 'fix-for-issue-4126'
Naitoreivun 26475f6
pass JournalAbbrevRepo instead of Loader and Prefs
Naitoreivun 218ad5c
Merge remote-tracking branch 'upstream/master'
Naitoreivun ac10593
code review fixes
Naitoreivun 481007b
Merge branch 'master' into fix-for-issue-4126
Naitoreivun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/org/jabref/gui/fieldeditors/ContextMenuAddable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.jabref.gui.fieldeditors; | ||
|
||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
import javafx.scene.control.MenuItem; | ||
|
||
public interface ContextMenuAddable { | ||
/** | ||
* Adds the given list of menu items to the context menu. The usage of {@link Supplier} prevents that the menus need | ||
* to be instantiated at this point. They are populated when the user needs them which prevents many unnecessary | ||
* allocations when the main table is just scrolled with the entry editor open. | ||
*/ | ||
void addToContextMenu(final Supplier<List<MenuItem>> items); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/main/java/org/jabref/gui/fieldeditors/EditorTextField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package org.jabref.gui.fieldeditors; | ||
|
||
import java.net.URL; | ||
import java.util.List; | ||
import java.util.ResourceBundle; | ||
import java.util.function.Supplier; | ||
|
||
import javafx.fxml.Initializable; | ||
import javafx.scene.control.ContextMenu; | ||
import javafx.scene.control.MenuItem; | ||
import javafx.scene.input.KeyCode; | ||
import javafx.scene.input.KeyEvent; | ||
|
||
import com.sun.javafx.scene.control.skin.TextFieldSkin; | ||
|
||
public class EditorTextField extends javafx.scene.control.TextField implements Initializable, ContextMenuAddable { | ||
|
||
public EditorTextField() { | ||
this(""); | ||
} | ||
|
||
public EditorTextField(final String text) { | ||
super(text); | ||
|
||
setMinHeight(1); | ||
setMinWidth(200); | ||
|
||
// Should behave as a normal text field with respect to TAB behaviour | ||
addEventFilter(KeyEvent.KEY_PRESSED, event -> { | ||
if (event.getCode() == KeyCode.TAB) { | ||
TextFieldSkin skin = (TextFieldSkin) getSkin(); | ||
if (event.isShiftDown()) { | ||
// Shift + Tab > previous text area | ||
skin.getBehavior().traversePrevious(); | ||
} else { | ||
if (event.isControlDown()) { | ||
// Ctrl + Tab > insert tab | ||
skin.getBehavior().callAction("InsertTab"); | ||
} else { | ||
// Tab > next text area | ||
skin.getBehavior().traverseNext(); | ||
} | ||
} | ||
event.consume(); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void addToContextMenu(final Supplier<List<MenuItem>> items) { | ||
TextFieldSkin customContextSkin = new TextFieldSkin(this) { | ||
@Override | ||
public void populateContextMenu(ContextMenu contextMenu) { | ||
super.populateContextMenu(contextMenu); | ||
contextMenu.getItems().addAll(0, items.get()); | ||
} | ||
}; | ||
setSkin(customContextSkin); | ||
} | ||
|
||
@Override | ||
public void initialize(URL location, ResourceBundle resources) { | ||
// not needed | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
package org.jabref.gui.fieldeditors; | ||
|
||
import java.time.format.DateTimeFormatter; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
|
@@ -13,8 +16,7 @@ | |
import org.jabref.gui.autocompleter.SuggestionProviders; | ||
import org.jabref.gui.util.TaskExecutor; | ||
import org.jabref.logic.integrity.FieldCheckers; | ||
import org.jabref.logic.journals.JournalAbbreviationLoader; | ||
import org.jabref.logic.journals.JournalAbbreviationPreferences; | ||
import org.jabref.logic.journals.JournalAbbreviationRepository; | ||
import org.jabref.model.database.BibDatabaseContext; | ||
import org.jabref.model.entry.FieldName; | ||
import org.jabref.model.entry.FieldProperty; | ||
|
@@ -25,16 +27,39 @@ | |
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import static org.jabref.model.entry.FieldName.AUTHOR; | ||
import static org.jabref.model.entry.FieldName.INSTITUTION; | ||
import static org.jabref.model.entry.FieldName.TITLE; | ||
import static org.jabref.model.entry.FieldName.YEAR; | ||
|
||
public class FieldEditors { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(FieldEditors.class); | ||
|
||
public static FieldEditorFX getForField(String fieldName, TaskExecutor taskExecutor, DialogService dialogService, JournalAbbreviationLoader journalAbbreviationLoader, JournalAbbreviationPreferences journalAbbreviationPreferences, JabRefPreferences preferences, BibDatabaseContext databaseContext, String entryType, SuggestionProviders suggestionProviders, UndoManager undoManager) { | ||
private static final Set<String> SINGLE_LINE_FIELDS = Collections.unmodifiableSet(new HashSet<>( | ||
Arrays.asList(TITLE, AUTHOR, YEAR, INSTITUTION) | ||
)); | ||
|
||
public static FieldEditorFX getForField(final String fieldName, | ||
final TaskExecutor taskExecutor, | ||
final DialogService dialogService, | ||
final JournalAbbreviationRepository journalAbbreviationRepository, | ||
final JabRefPreferences preferences, | ||
final BibDatabaseContext databaseContext, | ||
final String entryType, | ||
final SuggestionProviders suggestionProviders, | ||
final UndoManager undoManager) { | ||
final Set<FieldProperty> fieldExtras = InternalBibtexFields.getFieldProperties(fieldName); | ||
|
||
AutoCompleteSuggestionProvider<?> suggestionProvider = getSuggestionProvider(fieldName, suggestionProviders, databaseContext.getMetaData()); | ||
final AutoCompleteSuggestionProvider<?> suggestionProvider = getSuggestionProvider(fieldName, suggestionProviders, databaseContext.getMetaData()); | ||
|
||
final FieldCheckers fieldCheckers = new FieldCheckers( | ||
databaseContext, | ||
preferences.getFileDirectoryPreferences(), | ||
journalAbbreviationRepository, | ||
preferences.getBoolean(JabRefPreferences.ENFORCE_LEGAL_BIBTEX_KEY)); | ||
|
||
FieldCheckers fieldCheckers = new FieldCheckers(databaseContext, preferences.getFileDirectoryPreferences(), journalAbbreviationLoader.getRepository(journalAbbreviationPreferences), preferences.getBoolean(JabRefPreferences.ENFORCE_LEGAL_BIBTEX_KEY)); | ||
final boolean hasSingleLine = SINGLE_LINE_FIELDS.contains(fieldName.toLowerCase()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might be mistaken here, but |
||
|
||
if (preferences.getTimestampPreferences().getTimestampField().equals(fieldName) || fieldExtras.contains(FieldProperty.DATE)) { | ||
if (fieldExtras.contains(FieldProperty.ISO_DATE)) { | ||
|
@@ -45,7 +70,7 @@ public static FieldEditorFX getForField(String fieldName, TaskExecutor taskExecu | |
} else if (fieldExtras.contains(FieldProperty.EXTERNAL)) { | ||
return new UrlEditor(fieldName, dialogService, suggestionProvider, fieldCheckers, preferences); | ||
} else if (fieldExtras.contains(FieldProperty.JOURNAL_NAME)) { | ||
return new JournalEditor(fieldName, journalAbbreviationLoader, preferences, suggestionProvider, fieldCheckers); | ||
return new JournalEditor(fieldName, journalAbbreviationRepository, preferences, suggestionProvider, fieldCheckers); | ||
} else if (fieldExtras.contains(FieldProperty.DOI) || fieldExtras.contains(FieldProperty.EPRINT) || fieldExtras.contains(FieldProperty.ISBN)) { | ||
return new IdentifierEditor(fieldName, taskExecutor, dialogService, suggestionProvider, fieldCheckers, preferences); | ||
} else if (fieldExtras.contains(FieldProperty.OWNER)) { | ||
|
@@ -71,7 +96,7 @@ public static FieldEditorFX getForField(String fieldName, TaskExecutor taskExecu | |
} else if (fieldExtras.contains(FieldProperty.SINGLE_ENTRY_LINK) || fieldExtras.contains(FieldProperty.MULTIPLE_ENTRY_LINK)) { | ||
return new LinkedEntriesEditor(fieldName, databaseContext, suggestionProvider, fieldCheckers); | ||
} else if (fieldExtras.contains(FieldProperty.PERSON_NAMES)) { | ||
return new PersonsEditor(fieldName, suggestionProvider, preferences, fieldCheckers); | ||
return new PersonsEditor(fieldName, suggestionProvider, preferences, fieldCheckers, hasSingleLine); | ||
} else if (FieldName.KEYWORDS.equals(fieldName)) { | ||
return new KeywordsEditor(fieldName, suggestionProvider, fieldCheckers, preferences); | ||
} else if (fieldExtras.contains(FieldProperty.MULTILINE_TEXT)) { | ||
|
@@ -81,7 +106,7 @@ public static FieldEditorFX getForField(String fieldName, TaskExecutor taskExecu | |
} | ||
|
||
// default | ||
return new SimpleEditor(fieldName, suggestionProvider, fieldCheckers, preferences); | ||
return new SimpleEditor(fieldName, suggestionProvider, fieldCheckers, preferences, hasSingleLine); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add this list two
InternalBibtexFields
(this class needs to be refactored at some point, but for now it is good to have anything at one place).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. Sorry for delay, I will do that on Saturday.