-
-
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 duplicate external file type issue when change language and other corresponding issue of external file type preferences #10496
Changes from 58 commits
2a4d378
5bb7c74
7187b69
cee577c
341c52c
76519e5
f7cc511
f6166c0
df69445
5fe6df9
e194bb9
f0b21d0
7ccf1f6
a84d4da
b5c1d16
ac06f61
c5bd645
c604ecb
5bf5688
ca3ed25
ee00a17
d797e03
0399982
2c5de27
ca54d17
7da3779
4f7ce6d
74aa42d
c9f130c
52b1ad7
1cbb1e2
33c6db3
afa9a5c
78bce2a
2b92fc8
7eb9eeb
c290c86
490a8a5
8b89bf6
7a08321
d97608f
660dd03
e5ddf1f
5fb1c2c
e488411
05024d3
a33f038
424adb7
ce80a75
7bc67c4
ca9eaeb
eec134f
73cf3d5
d983edd
3fa21a3
59e8ff4
0a2bcf0
275cf46
fd0835f
cb9210e
134251d
a9db8af
b4e8c21
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 |
---|---|---|
|
@@ -8,14 +8,19 @@ | |
import javafx.collections.ObservableList; | ||
|
||
import org.jabref.gui.DialogService; | ||
import org.jabref.gui.exporter.CreateModifyExporterDialogViewModel; | ||
import org.jabref.gui.externalfiletype.ExternalFileType; | ||
import org.jabref.gui.externalfiletype.ExternalFileTypes; | ||
import org.jabref.gui.preferences.PreferenceTabViewModel; | ||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.preferences.FilePreferences; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class ExternalFileTypesTabViewModel implements PreferenceTabViewModel { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(CreateModifyExporterDialogViewModel.class); | ||
private final ObservableList<ExternalFileTypeItemViewModel> fileTypes = FXCollections.observableArrayList(); | ||
|
||
private final FilePreferences filePreferences; | ||
|
@@ -54,25 +59,69 @@ public void resetToDefaults() { | |
fileTypes.sort(Comparator.comparing(ExternalFileTypeItemViewModel::getName)); | ||
} | ||
|
||
public void addNewType() { | ||
public boolean addNewType() { | ||
ExternalFileTypeItemViewModel item = new ExternalFileTypeItemViewModel(); | ||
fileTypes.add(item); | ||
showEditDialog(item, Localization.lang("Add new file type")); | ||
|
||
if (!isValidExternalFileType(item)) { | ||
return false; | ||
} | ||
|
||
fileTypes.add(item); | ||
return true; | ||
} | ||
|
||
public ObservableList<ExternalFileTypeItemViewModel> getFileTypes() { | ||
return fileTypes; | ||
} | ||
|
||
private void showEditDialog(ExternalFileTypeItemViewModel item, String dialogTitle) { | ||
dialogService.showCustomDialogAndWait(new EditExternalFileTypeEntryDialog(item, dialogTitle)); | ||
protected void showEditDialog(ExternalFileTypeItemViewModel item, String dialogTitle) { | ||
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 this visibility change? I don't find a class inheriting from this one. 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. @papatekken Please reply 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. I think it was because I try to call the method from ExternalFileTypesTabViewModelTest class. 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. checked and confirm it is for the test class |
||
dialogService.showCustomDialogAndWait(new EditExternalFileTypeEntryDialog(item, dialogTitle, fileTypes)); | ||
} | ||
|
||
public void edit(ExternalFileTypeItemViewModel type) { | ||
showEditDialog(type, Localization.lang("Edit file type")); | ||
public boolean edit(ExternalFileTypeItemViewModel type) { | ||
ExternalFileTypeItemViewModel typeToModify = new ExternalFileTypeItemViewModel(type.toExternalFileType()); | ||
showEditDialog(typeToModify, Localization.lang("Edit file type")); | ||
|
||
if (!isValidExternalFileType(typeToModify)) { | ||
return false; | ||
} | ||
|
||
fileTypes.remove(type); | ||
fileTypes.add(typeToModify); | ||
return true; | ||
} | ||
|
||
public void remove(ExternalFileTypeItemViewModel type) { | ||
fileTypes.remove(type); | ||
} | ||
|
||
public boolean isValidExternalFileType(ExternalFileTypeItemViewModel item) { | ||
if (withEmptyValue(item)) { | ||
LOGGER.debug("One of the fields is empty or invalid."); | ||
return false; | ||
} | ||
|
||
if (!isUniqueExtension(item)) { | ||
LOGGER.debug("File Extension exists already."); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private boolean withEmptyValue(ExternalFileTypeItemViewModel item) { | ||
return item.getName().isEmpty() || item.extensionProperty().get().isEmpty() || item.mimetypeProperty().get().isEmpty(); | ||
} | ||
|
||
private boolean isUniqueExtension(ExternalFileTypeItemViewModel item) { | ||
// check extension need to be unique in the list | ||
papatekken marked this conversation as resolved.
Show resolved
Hide resolved
|
||
String newExt = item.extensionProperty().get(); | ||
for (ExternalFileTypeItemViewModel fileTypeItem : fileTypes) { | ||
if (newExt.equalsIgnoreCase(fileTypeItem.extensionProperty().get())) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} |
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.
Where do I see these messages? I did not see them here? @Siedlerchr Do we need to change something in the overall code?
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.
@koppor
I following the code from GroupDialogViewModel.java.
In that class there is a function validationHandler. However even with that function I still cannot see the error message, so I didnt include that.