-
-
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
Add "Do not ask again" for empty entry confirmation #8297
Changes from 16 commits
44b3b4b
91335d3
dbfd569
f6caf3a
cd195cd
bebbc90
4eed604
9388fc8
6c15642
8cd129e
e4779fd
9e1ac51
c1303fb
66cb560
a6c7636
081fe2a
074f3df
6023c7b
0fb91b0
50750a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -397,8 +397,16 @@ public boolean quit() { | |
final BibDatabaseContext context = libraryTab.getBibDatabaseContext(); | ||
|
||
if (context.hasEmptyEntries()) { | ||
if (!confirmEmptyEntry(libraryTab, context)) { | ||
return false; | ||
if (prefs.getGeneralPreferences().shouldConfirmEmptyEntries()) { | ||
Optional<ButtonType> response = confirmEmptyEntry(libraryTab); | ||
if (!deleteEmptyEntry(libraryTab, context, response)) { | ||
return false; | ||
} | ||
} else if (prefs.getGeneralPreferences().shouldDeleteEmptyEntries()) { | ||
Optional<ButtonType> response = Optional.of(new ButtonType(Localization.lang("Delete empty entries"), ButtonBar.ButtonData.YES)); | ||
if (!deleteEmptyEntry(libraryTab, context, response)) { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
|
@@ -1169,8 +1177,10 @@ private boolean confirmClose(LibraryTab libraryTab) { | |
|
||
/** | ||
* Ask if the user really wants to remove any empty entries | ||
* | ||
* @return user response from the confirmation dialog | ||
*/ | ||
private Boolean confirmEmptyEntry(LibraryTab libraryTab, BibDatabaseContext context) { | ||
private Optional<ButtonType> confirmEmptyEntry(LibraryTab libraryTab) { | ||
String filename = libraryTab.getBibDatabaseContext() | ||
.getDatabasePath() | ||
.map(Path::toAbsolutePath) | ||
|
@@ -1181,11 +1191,22 @@ private Boolean confirmEmptyEntry(LibraryTab libraryTab, BibDatabaseContext cont | |
ButtonType keepEmptyEntries = new ButtonType(Localization.lang("Keep empty entries"), ButtonBar.ButtonData.NO); | ||
ButtonType cancel = new ButtonType(Localization.lang("Return to JabRef"), ButtonBar.ButtonData.CANCEL_CLOSE); | ||
|
||
Optional<ButtonType> response = dialogService.showCustomButtonDialogAndWait(Alert.AlertType.CONFIRMATION, | ||
Optional<ButtonType> response = dialogService.showCustomButtonDialogWithOptOutAndWait(Alert.AlertType.CONFIRMATION, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't you use the showConfirmationDialogWithOptOutAndWait? The AlertType.CONFIRMATION is used there too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason I added showCustomButtonDialogWithOptOutAndWait is because I would like to include the 'Return to JabRef' option as it has now. I believe showConfirmationDialogWithOptOutAndWait only allows for Yes/No choice, but not the third option. |
||
Localization.lang("Empty entries"), | ||
Localization.lang("Library '%0' has empty entries. Do you want to delete them?", filename), | ||
Localization.lang("Do not ask again"), | ||
optOut -> prefs.getGeneralPreferences().setConfirmEmptyEntries(!optOut), | ||
deleteEmptyEntries, keepEmptyEntries, cancel); | ||
if (response.isPresent() && response.get().equals(deleteEmptyEntries)) { | ||
if (response.isPresent() && response.get().getButtonData().equals(ButtonBar.ButtonData.NO)) { | ||
prefs.getGeneralPreferences().setDeleteEmptyEntries(false); | ||
} else if (response.isPresent() && response.get().getButtonData().equals(ButtonBar.ButtonData.YES)) { | ||
prefs.getGeneralPreferences().setDeleteEmptyEntries(true); | ||
} | ||
return response; | ||
} | ||
|
||
private Boolean deleteEmptyEntry(LibraryTab libraryTab, BibDatabaseContext context, Optional<ButtonType> response) { | ||
if (response.isPresent() && response.get().getButtonData() == ButtonBar.ButtonData.YES) { | ||
// The user wants to delete. | ||
try { | ||
for (BibEntry currentEntry : new ArrayList<>(context.getEntries())) { | ||
|
@@ -1206,19 +1227,26 @@ private Boolean confirmEmptyEntry(LibraryTab libraryTab, BibDatabaseContext cont | |
// Save was cancelled or an error occurred. | ||
return false; | ||
} | ||
return !response.get().equals(cancel); | ||
return !(response.get().getButtonData() == ButtonBar.ButtonData.CANCEL_CLOSE); | ||
} | ||
|
||
private void closeTab(LibraryTab libraryTab) { | ||
// empty tab without database | ||
if (libraryTab == null) { | ||
return; | ||
} | ||
|
||
final BibDatabaseContext context = libraryTab.getBibDatabaseContext(); | ||
if (context.hasEmptyEntries()) { | ||
if (!confirmEmptyEntry(libraryTab, context)) { | ||
return; | ||
if (prefs.getGeneralPreferences().shouldConfirmEmptyEntries()) { | ||
Optional<ButtonType> response = confirmEmptyEntry(libraryTab); | ||
if (!deleteEmptyEntry(libraryTab, context, response)) { | ||
return; | ||
} | ||
} else if (prefs.getGeneralPreferences().shouldDeleteEmptyEntries()) { | ||
Optional<ButtonType> response = Optional.of(new ButtonType(Localization.lang("Delete empty entries"), ButtonBar.ButtonData.YES)); | ||
if (!deleteEmptyEntry(libraryTab, context, response)) { | ||
return; | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ public class GeneralPreferences { | |
private final ObjectProperty<BibDatabaseMode> defaultBibDatabaseMode; | ||
private final BooleanProperty warnAboutDuplicatesInInspection; | ||
private final BooleanProperty confirmDelete; | ||
private final BooleanProperty confirmEmptyEntries; | ||
private final BooleanProperty deleteEmptyEntries; | ||
|
||
private final BooleanProperty memoryStickMode; | ||
private final BooleanProperty showAdvancedHints; | ||
|
@@ -22,12 +24,16 @@ public GeneralPreferences(Charset defaultEncoding, | |
BibDatabaseMode defaultBibDatabaseMode, | ||
boolean warnAboutDuplicatesInInspection, | ||
boolean confirmDelete, | ||
boolean confirmEmptyEntries, | ||
boolean deleteEmptyEntries, | ||
boolean memoryStickMode, | ||
boolean showAdvancedHints) { | ||
this.defaultEncoding = new SimpleObjectProperty<>(defaultEncoding); | ||
this.defaultBibDatabaseMode = new SimpleObjectProperty<>(defaultBibDatabaseMode); | ||
this.warnAboutDuplicatesInInspection = new SimpleBooleanProperty(warnAboutDuplicatesInInspection); | ||
this.confirmDelete = new SimpleBooleanProperty(confirmDelete); | ||
this.confirmEmptyEntries = new SimpleBooleanProperty(confirmEmptyEntries); | ||
this.deleteEmptyEntries = new SimpleBooleanProperty(deleteEmptyEntries); | ||
|
||
this.memoryStickMode = new SimpleBooleanProperty(memoryStickMode); | ||
this.showAdvancedHints = new SimpleBooleanProperty(showAdvancedHints); | ||
|
@@ -81,6 +87,60 @@ public void setConfirmDelete(boolean confirmDelete) { | |
this.confirmDelete.set(confirmDelete); | ||
} | ||
|
||
/** | ||
* Get the preference of whether to give a confirmation dialog when empty entries are detected in the library | ||
* | ||
* @return true if the preference is set as yes | ||
*/ | ||
public boolean shouldConfirmEmptyEntries() { | ||
return confirmEmptyEntries.get(); | ||
} | ||
|
||
/** | ||
* Get the BooleanProperty of the preference of whether to give a confirmation dialog when empty entries are detected in the library | ||
* | ||
* @return BooleanProperty | ||
*/ | ||
public BooleanProperty confirmEmptyEntriesProperty() { | ||
return confirmEmptyEntries; | ||
} | ||
|
||
/** | ||
* Set the preference of whether to give a confirmation dialog when empty entries are detected in the library | ||
* | ||
* @param confirmEmptyEntries boolean for the preference | ||
*/ | ||
public void setConfirmEmptyEntries(boolean confirmEmptyEntries) { | ||
this.confirmEmptyEntries.set(confirmEmptyEntries); | ||
} | ||
|
||
/** | ||
* Get the preference of whether to delete the empty entries detected in the library if confirmation dialog is opted out | ||
* | ||
* @return true if the preference is set as yes (delete) | ||
*/ | ||
public boolean shouldDeleteEmptyEntries() { | ||
return deleteEmptyEntries.get(); | ||
} | ||
|
||
/** | ||
* Get the BooleanProperty of the preference of whether to delete the empty entries detected in the library if confirmation dialog is opted out | ||
* | ||
* @return BooleanProperty | ||
*/ | ||
public BooleanProperty deleteEmptyEntriesProperty() { | ||
return deleteEmptyEntries; | ||
} | ||
|
||
/** | ||
* Set the preference of whether to delete the empty entries detected in the library if confirmation dialog is opted out | ||
* | ||
* @param deleteEmptyEntries boolean for the preference | ||
*/ | ||
public void setDeleteEmptyEntries(boolean deleteEmptyEntries) { | ||
this.deleteEmptyEntries.set(deleteEmptyEntries); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This javadoc is superfluous. Please comment on the the variable or the property, but not on every getter and setter There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry about this. I removed these comments. Let me know if you would like have any other changes. |
||
|
||
public boolean isMemoryStickMode() { | ||
return memoryStickMode.get(); | ||
} | ||
|
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.
There still seems to be some code duplication with
showConfirmationDialogWithOptOutAndWait
, which is basically now a subset of this method here. Should call this instead.Also the method argument
type
in the method signature, but is not used in the method.