From cb497fbed11afeabdec400cbcfc99a3b64f32520 Mon Sep 17 00:00:00 2001 From: systemoperator <3658393+systemoperator@users.noreply.github.com> Date: Thu, 30 Jan 2020 23:32:32 +0100 Subject: [PATCH 1/5] - edit/customize external file types: radio button for "default program"/"custom program" fixed: it now gets updated properly (binding added); - "Edit file type dialog": correct value get loaded now for the input field "Name" - when storing an updated file type: no differentiation will be made any more whether program runs on Windows or somewhere else - quick fix for pending issue: editing an ExternalFileType works now (still room for improvement); visual bug concerning "lazy" update of table could be a Linux issue, since other tables are affected as well; so basically - except the "lazy" update thing -- everything works concerning external file types --- .../CustomizeExternalFileTypesDialog.java | 1 + .../CustomizeExternalFileTypesViewModel.java | 2 ++ .../EditExternalFileTypeEntryDialog.java | 1 + .../EditExternalFileTypeViewModel.java | 28 +++++++++++-------- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesDialog.java b/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesDialog.java index e7a2d1492ef..31a888bf111 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesDialog.java +++ b/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesDialog.java @@ -40,6 +40,7 @@ public CustomizeExternalFileTypesDialog() { this.setResultConverter(button -> { if (button == ButtonType.OK) { viewModel.storeSettings(); + fileTypesTable.refresh(); } return null; }); diff --git a/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java b/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java index 4a250f6f549..e7ee73267b2 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java +++ b/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java @@ -49,6 +49,8 @@ private void showEditDialog(ExternalFileType type, String dialogTitle) { typeForEdit = (CustomExternalFileType) type; } else { typeForEdit = new CustomExternalFileType(type); + fileTypes.add(fileTypes.indexOf(type), typeForEdit); + fileTypes.remove(type); } EditExternalFileTypeEntryDialog dlg = new EditExternalFileTypeEntryDialog(typeForEdit, dialogTitle); diff --git a/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeEntryDialog.java b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeEntryDialog.java index 88566e07772..bafbece5ded 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeEntryDialog.java +++ b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeEntryDialog.java @@ -62,6 +62,7 @@ public void initialize() { icon.setGraphic(viewModel.getIcon()); defaultApplication.selectedProperty().bindBidirectional(viewModel.defaultApplicationSelectedProperty()); + customApplication.selectedProperty().bindBidirectional(viewModel.customApplicationSelectedProperty()); selectedApplication.disableProperty().bind(viewModel.defaultApplicationSelectedProperty()); btnBrowse.disableProperty().bind(viewModel.defaultApplicationSelectedProperty()); diff --git a/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeViewModel.java b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeViewModel.java index 331e1a8d835..dde400a90c3 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeViewModel.java +++ b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeViewModel.java @@ -15,19 +15,25 @@ public class EditExternalFileTypeViewModel { private final StringProperty mimeTypeProperty = new SimpleStringProperty(""); private final StringProperty selectedApplicationProperty = new SimpleStringProperty(""); private final BooleanProperty defaultApplicationSelectedProperty = new SimpleBooleanProperty(false); + private final BooleanProperty customApplicationSelectedProperty = new SimpleBooleanProperty(false); private final Node icon; private final CustomExternalFileType fileType; public EditExternalFileTypeViewModel(CustomExternalFileType fileType) { this.fileType = fileType; extensionProperty.setValue(fileType.getExtension()); - nameProperty.setValue(fileType.getField().getDisplayName()); + nameProperty.setValue(fileType.getName()); mimeTypeProperty.setValue(fileType.getMimeType()); selectedApplicationProperty.setValue(fileType.getOpenWithApplication()); icon = fileType.getIcon().getGraphicNode(); if (fileType.getOpenWithApplication().isEmpty()) { defaultApplicationSelectedProperty.setValue(true); + customApplicationSelectedProperty.setValue(false); + } + else { + defaultApplicationSelectedProperty.setValue(false); + customApplicationSelectedProperty.setValue(true); } } @@ -52,6 +58,10 @@ public BooleanProperty defaultApplicationSelectedProperty() { return defaultApplicationSelectedProperty; } + public BooleanProperty customApplicationSelectedProperty() { + return customApplicationSelectedProperty; + } + public Node getIcon() { return icon; } @@ -69,20 +79,14 @@ public void storeSettings() { } String application = selectedApplicationProperty.getValue().trim(); - if (OS.WINDOWS) { - // On Windows, store application as empty if the "Default" option is selected, - // or if the application name is empty: - if (defaultApplicationSelectedProperty.getValue() || application.isEmpty()) { - fileType.setOpenWith(""); - selectedApplicationProperty.setValue(""); - - } else { - fileType.setOpenWith(application); - } + + // store application as empty if the "Default" option is selected, or if the application name is empty: + if (defaultApplicationSelectedProperty.getValue() || application.isEmpty()) { + fileType.setOpenWith(""); + selectedApplicationProperty.setValue(""); } else { fileType.setOpenWith(application); } - } } From 25285b9af2026f184ed4737a23aaf3c1f6db16cc Mon Sep 17 00:00:00 2001 From: systemoperator <3658393+systemoperator@users.noreply.github.com> Date: Sat, 1 Feb 2020 00:47:27 +0100 Subject: [PATCH 2/5] cleanup + changelog --- AUTHORS | 8 ++++++++ CHANGELOG.md | 1 + .../CustomizeExternalFileTypesDialog.java | 1 - .../externalfiletype/EditExternalFileTypeViewModel.java | 4 ---- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/AUTHORS b/AUTHORS index 3b4f540c584..81f3ca3c37e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -10,6 +10,7 @@ Admir Obralija Adrian Daerr Akash Deep Alain Vaucher +alauber Aleksandrs Gusevs Alessio Pollero Alex Montgomery @@ -127,6 +128,7 @@ Hannes Restel Harinda Samarasekara Igor Chernyavsky Igor Steinmacher +igorsteinmacher Illes Solt Ingvar Jackal Jackson Ryan @@ -153,6 +155,7 @@ josephshin93 Joshua Ramon Enslin José Jesús Sinohui Fernández Julian Pfeifer +Julien29121998 Jure Slak József Pallagi Jörg Lenhard @@ -203,6 +206,7 @@ Mattia Bunel Mattias Ulbrich mcmoody Meltem Demirköprü +MhhhxX Michael Beckmann Michael Falkenthal Michael Lass @@ -239,6 +243,7 @@ Oliver Beckmann Oliver Kopp omer-rotem1 Oscar Gustafsson +oscargus Owen Huang P4trice Param Mittal @@ -301,8 +306,10 @@ Stephen Beitzel Stéphane Curet Super-Tang Sven Jäger +systemoperator Thiago Toledo Thomas Arildsen +Thomas F. Duellmann Thomas Ilsche Thorsten Dahlheimer Tim Kilian @@ -312,6 +319,7 @@ Tobias Boceck Tobias Bouschen Tobias Denkinger Tobias Diez +Tomás Morales de Luna Tony K Toralf Senger uid112001 diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ffa4e88747..e840a5fcbcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - We fixed an issue where an erroneous "The library has been modified by another program" message was shown when saving. [#4877](https://github.com/JabRef/jabref/issues/4877) - We fixed an issue where the file extension was missing after downloading a file (we now fall-back to pdf). [#5816](https://github.com/JabRef/jabref/issues/5816) - We fixed an issue where cleaning up entries broke web URLs, if "Make paths of linked files relative (if possible)" was enabled, which resulted in various other issues subsequently. [#5861](https://github.com/JabRef/jabref/issues/5861) +- We fixed several issues concerning managing external file types: Now everything is usable and fully functional. Previously, there were problems with the radio buttons, with saving the settings and with loading an input field value. Furthermore, different behavior for Windows and other operating systems was given, which was unified as well. [#5846](https://github.com/JabRef/jabref/issues/5846) ### Removed - Ampersands are no longer escaped by default in the `bib` file. If you want to keep the current behaviour, you can use the new "Escape Ampersands" formatter as a save action. diff --git a/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesDialog.java b/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesDialog.java index 31a888bf111..e7a2d1492ef 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesDialog.java +++ b/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesDialog.java @@ -40,7 +40,6 @@ public CustomizeExternalFileTypesDialog() { this.setResultConverter(button -> { if (button == ButtonType.OK) { viewModel.storeSettings(); - fileTypesTable.refresh(); } return null; }); diff --git a/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeViewModel.java b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeViewModel.java index dde400a90c3..dc573aa2c36 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeViewModel.java +++ b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeViewModel.java @@ -6,8 +6,6 @@ import javafx.beans.property.StringProperty; import javafx.scene.Node; -import org.jabref.logic.util.OS; - public class EditExternalFileTypeViewModel { private final StringProperty extensionProperty = new SimpleStringProperty(""); @@ -29,10 +27,8 @@ public EditExternalFileTypeViewModel(CustomExternalFileType fileType) { if (fileType.getOpenWithApplication().isEmpty()) { defaultApplicationSelectedProperty.setValue(true); - customApplicationSelectedProperty.setValue(false); } else { - defaultApplicationSelectedProperty.setValue(false); customApplicationSelectedProperty.setValue(true); } From 8dc7d1ca58283b0bbf1d8586cc671bdc2bf35200 Mon Sep 17 00:00:00 2001 From: systemoperator <3658393+systemoperator@users.noreply.github.com> Date: Sun, 2 Feb 2020 00:39:28 +0100 Subject: [PATCH 3/5] revert authors --- AUTHORS | 7 ------- 1 file changed, 7 deletions(-) diff --git a/AUTHORS b/AUTHORS index 81f3ca3c37e..da7ac9bf114 100644 --- a/AUTHORS +++ b/AUTHORS @@ -10,7 +10,6 @@ Admir Obralija Adrian Daerr Akash Deep Alain Vaucher -alauber Aleksandrs Gusevs Alessio Pollero Alex Montgomery @@ -128,7 +127,6 @@ Hannes Restel Harinda Samarasekara Igor Chernyavsky Igor Steinmacher -igorsteinmacher Illes Solt Ingvar Jackal Jackson Ryan @@ -155,7 +153,6 @@ josephshin93 Joshua Ramon Enslin José Jesús Sinohui Fernández Julian Pfeifer -Julien29121998 Jure Slak József Pallagi Jörg Lenhard @@ -206,7 +203,6 @@ Mattia Bunel Mattias Ulbrich mcmoody Meltem Demirköprü -MhhhxX Michael Beckmann Michael Falkenthal Michael Lass @@ -243,7 +239,6 @@ Oliver Beckmann Oliver Kopp omer-rotem1 Oscar Gustafsson -oscargus Owen Huang P4trice Param Mittal @@ -309,7 +304,6 @@ Sven Jäger systemoperator Thiago Toledo Thomas Arildsen -Thomas F. Duellmann Thomas Ilsche Thorsten Dahlheimer Tim Kilian @@ -319,7 +313,6 @@ Tobias Boceck Tobias Bouschen Tobias Denkinger Tobias Diez -Tomás Morales de Luna Tony K Toralf Senger uid112001 From 57c9082ea3edef3aa5b83dd6890fef527686f608 Mon Sep 17 00:00:00 2001 From: systemoperator <3658393+systemoperator@users.noreply.github.com> Date: Sun, 2 Feb 2020 18:35:05 +0100 Subject: [PATCH 4/5] extractor property added (as used in some other JavaFX tables as well) --- src/main/java/org/jabref/gui/BasePanel.java | 2 +- .../org/jabref/gui/desktop/JabRefDesktop.java | 4 +- .../java/org/jabref/gui/desktop/os/Linux.java | 4 +- .../java/org/jabref/gui/desktop/os/OSX.java | 4 +- .../org/jabref/gui/desktop/os/Windows.java | 4 +- .../externalfiles/AutoSetFileLinksUtil.java | 4 +- .../ExternalFilesEntryLinker.java | 2 +- .../CustomExternalFileType.java | 61 +++++++++++-------- .../CustomizeExternalFileTypesDialog.java | 8 +-- .../CustomizeExternalFileTypesViewModel.java | 7 ++- .../EditExternalFileTypeViewModel.java | 10 +-- .../externalfiletype/ExternalFileType.java | 18 ++++-- .../externalfiletype/ExternalFileTypes.java | 18 +++--- .../StandardExternalFileType.java | 43 ++++++++----- .../UnknownExternalFileType.java | 33 +++++++--- .../gui/fieldeditors/LinkedFileViewModel.java | 2 +- .../LinkedFilesEditorViewModel.java | 2 +- .../jabref/gui/filelist/FileListEntry.java | 4 +- .../preferences/TableColumnsTabViewModel.java | 2 +- 19 files changed, 140 insertions(+), 92 deletions(-) diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index efec6542ab0..c1721826976 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -1097,7 +1097,7 @@ public void searchAndOpen() { final Set types = ExternalFileTypes.getInstance().getExternalFileTypeSelection(); final List dirs = basePanel.getBibDatabaseContext().getFileDirectoriesAsPaths(Globals.prefs.getFilePreferences()); - final List extensions = types.stream().map(ExternalFileType::getExtension).collect(Collectors.toList()); + final List extensions = types.stream().map(ExternalFileType::getExtensionAsString).collect(Collectors.toList()); // Run the search operation: FileFinder fileFinder = FileFinders.constructFromConfiguration(Globals.prefs.getAutoLinkPreferences()); diff --git a/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java b/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java index 78a679cc39e..d0d0c3c1717 100644 --- a/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java +++ b/src/main/java/org/jabref/gui/desktop/JabRefDesktop.java @@ -146,10 +146,10 @@ public static boolean openExternalFileAnyFormat(Path file, final BibDatabaseCont private static void openExternalFilePlatformIndependent(Optional fileType, String filePath) throws IOException { if (fileType.isPresent()) { - String application = fileType.get().getOpenWithApplication(); + String application = fileType.get().getOpenWithApplication().getValue(); if (application.isEmpty()) { - NATIVE_DESKTOP.openFile(filePath, fileType.get().getExtension()); + NATIVE_DESKTOP.openFile(filePath, fileType.get().getExtension().getValue()); } else { NATIVE_DESKTOP.openFileWithApplication(filePath, application); } diff --git a/src/main/java/org/jabref/gui/desktop/os/Linux.java b/src/main/java/org/jabref/gui/desktop/os/Linux.java index a39c6e335d2..37aed2e1089 100644 --- a/src/main/java/org/jabref/gui/desktop/os/Linux.java +++ b/src/main/java/org/jabref/gui/desktop/os/Linux.java @@ -29,8 +29,8 @@ public void openFile(String filePath, String fileType) throws IOException { Optional type = ExternalFileTypes.getInstance().getExternalFileTypeByExt(fileType); String viewer; - if (type.isPresent() && !type.get().getOpenWithApplication().isEmpty()) { - viewer = type.get().getOpenWithApplication(); + if (type.isPresent() && !type.get().getOpenWithApplication().getValue().isEmpty()) { + viewer = type.get().getOpenWithApplication().getValue(); } else { viewer = "xdg-open"; } diff --git a/src/main/java/org/jabref/gui/desktop/os/OSX.java b/src/main/java/org/jabref/gui/desktop/os/OSX.java index c4a6c495431..a326f9a9afb 100644 --- a/src/main/java/org/jabref/gui/desktop/os/OSX.java +++ b/src/main/java/org/jabref/gui/desktop/os/OSX.java @@ -16,8 +16,8 @@ public class OSX implements NativeDesktop { @Override public void openFile(String filePath, String fileType) throws IOException { Optional type = ExternalFileTypes.getInstance().getExternalFileTypeByExt(fileType); - if (type.isPresent() && !type.get().getOpenWithApplication().isEmpty()) { - openFileWithApplication(filePath, type.get().getOpenWithApplication()); + if (type.isPresent() && !type.get().getOpenWithApplication().getValue().isEmpty()) { + openFileWithApplication(filePath, type.get().getOpenWithApplication().getValue()); } else { String[] cmd = {"/usr/bin/open", filePath}; Runtime.getRuntime().exec(cmd); diff --git a/src/main/java/org/jabref/gui/desktop/os/Windows.java b/src/main/java/org/jabref/gui/desktop/os/Windows.java index 5de0f056f65..b90dce5a2ff 100644 --- a/src/main/java/org/jabref/gui/desktop/os/Windows.java +++ b/src/main/java/org/jabref/gui/desktop/os/Windows.java @@ -22,8 +22,8 @@ public class Windows implements NativeDesktop { public void openFile(String filePath, String fileType) throws IOException { Optional type = ExternalFileTypes.getInstance().getExternalFileTypeByExt(fileType); - if (type.isPresent() && !type.get().getOpenWithApplication().isEmpty()) { - openFileWithApplication(filePath, type.get().getOpenWithApplication()); + if (type.isPresent() && !type.get().getOpenWithApplication().getValue().isEmpty()) { + openFileWithApplication(filePath, type.get().getOpenWithApplication().getValue()); } else { // quote String so explorer handles URL query strings correctly String quotePath = "\"" + filePath + "\""; diff --git a/src/main/java/org/jabref/gui/externalfiles/AutoSetFileLinksUtil.java b/src/main/java/org/jabref/gui/externalfiles/AutoSetFileLinksUtil.java index f771d0bed44..e7fb40a37c8 100644 --- a/src/main/java/org/jabref/gui/externalfiles/AutoSetFileLinksUtil.java +++ b/src/main/java/org/jabref/gui/externalfiles/AutoSetFileLinksUtil.java @@ -81,7 +81,7 @@ public List linkAssociatedFiles(List entries, NamedCompound public List findAssociatedNotLinkedFiles(BibEntry entry) throws IOException { List linkedFiles = new ArrayList<>(); - List extensions = externalFileTypes.getExternalFileTypeSelection().stream().map(ExternalFileType::getExtension).collect(Collectors.toList()); + List extensions = externalFileTypes.getExternalFileTypeSelection().stream().map(ExternalFileType::getExtensionAsString).collect(Collectors.toList()); // Run the search operation FileFinder fileFinder = FileFinders.constructFromConfiguration(autoLinkPreferences); @@ -105,7 +105,7 @@ public List findAssociatedNotLinkedFiles(BibEntry entry) throws IOEx .map(externalFileTypes::getExternalFileTypeByExt) .orElse(Optional.of(new UnknownExternalFileType(""))); - String strType = type.isPresent() ? type.get().getName() : ""; + String strType = type.isPresent() ? type.get().getName().getValue() : ""; Path relativeFilePath = FileUtil.relativize(foundFile, directories); LinkedFile linkedFile = new LinkedFile("", relativeFilePath, strType); linkedFiles.add(linkedFile); diff --git a/src/main/java/org/jabref/gui/externalfiles/ExternalFilesEntryLinker.java b/src/main/java/org/jabref/gui/externalfiles/ExternalFilesEntryLinker.java index 657ece362e5..bde1883769c 100644 --- a/src/main/java/org/jabref/gui/externalfiles/ExternalFilesEntryLinker.java +++ b/src/main/java/org/jabref/gui/externalfiles/ExternalFilesEntryLinker.java @@ -57,7 +57,7 @@ public void addFilesToEntry(BibEntry entry, List files) { ExternalFileType type = externalFileTypes.getExternalFileTypeByExt(ext) .orElse(new UnknownExternalFileType(ext)); Path relativePath = FileUtil.relativize(file, bibDatabaseContext.getFileDirectoriesAsPaths(filePreferences)); - LinkedFile linkedfile = new LinkedFile("", relativePath.toString(), type.getName()); + LinkedFile linkedfile = new LinkedFile("", relativePath.toString(), type.getName().getValue()); entry.addFile(linkedfile); }); } diff --git a/src/main/java/org/jabref/gui/externalfiletype/CustomExternalFileType.java b/src/main/java/org/jabref/gui/externalfiletype/CustomExternalFileType.java index 5a4887c6fd3..a1be9f1db13 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/CustomExternalFileType.java +++ b/src/main/java/org/jabref/gui/externalfiletype/CustomExternalFileType.java @@ -2,6 +2,9 @@ import java.util.Objects; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + import org.jabref.gui.icon.IconTheme; import org.jabref.gui.icon.JabRefIcon; @@ -12,26 +15,26 @@ */ public class CustomExternalFileType implements ExternalFileType { - private String name; - private String extension; - private String openWith; - private String iconName; - private String mimeType; + private StringProperty name; + private StringProperty extension; + private StringProperty openWith; + private StringProperty iconName; + private StringProperty mimeType; private JabRefIcon icon; - public CustomExternalFileType(String name, String extension, String mimeType, - String openWith, String iconName, JabRefIcon icon) { + public CustomExternalFileType(StringProperty name, StringProperty extension, StringProperty mimeType, + StringProperty openWith, StringProperty iconName, JabRefIcon icon) { this.name = name; this.extension = extension; this.mimeType = mimeType; this.openWith = openWith; - setIconName(iconName); + setIconName(iconName.getValue()); setIcon(icon); } public CustomExternalFileType(ExternalFileType type) { - this(type.getName(), type.getExtension(), type.getMimeType(), type.getOpenWithApplication(), "", type.getIcon()); + this(type.getName(), type.getExtension(), type.getMimeType(), type.getOpenWithApplication(), new SimpleStringProperty(""), type.getIcon()); } /** @@ -75,52 +78,62 @@ public static ExternalFileType buildFromArgs(String[] val) { } } - return new CustomExternalFileType(name, extension, mimeType, openWith, iconName, icon); + return new CustomExternalFileType(new SimpleStringProperty(name), new SimpleStringProperty(extension), new SimpleStringProperty(mimeType), new SimpleStringProperty(openWith), new SimpleStringProperty(iconName), icon); } @Override - public String getName() { + public StringProperty getName() { return name; } + @Override + public String getNameAsString() { + return name.getValue(); + } + public void setName(String name) { - this.name = name; + this.name = new SimpleStringProperty(name); } @Override - public String getExtension() { + public StringProperty getExtension() { if (extension == null) { - return ""; + return new SimpleStringProperty(""); } return extension; } + @Override + public String getExtensionAsString() { + return extension.getValue(); + } + public void setExtension(String extension) { - this.extension = extension; + this.extension = new SimpleStringProperty(extension); } @Override - public String getMimeType() { + public StringProperty getMimeType() { if (mimeType == null) { - return ""; + return new SimpleStringProperty(""); } return mimeType; } public void setMimeType(String mimeType) { - this.mimeType = mimeType; + this.mimeType = new SimpleStringProperty(mimeType); } @Override - public String getOpenWithApplication() { + public StringProperty getOpenWithApplication() { if (openWith == null) { - return ""; + return new SimpleStringProperty(""); } return openWith; } public void setOpenWith(String openWith) { - this.openWith = openWith; + this.openWith = new SimpleStringProperty(openWith); } /** @@ -129,7 +142,7 @@ public void setOpenWith(String openWith) { * @return The icon name. */ public String getIconName() { - return iconName; + return iconName.getValue(); } /** @@ -138,7 +151,7 @@ public String getIconName() { * @param name The icon name to use. */ public void setIconName(String name) { - this.iconName = name; + this.iconName = new SimpleStringProperty(name); } @Override @@ -153,7 +166,7 @@ public void setIcon(JabRefIcon icon) { @Override public String toString() { - return getName(); + return getName().toString(); } public ExternalFileType copy() { diff --git a/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesDialog.java b/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesDialog.java index e7a2d1492ef..a002a75f898 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesDialog.java +++ b/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesDialog.java @@ -52,10 +52,10 @@ public void initialize() { fileTypesTable.setItems(viewModel.getFileTypes()); fileTypesTableIconColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getIcon())); - fileTypesTableNameColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getName())); - fileTypesTableExtensionColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getExtension())); - fileTypesTableTypeColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getMimeType())); - fileTypesTableApplicationColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getOpenWithApplication())); + fileTypesTableNameColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getName().getValue())); + fileTypesTableExtensionColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getExtension().getValue())); + fileTypesTableTypeColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getMimeType().getValue())); + fileTypesTableApplicationColumn.setCellValueFactory(data -> BindingsHelper.constantOf(data.getValue().getOpenWithApplication().getValue())); fileTypesTableEditColumn.setCellValueFactory(data -> BindingsHelper.constantOf(true)); fileTypesTableDeleteColumn.setCellValueFactory(data -> BindingsHelper.constantOf(true)); diff --git a/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java b/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java index e7ee73267b2..db3c3331c57 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java +++ b/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.Set; +import javafx.beans.property.SimpleStringProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; @@ -17,7 +18,7 @@ public class CustomizeExternalFileTypesViewModel { public CustomizeExternalFileTypesViewModel() { Set types = ExternalFileTypes.getInstance().getExternalFileTypeSelection(); fileTypes = FXCollections.observableArrayList(types); - fileTypes.sort(Comparator.comparing(ExternalFileType::getName)); + fileTypes.sort(Comparator.comparing(ExternalFileType::getNameAsString)); } /** @@ -30,11 +31,11 @@ public void storeSettings() { public void resetToDefaults() { List list = ExternalFileTypes.getDefaultExternalFileTypes(); fileTypes.setAll(list); - fileTypes.sort(Comparator.comparing(ExternalFileType::getName)); + fileTypes.sort(Comparator.comparing(ExternalFileType::getNameAsString)); } public void addNewType() { - CustomExternalFileType type = new CustomExternalFileType("", "", "", "", "new", IconTheme.JabRefIcons.FILE); + CustomExternalFileType type = new CustomExternalFileType(new SimpleStringProperty(""), new SimpleStringProperty(""), new SimpleStringProperty(""), new SimpleStringProperty(""), new SimpleStringProperty("new"), IconTheme.JabRefIcons.FILE); fileTypes.add(type); showEditDialog(type, Localization.lang("Add new file type")); } diff --git a/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeViewModel.java b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeViewModel.java index dc573aa2c36..2b34a73d0a9 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeViewModel.java +++ b/src/main/java/org/jabref/gui/externalfiletype/EditExternalFileTypeViewModel.java @@ -19,13 +19,13 @@ public class EditExternalFileTypeViewModel { public EditExternalFileTypeViewModel(CustomExternalFileType fileType) { this.fileType = fileType; - extensionProperty.setValue(fileType.getExtension()); - nameProperty.setValue(fileType.getName()); - mimeTypeProperty.setValue(fileType.getMimeType()); - selectedApplicationProperty.setValue(fileType.getOpenWithApplication()); + extensionProperty.setValue(fileType.getExtension().getValue()); + nameProperty.setValue(fileType.getName().getValue()); + mimeTypeProperty.setValue(fileType.getMimeType().getValue()); + selectedApplicationProperty.setValue(fileType.getOpenWithApplication().getValue()); icon = fileType.getIcon().getGraphicNode(); - if (fileType.getOpenWithApplication().isEmpty()) { + if (fileType.getOpenWithApplication().getValue().isEmpty()) { defaultApplicationSelectedProperty.setValue(true); } else { diff --git a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileType.java b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileType.java index 1e7c7a0315f..be328dfea39 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileType.java +++ b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileType.java @@ -1,15 +1,21 @@ package org.jabref.gui.externalfiletype; +import javafx.beans.property.StringProperty; + import org.jabref.gui.icon.JabRefIcon; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.FieldFactory; public interface ExternalFileType { - String getName(); + StringProperty getName(); + + String getNameAsString(); - String getExtension(); + StringProperty getExtension(); - String getMimeType(); + String getExtensionAsString(); + + StringProperty getMimeType(); /** * Get the bibtex field name used for this file type. @@ -18,10 +24,12 @@ public interface ExternalFileType { * @return The field name. */ default Field getField() { - return FieldFactory.parseField(getExtension()); + return FieldFactory.parseField(getExtension().getValue()); } - String getOpenWithApplication(); + StringProperty getOpenWithApplication(); JabRefIcon getIcon(); + + String toString(); } diff --git a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypes.java b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypes.java index 7e7d2836f1b..0aa11d646a2 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypes.java +++ b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypes.java @@ -26,7 +26,7 @@ public class ExternalFileTypes { // The only instance of this class: private static ExternalFileTypes singleton; // Map containing all registered external file types: - private final Set externalFileTypes = new TreeSet<>(Comparator.comparing(ExternalFileType::getName)); + private final Set externalFileTypes = new TreeSet<>(Comparator.comparing(ExternalFileType::getNameAsString)); private final ExternalFileType HTML_FALLBACK_TYPE = StandardExternalFileType.URL; @@ -72,7 +72,7 @@ public Optional getExternalFileTypeByName(String name) { */ public Optional getExternalFileTypeByExt(String extension) { String extensionCleaned = extension.replace(".", "").replace("*", ""); - return externalFileTypes.stream().filter(type -> type.getExtension().equalsIgnoreCase(extensionCleaned)).findFirst(); + return externalFileTypes.stream().filter(type -> type.getExtension().getValue().equalsIgnoreCase(extensionCleaned)).findFirst(); } /** @@ -82,7 +82,7 @@ public Optional getExternalFileTypeByExt(String extension) { * @return true if an ExternalFileType with the extension exists, false otherwise */ public boolean isExternalFileTypeByExt(String extension) { - return externalFileTypes.stream().anyMatch(type -> type.getExtension().equalsIgnoreCase(extension)); + return externalFileTypes.stream().anyMatch(type -> type.getExtension().getValue().equalsIgnoreCase(extension)); } /** @@ -95,9 +95,9 @@ public Optional getExternalFileTypeForName(String filename) { int longestFound = -1; ExternalFileType foundType = null; for (ExternalFileType type : externalFileTypes) { - if (!type.getExtension().isEmpty() && filename.toLowerCase(Locale.ROOT).endsWith(type.getExtension().toLowerCase(Locale.ROOT)) - && (type.getExtension().length() > longestFound)) { - longestFound = type.getExtension().length(); + if (!type.getExtension().getValue().isEmpty() && filename.toLowerCase(Locale.ROOT).endsWith(type.getExtension().getValue().toLowerCase(Locale.ROOT)) + && (type.getExtension().getValue().length() > longestFound)) { + longestFound = type.getExtension().getValue().length(); foundType = type; } } @@ -113,7 +113,7 @@ public Optional getExternalFileTypeForName(String filename) { */ public Optional getExternalFileTypeByMimeType(String mimeType) { for (ExternalFileType type : externalFileTypes) { - if (type.getMimeType().equalsIgnoreCase(mimeType)) { + if (type.getMimeType().getValue().equalsIgnoreCase(mimeType)) { return Optional.of(type); } } @@ -176,7 +176,7 @@ public void setExternalFileTypes(List types) { i++; } for (ExternalFileType type : defTypes) { - array[i] = new String[] {type.getName(), FILE_TYPE_REMOVED_FLAG}; + array[i] = new String[] {type.getName().getValue(), FILE_TYPE_REMOVED_FLAG}; i++; } Globals.prefs.put(JabRefPreferences.EXTERNAL_FILE_TYPES, FileFieldWriter.encodeStringArray(array)); @@ -190,7 +190,7 @@ public void setExternalFileTypes(List types) { * @return A String[] containing all information about this file type. */ private String[] getStringArrayRepresentation(ExternalFileType type) { - return new String[]{type.getName(), type.getExtension(), type.getMimeType(), type.getOpenWithApplication(), type.getIcon().name()}; + return new String[]{type.getName().getValue(), type.getExtension().getValue(), type.getMimeType().getValue(), type.getOpenWithApplication().getValue(), type.getIcon().name()}; } /** diff --git a/src/main/java/org/jabref/gui/externalfiletype/StandardExternalFileType.java b/src/main/java/org/jabref/gui/externalfiletype/StandardExternalFileType.java index 92718e09a7a..e5693517f72 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/StandardExternalFileType.java +++ b/src/main/java/org/jabref/gui/externalfiletype/StandardExternalFileType.java @@ -1,5 +1,8 @@ package org.jabref.gui.externalfiletype; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + import org.jabref.gui.icon.IconTheme; import org.jabref.gui.icon.JabRefIcon; import org.jabref.logic.l10n.Localization; @@ -30,42 +33,52 @@ public enum StandardExternalFileType implements ExternalFileType { MHT("MHT", "mht", "multipart/related", "firefox", "www", IconTheme.JabRefIcons.WWW), ePUB("ePUB", "epub", "application/epub+zip", "firefox", "www", IconTheme.JabRefIcons.WWW); - private final String name; - private final String extension; - private final String mimeType; - private final String openWith; - private final String iconName; + private final StringProperty name; + private final StringProperty extension; + private final StringProperty mimeType; + private final StringProperty openWith; + private final StringProperty iconName; private final JabRefIcon icon; StandardExternalFileType(String name, String extension, String mimeType, String openWith, String iconName, JabRefIcon icon) { - this.name = name; - this.extension = extension; - this.mimeType = mimeType; - this.openWith = openWith; - this.iconName = iconName; + this.name = new SimpleStringProperty(name); + this.extension = new SimpleStringProperty(extension); + this.mimeType = new SimpleStringProperty(mimeType); + this.openWith = new SimpleStringProperty(openWith); + this.iconName = new SimpleStringProperty(iconName); this.icon = icon; } @Override - public String getName() { + public StringProperty getName() { return name; } @Override - public String getExtension() { + public String getNameAsString() { + return name.getValue(); + } + + @Override + public StringProperty getExtension() { return extension; } @Override - public String getMimeType() { + public String getExtensionAsString() { + return extension.getValue(); + } + + @Override + public StringProperty getMimeType() { return mimeType; } @Override - public String getOpenWithApplication() { + public StringProperty getOpenWithApplication() { // On all OSes there is a generic application available to handle file opening, so use this one - return ""; + return new SimpleStringProperty(""); } @Override diff --git a/src/main/java/org/jabref/gui/externalfiletype/UnknownExternalFileType.java b/src/main/java/org/jabref/gui/externalfiletype/UnknownExternalFileType.java index 41be901f9e8..3e756463cdc 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/UnknownExternalFileType.java +++ b/src/main/java/org/jabref/gui/externalfiletype/UnknownExternalFileType.java @@ -1,5 +1,8 @@ package org.jabref.gui.externalfiletype; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + import org.jabref.gui.icon.IconTheme; import org.jabref.gui.icon.JabRefIcon; @@ -11,36 +14,46 @@ */ public class UnknownExternalFileType implements ExternalFileType { - private final String name; - private final String extension; + private final StringProperty name; + private final StringProperty extension; public UnknownExternalFileType(String name) { this(name, ""); } public UnknownExternalFileType(String name, String extension) { - this.name = name; - this.extension = extension; + this.name = new SimpleStringProperty(name); + this.extension = new SimpleStringProperty(extension); } @Override - public String getName() { + public StringProperty getName() { return name; } @Override - public String getExtension() { + public String getNameAsString() { + return name.getValue(); + } + + @Override + public StringProperty getExtension() { return extension; } @Override - public String getMimeType() { - return ""; + public String getExtensionAsString() { + return extension.getValue(); + } + + @Override + public StringProperty getMimeType() { + return new SimpleStringProperty(""); } @Override - public String getOpenWithApplication() { - return ""; + public StringProperty getOpenWithApplication() { + return new SimpleStringProperty(""); } @Override diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java index 103a352fd03..f6a0aa47e5a 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java @@ -421,7 +421,7 @@ public BackgroundTask prepareDownloadTask(Path targetDirectory, URLDownloa BackgroundTask downloadTask = BackgroundTask .wrap(() -> { Optional suggestedType = inferFileType(urlDownload); - String suggestedTypeName = suggestedType.orElse(StandardExternalFileType.PDF).getName(); + String suggestedTypeName = suggestedType.orElse(StandardExternalFileType.PDF).getName().getValue(); linkedFile.setFileType(suggestedTypeName); String suggestedName = linkedFileHandler.getSuggestedFileName(suggestedTypeName); diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java index 471af98aa2f..a1060de07ba 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java @@ -94,7 +94,7 @@ public static LinkedFile fromFile(Path file, List fileDirectories, Externa .getExternalFileTypeByExt(fileExtension) .orElse(new UnknownExternalFileType(fileExtension)); Path relativePath = FileUtil.relativize(file, fileDirectories); - return new LinkedFile("", relativePath.toString(), suggestedFileType.getName()); + return new LinkedFile("", relativePath.toString(), suggestedFileType.getName().getValue()); } public LinkedFileViewModel fromFile(Path file) { diff --git a/src/main/java/org/jabref/gui/filelist/FileListEntry.java b/src/main/java/org/jabref/gui/filelist/FileListEntry.java index 23ebefc2a92..9453c997fcf 100644 --- a/src/main/java/org/jabref/gui/filelist/FileListEntry.java +++ b/src/main/java/org/jabref/gui/filelist/FileListEntry.java @@ -38,7 +38,7 @@ public String[] getStringArrayRepresentation() { } private String getTypeName() { - return this.getType().isPresent() ? this.getType().get().getName() : ""; + return this.getType().isPresent() ? this.getType().get().getName().getValue() : ""; } @Override @@ -47,7 +47,7 @@ public String toString() { } public LinkedFile toParsedFileField() { - return new LinkedFile(getDescription(), getLink(), getType().isPresent() ? getType().get().getName() : ""); + return new LinkedFile(getDescription(), getLink(), getType().isPresent() ? getType().get().getName().getValue() : ""); } public String getDescription() { diff --git a/src/main/java/org/jabref/gui/preferences/TableColumnsTabViewModel.java b/src/main/java/org/jabref/gui/preferences/TableColumnsTabViewModel.java index 1990315fe01..ec80f59060a 100644 --- a/src/main/java/org/jabref/gui/preferences/TableColumnsTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/TableColumnsTabViewModel.java @@ -160,7 +160,7 @@ private void removeSpecialFieldColumns() { private void insertExtraFileColumns() { ExternalFileTypes.getInstance().getExternalFileTypeSelection().stream() .map(ExternalFileType::getName) - .map(name -> new MainTableColumnModel(MainTableColumnModel.Type.EXTRAFILE, name)) + .map(name -> new MainTableColumnModel(MainTableColumnModel.Type.EXTRAFILE, name.getValue())) .forEach(item -> availableColumnsProperty.getValue().add(item)); } From 3ddb71166cd88578a94f1baceb16536a9e6e4105 Mon Sep 17 00:00:00 2001 From: systemoperator <3658393+systemoperator@users.noreply.github.com> Date: Sun, 2 Feb 2020 18:35:23 +0100 Subject: [PATCH 5/5] add --- .../externalfiletype/CustomizeExternalFileTypesViewModel.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java b/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java index db3c3331c57..d2758a9899f 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java +++ b/src/main/java/org/jabref/gui/externalfiletype/CustomizeExternalFileTypesViewModel.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.Set; +import javafx.beans.Observable; import javafx.beans.property.SimpleStringProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; @@ -17,7 +18,8 @@ public class CustomizeExternalFileTypesViewModel { public CustomizeExternalFileTypesViewModel() { Set types = ExternalFileTypes.getInstance().getExternalFileTypeSelection(); - fileTypes = FXCollections.observableArrayList(types); + fileTypes = FXCollections.observableArrayList(extractor -> new Observable[] {extractor.getName(), extractor.getExtension(), extractor.getMimeType(), extractor.getOpenWithApplication()}); + fileTypes.addAll(types); fileTypes.sort(Comparator.comparing(ExternalFileType::getNameAsString)); }