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

Fix for issue 571: File folders: Move between global and user-specific #12059

Draft
wants to merge 52 commits into
base: main
Choose a base branch
from

Conversation

Officialshubham
Copy link

Describe the changes you have made here:
Created a separate class to handle movement of files between directories. The class follows the structure and logic mention in issue #571

Class Location: org.jabref/gui/fieldeditors
Class Name: FileDirectoryHandler
Class Description: Primary objective of this class to give target directory based on the current location/path of the file.

Changes in LinkedFilesEditor.java

  1. Instead of relying upon static text in context menu, based on target path, the text will change.
  2. Dynamic update of text once the file moved to its destination.
  3. Changes to both MOVE_TO_FOLDER and MOVE_TO_FOLDER_AND_RENAME menu item and action.

Changes in LinkedFileViewModel.java

  1. Add moveToDirectory function responsible for actually moving the file based on the return value from file directory handler class.
  2. Add extra helper functions to update text in context menu as well as to determine OS specific directories.
  3. Preserved the sub directory structures.

Add some tests to check the functionality of FileDirectoryHandler

Closes koppor#571

Special Note: Want to confirm whether going in right direction or not. Unit Testing is in process.
Manual testing is performed. Creating a draft PR for review.

Screenshots

library-specific

user-specific

Mandatory checks

  • I own the copyright of the code submitted and I licence it under the MIT license
  • 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.

Officialshubham and others added 30 commits October 8, 2024 01:26
@koppor
Copy link
Member

koppor commented Oct 23, 2024

@Officialshubham Please revert updates in `csl-styles. See https://devdocs.jabref.org/code-howtos/faq.html#fix. -- I checked the GitHub Diff (tab "Files") and it still shows changes there.

CHANGELOG.md 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.

Some general remark.

@koppor
Copy link
Member

koppor commented Oct 23, 2024

GitHub removed my text, here it is:

The class FileDirectoryHandler should go to logic. (Update: Maybe, it should just be included in FileUtil?)

Add another method to BibDatabaseContext similar to org.jabref.model.database.BibDatabaseContext#getFileDirectories

getFileDirectoriesInfo

It returns a record(Path mainFileDirecotry, Optional<Path> librarySpecificDirectory, Optional<Path> userFileDirectory).

(See #12037 for the PR renaming the variables properly)

Then, your method getAvailableDirectories will be obsolete.

The code of the handleXcase will be more readable. Also it will be one method. You can ask userFileDirectory for isEmpty() etc.

@Officialshubham
Copy link
Author

Thanks @koppor
I will work on your feedback. If I'll encounter any issues, I will let you know.

String user = preferences.getFilePreferences().getUserAndHost().split("-")[0];

// Create a set of root-like directories and include the user dynamically
Set<String> rootLikeDirs = new HashSet<>(Set.of(
Copy link
Member

Choose a reason for hiding this comment

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

We are recreating the same set each time we check if the directory is root. This doesn't sound efficient.

Copy link
Author

Choose a reason for hiding this comment

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

Yes it is not correct. I am moving it as static and final. It will be loaded once now.

Comment on lines 342 to 344
BooleanProperty isMoveFileDisabled = new SimpleBooleanProperty(true);
moveFileItem.disableProperty().bind(isMoveFileDisabled);
moveFileItem.setText(Localization.lang("Move file"));
Copy link
Member

Choose a reason for hiding this comment

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

Why are we binding to isMoveFileDisabled here? It is declared locally so its value (true) won't change.

Copy link
Author

@Officialshubham Officialshubham Oct 24, 2024

Choose a reason for hiding this comment

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

Hi @HoussemNasri
I bind it to follow the consistency in both the classes: LinkedFilesEditor and LinkedFileViewModel
I am aware that we can disable it directly using setDisable().
I will change it. Let me know your views. Thanks

@Officialshubham
Copy link
Author

@koppor and @HoussemNasri.
I have resolved all the comments mentioned. Have a look at it. Thanks

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.

an old review comment was not posted - it is still valid.

Pleae also fix buildres/abbrv.jabref.org

}
}

public void moveToDirectory(MenuItem moveFileItem, MenuItem moveAndRenameFileItem, boolean toRename) {
Copy link
Member

Choose a reason for hiding this comment

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

I think, a similar function already exists at org.jabref.logic.externalfiles.LinkedFileHandler#copyOrMoveToDefaultDirectory. One "just" needs to make it more generic to get the target directory (instead of databaseContext.getFirstExistingFileDir(filePreferences);).

With the record I proposed, this should be very easy.

@@ -325,68 +371,96 @@ private ContextMenu createContextMenuForFile(LinkedFileViewModel linkedFile) {
factory.createMenuItem(StandardActions.OPEN_FOLDER, new ContextAction(StandardActions.OPEN_FOLDER, linkedFile, preferences)),
new SeparatorMenuItem(),
factory.createMenuItem(StandardActions.DOWNLOAD_FILE, new ContextAction(StandardActions.DOWNLOAD_FILE, linkedFile, preferences)),
moveFileItems[0],
Copy link
Member

Choose a reason for hiding this comment

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

No - not any arrays in Java.

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.

File folders: Move between global and user-specific
5 participants