Skip to content

Commit

Permalink
Rework File links logic (#2529)
Browse files Browse the repository at this point in the history
* Add file link button now appends to the file list

* Download from URL will set file link at first position #2453

* Resolves #2453 Download from URL will set file link at first position
  • Loading branch information
stefan-kolb authored and Siedlerchr committed Feb 8, 2017
1 parent a01edc4 commit 89eb15c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ public void update() {
basePanel.getBibDatabaseContext(), entry);
try {
def.download(result.get(), file -> {
FileListTableModel tm = new FileListTableModel();
entry.getField(FieldName.FILE).ifPresent(tm::setContent);
tm.addEntry(tm.getRowCount(), file);
String newValue = tm.getStringRepresentation();
FileListTableModel fileLinkModel = new FileListTableModel();
entry.getField(FieldName.FILE).ifPresent(fileLinkModel::setContent);
// add full text file link at first position
fileLinkModel.addEntry(0, file);
String newValue = fileLinkModel.getStringRepresentation();
UndoableFieldChange edit = new UndoableFieldChange(entry, FieldName.FILE,
entry.getField(FieldName.FILE).orElse(null), newValue);
entry.setField(FieldName.FILE, newValue);
Expand Down
32 changes: 14 additions & 18 deletions src/main/java/net/sf/jabref/gui/fieldeditors/FileListEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -338,26 +338,24 @@ public String getSelectedText() {
return null;
}

private void addEntry(String initialLink) {
int row = getSelectedRow();
if (row == -1) {
row = 0;
}
FileListEntry entry = new FileListEntry("", initialLink);
if (editListEntry(entry, true)) {
tableModel.addEntry(row, entry);
}
entryEditor.updateField(this);
adjustColumnWidth();
}

/**
* Will append a new file link at the last position
*/
private void addEntry() {
List<String> defaultDirectory = databaseContext.getFileDirectories(Globals.prefs.getFileDirectoryPreferences());

FileListEntry entry;
if (defaultDirectory.isEmpty() || (defaultDirectory.get(0) == null)) {
addEntry("");
entry = new FileListEntry("", "");
} else {
addEntry(defaultDirectory.get(0));
entry = new FileListEntry("", defaultDirectory.get(0));
}

if (editListEntry(entry, true)) {
tableModel.addEntry(tableModel.getRowCount(), entry);
}
entryEditor.updateField(this);
adjustColumnWidth();
}

private void removeEntries() {
Expand Down Expand Up @@ -474,14 +472,12 @@ private void downloadFile() {
*/
@Override
public void downloadComplete(FileListEntry file) {
tableModel.addEntry(tableModel.getRowCount(), file);
tableModel.addEntry(0, file);
entryEditor.updateField(this);
adjustColumnWidth();
}


class TableClickListener extends MouseAdapter {

@Override
public void mouseClicked(MouseEvent e) {
if ((e.getButton() == MouseEvent.BUTTON1) && (e.getClickCount() == 2)) {
Expand Down

0 comments on commit 89eb15c

Please sign in to comment.