Skip to content

Commit

Permalink
URL in clipboard is automatically filled when adding file from URL
Browse files Browse the repository at this point in the history
Closes #2
  • Loading branch information
Gpax971 committed Oct 22, 2022
1 parent 76bd95b commit e88fb1d
Showing 1 changed file with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
package org.jabref.gui.fieldeditors;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ListProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

import org.jabref.gui.ClipBoardManager;
import org.jabref.gui.DialogService;
import org.jabref.gui.autocompleter.SuggestionProvider;
import org.jabref.gui.externalfiles.AutoSetFileLinksUtil;
Expand All @@ -41,6 +32,15 @@
import org.jabref.preferences.FilePreferences;
import org.jabref.preferences.PreferencesService;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

public class LinkedFilesEditorViewModel extends AbstractEditorViewModel {

private final ListProperty<LinkedFileViewModel> files = new SimpleListProperty<>(FXCollections.observableArrayList(LinkedFileViewModel::getObservables));
Expand Down Expand Up @@ -214,8 +214,16 @@ public void fetchFulltext() {
}

public void addFromURL() {
Optional<String> urlText = dialogService.showInputDialogAndWait(
Localization.lang("Download file"), Localization.lang("Enter URL to download"));
String clipText = ClipBoardManager.getContents();
Optional<String> urlText;
if (clipText.startsWith("http://") || clipText.startsWith("https://") || clipText.startsWith("ftp://")) {
urlText = dialogService.showInputDialogWithDefaultAndWait(
Localization.lang("Download file"), Localization.lang("Enter URL to download"), clipText);
} else {
urlText = dialogService.showInputDialogAndWait(
Localization.lang("Download file"), Localization.lang("Enter URL to download"));

}
if (urlText.isPresent()) {
try {
URL url = new URL(urlText.get());
Expand Down

0 comments on commit e88fb1d

Please sign in to comment.