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

fixed 'copy key and link' #6871

Merged
merged 8 commits into from Sep 29, 2020
Merged

Conversation

PremKolar
Copy link
Contributor

@PremKolar PremKolar commented Sep 4, 2020

'copy key and link' from right-click menu creates a string that is not a url. it includes the url, but it also includes the key.
setHtmlContent() was not appropriate.

Fixes #5835
#5835

  • Change in CHANGELOG.md described (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 documentation: Is the information available and up to date? If not created an issue at https://github.com/JabRef/user-documentation/issues or, even better, submitted a pull request to the documentation repository.

…t a url. it includes the url, but it also includes the key... it works now
@Siedlerchr Siedlerchr added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Sep 4, 2020
Copy link
Member

@tobiasdiez tobiasdiez left a comment

Choose a reason for hiding this comment

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

Welcome to JabRef, and thanks a lot for your contribution.

The idea to use setContent is the correct one. However, the html content should also be preserved. How this can be done is outlined below.

@@ -224,7 +224,7 @@ private void copyKeyAndLink() {
keyAndLink.append(OS.NEWLINE);
}

clipBoardManager.setHtmlContent(keyAndLink.toString());
clipBoardManager.setContent(keyAndLink.toString());
Copy link
Member

Choose a reason for hiding this comment

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

This really puts the html string into the clipboard, so if you paste it into say notepad you get <a href="url">key</a>. Instead, its better to add the html, and in addition also a fallback string of the format key - url. In this way, you get the desired behavior also when you paste in applications that do understand html (e.g onenote).

In order for this to work, you probably need to add a second fallback argument to

public void setHtmlContent(String html) {
final ClipboardContent content = new ClipboardContent();
content.putHtml(html);
clipboard.setContent(content);
setPrimaryClipboardContent(content);
}

which is then added to the ClipboardContent via putString.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @tobiasdiez !
Ah ok that makes sense.. I guess I should have looked deeper into what setHtmlContent() actually does.. I assumed it would be applicable for url's on their own only. So that means, both, setContent() and setHtmlContent() should be called?
Sorry for my noobness! This was my first open-source contribution ever :D
Can I fix the issue tonight (German time) and commit the changes?
thanks,
Niko

Copy link
Member

Choose a reason for hiding this comment

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

No worries, you were on the right track. Calling setContent and setHtmlContent is the right idea, but I suspect that this will push two different clipboard items. Instead, the setHtmlContent should be modified as follows:

public void setHtmlContent(String html, String fallbackPlain) { 
     final ClipboardContent content = new ClipboardContent(); 
     content.putHtml(html);
     content.putString(fallbackPlain);
     clipboard.setContent(content); 
     setPrimaryClipboardContent(content); 
 }

This should add one clipboard item, containing both the html as well as the normal string. (I hope)

Let me know if you encounter any further questions. There is not such a thing as noobness. We all can learn more. And learning in a relaxed environment is one of the main points of open source, so don't worry. Happy coding!

Copy link
Contributor Author

@PremKolar PremKolar Sep 5, 2020

Choose a reason for hiding this comment

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

but I suspect that this will push two different clipboard items.

That was exactly my next thought :)
Ok, I will try..
Thanks for the kind words!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

alright, i hope i did what you meant. I have to say, I still don't understand why copyKeyAndLink() creates html content for the clipboard, but e.g. copyKeyAndTitle() does not?
cheers,
Niko

@@ -144,6 +144,15 @@ public void setHtmlContent(String html) {
setPrimaryClipboardContent(content);
}

//@overload
Copy link
Member

Choose a reason for hiding this comment

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

Please remove the comment

Copy link
Member

Choose a reason for hiding this comment

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

Can the old setHtmlContent method be removed? If it's still used by other code, it might be a good idea to provide a fallback string in these cases as well. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Tobias,
If I am not mistaken, there is no usage of setHtmlContent(String html) anywhere...
Only setHtmlContent(String html, String fallbackPlain) is used once on line 230 of CopyMoreAction.java.
Should I remove the unused version?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, just remove the the unused method.

src/main/java/org/jabref/gui/edit/CopyMoreAction.java Outdated Show resolved Hide resolved
Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

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

I think, there were issues with git. I still have some code comments.

CHANGELOG.md Outdated Show resolved Hide resolved
@tobiasdiez tobiasdiez added the status: changes required Pull requests that are not yet complete label Sep 18, 2020
@koppor koppor added this to backlog in JabRef Maintainers' Focus via automation Sep 20, 2020
@koppor koppor moved this from backlog to contributor working on it in JabRef Maintainers' Focus Sep 20, 2020
@Siedlerchr
Copy link
Member

Siedlerchr commented Sep 23, 2020

Codewise looks good. Plase fix the remaining checkstyle errors. Just click on the Details of the failing tests to see them

calixtus and others added 2 commits September 29, 2020 08:32
@Siedlerchr Siedlerchr merged commit 2d92025 into JabRef:master Sep 29, 2020
JabRef Maintainers' Focus automation moved this from external contributor working on it to done (merged into master) Sep 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: changes required Pull requests that are not yet complete status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers
Projects
No open projects
JabRef Maintainers' Focus
  
done (merged into master)
Development

Successfully merging this pull request may close these issues.

Menu item 'Copy DOI link' no more visible/accessible
5 participants