Skip to content

Commit

Permalink
Add Remove link context menu entry in file editor (#2972)
Browse files Browse the repository at this point in the history
  • Loading branch information
Siedlerchr authored Jul 10, 2017
1 parent f81db54 commit d972f45
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/gui/FXDialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import javafx.scene.control.ButtonType;
import javafx.scene.control.DialogPane;
import javafx.scene.control.TextInputDialog;
import javafx.scene.layout.Region;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;

Expand All @@ -37,6 +38,7 @@ private static FXDialog createDialog(AlertType type, String title, String conten
FXDialog alert = new FXDialog(type, title, true);
alert.setHeaderText(null);
alert.setContentText(content);
alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
return alert;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public boolean delete() {
if (file.isPresent()) {

ButtonType removeFromEntry = new ButtonType(Localization.lang("Remove from entry"));

ButtonType deleteFromEntry = new ButtonType(Localization.lang("Delete from disk"));
Optional<ButtonType> buttonType = dialogService.showCustomButtonDialogAndWait(AlertType.INFORMATION,
Localization.lang("Delete '%0'", file.get().toString()),
Expand Down
26 changes: 15 additions & 11 deletions src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
public class LinkedFilesEditor extends HBox implements FieldEditorFX {

private final String fieldName;
@FXML private LinkedFilesEditorViewModel viewModel;
@FXML private final LinkedFilesEditorViewModel viewModel;
@FXML private ListView<LinkedFileViewModel> listView;

public LinkedFilesEditor(String fieldName, DialogService dialogService, BibDatabaseContext databaseContext, TaskExecutor taskExecutor) {
Expand Down Expand Up @@ -79,15 +79,15 @@ private void setUpKeyBindings() {
Optional<KeyBinding> keyBinding = Globals.getKeyPrefs().mapToKeyBinding(event);
if (keyBinding.isPresent()) {
switch (keyBinding.get()) {
case DELETE_ENTRY:
LinkedFileViewModel selectedItem = listView.getSelectionModel().getSelectedItem();
if (selectedItem != null) {
viewModel.deleteFile(selectedItem);
}
event.consume();
break;
default:
// Pass other keys to children
case DELETE_ENTRY:
LinkedFileViewModel selectedItem = listView.getSelectionModel().getSelectedItem();
if (selectedItem != null) {
viewModel.deleteFile(selectedItem);
}
event.consume();
break;
default:
// Pass other keys to children
}
}
});
Expand Down Expand Up @@ -146,11 +146,15 @@ private ContextMenu createContextMenuForFile(LinkedFileViewModel linkedFile) {
deleteFile.setOnAction(event -> viewModel.deleteFile(linkedFile));
deleteFile.setDisable(linkedFile.getFile().isOnlineLink());

MenuItem deleteLink = new MenuItem(Localization.lang("Remove link"));
deleteLink.setOnAction(event -> viewModel.removeFileLink(linkedFile));
deleteLink.setDisable(linkedFile.getFile().isOnlineLink());

menu.getItems().add(edit);
menu.getItems().add(new SeparatorMenuItem());
menu.getItems().addAll(openFile, openFolder);
menu.getItems().add(new SeparatorMenuItem());
menu.getItems().addAll(renameFile, moveFile, deleteFile);
menu.getItems().addAll(renameFile, moveFile, deleteLink, deleteFile);

return menu;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@
import org.apache.commons.logging.LogFactory;

public class LinkedFilesEditorViewModel extends AbstractEditorViewModel {

private static final Log LOGGER = LogFactory.getLog(LinkedFilesEditorViewModel.class);

private ListProperty<LinkedFileViewModel> files = new SimpleListProperty<>(FXCollections.observableArrayList(LinkedFileViewModel::getObservables));
private BooleanProperty fulltextLookupInProgress = new SimpleBooleanProperty(false);
private DialogService dialogService;
private BibDatabaseContext databaseContext;
private TaskExecutor taskExecutor;
private final ListProperty<LinkedFileViewModel> files = new SimpleListProperty<>(FXCollections.observableArrayList(LinkedFileViewModel::getObservables));
private final BooleanProperty fulltextLookupInProgress = new SimpleBooleanProperty(false);
private final DialogService dialogService;
private final BibDatabaseContext databaseContext;
private final TaskExecutor taskExecutor;

public LinkedFilesEditorViewModel(DialogService dialogService, BibDatabaseContext databaseContext, TaskExecutor taskExecutor) {
this.dialogService = dialogService;
Expand All @@ -63,8 +64,7 @@ public LinkedFilesEditorViewModel(DialogService dialogService, BibDatabaseContex
files,
text,
LinkedFilesEditorViewModel::getStringRepresentation,
this::parseToFileViewModel
);
this::parseToFileViewModel);
}

private static String getStringRepresentation(List<LinkedFileViewModel> files) {
Expand Down Expand Up @@ -126,8 +126,7 @@ public void addNewFile() {
newFile -> {
LinkedFile newLinkedFile = fromFile(newFile, fileDirectories);
files.add(new LinkedFileViewModel(newLinkedFile, entry, databaseContext));
}
);
});
}

@Override
Expand Down Expand Up @@ -193,8 +192,7 @@ public void addFromURL() {
} catch (MalformedURLException exception) {
dialogService.showErrorDialogAndWait(
Localization.lang("Invalid URL"),
exception
);
exception);
}
}
}
Expand All @@ -217,8 +215,7 @@ private void addFromURL(URL url) {
LinkedFile newLinkedFile = fromFile(destination, fileDirectories);
files.add(new LinkedFileViewModel(newLinkedFile, entry, databaseContext));
});
downloadTask.setOnFailed(event ->
dialogService.showErrorDialogAndWait("", downloadTask.getException()));
downloadTask.setOnFailed(event -> dialogService.showErrorDialogAndWait("", downloadTask.getException()));
taskExecutor.execute(downloadTask);
}

Expand Down Expand Up @@ -303,4 +300,8 @@ public void deleteFile(LinkedFileViewModel file) {
files.remove(file);
}
}

public void removeFileLink(LinkedFileViewModel file) {
files.remove(file);
}
}

0 comments on commit d972f45

Please sign in to comment.