Skip to content

Commit

Permalink
Implemented #1682
Browse files Browse the repository at this point in the history
  • Loading branch information
oscargus committed Aug 6, 2016
1 parent 381b569 commit 5461b75
Show file tree
Hide file tree
Showing 19 changed files with 90 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
58 changes: 57 additions & 1 deletion src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -638,7 +642,8 @@ private void pushEntries(boolean inParenthesisIn, boolean withText, boolean addP
if (panel != null) {
final BibDatabase database = panel.getDatabase();
List<BibEntry> entries = panel.getSelectedEntries();
if (!entries.isEmpty()) {
if (!entries.isEmpty() && checkThatEntriesHaveKeys(entries)) {

try {
if (style == null) {
style = loader.getUsedStyle();
Expand Down Expand Up @@ -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<BibEntry> 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. "
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_da.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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?=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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?=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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?
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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?=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_fa.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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?=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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?=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_in.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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?=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_it.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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?=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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?=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_nl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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?=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_no.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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?=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_pt_BR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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?=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_ru.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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?=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_sv.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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?
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_tr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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?=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_vi.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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?=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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?=

0 comments on commit 5461b75

Please sign in to comment.