-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Change copy-paste function to handle string constants #10992
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
Closed
Closed
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a0d6f72
[Copy] Include string constants in copy (#11)
andersblomqvist 5e98a05
[Copy] New method for serializing string constants (#12)
andersblomqvist 4dc86bb
Add a sanity check for null for clipboard content
JXNCTED 765cb0e
[Fix] Add parsed serilization when save settings
JXNCTED ea946c4
Merge pull request #14 from DD2480-Group1/issue-13/null-when-copying
andersblomqvist 5129ae9
feat: import string constants when pasting #9
hanstig dd821b9
feat: Add string constant validity checker and dialog messages #9
hanstig 404e781
[Copy] Copy referenced constant strings to clipboard (#16)
JXNCTED e49562f
Merge pull request #19 from DD2480-Group1/paste-function-revert
andersblomqvist 7485e16
feat: new unit tests
real-darth 1e69400
Merge branch 'JabRef:main' into fix-for-issue-10872
andersblomqvist 997537a
Merge remote-tracking branch 'origin/main' into fix-for-issue-10872
JXNCTED c00ee33
Update CHANGELOG with copy and paste function
JXNCTED 7a53d8a
Fix Checkstyle failing by reformat the code
JXNCTED bae8338
Fix OpenRewrite failing by running rewriteRun
JXNCTED c3ffd8b
Refactor by extract methods in setContent
JXNCTED 053b25e
Merge branch 'main' into fix-for-issue-10872
JXNCTED 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 hidden or 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
Submodule abbrv.jabref.org
updated
2 files
| +0 −15 | .github/workflows/keep-alive.yml | |
| +0 −2 | journals/journal_abbreviations_mathematics.csv |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Submodule csl-styles
updated
6 files
This file contains hidden or 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 hidden or 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,133 @@ | ||
| package org.jabref.gui; | ||
|
|
||
| import java.awt.Toolkit; | ||
| import java.awt.datatransfer.StringSelection; | ||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| import javafx.collections.FXCollections; | ||
| import javafx.collections.ObservableList; | ||
| import javafx.scene.input.Clipboard; | ||
|
|
||
| import org.jabref.architecture.AllowedToUseAwt; | ||
| import org.jabref.logic.bibtex.FieldPreferences; | ||
| import org.jabref.model.entry.BibEntry; | ||
| import org.jabref.model.entry.BibEntryType; | ||
| import org.jabref.model.entry.BibEntryTypesManager; | ||
| import org.jabref.model.entry.BibtexString; | ||
| import org.jabref.model.entry.field.Field; | ||
| import org.jabref.model.entry.field.StandardField; | ||
| import org.jabref.model.entry.types.StandardEntryType; | ||
| import org.jabref.preferences.PreferencesService; | ||
|
|
||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| @AllowedToUseAwt("Requires AWT for clipboard access") | ||
| public class ClipBoardManagerTest { | ||
|
|
||
| private BibEntryTypesManager entryTypesManager; | ||
| private ClipBoardManager clipBoardManager; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| // create preference service mock | ||
| PreferencesService preferencesService = mock(PreferencesService.class); | ||
| FieldPreferences fieldPreferences = mock(FieldPreferences.class); | ||
| List<Field> fields = Arrays.asList(StandardField.URL); | ||
| ObservableList<Field> nonWrappableFields = FXCollections.observableArrayList(fields); | ||
| // set up mock behaviours for preferences service | ||
| when(fieldPreferences.getNonWrappableFields()).thenReturn(nonWrappableFields); | ||
| when(preferencesService.getFieldPreferences()).thenReturn(fieldPreferences); | ||
|
|
||
| // create mock clipboard | ||
| Clipboard clipboard = mock(Clipboard.class); | ||
| // create primary clipboard and set a temporary value | ||
| StringSelection selection = new StringSelection("test"); | ||
| java.awt.datatransfer.Clipboard clipboardPrimary = Toolkit.getDefaultToolkit().getSystemClipboard(); | ||
| clipboardPrimary.setContents(selection, selection); | ||
|
|
||
| // create mock entry manager and set up behaviour for mock | ||
| entryTypesManager = mock(BibEntryTypesManager.class); | ||
| BibEntryType entryTypeMock = mock(BibEntryType.class); | ||
| when(entryTypesManager.enrich(any(), any())).thenReturn(Optional.of(entryTypeMock)); | ||
| // initialize a clipBoardManager | ||
| clipBoardManager = new ClipBoardManager(clipboard, clipboardPrimary, preferencesService); | ||
| } | ||
|
|
||
| @DisplayName("Check that the ClipBoardManager can set a bibentry as its content from the clipboard") | ||
| @Test | ||
| void copyStringBibEntry() throws IOException { | ||
| // Arrange | ||
| String expected = "@Article{,\n author = {Claudepierre, S. G.},\n journal = {IEEE},\n}"; | ||
|
|
||
| // create BibEntry | ||
| BibEntry bibEntry = new BibEntry(); | ||
| // construct an entry | ||
| bibEntry.setType(StandardEntryType.Article); | ||
| bibEntry.setField(StandardField.JOURNAL, "IEEE"); | ||
| bibEntry.setField(StandardField.AUTHOR, "Claudepierre, S. G."); | ||
| // add entry to list | ||
| List<BibEntry> bibEntries = new ArrayList<>(); | ||
| bibEntries.add(bibEntry); | ||
|
|
||
| // Act | ||
| clipBoardManager.setContent(bibEntries, entryTypesManager); | ||
|
|
||
| // Assert | ||
| String actual = ClipBoardManager.getContentsPrimary(); | ||
| // clean strings | ||
| actual = actual.replaceAll("\\s+", " ").trim(); | ||
| expected = expected.replaceAll("\\s+", " ").trim(); | ||
|
|
||
| assertEquals(expected, actual); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Check that the ClipBoardManager can handle a bibentry with string constants correctly from the clipboard") | ||
| void copyStringBibEntryWithStringConstants() throws IOException { | ||
| // Arrange | ||
| String expected = "@String{grl = \"Geophys. Res. Lett.\"}@Article{,\n" + " author = {Claudepierre, S. G.},\n" + | ||
| " journal = {grl},\n" + "}"; | ||
| // create BibEntry | ||
| BibEntry bibEntry = new BibEntry(); | ||
| // construct an entry | ||
| bibEntry.setType(StandardEntryType.Article); | ||
| bibEntry.setField(StandardField.JOURNAL, "grl"); | ||
| bibEntry.setField(StandardField.AUTHOR, "Claudepierre, S. G."); | ||
| // add entry to list | ||
| List<BibEntry> bibEntries = new ArrayList<>(); | ||
| bibEntries.add(bibEntry); | ||
|
|
||
| // string constants | ||
| List<BibtexString> constants = new ArrayList<>(); | ||
|
|
||
| // Mock BibtexString | ||
| BibtexString bibtexString = mock(BibtexString.class); | ||
|
|
||
| // define return value for getParsedSerialization() | ||
| when(bibtexString.getParsedSerialization()).thenReturn("@String{grl = \"Geophys. Res. Lett.\"}"); | ||
| // add the constant | ||
| constants.add(bibtexString); | ||
|
|
||
| // Act | ||
| clipBoardManager.setContent(bibEntries, entryTypesManager, constants); | ||
|
|
||
| // Assert | ||
| String actual = ClipBoardManager.getContentsPrimary(); | ||
| // clean strings | ||
| actual = actual.replaceAll("\\s+", " ").trim(); | ||
| expected = expected.replaceAll("\\s+", " ").trim(); | ||
|
|
||
| assertEquals(expected, actual); | ||
| } | ||
| } |
This file contains hidden or 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
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.
I have a better idea: