From 5461b75154fa6a64bcb3131f1757836d33349295 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Fri, 5 Aug 2016 15:36:52 +0200 Subject: [PATCH] Implemented #1682 --- CHANGELOG.md | 1 + .../gui/openoffice/OpenOfficePanel.java | 58 ++++++++++++++++++- src/main/resources/l10n/JabRef_da.properties | 2 + src/main/resources/l10n/JabRef_de.properties | 2 + src/main/resources/l10n/JabRef_en.properties | 1 + src/main/resources/l10n/JabRef_es.properties | 2 + src/main/resources/l10n/JabRef_fa.properties | 2 + src/main/resources/l10n/JabRef_fr.properties | 1 + src/main/resources/l10n/JabRef_in.properties | 2 + src/main/resources/l10n/JabRef_it.properties | 2 + src/main/resources/l10n/JabRef_ja.properties | 2 + src/main/resources/l10n/JabRef_nl.properties | 2 + src/main/resources/l10n/JabRef_no.properties | 2 + .../resources/l10n/JabRef_pt_BR.properties | 2 + src/main/resources/l10n/JabRef_ru.properties | 2 + src/main/resources/l10n/JabRef_sv.properties | 2 + src/main/resources/l10n/JabRef_tr.properties | 2 + src/main/resources/l10n/JabRef_vi.properties | 2 + src/main/resources/l10n/JabRef_zh.properties | 2 + 19 files changed, 90 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c36251cc8f8..b28c456d89d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - Fixed [#1643](https://github.com/JabRef/jabref/issues/1643): Searching with double quotes in a specific field ignores the last character - Fixed [#1288](https://github.com/JabRef/jabref/issues/1288): Newly opened bib-file is not focused - Fixed [#1669](https://github.com/JabRef/jabref/issues/1669): Dialog for manual connection to OpenOffice/LibreOffice works again on Linux +- Fixed [#16682](https://github.com/JabRef/jabref/issues/1682): An entry now must have a BibTeX key to be cited in OpenOffice/LibreOffice ### Removed diff --git a/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java b/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java index 4fd6a89fc806..9b4aeab180c2 100644 --- a/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java @@ -57,9 +57,13 @@ import net.sf.jabref.gui.actions.BrowseAction; import net.sf.jabref.gui.help.HelpAction; import net.sf.jabref.gui.keyboard.KeyBinding; +import net.sf.jabref.gui.undo.NamedCompound; +import net.sf.jabref.gui.undo.UndoableKeyChange; import net.sf.jabref.gui.worker.AbstractWorker; import net.sf.jabref.logic.help.HelpFile; import net.sf.jabref.logic.l10n.Localization; +import net.sf.jabref.logic.labelpattern.LabelPatternPreferences; +import net.sf.jabref.logic.labelpattern.LabelPatternUtil; import net.sf.jabref.logic.layout.LayoutFormatterPreferences; import net.sf.jabref.logic.openoffice.OOBibStyle; import net.sf.jabref.logic.openoffice.OpenOfficePreferences; @@ -638,7 +642,8 @@ private void pushEntries(boolean inParenthesisIn, boolean withText, boolean addP if (panel != null) { final BibDatabase database = panel.getDatabase(); List entries = panel.getSelectedEntries(); - if (!entries.isEmpty()) { + if (!entries.isEmpty() && checkThatEntriesHaveKeys(entries)) { + try { if (style == null) { style = loader.getUsedStyle(); @@ -669,6 +674,57 @@ private void pushEntries(boolean inParenthesisIn, boolean withText, boolean addP } + /** + * Check that all entries in the list have BibTeX keys, if not ask if they should be generated + * + * @param entries A list of entries to be checked + * @return true if all entries have BibTeX keys, if it so may be after generating them + */ + private boolean checkThatEntriesHaveKeys(List entries) { + // Check if there are empty keys + boolean emptyKeys = false; + for (BibEntry entry : entries) { + if (entry.getCiteKey() == null) { + // Found one, no need to look further for now + emptyKeys = true; + break; + } + } + + // If no empty keys, return true + if (!emptyKeys) { + return true; + } + + // Ask if keys should be generated + int answer = JOptionPane.showConfirmDialog(this.frame, + Localization.lang("Cannot cite entries without BibTeX keys. Generate keys now?"), + Localization.lang("Cite"), JOptionPane.YES_NO_OPTION); + BasePanel panel = frame.getCurrentBasePanel(); + if ((answer == JOptionPane.YES_OPTION) && (panel != null)) { + // Generate keys + LabelPatternPreferences prefs = LabelPatternPreferences.fromPreferences(Globals.prefs); + NamedCompound undoCompound = new NamedCompound(Localization.lang("Cite")); + for (BibEntry entry : entries) { + if (entry.getCiteKey() == null) { + // Generate key + LabelPatternUtil.makeLabel(panel.getBibDatabaseContext().getMetaData(), panel.getDatabase(), entry, + prefs); + // Add undo change + undoCompound.addEdit(new UndoableKeyChange(panel.getDatabase(), entry, null, entry.getCiteKey())); + } + } + undoCompound.end(); + // Add all undos + panel.getUndoManager().addEdit(undoCompound); + // Now every entry has a key + return true; + } else { + // No, we canceled (or there is no panel to get the database from, highly unlikely) + return false; + } + } + private void showConnectionLostErrorMessage() { JOptionPane.showMessageDialog(frame, Localization.lang("Connection to OpenOffice/LibreOffice has been lost. " diff --git a/src/main/resources/l10n/JabRef_da.properties b/src/main/resources/l10n/JabRef_da.properties index f27c94f1b7ac..afdb9d728392 100644 --- a/src/main/resources/l10n/JabRef_da.properties +++ b/src/main/resources/l10n/JabRef_da.properties @@ -1731,3 +1731,5 @@ Add_selected_text_to_list= Add_{}_around_selected_text= Format_field= New_protected_terms_file= + +Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?= diff --git a/src/main/resources/l10n/JabRef_de.properties b/src/main/resources/l10n/JabRef_de.properties index 0ba423d4265c..4785a146bb47 100644 --- a/src/main/resources/l10n/JabRef_de.properties +++ b/src/main/resources/l10n/JabRef_de.properties @@ -2447,3 +2447,5 @@ Add_selected_text_to_list= Add_{}_around_selected_text= Format_field= New_protected_terms_file= + +Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?= diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 9ed194431137..ad4e46974c4c 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2294,3 +2294,4 @@ Add_selected_text_to_list=Add_selected_text_to_list Add_{}_around_selected_text=Add_{}_around_selected_text Format_field=Format_field New_protected_terms_file=New_protected_terms_file +Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?=Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now? diff --git a/src/main/resources/l10n/JabRef_es.properties b/src/main/resources/l10n/JabRef_es.properties index 91182e50b6b2..a29fc102365a 100644 --- a/src/main/resources/l10n/JabRef_es.properties +++ b/src/main/resources/l10n/JabRef_es.properties @@ -1635,3 +1635,5 @@ Add_selected_text_to_list= Add_{}_around_selected_text= Format_field= New_protected_terms_file= + +Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?= diff --git a/src/main/resources/l10n/JabRef_fa.properties b/src/main/resources/l10n/JabRef_fa.properties index c28c9037aeb9..f544ca0bcb20 100644 --- a/src/main/resources/l10n/JabRef_fa.properties +++ b/src/main/resources/l10n/JabRef_fa.properties @@ -2415,3 +2415,5 @@ Add_selected_text_to_list= Add_{}_around_selected_text= Format_field= New_protected_terms_file= + +Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?= diff --git a/src/main/resources/l10n/JabRef_fr.properties b/src/main/resources/l10n/JabRef_fr.properties index 2ab2c419d736..1dbe475d7625 100644 --- a/src/main/resources/l10n/JabRef_fr.properties +++ b/src/main/resources/l10n/JabRef_fr.properties @@ -1676,3 +1676,4 @@ Add_selected_text_to_list= Add_{}_around_selected_text= Format_field= New_protected_terms_file= +Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?= diff --git a/src/main/resources/l10n/JabRef_in.properties b/src/main/resources/l10n/JabRef_in.properties index c705f114ca3d..06ed01d59cfb 100644 --- a/src/main/resources/l10n/JabRef_in.properties +++ b/src/main/resources/l10n/JabRef_in.properties @@ -1653,3 +1653,5 @@ Add_selected_text_to_list= Add_{}_around_selected_text= Format_field= New_protected_terms_file= + +Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?= diff --git a/src/main/resources/l10n/JabRef_it.properties b/src/main/resources/l10n/JabRef_it.properties index 11f041220ce3..18a5f1d6d278 100644 --- a/src/main/resources/l10n/JabRef_it.properties +++ b/src/main/resources/l10n/JabRef_it.properties @@ -1752,3 +1752,5 @@ Add_selected_text_to_list= Add_{}_around_selected_text= Format_field= New_protected_terms_file= + +Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?= diff --git a/src/main/resources/l10n/JabRef_ja.properties b/src/main/resources/l10n/JabRef_ja.properties index 712036efbe82..02db04ac1c20 100644 --- a/src/main/resources/l10n/JabRef_ja.properties +++ b/src/main/resources/l10n/JabRef_ja.properties @@ -2393,3 +2393,5 @@ Add_selected_text_to_list= Add_{}_around_selected_text= Format_field= New_protected_terms_file= + +Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?= diff --git a/src/main/resources/l10n/JabRef_nl.properties b/src/main/resources/l10n/JabRef_nl.properties index 5a9a7f66d714..053b32fc0ef0 100644 --- a/src/main/resources/l10n/JabRef_nl.properties +++ b/src/main/resources/l10n/JabRef_nl.properties @@ -2427,3 +2427,5 @@ Add_selected_text_to_list= Add_{}_around_selected_text= Format_field= New_protected_terms_file= + +Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?= diff --git a/src/main/resources/l10n/JabRef_no.properties b/src/main/resources/l10n/JabRef_no.properties index 0365fca64597..acbcd64ddd1c 100644 --- a/src/main/resources/l10n/JabRef_no.properties +++ b/src/main/resources/l10n/JabRef_no.properties @@ -2820,3 +2820,5 @@ Add_selected_text_to_list= Add_{}_around_selected_text= Format_field= New_protected_terms_file= + +Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?= diff --git a/src/main/resources/l10n/JabRef_pt_BR.properties b/src/main/resources/l10n/JabRef_pt_BR.properties index 9b2c26300dec..c0608ee56525 100644 --- a/src/main/resources/l10n/JabRef_pt_BR.properties +++ b/src/main/resources/l10n/JabRef_pt_BR.properties @@ -1648,3 +1648,5 @@ Add_selected_text_to_list= Add_{}_around_selected_text= Format_field= New_protected_terms_file= + +Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?= diff --git a/src/main/resources/l10n/JabRef_ru.properties b/src/main/resources/l10n/JabRef_ru.properties index 2315321095a2..05f3257848cb 100644 --- a/src/main/resources/l10n/JabRef_ru.properties +++ b/src/main/resources/l10n/JabRef_ru.properties @@ -2394,3 +2394,5 @@ Add_selected_text_to_list= Add_{}_around_selected_text= Format_field= New_protected_terms_file= + +Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?= diff --git a/src/main/resources/l10n/JabRef_sv.properties b/src/main/resources/l10n/JabRef_sv.properties index 3ee425bb4722..f21d721a705f 100644 --- a/src/main/resources/l10n/JabRef_sv.properties +++ b/src/main/resources/l10n/JabRef_sv.properties @@ -1592,3 +1592,5 @@ Add_selected_text_to_list=Lägg_till_markerad_text_till_lista Add_{}_around_selected_text=Lägg_till_{}_runt_markerad_text Format_field=Formattera_fält New_protected_terms_file=Ny_lista_med_skyddade_ord + +Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?=Kan_inte_citera_poster_utan_BibTeX-nycklar._Generera_nycklar_nu? diff --git a/src/main/resources/l10n/JabRef_tr.properties b/src/main/resources/l10n/JabRef_tr.properties index 5d97eb22d2b4..0604bb54b474 100644 --- a/src/main/resources/l10n/JabRef_tr.properties +++ b/src/main/resources/l10n/JabRef_tr.properties @@ -1666,3 +1666,5 @@ Add_selected_text_to_list= Add_{}_around_selected_text= Format_field= New_protected_terms_file= + +Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?= diff --git a/src/main/resources/l10n/JabRef_vi.properties b/src/main/resources/l10n/JabRef_vi.properties index 6306f6a05d32..2f4aaaaebf3a 100644 --- a/src/main/resources/l10n/JabRef_vi.properties +++ b/src/main/resources/l10n/JabRef_vi.properties @@ -2419,3 +2419,5 @@ Add_selected_text_to_list= Add_{}_around_selected_text= Format_field= New_protected_terms_file= + +Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?= diff --git a/src/main/resources/l10n/JabRef_zh.properties b/src/main/resources/l10n/JabRef_zh.properties index 3cab938af4f4..f6bb68cec45a 100644 --- a/src/main/resources/l10n/JabRef_zh.properties +++ b/src/main/resources/l10n/JabRef_zh.properties @@ -1661,3 +1661,5 @@ Add_selected_text_to_list= Add_{}_around_selected_text= Format_field= New_protected_terms_file= + +Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?=