-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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: Prevent overwriting of imported preferences on save #11926
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Thanks for taking a years long unsolved issue!
The solution looks simple and I think it works, but probably we need something smarter.
I think immediately closing the preferences dialog is a better way (#10939 (comment)). Because after user imported settings there are no actions to do in preferences... After all, new values are not inserted into fields, and if user starts to modify something, then it won't be changed, because justImported
is true
.
So I think there are two ways to solve this problem:
- Immediately close the window after import.
- Or set all values to the fields (IMHO, this is nice UX, but it's too hard to do this in JabRef, so the first approach is better now).
I wonder what other maintainers think
@@ -174,6 +177,12 @@ public void storeAllSettings() { | |||
return; | |||
} | |||
|
|||
if (justImported) { | |||
dialogService.notify(Localization.lang("Preferences were just imported. No additional changes to save.")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think no additional message should be displayed, as nothing special happened. Also that would introduce a new translation string.
@@ -174,6 +177,12 @@ public void storeAllSettings() { | |||
return; | |||
} | |||
|
|||
if (justImported) { | |||
dialogService.notify(Localization.lang("Preferences were just imported. No additional changes to save.")); | |||
justImported = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this is not necessary 😄 , as no code will check it, because the function immediately returns after that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, Git review moment.
By this
in my comment I meant justImported = false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, this does not fully solve the issue.
Scenario:
- I as user import the preference. Assume the AI is disabled
- I as user activate AI
- I press save
- I open the preference dialog again
- I switch to the AI tab
- AI is deactivated, but it should be activated
I think, the issue is to understand, why setValues()
does not work.
To reproduce:
- Get a saved preferences
- Imort
- Save
- Check the diff to the saved preferences
- Think
Yes, Oliver right now described the situation I mentioned: user decided to change a parameter after importing. But that wouldn't be applied because |
The reason why You see, preferences are just a Thus I propose just to immediately close the window 😄 . Maybe it's not exactly the user would expect, but it will solve the issue correctly |
It is called public void setValues() {
memoryStickProperty.setValue(preferences.getInternalPreferences().isMemoryStickMode());
for (PreferencesTab preferencesTab : preferenceTabs) {
preferencesTab.setValues();
}
} I don't understand, why it does not work. Therefore, the question to replicate the issue by createing an exported preference, changing something, importing it, exporting again and see what is changed. |
…lues() with updateAllTabs() in PreferencesDialogViewModel.importPreferences
…ogViewModel.importPreferences
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you test the changes systematically?
The code seems to be written by an AI, isn't it?
@@ -103,7 +103,8 @@ public void importPreferences() { | |||
.ifPresent(file -> { | |||
try { | |||
preferences.importPreferences(file); | |||
setValues(); | |||
// setValues(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove comment
if (tab instanceof PreferenceTabViewModel) { | ||
((PreferenceTabViewModel) tab).setValues(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the cast? -- org.jabref.gui.preferences.PreferencesTab#setValues
is available in the interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your code currently does not meet JabRef's code guidelines.
We use Checkstyle to identify issues.
The tool reviewdog already placed comments on GitHub to indicate the places. See the tab "Files" in you PR.
Please carefully follow the setup guide for the codestyle.
Afterwards, please run checkstyle locally and fix the issues.
You can check review dog's comments at the tab "Files changed" of your pull request.
I apologize for the premature submission. This PR is still a work in progress, and our members haven't fully tested the changes yet. I converted this into a draft PR for its current status. Thank you for your patience as I continue to develop and verify this solution. |
As stated above: If you test, follow the steps at #11926 (review) I think, your PR could work - you just need to fix checkstyle and remove the cast. |
…Values() in importPreferences() to avoid imported preferences overwritten when clicking "Save" but still don't know why this works.
Sorry, I see. I thought we had to manually call |
@JxCl-L In |
Thus, we are at the beginning and do not know why this does not work? @JxCl-L Did you or someone of your team follow the steps at #11926 (review) to be able to reproduce and narrow down the issue? |
We just found out that by removing the setValue(), the imported preferences would not be overwritten by clicking "Save", which kind of "solve" the issue. We are working on narrowing it down and figuring out why. |
I think, there should be a step-by-step guide how to reproduce the issue and what happens on which code changes. Example:
Thus, there is something wrong at the import. Please debug the import! |
Thank you for the advice. Here is how to reproduce the issue: This is based on the code of JabRef main repo:
Conclusion: Clicking “Save” overwriting imported preferences only happens in some settings e.g. Export sort order in Export Tab, not Visual theme in General Tab. This is based on the code of my forked JabRef repo branch fix-10939:
Conclusion: Removing the setValues() could avoid preferences overwritten by clicking “Save”. However, we are unsure why this would work and it is kind of beyond our current capabilities. Would you help us to narrow it down? |
I started reading the code.
The culpit is that "caching" at the beginning of the getter method:
They are not null after the import, thus the old version is returned. If all the objects are set to Task:
@calixtus Discussion The other option is that all preference objects get a
This seems to be much too much effort for me - and thus I asked @JxCl-L to However, since the lifecycle of our objects is long (e.g., entry editor tabs), it won't be affected by that |
…esDialogViewModel.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
img.png
not linked. Please remove.
@@ -960,6 +961,32 @@ public void exportPreferences(Path path) throws JabRefException { | |||
public void importPreferences(Path file) throws JabRefException { | |||
try (InputStream is = Files.newInputStream(file)) { | |||
Preferences.importPreferences(is); | |||
citationKeyPatternPreferences = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment above stating that null
in will trigger re-reading the preferences.
Extract method forcePreferenceCacheRefresh
and put all setting null
to there.
@@ -27,6 +27,7 @@ | |||
import java.util.stream.Collectors; | |||
import java.util.stream.Stream; | |||
|
|||
import javafx.application.Platform; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this new import?
@@ -141,6 +141,7 @@ void exportPreferences() { | |||
@FXML | |||
void importPreferences() { | |||
viewModel.importPreferences(); | |||
preferenceTabList.refresh(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this necessary - add a Java comment ore remove.
Closing this issue due to inactivity 💤 |
This PR addresses the issue where imported preferences were inadvertently overwritten when clicking the save button after an import.
Changes implemented:
These changes prevent unintended overwrite of imported settings without requiring extensive changes to the PreferencesTab interface or its implementations. It improves user experience by clearly communicating the state of preferences after import.
Closes #10939
Mandatory checks
CHANGELOG.md
described in a way that is understandable for the average user (if applicable)