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 menu bar gone on macOS #10967

Merged
merged 2 commits into from
Mar 4, 2024
Merged

Fix menu bar gone on macOS #10967

merged 2 commits into from
Mar 4, 2024

Conversation

Siedlerchr
Copy link
Member

Fixes #10966

was introduced in bec55f8

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.

Fixes #10966

was introduced in bec55f8
@Siedlerchr Siedlerchr enabled auto-merge March 3, 2024 22:09
@@ -2204,7 +2202,7 @@ public FilePreferences getFilePreferences() {
// We choose the data directory, because a ".bak" file should survive cache cleanups
getPath(BACKUP_DIRECTORY, OS.getNativeDesktop().getBackupDirectory()),
getBoolean(CONFIRM_LINKED_FILE_DELETE),
getBoolean(TRASH_INSTEAD_OF_DELETE));
getBoolean(TRASH_INSTEAD_OF_DELETE, OS.getNativeDesktop().moveToTrashSupported()));
Copy link
Member

Choose a reason for hiding this comment

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

This is wrong. Can this be enabled in the preferences even though it is not supported?

Copy link
Member

Choose a reason for hiding this comment

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

Was already wrong before the chris change. 😉 isSupported is logic, not a preferences option.

Copy link
Member Author

Choose a reason for hiding this comment

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

grafik

Copy link
Member Author

Choose a reason for hiding this comment

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

moveToTrash.setDisable(!OS.getNativeDesktop().moveToTrashSupported());

Copy link
Member

Choose a reason for hiding this comment

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

Nevertheless, the preference should not be true if it is not supported system-wide. I thought, in #10591 I implemented it as: "default = supported by OS" and then "disabled/enabled = supported by OS".

Maybe an additional line:

if (!OS.getNativeDesktop().moveToTrashSupported()) {
  moveToTrash.setValue(false)
}

to ensure that it is both disabled and false if trash is not supported.

Copy link
Member Author

Choose a reason for hiding this comment

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

It was in defaults. but this broke the system menu bar in macOS. This is why i removed it in defaults and just added it as fallback value

Copy link
Member

Choose a reason for hiding this comment

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

Which part exactly broke the menu bar? The issue did not show any exception, so I cannot understand the root cause.

Copy link
Member

Choose a reason for hiding this comment

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

My suggestion would be just to make true the default, but it's greyed out in the preferences and where moveToTrash is used, there is an additional check, if this is supported. Check could go to JabRefDesktop#moveToTrash or sthg and then delete instead.

@koppor
Copy link
Member

koppor commented Mar 4, 2024

Failing tests are "only" architecture tests

org.jabref.architecture.MainArchitectureTest

  Test nativeDesktopIsRestricted FAILED

  java.lang.AssertionError: Architecture Violation [Priority: MEDIUM] - Rule 'no classes that do not have simple name 'JabRefDesktop' and do not have simple name 'Launcher' and do not have simple name 'DefaultDesktop' and do not have simple name 'OS' and do not have simple name 'Linux' and do not have simple name 'OSX' and do not have simple name 'Windows' and do not have simple name 'JabRefPreferences' and have name not matching '.*Test' should depend on classes that have simple name 'NativeDesktop'' was violated (5 times):
  Constructor <org.jabref.gui.preferences.externalfiletypes.EditExternalFileTypeEntryDialog.<init>(org.jabref.gui.preferences.externalfiletypes.ExternalFileTypeItemViewModel, java.lang.String, javafx.collections.ObservableList)> calls method <org.jabref.gui.desktop.os.NativeDesktop.getApplicationDirectory()> in (EditExternalFileTypeEntryDialog.java:37)
  Method <org.jabref.gui.linkedfile.DeleteFileAction.deleteFileHelper(org.jabref.model.database.BibDatabaseContext, org.jabref.model.entry.LinkedFile)> calls method <org.jabref.gui.desktop.os.NativeDesktop.moveToTrash(java.nio.file.Path)> in (DeleteFileAction.java:194)
  Method <org.jabref.gui.openoffice.DetectOpenOfficeInstallation.selectInstallationPath()> calls method <org.jabref.gui.desktop.os.NativeDesktop.getApplicationDirectory()> in (DetectOpenOfficeInstallation.java:37)
  Method <org.jabref.gui.preferences.linkedfiles.LinkedFilesTab.initialize()> calls method <org.jabref.gui.desktop.os.NativeDesktop.moveToTrashSupported()> in (LinkedFilesTab.java:67)
  Method <org.jabref.model.database.BibDatabaseContext.getFulltextIndexPath()> calls method <org.jabref.gui.desktop.os.NativeDesktop.getFulltextIndexBaseDirectory()> in (BibDatabaseContext.java:247)

@koppor
Copy link
Member

koppor commented Mar 4, 2024

Ah, I think org.jabref.gui.desktop.JabRefDesktop#moveToTrashSupported should be called. Not OS directly. We do have JabRefDesktop as bridge.

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 don't know, how to solve this.

My thoughts:

  1. Users should not be required to set any preference on first use.
  2. JabRef should not delete data if it can do other way
  3. Trashing files instead of deleting files is a way to prevent data loss.
  4. Some operating systems do not support trashing
  5. Thus, the default for trashing is the OS support for trashing.

Point 5 seemed to cause troubles with OSX. I don't know which troubles. @calixtus says, OS-depended defaults are not OK. I am curious about our ideas how to resolve points 1 to 4 above.

Comment on lines 319 to 316
/**
* Moves the given file to the trash.
*
* @throws UnsupportedOperationException if the current platform does not support the {@link Desktop.Action#MOVE_TO_TRASH} action
* @see Desktop#moveToTrash(File)
*/
public static void moveToTrash(Path path) {
NATIVE_DESKTOP.moveToTrash(path);
}

public static boolean moveToTrashSupported() {
return NATIVE_DESKTOP.moveToTrashSupported();
}

public static Path getApplicationDirectory() {
return NATIVE_DESKTOP.getApplicationDirectory();
}

public static Path getFulltextIndexBaseDirectory() {
return NATIVE_DESKTOP.getFulltextIndexBaseDirectory();
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Please keep the methods here. OS.getNativeDesktop() may only be used by certain classes. See org.jabref.architecture.MainArchitectureTest#nativeDesktopIsRestricted.

Copy link
Member Author

Choose a reason for hiding this comment

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

For me this is a code smell because we essentially have duplicate methods now. Before the mentioned PR we didn't have this architecture check

Copy link
Member

Choose a reason for hiding this comment

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

When introducing, I checked all calls to JabRef desktop and refactored out the implied ArchitectureCheck.

I like the FacadePattern :p

@@ -710,7 +709,6 @@ private JabRefPreferences() {
defaults.put(WARN_BEFORE_OVERWRITING_KEY, Boolean.TRUE);
defaults.put(CONFIRM_DELETE, Boolean.TRUE);
defaults.put(CONFIRM_LINKED_FILE_DELETE, Boolean.TRUE);
defaults.put(TRASH_INSTEAD_OF_DELETE, JabRefDesktop.moveToTrashSupported());
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't there a true be put?

OK, what if the OS does not support move to trash?

This were my thoughts. Therefore, I made the default rely on the current OS's capabilities.

Copy link
Member Author

@Siedlerchr Siedlerchr Mar 4, 2024

Choose a reason for hiding this comment

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

Exactly this line broke the menu bar! That's why I moved the check. I guess it has something to do with the initalization order of javafx <-> awt because we are here in a static context early at startup. That's why I moved the check down where the value is first read

@@ -2204,7 +2202,7 @@ public FilePreferences getFilePreferences() {
// We choose the data directory, because a ".bak" file should survive cache cleanups
getPath(BACKUP_DIRECTORY, OS.getNativeDesktop().getBackupDirectory()),
getBoolean(CONFIRM_LINKED_FILE_DELETE),
getBoolean(TRASH_INSTEAD_OF_DELETE));
getBoolean(TRASH_INSTEAD_OF_DELETE, OS.getNativeDesktop().moveToTrashSupported()));
Copy link
Member

Choose a reason for hiding this comment

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

Which part exactly broke the menu bar? The issue did not show any exception, so I cannot understand the root cause.

@Siedlerchr Siedlerchr added this pull request to the merge queue Mar 4, 2024
Copy link
Contributor

github-actions bot commented Mar 4, 2024

The build for this PR is no longer available. Please visit https://builds.jabref.org/main/ for the latest build.

Merged via the queue into main with commit f1c099c Mar 4, 2024
20 checks passed
@Siedlerchr Siedlerchr deleted the fixOsxMenubar branch March 4, 2024 20:06
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.

Menu bar at wrong position on Mac OS since commit bec55f8
3 participants