diff --git a/src/main/java/org/jabref/gui/Base.css b/src/main/java/org/jabref/gui/Base.css index ec78513a06b..ab4097899cc 100644 --- a/src/main/java/org/jabref/gui/Base.css +++ b/src/main/java/org/jabref/gui/Base.css @@ -975,3 +975,21 @@ We want to have a look that matches our icons in the tool-bar */ .color-palette-region .button { -fx-border-width: 0px; } + + +.warning-icon { + -fx-fill: -jr-warn; +} + +.error-icon { + -fx-text-fill: -jr-error; + -fx-fill: -jr-error; +} + +.tooltip-warning { + -fx-background-color: -jr-warn; +} + +.tooltip-error { + -fx-background-color: -jr-error; +} diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 777c06eaf6f..ef5e2875994 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -150,7 +150,6 @@ public class BasePanel extends StackPane { // Used to track whether the base has changed since last save. private BibEntry showing; - private StringDialog stringDialog; private SuggestionProviders suggestionProviders; @SuppressWarnings({"FieldCanBeLocal", "unused"}) private Subscription dividerPositionSubscription; @@ -308,17 +307,6 @@ private void setupActions() { actions.put(Actions.SELECT_ALL, mainTable.getSelectionModel()::selectAll); - // The action for opening the string editor - actions.put(Actions.EDIT_STRINGS, () -> { - if (stringDialog == null) { - StringDialog form = new StringDialog(frame, BasePanel.this, bibDatabaseContext.getDatabase()); - form.setVisible(true); - stringDialog = form; - } else { - stringDialog.setVisible(true); - } - }); - // The action for auto-generating keys. actions.put(Actions.MAKE_KEY, new GenerateBibtexKeyAction(this, frame.getDialogService())); @@ -374,36 +362,36 @@ private void setupActions() { actions.put(Actions.MERGE_WITH_FETCHED_ENTRY, new MergeWithFetchedEntryAction(this, frame.getDialogService())); - actions.put(Actions.REPLACE_ALL, ()-> (new ReplaceStringAction(this)).execute()); + actions.put(Actions.REPLACE_ALL, () -> (new ReplaceStringAction(this)).execute()); actions.put(new SpecialFieldValueViewModel(SpecialField.RELEVANCE.getValues().get(0)).getCommand(), - new SpecialFieldViewModel(SpecialField.RELEVANCE, undoManager).getSpecialFieldAction(SpecialField.RELEVANCE.getValues().get(0), frame)); + new SpecialFieldViewModel(SpecialField.RELEVANCE, undoManager).getSpecialFieldAction(SpecialField.RELEVANCE.getValues().get(0), frame)); actions.put(new SpecialFieldValueViewModel(SpecialField.QUALITY.getValues().get(0)).getCommand(), - new SpecialFieldViewModel(SpecialField.QUALITY, undoManager).getSpecialFieldAction(SpecialField.QUALITY.getValues().get(0), frame)); + new SpecialFieldViewModel(SpecialField.QUALITY, undoManager).getSpecialFieldAction(SpecialField.QUALITY.getValues().get(0), frame)); actions.put(new SpecialFieldValueViewModel(SpecialField.PRINTED.getValues().get(0)).getCommand(), - new SpecialFieldViewModel(SpecialField.PRINTED, undoManager).getSpecialFieldAction(SpecialField.PRINTED.getValues().get(0), frame)); + new SpecialFieldViewModel(SpecialField.PRINTED, undoManager).getSpecialFieldAction(SpecialField.PRINTED.getValues().get(0), frame)); for (SpecialFieldValue prio : SpecialField.PRIORITY.getValues()) { actions.put(new SpecialFieldValueViewModel(prio).getCommand(), - new SpecialFieldViewModel(SpecialField.PRIORITY, undoManager).getSpecialFieldAction(prio, this.frame)); + new SpecialFieldViewModel(SpecialField.PRIORITY, undoManager).getSpecialFieldAction(prio, this.frame)); } for (SpecialFieldValue rank : SpecialField.RANKING.getValues()) { actions.put(new SpecialFieldValueViewModel(rank).getCommand(), - new SpecialFieldViewModel(SpecialField.RANKING, undoManager).getSpecialFieldAction(rank, this.frame)); + new SpecialFieldViewModel(SpecialField.RANKING, undoManager).getSpecialFieldAction(rank, this.frame)); } for (SpecialFieldValue status : SpecialField.READ_STATUS.getValues()) { actions.put(new SpecialFieldValueViewModel(status).getCommand(), - new SpecialFieldViewModel(SpecialField.READ_STATUS, undoManager).getSpecialFieldAction(status, this.frame)); + new SpecialFieldViewModel(SpecialField.READ_STATUS, undoManager).getSpecialFieldAction(status, this.frame)); } actions.put(Actions.TOGGLE_PREVIEW, () -> { PreviewPreferences previewPreferences = Globals.prefs.getPreviewPreferences(); boolean enabled = !previewPreferences.isPreviewPanelEnabled(); PreviewPreferences newPreviewPreferences = previewPreferences.getBuilder() - .withPreviewPanelEnabled(enabled) - .build(); + .withPreviewPanelEnabled(enabled) + .build(); Globals.prefs.storePreviewPreferences(newPreviewPreferences); DefaultTaskExecutor.runInJavaFXThread(() -> setPreviewActiveBasePanels(enabled)); }); @@ -496,9 +484,9 @@ private void copyTitle() { if (!selectedBibEntries.isEmpty()) { // Collect all non-null titles. List titles = selectedBibEntries.stream() - .filter(bibEntry -> bibEntry.getTitle().isPresent()) - .map(bibEntry -> bibEntry.getTitle().get()) - .collect(Collectors.toList()); + .filter(bibEntry -> bibEntry.getTitle().isPresent()) + .map(bibEntry -> bibEntry.getTitle().get()) + .collect(Collectors.toList()); if (titles.isEmpty()) { output(Localization.lang("None of the selected entries have titles.")); @@ -530,8 +518,8 @@ private void copyCiteKey() { String sb = String.join(",", keys); String citeCommand = Optional.ofNullable(Globals.prefs.get(JabRefPreferences.CITE_COMMAND)) - .filter(cite -> cite.contains("\\")) // must contain \ - .orElse("\\cite"); + .filter(cite -> cite.contains("\\")) // must contain \ + .orElse("\\cite"); Globals.clipboardManager.setContent(citeCommand + "{" + sb + '}'); if (keys.size() == bes.size()) { @@ -575,7 +563,7 @@ private void copyKeyAndTitle() { Layout layout; try { layout = new LayoutHelper(sr, Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader)) - .getLayoutFromText(); + .getLayoutFromText(); } catch (IOException e) { LOGGER.info("Could not get layout", e); return; @@ -719,12 +707,12 @@ private void createMainTable() { // Update entry editor and preview according to selected entries mainTable.addSelectionListener(event -> mainTable.getSelectedEntries() - .stream() - .findFirst() - .ifPresent(entry -> { - preview.setEntry(entry); - entryEditor.setEntry(entry); - })); + .stream() + .findFirst() + .ifPresent(entry -> { + preview.setEntry(entry); + entryEditor.setEntry(entry); + })); // TODO: Register these actions globally /* @@ -814,8 +802,8 @@ public void setupMainPanel() { // Saves the divider position as soon as it changes // We need to keep a reference to the subscription, otherwise the binding gets garbage collected dividerPositionSubscription = EasyBind.monadic(Bindings.valueAt(splitPane.getDividers(), 0)) - .flatMap(SplitPane.Divider::positionProperty) - .subscribe((observable, oldValue, newValue) -> saveDividerLocation(newValue)); + .flatMap(SplitPane.Divider::positionProperty) + .subscribe((observable, oldValue, newValue) -> saveDividerLocation(newValue)); } /** @@ -846,18 +834,6 @@ private void instantiateSearchAutoCompleter() { } } - public void assureStringDialogNotEditing() { - if (stringDialog != null) { - stringDialog.assureNotEditing(); - } - } - - public void updateStringDialog() { - if (stringDialog != null) { - stringDialog.refreshTable(); - } - } - private void adjustSplitter() { if (mode == BasePanelMode.SHOWING_PREVIEW) { splitPane.setDividerPositions(Globals.prefs.getPreviewPreferences().getPreviewPanelDividerPosition().doubleValue()); @@ -945,9 +921,9 @@ public void previousPreviewStyle() { private void cyclePreview(int newPosition) { PreviewPreferences previewPreferences = Globals.prefs.getPreviewPreferences() - .getBuilder() - .withPreviewCyclePosition(newPosition) - .build(); + .getBuilder() + .withPreviewCyclePosition(newPosition) + .build(); Globals.prefs.storePreviewPreferences(previewPreferences); preview.updateLayout(previewPreferences); @@ -997,7 +973,7 @@ public void entryEditorClosing(EntryEditor editor) { */ public void ensureNotShowingBottomPanel(BibEntry entry) { if (((mode == BasePanelMode.SHOWING_EDITOR) && (entryEditor.getEntry() == entry)) - || ((mode == BasePanelMode.SHOWING_PREVIEW) && (preview.getEntry() == entry))) { + || ((mode == BasePanelMode.SHOWING_PREVIEW) && (preview.getEntry() == entry))) { closeBottomPane(); } } @@ -1054,10 +1030,6 @@ public BibDatabase getDatabase() { return bibDatabaseContext.getDatabase(); } - public void stringsClosing() { - stringDialog = null; - } - public void changeTypeOfSelectedEntries(String newType) { List bes = mainTable.getSelectedEntries(); changeType(bes, newType); @@ -1105,11 +1077,11 @@ public boolean showDeleteConfirmationDialog(int numberOfEntries) { } return dialogService.showConfirmationDialogWithOptOutAndWait(title, - message, - okButton, - cancelButton, - Localization.lang("Disable this confirmation dialog"), - optOut -> Globals.prefs.putBoolean(JabRefPreferences.CONFIRM_DELETE, !optOut)); + message, + okButton, + cancelButton, + Localization.lang("Disable this confirmation dialog"), + optOut -> Globals.prefs.putBoolean(JabRefPreferences.CONFIRM_DELETE, !optOut)); } else { return true; } @@ -1125,16 +1097,15 @@ private void saveDividerLocation(Number position) { if (mode == BasePanelMode.SHOWING_PREVIEW) { PreviewPreferences previewPreferences = Globals.prefs.getPreviewPreferences() - .getBuilder() - .withPreviewPanelDividerPosition(position) - .build(); + .getBuilder() + .withPreviewPanelDividerPosition(position) + .build(); Globals.prefs.storePreviewPreferences(previewPreferences); } else if (mode == BasePanelMode.SHOWING_EDITOR) { preferences.setEntryEditorDividerPosition(position.doubleValue()); } } - /** * Perform necessary cleanup when this BasePanel is closed. */ @@ -1432,8 +1403,8 @@ public void action() { Optional linkedFile = files.stream() .filter(file -> (FieldName.URL.equalsIgnoreCase(file.getFileType()) - || FieldName.PS.equalsIgnoreCase(file.getFileType()) - || FieldName.PDF.equalsIgnoreCase(file.getFileType()))) + || FieldName.PS.equalsIgnoreCase(file.getFileType()) + || FieldName.PDF.equalsIgnoreCase(file.getFileType()))) .findFirst(); if (linkedFile.isPresent()) { @@ -1441,8 +1412,8 @@ public void action() { try { JabRefDesktop.openExternalFileAnyFormat(bibDatabaseContext, - linkedFile.get().getLink(), - ExternalFileTypes.getInstance().fromLinkedFile(linkedFile.get(), true)); + linkedFile.get().getLink(), + ExternalFileTypes.getInstance().fromLinkedFile(linkedFile.get(), true)); output(Localization.lang("External viewer called") + '.'); } catch (IOException e) { diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 8e4ca768b05..b657ee1e1db 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -98,6 +98,8 @@ import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.menus.FileHistoryMenu; import org.jabref.gui.mergeentries.MergeEntriesAction; +import org.jabref.gui.metadata.BibtexStringEditorAction; +import org.jabref.gui.metadata.PreambleEditor; import org.jabref.gui.push.PushToApplicationButton; import org.jabref.gui.push.PushToApplications; import org.jabref.gui.search.GlobalSearchBar; @@ -848,7 +850,8 @@ private MenuBar createMenu() { factory.createMenuItem(StandardActions.LIBRARY_PROPERTIES, new DatabasePropertiesAction(this)), factory.createMenuItem(StandardActions.EDIT_PREAMBLE, new PreambleEditor(this)), - factory.createMenuItem(StandardActions.EDIT_STRINGS, new OldDatabaseCommandWrapper(Actions.EDIT_STRINGS, this, Globals.stateManager)) + factory.createMenuItem(StandardActions.EDIT_STRINGS, new BibtexStringEditorAction(this)) + ); Menu lookupIdentifiers = factory.createSubMenu(StandardActions.LOOKUP_DOC_IDENTIFIER); @@ -857,6 +860,7 @@ private MenuBar createMenu() { lookupIdentifiers.getItems().add(factory.createMenuItem(identifierAction.getAction(), identifierAction)); } + //@formatter:off quality.getItems().addAll( factory.createMenuItem(StandardActions.FIND_DUPLICATES, new DuplicateSearch(this, dialogService)), factory.createMenuItem(StandardActions.MERGE_ENTRIES, new MergeEntriesAction(this)), @@ -971,7 +975,7 @@ private MenuBar createMenu() { ), factory.createMenuItem(StandardActions.ABOUT, new AboutAction()) ); - + //@formatter:on MenuBar menu = new MenuBar(); menu.getStyleClass().add("mainMenu"); menu.getMenus().addAll( diff --git a/src/main/java/org/jabref/gui/StringDialog.java b/src/main/java/org/jabref/gui/StringDialog.java deleted file mode 100644 index 1169b1f7dce..00000000000 --- a/src/main/java/org/jabref/gui/StringDialog.java +++ /dev/null @@ -1,455 +0,0 @@ -package org.jabref.gui; - -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Container; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.event.ActionEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.io.File; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ActionMap; -import javax.swing.DefaultCellEditor; -import javax.swing.InputMap; -import javax.swing.JComponent; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.JTextField; -import javax.swing.JToolBar; -import javax.swing.LayoutFocusTraversalPolicy; -import javax.swing.table.AbstractTableModel; -import javax.swing.table.TableColumnModel; -import javax.swing.undo.CompoundEdit; - -import org.jabref.Globals; -import org.jabref.gui.actions.Actions; -import org.jabref.gui.help.HelpAction; -import org.jabref.gui.icon.IconTheme; -import org.jabref.gui.keyboard.KeyBinding; -import org.jabref.gui.undo.UndoableInsertString; -import org.jabref.gui.undo.UndoableRemoveString; -import org.jabref.gui.undo.UndoableStringChange; -import org.jabref.gui.util.WindowLocation; -import org.jabref.logic.bibtex.InvalidFieldValueException; -import org.jabref.logic.bibtex.LatexFieldFormatter; -import org.jabref.logic.bibtex.comparator.BibtexStringComparator; -import org.jabref.logic.help.HelpFile; -import org.jabref.logic.l10n.Localization; -import org.jabref.model.database.BibDatabase; -import org.jabref.model.database.KeyCollisionException; -import org.jabref.model.entry.BibtexString; -import org.jabref.preferences.JabRefPreferences; - -class StringDialog extends JabRefDialog { - - private static final String STRINGS_TITLE = Localization.lang("Strings for library"); - // A reference to the entry this object works on. - private final BibDatabase base; - private final BasePanel panel; - private final StringTable table; - private final HelpAction helpAction; - - private final SaveDatabaseAction saveAction = new SaveDatabaseAction(this); - - // The action concerned with closing the window. - private final CloseAction closeAction = new CloseAction(); - private List strings; - - - public StringDialog(JabRefFrame frame, BasePanel panel, BibDatabase base) { - super(StringDialog.class); - this.panel = panel; - this.base = base; - - sortStrings(); - - helpAction = new HelpAction(Localization.lang("Help"), HelpFile.STRING_EDITOR); - - addWindowListener(new WindowAdapter() { - - @Override - public void windowClosing(WindowEvent e) { - closeAction.actionPerformed(null); - } - }); - - // We replace the default FocusTraversalPolicy with a subclass - // that only allows the StringTable to gain keyboard focus. - setFocusTraversalPolicy(new LayoutFocusTraversalPolicy() { - - @Override - protected boolean accept(Component c) { - return super.accept(c) && (c instanceof StringTable); - } - }); - - JPanel pan = new JPanel(); - GridBagLayout gbl = new GridBagLayout(); - pan.setLayout(gbl); - GridBagConstraints con = new GridBagConstraints(); - con.fill = GridBagConstraints.BOTH; - con.weighty = 1; - con.weightx = 1; - - StringTableModel stm = new StringTableModel(this, base); - table = new StringTable(stm); - if (!base.hasNoStrings()) { - table.setRowSelectionInterval(0, 0); - } - - gbl.setConstraints(table.getPane(), con); - pan.add(table.getPane()); - - JToolBar tlb = new OSXCompatibleToolbar(); - InputMap im = tlb.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); - ActionMap am = tlb.getActionMap(); - im.put(Globals.getKeyPrefs().getKey(KeyBinding.STRING_DIALOG_ADD_STRING), "add"); - NewStringAction newStringAction = new NewStringAction(this); - am.put("add", newStringAction); - im.put(Globals.getKeyPrefs().getKey(KeyBinding.STRING_DIALOG_REMOVE_STRING), "remove"); - RemoveStringAction removeStringAction = new RemoveStringAction(this); - am.put("remove", removeStringAction); - im.put(Globals.getKeyPrefs().getKey(KeyBinding.SAVE_DATABASE), "save"); - am.put("save", saveAction); - im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE), "close"); - am.put("close", closeAction); - im.put(Globals.getKeyPrefs().getKey(KeyBinding.HELP), "help"); - am.put("help", helpAction); - im.put(Globals.getKeyPrefs().getKey(KeyBinding.UNDO), "undo"); - UndoAction undoAction = new UndoAction(); - am.put("undo", undoAction); - im.put(Globals.getKeyPrefs().getKey(KeyBinding.REDO), "redo"); - RedoAction redoAction = new RedoAction(); - am.put("redo", redoAction); - - tlb.add(newStringAction); - tlb.add(removeStringAction); - tlb.addSeparator(); - tlb.add(helpAction); - Container conPane = getContentPane(); - conPane.add(tlb, BorderLayout.NORTH); - conPane.add(pan, BorderLayout.CENTER); - - setTitle(STRINGS_TITLE + ": " - + panel.getBibDatabaseContext().getDatabaseFile().map(File::getName).orElse(GUIGlobals.UNTITLED_TITLE)); - WindowLocation pw = new WindowLocation(this, JabRefPreferences.STRINGS_POS_X, JabRefPreferences.STRINGS_POS_Y, - JabRefPreferences.STRINGS_SIZE_X, JabRefPreferences.STRINGS_SIZE_Y); - pw.displayWindowAtStoredLocation(); - } - - private static boolean isNumber(String name) { - // A pure integer number cannot be used as a string label, - // since Bibtex will read it as a number. - try { - Integer.parseInt(name); - return true; - } catch (NumberFormatException ex) { - return false; - } - } - - private void sortStrings() { - // Rebuild our sorted set of strings: - strings = new ArrayList<>(); - for (String s : base.getStringKeySet()) { - strings.add(base.getString(s)); - } - Collections.sort(strings, new BibtexStringComparator(false)); - } - - public void refreshTable() { - sortStrings(); - table.revalidate(); - table.clearSelection(); - table.repaint(); - } - - public void saveDatabase() { - panel.runCommand(Actions.SAVE); - } - - public void assureNotEditing() { - if (table.isEditing()) { - int col = table.getEditingColumn(); - int row = table.getEditingRow(); - table.getCellEditor(row, col).stopCellEditing(); - } - } - - static class SaveDatabaseAction extends AbstractAction { - - private final StringDialog parent; - - - public SaveDatabaseAction(StringDialog parent) { - super("Save library", IconTheme.JabRefIcons.SAVE.getIcon()); - putValue(Action.SHORT_DESCRIPTION, Localization.lang("Save library")); - this.parent = parent; - } - - @Override - public void actionPerformed(ActionEvent e) { - parent.saveDatabase(); - } - } - - class StringTable extends JTable { - - private final JScrollPane sp = new JScrollPane(this); - - - public StringTable(StringTableModel stm) { - super(stm); - setShowVerticalLines(true); - setShowHorizontalLines(true); - setColumnSelectionAllowed(true); - DefaultCellEditor dce = new DefaultCellEditor(new JTextField()); - dce.setClickCountToStart(2); - setDefaultEditor(String.class, dce); - TableColumnModel cm = getColumnModel(); - cm.getColumn(0).setPreferredWidth(800); - cm.getColumn(1).setPreferredWidth(2000); - getInputMap().put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE), "close"); - getActionMap().put("close", closeAction); - getInputMap().put(Globals.getKeyPrefs().getKey(KeyBinding.HELP), "help"); - getActionMap().put("help", helpAction); - } - - public JComponent getPane() { - return sp; - } - - } - - class StringTableModel extends AbstractTableModel { - - private final BibDatabase tbase; - private final StringDialog parent; - - - public StringTableModel(StringDialog parent, BibDatabase base) { - this.parent = parent; - this.tbase = base; - } - - @Override - public Object getValueAt(int row, int col) { - return col == 0 ? strings.get(row).getName() : strings.get(row).getContent(); - } - - @Override - public void setValueAt(Object value, int row, int col) { - if (col == 0) { - // Change name of string. - if (!value.equals(strings.get(row).getName())) { - if (tbase.hasStringLabel((String) value)) { - JOptionPane.showMessageDialog(parent, Localization.lang("A string with that label already exists"), - Localization.lang("Label"), JOptionPane.ERROR_MESSAGE); - } else if (((String) value).contains(" ")) { - JOptionPane.showMessageDialog(parent, Localization.lang("The label of the string cannot contain spaces."), - Localization.lang("Label"), JOptionPane.ERROR_MESSAGE); - } else if (((String) value).contains("#")) { - JOptionPane.showMessageDialog(parent, Localization.lang("The label of the string cannot contain the '#' character."), - Localization.lang("Label"), JOptionPane.ERROR_MESSAGE); - } else if (isNumber((String) value)) { - JOptionPane.showMessageDialog(parent, Localization.lang("The label of the string cannot be a number."), - Localization.lang("Label"), JOptionPane.ERROR_MESSAGE); - } else { - // Store undo information. - BibtexString subject = strings.get(row); - panel.getUndoManager().addEdit( - new UndoableStringChange(panel, subject, true, subject.getName(), (String) value)); - subject.setName((String) value); - panel.markBaseChanged(); - refreshTable(); - } - } - } else { - // Change content of string. - BibtexString subject = strings.get(row); - - if (!value.equals(subject.getContent())) { - try { - new LatexFieldFormatter(Globals.prefs.getLatexFieldFormatterPreferences()) - .format((String) value, "__dummy"); - } catch (InvalidFieldValueException ex) { - return; - } - // Store undo information. - panel.getUndoManager().addEdit( - new UndoableStringChange(panel, subject, false, subject.getContent(), (String) value)); - - subject.setContent((String) value); - panel.markBaseChanged(); - } - } - } - - @Override - public int getColumnCount() { - return 2; - } - - @Override - public int getRowCount() { - return strings.size(); - } - - @Override - public String getColumnName(int col) { - return col == 0 ? Localization.lang("Label") : - Localization.lang("Content"); - } - - @Override - public boolean isCellEditable(int row, int col) { - return true; - } - } - - class CloseAction extends AbstractAction { - - public CloseAction() { - super("Close window"); - putValue(Action.SHORT_DESCRIPTION, Localization.lang("Close dialog")); - } - - @Override - public void actionPerformed(ActionEvent e) { - panel.stringsClosing(); - dispose(); - } - } - - class NewStringAction extends AbstractAction { - - private final StringDialog parent; - - - public NewStringAction(StringDialog parent) { - super("New string", IconTheme.JabRefIcons.ADD.getIcon()); - putValue(Action.SHORT_DESCRIPTION, Localization.lang("New string")); - this.parent = parent; - } - - @Override - public void actionPerformed(ActionEvent e) { - String name = JOptionPane.showInputDialog(parent, Localization.lang("Please enter the string's label")); - if (name == null) { - return; - } - if (isNumber(name)) { - JOptionPane.showMessageDialog(parent, Localization.lang("The label of the string cannot be a number."), - Localization.lang("Label"), JOptionPane.ERROR_MESSAGE); - return; - } - if (name.contains("#")) { - JOptionPane.showMessageDialog(parent, Localization.lang("The label of the string cannot contain the '#' character."), - Localization.lang("Label"), JOptionPane.ERROR_MESSAGE); - return; - } - if (name.contains(" ")) { - JOptionPane.showMessageDialog(parent, Localization.lang("The label of the string cannot contain spaces."), - Localization.lang("Label"), JOptionPane.ERROR_MESSAGE); - return; - } - try { - BibtexString bs = new BibtexString(name, ""); - - // Store undo information: - panel.getUndoManager().addEdit(new UndoableInsertString(panel, panel.getDatabase(), bs)); - - base.addString(bs); - refreshTable(); - panel.markBaseChanged(); - } catch (KeyCollisionException ex) { - JOptionPane.showMessageDialog(parent, - Localization.lang("A string with that label already exists"), - Localization.lang("Label"), JOptionPane.ERROR_MESSAGE); - } - } - } - - class RemoveStringAction extends AbstractAction { - - private final StringDialog parent; - - - public RemoveStringAction(StringDialog parent) { - super("Remove selected strings", IconTheme.JabRefIcons.REMOVE.getIcon()); - putValue(Action.SHORT_DESCRIPTION, Localization.lang("Remove selected strings")); - this.parent = parent; - } - - @Override - public void actionPerformed(ActionEvent e) { - int[] sel = table.getSelectedRows(); - if (sel.length > 0) { - - // Make sure no cell is being edited, as caused by the - // keystroke. This makes the content hang on the screen. - assureNotEditing(); - - String msg = (sel.length > 1 ? Localization.lang("Really delete the %0 selected entries?", - Integer.toString(sel.length)) : Localization.lang("Really delete the selected entry?")); - int answer = JOptionPane.showConfirmDialog(parent, msg, Localization.lang("Delete strings"), - JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); - if (answer == JOptionPane.YES_OPTION) { - CompoundEdit ce = new CompoundEdit(); - for (int i = sel.length - 1; i >= 0; i--) { - // Delete the strings backwards to avoid moving indexes. - - BibtexString subject = strings.get(sel[i]); - - // Store undo information: - ce.addEdit(new UndoableRemoveString(panel, base, subject)); - - base.removeString(subject.getId()); - } - ce.end(); - panel.getUndoManager().addEdit(ce); - - refreshTable(); - if (!base.hasNoStrings()) { - table.setRowSelectionInterval(0, 0); - } - } - } - } - } - - class UndoAction extends AbstractAction { - - public UndoAction() { - super("Undo", IconTheme.JabRefIcons.UNDO.getIcon()); - putValue(Action.SHORT_DESCRIPTION, Localization.lang("Undo")); - } - - @Override - public void actionPerformed(ActionEvent e) { - panel.runCommand(Actions.UNDO); - } - } - - class RedoAction extends AbstractAction { - - public RedoAction() { - super("Redo", IconTheme.JabRefIcons.REDO.getIcon()); - putValue(Action.SHORT_DESCRIPTION, Localization.lang("Redo")); - } - - @Override - public void actionPerformed(ActionEvent e) { - panel.runCommand(Actions.REDO); - } - } -} diff --git a/src/main/java/org/jabref/gui/collab/StringAddChangeViewModel.java b/src/main/java/org/jabref/gui/collab/StringAddChangeViewModel.java index 20bf1099ef6..dafb80b125f 100644 --- a/src/main/java/org/jabref/gui/collab/StringAddChangeViewModel.java +++ b/src/main/java/org/jabref/gui/collab/StringAddChangeViewModel.java @@ -43,7 +43,7 @@ public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound try { panel.getDatabase().addString(string); - undoEdit.addEdit(new UndoableInsertString(panel, panel.getDatabase(), string)); + undoEdit.addEdit(new UndoableInsertString(panel.getDatabase(), string)); } catch (KeyCollisionException ex) { LOGGER.info("Error: could not add string '" + string.getName() + "': " + ex.getMessage(), ex); } diff --git a/src/main/java/org/jabref/gui/collab/StringChangeViewModel.java b/src/main/java/org/jabref/gui/collab/StringChangeViewModel.java index 19e68f3a0b9..d44ac099658 100644 --- a/src/main/java/org/jabref/gui/collab/StringChangeViewModel.java +++ b/src/main/java/org/jabref/gui/collab/StringChangeViewModel.java @@ -59,14 +59,14 @@ public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound BibtexString bs = new BibtexString(label, disk); try { panel.getDatabase().addString(bs); - undoEdit.addEdit(new UndoableInsertString(panel, panel.getDatabase(), bs)); + undoEdit.addEdit(new UndoableInsertString(panel.getDatabase(), bs)); } catch (KeyCollisionException ex) { LOGGER.info("Error: could not add string '" + bs.getName() + "': " + ex.getMessage(), ex); } } else { String mem = string.getContent(); string.setContent(disk); - undoEdit.addEdit(new UndoableStringChange(panel, string, false, mem, disk)); + undoEdit.addEdit(new UndoableStringChange(string, false, mem, disk)); } // Update tmp database: diff --git a/src/main/java/org/jabref/gui/collab/StringNameChangeViewModel.java b/src/main/java/org/jabref/gui/collab/StringNameChangeViewModel.java index e9bda7c9f40..b9cd5bb80fe 100644 --- a/src/main/java/org/jabref/gui/collab/StringNameChangeViewModel.java +++ b/src/main/java/org/jabref/gui/collab/StringNameChangeViewModel.java @@ -50,13 +50,13 @@ public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound BibtexString bs = new BibtexString(disk, content); try { panel.getDatabase().addString(bs); - undoEdit.addEdit(new UndoableInsertString(panel, panel.getDatabase(), bs)); + undoEdit.addEdit(new UndoableInsertString(panel.getDatabase(), bs)); } catch (KeyCollisionException ex) { LOGGER.info("Error: could not add string '" + bs.getName() + "': " + ex.getMessage(), ex); } } else { string.setName(disk); - undoEdit.addEdit(new UndoableStringChange(panel, string, true, mem, disk)); + undoEdit.addEdit(new UndoableStringChange(string, true, mem, disk)); } // Update tmp database: diff --git a/src/main/java/org/jabref/gui/collab/StringRemoveChangeViewModel.java b/src/main/java/org/jabref/gui/collab/StringRemoveChangeViewModel.java index 4501888a240..eaf66d47304 100644 --- a/src/main/java/org/jabref/gui/collab/StringRemoveChangeViewModel.java +++ b/src/main/java/org/jabref/gui/collab/StringRemoveChangeViewModel.java @@ -36,7 +36,7 @@ public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound try { panel.getDatabase().removeString(inMem.getId()); - undoEdit.addEdit(new UndoableRemoveString(panel, panel.getDatabase(), string)); + undoEdit.addEdit(new UndoableRemoveString(panel.getDatabase(), string)); } catch (Exception ex) { LOGGER.info("Error: could not add string '" + string.getName() + "': " + ex.getMessage(), ex); } diff --git a/src/main/java/org/jabref/gui/importer/actions/AppendDatabaseAction.java b/src/main/java/org/jabref/gui/importer/actions/AppendDatabaseAction.java index fbb5d71222e..5231d0edede 100644 --- a/src/main/java/org/jabref/gui/importer/actions/AppendDatabaseAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/AppendDatabaseAction.java @@ -45,14 +45,12 @@ public class AppendDatabaseAction implements BaseAction { private static final Logger LOGGER = LoggerFactory.getLogger(AppendDatabaseAction.class); - private final JabRefFrame frame; private final BasePanel panel; private final List filesToOpen = new ArrayList<>(); private final DialogService dialogService; public AppendDatabaseAction(JabRefFrame frame, BasePanel panel) { - this.frame = frame; this.panel = panel; dialogService = frame.getDialogService(); } @@ -87,7 +85,7 @@ private static void mergeFromBibtex(BasePanel panel, ParserResult parserResult, for (BibtexString bs : fromDatabase.getStringValues()) { if (!database.hasStringLabel(bs.getName())) { database.addString(bs); - ce.addEdit(new UndoableInsertString(panel, database, bs)); + ce.addEdit(new UndoableInsertString(database, bs)); } } } diff --git a/src/main/java/org/jabref/gui/metadata/BibtexStringEditorAction.java b/src/main/java/org/jabref/gui/metadata/BibtexStringEditorAction.java new file mode 100644 index 00000000000..7e37e175319 --- /dev/null +++ b/src/main/java/org/jabref/gui/metadata/BibtexStringEditorAction.java @@ -0,0 +1,20 @@ +package org.jabref.gui.metadata; + +import org.jabref.gui.JabRefFrame; +import org.jabref.gui.actions.SimpleCommand; +import org.jabref.model.database.BibDatabase; + +public class BibtexStringEditorAction extends SimpleCommand { + + private final JabRefFrame frame; + + public BibtexStringEditorAction(JabRefFrame jabRefFrame) { + this.frame = jabRefFrame; + } + + @Override + public void execute() { + BibDatabase database = frame.getCurrentBasePanel().getDatabase(); + new BibtexStringEditorDialogView(database).showAndWait(); + } +} diff --git a/src/main/java/org/jabref/gui/metadata/BibtexStringEditorDialog.fxml b/src/main/java/org/jabref/gui/metadata/BibtexStringEditorDialog.fxml new file mode 100644 index 00000000000..a9ceca60cd6 --- /dev/null +++ b/src/main/java/org/jabref/gui/metadata/BibtexStringEditorDialog.fxml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +