Skip to content
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

Change copy-paste function to handle string constants #10992

Closed
wants to merge 17 commits into from

Conversation

real-darth
Copy link
Contributor

We changed the copy and paste function to handle string constants automatically.

  • When copying a .bib reference, the string constants are added to the clipboard.
  • When pasting a .bib reference with string constants, these are processed and added to the library database.
    • If there are duplicate string constants, the user will be notified (error dialog) and the older string constants will be kept.

This was a quality of life features requested from a user and improves the workflow of the application. However, the user suggested originally to add a separate copy-string-constants option to the UI. We opted instead to add this feature automatically when copying with string constants to make the action more seamless.

Closes #10872

Mandatory checks

  • Change in CHANGELOG.md described in a way that is understandable for the average user (if applicable)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

andersblomqvist and others added 15 commits March 1, 2024 13:46
Signed-off-by: Anders Blomqvist <anders@minaemail.se>
Signed-off-by: Anders Blomqvist <anders@minaemail.se>
Currenlty, the clipboard content can be null since the database
does not seem to be updating. This is a sanity check to prevent
the program from adding null to the clipboard.

Link to #13
When loading from existing files or libraries, the parser will set
the serilization of the string constant to the correct value. However,
when editing via the GUI, the serilization was not set and a new
string constant list will be created without the serilization.
This result in the serilization being null and when copying with
the clipboard.

Link to #13
Add functionality to import string constants in the paste function

Should add functionality to handle colliding string constants.
Should also check that the constants are valid using the
ConstantsItemModel class.
Check that a pasted string constant is valid using the
ConstantsItemModel class.

Add diagnostic messages notifying users when adding a string constant
fails while pasting.
* feat: Add parsed serialized string when cloning
* feat: Add sanity check for null in ClipBoardManager
* closes #15
Add 4 new unit tests, testing the new features added for issue-10872. Specifically the tests are for the `storeSettings` method in the ConstantsPropertiesViewModel.java, and `setContent` in the ClipBaordManager.java.

Closes #6

public void setContent(List<BibEntry> entries, BibEntryTypesManager entryTypesManager, List<BibtexString> stringConstants) throws IOException {
final ClipboardContent content = new ClipboardContent();
BibEntryWriter writer = new BibEntryWriter(new FieldWriter(preferencesService.getFieldPreferences()), entryTypesManager);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see a lot of duplicated code with the other method. Please extract the common parts to a common method

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have extracted the methods as suggested, please check them when convenient, thanks!

@Siedlerchr
Copy link
Member

On a quick look this already goes in the right direction. Will take a closer look later

if (checker.combinedValidationValidProperty().get()) {
bibDatabaseContext.getDatabase().addString(stringConstantToAdd);
} else {
dialogService.showErrorDialogAndWait(Localization.lang("Pasted string constant \"%0\" was not added because it is not a valid string constant", stringConstantToAdd.getName()));
Copy link
Member

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:

  1. Make a list with strings constants that were imported/not imported
  2. Display them at the end of the loop, so the user does not have to click yes/no etc for each string contant

@Siedlerchr
Copy link
Member

Some minor changes!

@Siedlerchr
Copy link
Member

It would be great if you could address the small changes so this gets merged and we can reduce our open PRs

@Siedlerchr Siedlerchr marked this pull request as ready for review March 17, 2024 18:57
@Siedlerchr
Copy link
Member

I could not push to the original repo, therefore I created a follow up PR #11037

@Siedlerchr Siedlerchr closed this Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replacing String Constants During Copy-Paste
5 participants