Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into pushtoApplication
Browse files Browse the repository at this point in the history
* upstream/master:
  Add option for direct attached file renaming (#4887)
  Fixed Closing of the Shared Database Login Dialog if the user enters wrong authentication details - #4857 (#4892)

# Conflicts:
#	src/main/resources/l10n/JabRef_en.properties
  • Loading branch information
Siedlerchr committed Apr 18, 2019
2 parents f7cba5b + e230a95 commit b40e511
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We made modifications to improve contrast of UI elements. [#4583](https://github.com/JabRef/jabref/issues/4583)
- We added an option in the settings to set the default action in JabRef when right clicking on any entry in any database and selecting "Open folder". [#4763](https://github.com/JabRef/jabref/issues/4763)
- The Medline fetcher now normalizes the author names according to the BibTeX-Standard [#4345](https://github.com/JabRef/jabref/issues/4345)
- We added an option on the Linked File Viewer to rename the attached file of an entry directly on the JabRef. [#4844](https://github.com/JabRef/jabref/issues/4844)


### Fixed
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/jabref/gui/DialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ default <T> Optional<T> showChoiceDialogAndWait(String title, String content, St
*/
Optional<String> showInputDialogAndWait(String title, String content);

/**
* This will create and display new {@link TextInputDialog} with a text field with a default value to enter data
*/
Optional<String> showInputDialogWithDefaultAndWait(String title, String content, String defaultValue);

/**
* This will create and display a new information dialog.
* It will include a blue information icon on the left and
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/jabref/gui/JabRefDialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ public Optional<String> showInputDialogAndWait(String title, String content) {
return inputDialog.showAndWait();
}

@Override
public Optional<String> showInputDialogWithDefaultAndWait(String title, String content, String defaultValue) {
TextInputDialog inputDialog = new TextInputDialog(defaultValue);
inputDialog.setHeaderText(title);
inputDialog.setContentText(content);
return inputDialog.showAndWait();
}

@Override
public void showInformationDialogAndWait(String title, String content) {
FXDialog alert = createDialog(AlertType.INFORMATION, title, content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.jabref.logic.externalfiles.LinkedFileHandler;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.net.URLDownload;
import org.jabref.logic.util.io.FileUtil;
import org.jabref.logic.xmp.XmpPreferences;
import org.jabref.logic.xmp.XmpUtilWriter;
import org.jabref.model.database.BibDatabaseContext;
Expand Down Expand Up @@ -344,7 +345,6 @@ public boolean delete() {
}

public void edit() {

LinkedFileEditDialogView dialog = new LinkedFileEditDialogView(this.linkedFile);

Optional<LinkedFile> editedFile = dialog.showAndWait();
Expand All @@ -355,6 +355,17 @@ public void edit() {
});
}

public void renameFile() {
String oldFile = this.linkedFile.getLink();
Path oldFilePath = Paths.get(oldFile);
Optional<String> editedFile = dialogService.showInputDialogWithDefaultAndWait(Localization.lang("Rename file"), Localization.lang("New Filename"), oldFilePath.getFileName().toString());
editedFile.ifPresent(file -> {
Path newFile = Paths.get(oldFile).resolveSibling(file);
this.linkedFile.setLink(newFile.toString());
FileUtil.renameFile(Paths.get(oldFile), newFile);
});
}

public void writeXMPMetadata() {
// Localization.lang("Writing XMP-metadata...")
BackgroundTask<Void> writeTask = BackgroundTask.wrap(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,13 @@ private ContextMenu createContextMenuForFile(LinkedFileViewModel linkedFile) {
MenuItem download = new MenuItem(Localization.lang("Download file"));
download.setOnAction(event -> linkedFile.download());

MenuItem renameFile = new MenuItem(Localization.lang("Rename file"));
MenuItem renameFile = new MenuItem(Localization.lang("Rename file to defined pattern"));
renameFile.setOnAction(event -> linkedFile.rename());
renameFile.setDisable(linkedFile.getFile().isOnlineLink() || linkedFile.isGeneratedNameSameAsOriginal());

MenuItem renameFileName = new MenuItem(Localization.lang("Rename file to a given name"));
renameFileName.setOnAction(event -> linkedFile.renameFile());

MenuItem moveFile = new MenuItem(Localization.lang("Move file to file directory"));
moveFile.setOnAction(event -> linkedFile.moveToDefaultDirectory());
moveFile.setDisable(linkedFile.getFile().isOnlineLink() || linkedFile.isGeneratedPathSameAsOriginal());
Expand All @@ -244,7 +247,7 @@ private ContextMenu createContextMenuForFile(LinkedFileViewModel linkedFile) {
if (linkedFile.getFile().isOnlineLink()) {
menu.getItems().add(download);
}
menu.getItems().addAll(renameFile, moveFile, renameAndMoveFile, deleteLink, deleteFile);
menu.getItems().addAll(renameFile, renameFileName, moveFile, renameAndMoveFile, deleteLink, deleteFile);

return menu;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ public SharedDatabaseLoginDialogView(JabRefFrame frame) {

@FXML
private void openDatabase() {
viewModel.openDatabase();
this.close();
boolean connected = viewModel.openDatabase();

if (connected) {
this.close();
}
}

@FXML
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public SharedDatabaseLoginDialogViewModel(JabRefFrame frame, DialogService dialo
applyPreferences();
}

public void openDatabase() {
public boolean openDatabase() {

DBMSConnectionProperties connectionProperties = new DBMSConnectionProperties();
connectionProperties.setType(selectedDBMSType.getValue());
Expand All @@ -122,7 +122,8 @@ public void openDatabase() {
connectionProperties.setServerTimezone(serverTimezone.getValue());

setupKeyStore();
openSharedDatabase(connectionProperties);
boolean connected = openSharedDatabase(connectionProperties);
return connected;
}

private void setupKeyStore() {
Expand All @@ -131,12 +132,12 @@ private void setupKeyStore() {
System.setProperty("javax.net.debug", "ssl");
}

private void openSharedDatabase(DBMSConnectionProperties connectionProperties) {
private boolean openSharedDatabase(DBMSConnectionProperties connectionProperties) {
if (isSharedDatabaseAlreadyPresent(connectionProperties)) {

dialogService.showWarningDialogAndWait(Localization.lang("Shared database connection"),
Localization.lang("You are already connected to a database using entered connection details."));
return;
return true;
}

if (autosave.get()) {
Expand All @@ -149,7 +150,7 @@ private void openSharedDatabase(DBMSConnectionProperties connectionProperties) {
Localization.lang("Overwrite file"),
Localization.lang("Cancel"));
if (!overwriteFilePressed) {
return;
return true;
}
}
}
Expand All @@ -169,7 +170,7 @@ private void openSharedDatabase(DBMSConnectionProperties connectionProperties) {
}
}

return;
return true;
} catch (SQLException | InvalidDBMSConnectionPropertiesException exception) {

frame.getDialogService().showErrorDialogAndWait(Localization.lang("Connection error"), exception);
Expand All @@ -191,7 +192,7 @@ private void openSharedDatabase(DBMSConnectionProperties connectionProperties) {

}
loading.set(false);

return false;
}

private void setPreferences() {
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2088,4 +2088,9 @@ A\ string\ with\ the\ label\ '%0'\ already\ exists.=A string with the label '%0'
Executing\ command\ "%0"...=Executing command "%0"...
Rename\ file\ to\ a\ given\ name=Rename file to a given name
New\ Filename=New Filename
Rename\ file\ to\ defined\ pattern=Rename file to defined pattern
App\ settings=App settings

0 comments on commit b40e511

Please sign in to comment.