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

Context menu of linked file not updated after downloading #5777

Closed
1 task done
tobiasdiez opened this issue Dec 21, 2019 · 13 comments · Fixed by #7174
Closed
1 task done

Context menu of linked file not updated after downloading #5777

tobiasdiez opened this issue Dec 21, 2019 · 13 comments · Fixed by #7174
Labels
bug Confirmed bugs or reports that are very likely to be bugs entry-editor external files good first issue An issue intended for project-newcomers. Varies in difficulty. ui

Comments

@tobiasdiez
Copy link
Member

JabRef version on

Steps to reproduce the behavior:

  1. Add online link to a pdf to some entry
  2. Right-click pdf > Download
  3. Wait until downloaded.
  4. Right-click pdf again. Most of the options are still grayed-out, probably because JabRef still thinks that this is an online pdf and not a local pdf.

Relevant code:
context menu:

private ContextMenu createContextMenuForFile(LinkedFileViewModel linkedFile) {
ContextMenu menu = new ContextMenu();
MenuItem edit = new MenuItem(Localization.lang("Edit"));
edit.setOnAction(event -> linkedFile.edit());
MenuItem openFile = new MenuItem(Localization.lang("Open"));
openFile.setOnAction(event -> linkedFile.open());
MenuItem openFolder = new MenuItem(Localization.lang("Open folder"));
openFolder.setOnAction(event -> linkedFile.openFolder());
MenuItem download = new MenuItem(Localization.lang("Download file"));
download.setOnAction(event -> linkedFile.download());
MenuItem renameFile = new MenuItem(Localization.lang("Rename file to defined pattern"));
renameFile.setOnAction(event -> linkedFile.renameToSuggestion());
renameFile.setDisable(linkedFile.getFile().isOnlineLink() || linkedFile.isGeneratedNameSameAsOriginal());
MenuItem renameFileName = new MenuItem(Localization.lang("Rename file to a given name"));
renameFileName.setOnAction(event -> linkedFile.askForNameAndRename());
renameFileName.setDisable(linkedFile.getFile().isOnlineLink());
MenuItem moveFile = new MenuItem(Localization.lang("Move file to file directory"));
moveFile.setOnAction(event -> linkedFile.moveToDefaultDirectory());
moveFile.setDisable(linkedFile.getFile().isOnlineLink() || linkedFile.isGeneratedPathSameAsOriginal());
MenuItem renameAndMoveFile = new MenuItem(Localization.lang("Move file to file directory and rename file"));
renameAndMoveFile.setOnAction(event -> linkedFile.moveToDefaultDirectoryAndRename());
renameAndMoveFile.setDisable(linkedFile.getFile().isOnlineLink() || linkedFile.isGeneratedPathSameAsOriginal());
MenuItem copyLinkedFile = new MenuItem(Localization.lang("Copy linked file to folder..."));
copyLinkedFile.setOnAction(event -> new CopySingleFileAction(linkedFile.getFile(), dialogService, databaseContext).copyFile());
copyLinkedFile.setDisable(linkedFile.getFile().isOnlineLink());
MenuItem deleteFile = new MenuItem(Localization.lang("Permanently delete local file"));
deleteFile.setOnAction(event -> viewModel.deleteFile(linkedFile));
deleteFile.setDisable(linkedFile.getFile().isOnlineLink());
MenuItem deleteLink = new MenuItem(Localization.lang("Remove link"));
deleteLink.setOnAction(event -> viewModel.removeFileLink(linkedFile));
menu.getItems().add(edit);
menu.getItems().add(new SeparatorMenuItem());
menu.getItems().addAll(openFile, openFolder);
menu.getItems().add(new SeparatorMenuItem());
if (linkedFile.getFile().isOnlineLink()) {
menu.getItems().add(download);
}
menu.getItems().addAll(renameFile, renameFileName, moveFile, renameAndMoveFile, copyLinkedFile, deleteLink, deleteFile);
return menu;
}

download:
downloadTask.onSuccess(destination -> {
LinkedFile newLinkedFile = LinkedFilesEditorViewModel.fromFile(destination, databaseContext.getFileDirectoriesAsPaths(filePreferences), externalFileTypes);
linkedFile.setLink(newLinkedFile.getLink());
linkedFile.setFileType(newLinkedFile.getFileType());

Log File
Paste an excerpt of your log file here
@tobiasdiez tobiasdiez added bug Confirmed bugs or reports that are very likely to be bugs ui external files entry-editor good first issue An issue intended for project-newcomers. Varies in difficulty. labels Dec 21, 2019
@tobiasdiez tobiasdiez added this to the v5.0 milestone Dec 21, 2019
@kevone123
Copy link

Mac OS X 10.14.4
Java 13.0.1

I can’t recreate this bug.

  1. I clicked general and added the link http://www.africau.edu/images/default/sample.pdf to URL
  2. Then I right-clicked “Open URL or DOI”(I did this because Open File was grayed-out despite adding the URL
  3. I downloaded the pdf but Open File was still grayed - out.

Screen Shot 2019-12-31 at 12 24 04 AM

Then I tried to download from URL. I didn't get the same grayed out the issue.

Screen Shot 2019-12-31 at 12 26 52 AM

What am I missing to recreate this bug?

@tobiasdiez
Copy link
Member Author

@kevone123 Thanks for your interest! The entry context menu of the main table is working fine, but the context menu of the file is the problem (right click on "PDF" in your last screenshot). Sorry for being imprecise.

@kevone123
Copy link

@tobiasdiez I'm still unable to recreate this bug.

  1. Added the link to an entry

Screen Shot 2020-01-06 at 1 04 42 PM

  1. Downloaded the pdf

Screen Shot 2020-01-06 at 12 49 20 PM

  1. When I right-clicked the pdf it isn't grayed out.

Screen Shot 2020-01-06 at 12 50 53 PM

However it is greyed out when I clicked the empty grayed line after it.
Screen Shot 2020-01-06 at 12 51 09 PM

Thank you for your response.

@tobiasdiez
Copy link
Member Author

This is very strange. For me, the context menu looks like the one on your last screenshot. Only after I switch between entries, the context menu is updated correctly.

@tobiasdiez tobiasdiez removed this from the v5.0 milestone Jan 25, 2020
@Xuanxuan-Zou
Copy link

Hi, we are a team of 5 students, and we are interested in working on this issue.

Firstly, we had reproduced this bug. Thanks for your tips, we understand the reason. In our opinion, we find that only after downloading completed, LinkedFile object’s link attributes will update, and content menu will consequently update, making some options not grayed out.

We guess that it can’t immediately update for it not renews content menu, and can only reinitialize after switch between entries.

We consider whether it is possible to renew the content menu immediately after downloading complete, that is after onSuccess function. But we are a little confused about the onSuccess function, it seems like a blocking, which can make the program continue to do other things. And we have no ideas on where to add operation after this function. Therefore, we are stucking at this.

We would sincerely appreciate it if you could give us some hints or suggestions.

downloadTask.onSuccess(destination -> {
LinkedFile newLinkedFile = LinkedFilesEditorViewModel.fromFile(destination, databaseContext.getFileDirectoriesAsPaths(filePreferences), externalFileTypes);
linkedFile.setLink(newLinkedFile.getLink());
linkedFile.setFileType(newLinkedFile.getFileType());
entry.addFile(0, newLinkedFile);
});

@tobiasdiez
Copy link
Member Author

Thanks for your interest!

Updating the context menu manually would be one option. However, the "proper" JavaFX way would be to listen to the changes in the linked files. However, this automatic update should work in principle - but it doesn't for some reason.
I would start investigating this issue by debugging how often/ when

ContextMenu menu = new ContextMenu();
is called. Then go up the chain and check when these methods are called:
setContextMenu(toContextMenu.call(viewModel));

@Xuanxuan-Zou
Copy link

Many thanks for your guidance, we understand this issue better.

After re-syncing today, we find this bug seems to be solved due to issue # 6381. After downloading completed, the context menu will update immediately. And a new entry will be added but not overwrite. Sorry for not syncing this project in time.

Please point out if there is any misunderstanding. Thanks a lot!

@Siedlerchr
Copy link
Member

I think @btut still noticed some issues in his comment #6381 (comment)
Maybe you can work together on the remaining issues?

@Xuanxuan-Zou
Copy link

We will try to work on the remaining issues. Thanks.

@btut
Copy link
Contributor

btut commented May 6, 2020

I'd be happy to!
The issue that I am having is that it would be nice to somehow let the user know that the file is still being downloaded. Otherwise people may wonder why the file entry is missing while actually the file is not downloaded yet.
@Xuanxuan-Zou feel free to join the discussion in #6381

@calixtus
Copy link
Member

calixtus commented May 7, 2020

I noticed that the ContextMenu for the FileEditor is not using the factory methods, we normally use for JabRef menus.
Take a look at gui/maintable/RightClickMenu.java for an example. Maybe this is worth some programming time. 😉

@Xuanxuan-Zou
Copy link

Thanks for your reminder!We will try to. 😃

@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2020

This issue has been inactive for half a year. Since JabRef is constantly evolving this issue may not be relevant any longer and it will be closed in two weeks if no further activity occurs.

As part of an effort to ensure that the JabRef team is focusing on important and valid issues, we would like to ask if you could update the issue if it still persists. This could be in the following form:

  • If there has been a longer discussion, add a short summary of the most important points as a new comment (if not yet existing).
  • Provide further steps or information on how to reproduce this issue.
  • Upvote the initial post if you like to see it implemented soon. Votes are not the only metric that we use to determine the requests that are implemented, however, they do factor into our decision-making process.
  • If all information is provided and still up-to-date, then just add a short comment that the issue is still relevant.

Thank you for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bugs or reports that are very likely to be bugs entry-editor external files good first issue An issue intended for project-newcomers. Varies in difficulty. ui
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

6 participants