Skip to content

Commit

Permalink
Fix File Filter and some layout issues (JabRef#7385)
Browse files Browse the repository at this point in the history
* Fix File Filter and some layout issues

Fixes part of JabRef#7383

* better min width

* Any file instead of all

* remove style class

* l10n

Co-authored-by: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com>
  • Loading branch information
Siedlerchr and calixtus committed Jan 29, 2021
1 parent 034cf8c commit ec88998
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/Base.css
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,6 @@ TextFlow * {

}

.mainTable-header{
.mainTable-header {
-fx-fill: -fx-mid-text-color;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class FileExtensionViewModel {
private final ExternalFileTypes externalFileTypes;

FileExtensionViewModel(FileType fileType, ExternalFileTypes externalFileTypes) {
this.description = Localization.lang("%0 file", fileType.toString());
this.description = Localization.lang("%0 file", fileType.getName());
this.extensions = fileType.getExtensionsWithDot();
this.externalFileTypes = externalFileTypes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private FileNodeViewModel searchDirectory(Path directory, UnlinkedPDFFileFilter
Map<Boolean, List<Path>> fileListPartition;

try (Stream<Path> filesStream = StreamSupport.stream(Files.newDirectoryStream(directory, fileFilter).spliterator(), false)) {
fileListPartition = filesStream.collect(Collectors.partitioningBy(path -> path.toFile().isDirectory()));
fileListPartition = filesStream.collect(Collectors.partitioningBy(Files::isDirectory));
} catch (IOException e) {
LOGGER.error(String.format("%s while searching files: %s", e.getClass().getName(), e.getMessage()));
return parent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
<ColumnConstraints hgrow="SOMETIMES"/>
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="20.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="20.0" vgrow="SOMETIMES"/>
</rowConstraints>
<Label text="%Start directory:" GridPane.columnIndex="0" GridPane.rowIndex="0"/>
<TextField fx:id="directoryPathField" GridPane.columnIndex="1" GridPane.rowIndex="0"/>
<Button onAction="#browseFileDirectory" styleClass="icon-button,narrow"
GridPane.columnIndex="2" GridPane.rowIndex="0"
prefHeight="20.0" prefWidth="20.0">
minWidth="20.0" minHeight="20.0" prefHeight="20.0" prefWidth="20.0">
<graphic>
<JabRefIconView glyph="OPEN"/>
</graphic>
Expand All @@ -50,9 +50,9 @@
</tooltip>
</Button>

<Label text="%File extension:" GridPane.columnIndex="0" GridPane.rowIndex="1"/>
<Label text="%File type:" GridPane.columnIndex="0" GridPane.rowIndex="1"/>
<ComboBox fx:id="fileTypeCombo" maxWidth="Infinity" GridPane.columnIndex="1" GridPane.rowIndex="1"/>
<Button fx:id="scanButton" onAction="#scanFiles" text="%Scan directory"
<Button fx:id="scanButton" onAction="#scanFiles" text="%Search"
GridPane.columnIndex="2" GridPane.rowIndex="1">
<tooltip>
<Tooltip text="%Searches the selected directory for unlinked files."/>
Expand All @@ -71,11 +71,11 @@
<TableView fx:id="importResultTable">
<columns>
<TableColumn fx:id="colStatus" prefWidth="100.0" text="%Status"/>
<TableColumn fx:id="colMessage" prefWidth="300.0" text="%Message"/>
<TableColumn fx:id="colFile" prefWidth="500.0" text="%File"/>
<TableColumn fx:id="colMessage" prefWidth="300.0" text="%Message"/>
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/>
<TableView fx:constant="UNCONSTRAINED_RESIZE_POLICY"/>
</columnResizePolicy>
</TableView>
</TitledPane>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.DirectoryStream.Filter;
import java.nio.file.Files;
import java.nio.file.Path;

import org.jabref.logic.util.io.DatabaseFileLookup;
Expand Down Expand Up @@ -31,6 +32,11 @@ public UnlinkedPDFFileFilter(DirectoryStream.Filter<Path> fileFilter, BibDatabas

@Override
public boolean accept(Path pathname) throws IOException {
return fileFilter.accept(pathname) && !lookup.lookupDatabase(pathname.toFile());

if (Files.isDirectory(pathname)) {
return true;
} else {
return fileFilter.accept(pathname) && !lookup.lookupDatabase(pathname);
}
}
}
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/logic/util/FileType.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ default List<String> getExtensionsWithDot() {
}

List<String> getExtensions();

String getName();
}
78 changes: 42 additions & 36 deletions src/main/java/org/jabref/logic/util/StandardFileType.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,58 +10,64 @@
*/
public enum StandardFileType implements FileType {

BIBTEXML("bibx", "xml"),
ENDNOTE("ref", "enw"),
ISI("isi", "txt"),
MEDLINE("nbib", "xml"),
MEDLINE_PLAIN("nbib", "txt"),
PUBMED("fcgi"),
SILVER_PLATTER("dat", "txt"),

AUX("aux"),
BIBTEX_DB("bib"),
CITATION_STYLE("csl"),
CLASS("class"),
CSV("csv"),
HTML("html", "htm"),
JAR("jar"),
JAVA_KEYSTORE("jks"),
JSTYLE("jstyle"),
LAYOUT("layout"),
ODS("ods"),
PDF("pdf"),
RIS("ris"),
TERMS("terms"),
TXT("txt"),
RDF("rdf"),
RTF("rtf"),
SXC("sxc"),
TEX("tex"),
XML("xml"),
JSON("json"),
XMP("xmp"),
ZIP("zip"),
CSS("css"),
YAML("yaml"),
ANY_FILE("*");
BIBTEXML("BibTeXML", "bibx", "xml"),
ENDNOTE("Endnote", "ref", "enw"),
ISI("Isi", "isi", "txt"),
MEDLINE("Medline", "nbib", "xml"),
MEDLINE_PLAIN("Medline Plain", "nbib", "txt"),
PUBMED("Pubmed", "fcgi"),
SILVER_PLATTER("SilverPlatter", "dat", "txt"),
AUX("Aux file", "aux"),
BIBTEX_DB("Bibtex library", "bib"),
CITATION_STYLE("Citation Style", "csl"),
CLASS("Class file", "class"),
CSV("CSV", "csv"),
HTML("HTML", "html", "htm"),
JAR("JAR", "jar"),
JAVA_KEYSTORE("Java Keystore", "jks"),
JSTYLE("LibreOffice layout style", "jstyle"),
LAYOUT("Custom Exporter format", "layout"),
ODS("OpenOffice Calc", "ods"),
PDF("PDF", "pdf"),
RIS("RIS", "ris"),
TERMS("Protected terms", "terms"),
TXT("Plain Text", "txt"),
RDF("RDF", "rdf"),
RTF("RTF", "rtf"),
SXC("Open Office Calc 1.x", "sxc"),
TEX("LaTeX", "tex"),
XML("XML", "xml"),
JSON("JSON", "json"),
XMP("XMP", "xmp"),
ZIP("Zip Archive", "zip"),
CSS("CSS Styleshet", "css"),
YAML("YAML Markup", "yaml"),
ANY_FILE("Any", "*");

private final List<String> extensions;
private final String name;

StandardFileType(String... extensions) {
StandardFileType(String name, String... extensions) {
this.extensions = Arrays.asList(extensions);
this.name = name;
}

@Override
public List<String> getExtensions() {
return extensions;
}

@Override
public String getName() {
return this.name;
}

public static FileType fromExtensions(String... extensions) {
var exts = Arrays.asList(extensions);

return OptionalUtil.orElse(Arrays.stream(StandardFileType.values())
.filter(field -> field.getExtensions().stream().anyMatch(elem -> exts.contains(elem)))
.findAny(),
new UnknownFileType(extensions));
new UnknownFileType(extensions));
}
}
5 changes: 5 additions & 0 deletions src/main/java/org/jabref/logic/util/UnknownFileType.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(extensions);
}

@Override
public String getName() {
return "Unknown File Type" + extensions.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ public DatabaseFileLookup(BibDatabaseContext databaseContext, FilePreferences fi
* <br>
* For the matching, the absolute file paths will be used.
*
* @param file A {@link File} Object.
* @param pathname A {@link File} Object.
* @return <code>true</code>, if the file Object is stored in at least one
* entry in the database, otherwise <code>false</code>.
*/
public boolean lookupDatabase(File file) {
return fileCache.contains(file.toPath());
public boolean lookupDatabase(Path pathname) {
return fileCache.contains(pathname);
}

private List<Path> parseFileField(BibEntry entry) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1107,10 +1107,10 @@ Unable\ to\ clear\ preferences.=Unable to clear preferences.
Unselect\ all=Unselect all
Expand\ all=Expand all
Collapse\ all=Collapse all
Scan\ directory=Scan directory
Searches\ the\ selected\ directory\ for\ unlinked\ files.=Searches the selected directory for unlinked files.
Starts\ the\ import\ of\ BibTeX\ entries.=Starts the import of BibTeX entries.
Start\ directory\:=Start directory:
File\ type\:=File type:
Currently\ unlinked\ files=Currently unlinked files
Import\ result=Import result
Searching\ file\ system...=Searching file system...
Expand Down

0 comments on commit ec88998

Please sign in to comment.